2001-07-16 06:53:11 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Redmond KWin client
|
|
|
|
*
|
|
|
|
* Copyright 2001
|
|
|
|
* Karol Szwed <gallium@kde.org>
|
|
|
|
* http://gallium.n3.net/
|
|
|
|
*
|
|
|
|
* Based on the default KWin client.
|
|
|
|
*
|
|
|
|
* Updated to support toolwindows 3/2001 (KS)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
#include "redmond.h"
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2001-07-16 06:53:11 +00:00
|
|
|
#include <qdrawutil.h>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QDateTime>
|
2005-07-28 14:59:42 +00:00
|
|
|
//Added by qt3to4:
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPaintEvent>
|
2001-07-16 06:53:11 +00:00
|
|
|
#include <kpixmapeffect.h>
|
2002-07-04 02:43:54 +00:00
|
|
|
#include <kimageeffect.h>
|
2001-07-16 06:53:11 +00:00
|
|
|
#include <kdrawutil.h>
|
|
|
|
#include <klocale.h>
|
2006-05-08 08:14:01 +00:00
|
|
|
#include <QPixmap>
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QBitmap>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QApplication>
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2002-08-27 18:08:20 +00:00
|
|
|
namespace Redmond {
|
2001-07-16 06:53:11 +00:00
|
|
|
|
|
|
|
static const char *kdelogo[] = {
|
|
|
|
/* columns rows colors chars-per-pixel */
|
|
|
|
"16 16 8 1",
|
|
|
|
" c None",
|
|
|
|
". c #000000",
|
|
|
|
"+ c #A0A0A4",
|
|
|
|
"@ c #FFFFFF",
|
|
|
|
"# c #585858",
|
|
|
|
"$ c #C0C0C0",
|
|
|
|
"% c #808080",
|
|
|
|
"& c #DCDCDC",
|
|
|
|
" ",
|
|
|
|
" .. .. ",
|
|
|
|
" .+@. .@#. ",
|
|
|
|
" .@@@. .@@@# ",
|
|
|
|
" .@@@..$@@$. ",
|
|
|
|
" .@@@.@@@$. ",
|
|
|
|
" .@@@%@@$. ",
|
|
|
|
" .@@@&@@. ",
|
|
|
|
" .@@@@@@. ",
|
|
|
|
" .@@@$@@&. ",
|
|
|
|
" .@@@.@@@. ",
|
|
|
|
" .@@@.+@@@. ",
|
|
|
|
" .@@@..$@@&. ",
|
|
|
|
" .@@%. .@@@. ",
|
|
|
|
" .... ... ",
|
|
|
|
" "};
|
|
|
|
|
|
|
|
static unsigned char iconify_bits[] = {
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00};
|
|
|
|
|
|
|
|
static unsigned char close_bits[] = {
|
|
|
|
0x00, 0x00, 0x86, 0x01, 0xcc, 0x00, 0x78, 0x00, 0x30, 0x00, 0x78, 0x00,
|
|
|
|
0xcc, 0x00, 0x86, 0x01, 0x00, 0x00, 0x00, 0x00};
|
|
|
|
|
|
|
|
static unsigned char maximize_bits[] = {
|
|
|
|
0xff, 0x01, 0xff, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
|
|
0x01, 0x01, 0x01, 0x01, 0xff, 0x01, 0x00, 0x00};
|
|
|
|
|
|
|
|
static unsigned char minmax_bits[] = {
|
|
|
|
0xfc, 0x00, 0xfc, 0x00, 0x84, 0x00, 0xbf, 0x00, 0xbf, 0x00, 0xe1, 0x00,
|
|
|
|
0x21, 0x00, 0x21, 0x00, 0x3f, 0x00, 0x00, 0x00};
|
|
|
|
|
|
|
|
static unsigned char question_bits[] = {
|
|
|
|
0x00, 0x00, 0x3c, 0x00, 0x66, 0x00, 0x60, 0x00, 0x30, 0x00, 0x18, 0x00,
|
|
|
|
0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00};
|
|
|
|
|
|
|
|
|
|
|
|
// Up / Down titlebar button images
|
2006-05-08 08:14:01 +00:00
|
|
|
static QPixmap *btnPix1;
|
|
|
|
static QPixmap *iBtnPix1;
|
|
|
|
static QPixmap *btnDownPix1;
|
|
|
|
static QPixmap *iBtnDownPix1;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2006-05-08 08:14:01 +00:00
|
|
|
static QPixmap *miniBtnPix1;
|
|
|
|
static QPixmap *iMiniBtnPix1;
|
|
|
|
static QPixmap *miniBtnDownPix1;
|
|
|
|
static QPixmap *iMiniBtnDownPix1;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2006-05-08 08:14:01 +00:00
|
|
|
static QPixmap *defaultMenuPix;
|
2001-07-16 06:53:11 +00:00
|
|
|
static QColor *btnForeground;
|
|
|
|
static bool pixmaps_created = false;
|
|
|
|
|
2003-09-26 12:06:58 +00:00
|
|
|
static int toolTitleHeight;
|
|
|
|
static int normalTitleHeight;
|
|
|
|
static int borderWidth;
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
static inline const KDecorationOptions *options()
|
|
|
|
{
|
|
|
|
return KDecoration::options();
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
static void drawButtonFrame( QPixmap *pix, const QPalette &g, bool sunken )
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
|
|
|
QPainter p;
|
|
|
|
int x2 = pix->width() - 1;
|
|
|
|
int y2 = pix->height() - 1;
|
|
|
|
p.begin(pix);
|
|
|
|
|
|
|
|
// titlebar button frame
|
2006-04-30 09:16:13 +00:00
|
|
|
p.setPen( sunken ? g.color(QPalette::Dark).dark(155) : g.color(QPalette::Light));
|
2001-07-16 06:53:11 +00:00
|
|
|
p.drawLine(0, 0, x2-1, 0);
|
|
|
|
p.drawLine(0, 0, 0, y2-1);
|
|
|
|
|
|
|
|
if (sunken)
|
|
|
|
{
|
2006-04-30 09:16:13 +00:00
|
|
|
p.setPen( g.color(QPalette::Mid).dark(135) );
|
2001-07-16 06:53:11 +00:00
|
|
|
p.drawLine(1, 1, x2-2, 1);
|
|
|
|
p.drawLine(1, 1, 1, y2-2);
|
|
|
|
}
|
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
p.setPen( sunken ? g.color(QPalette::Light) : g.color(QPalette::Mid).dark(135));
|
2001-07-16 06:53:11 +00:00
|
|
|
p.drawLine(1, y2-1, x2-1, y2-1);
|
|
|
|
p.drawLine(x2-1, 1, x2-1, y2-1);
|
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
p.setPen( sunken ? g.color(QPalette::Light) : g.color(QPalette::Dark).dark(155));
|
2001-07-16 06:53:11 +00:00
|
|
|
p.drawLine(0, y2, x2, y2);
|
|
|
|
p.drawLine(x2, 0, x2, y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-26 12:06:58 +00:00
|
|
|
static void create_pixmaps ()
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2003-09-17 08:27:26 +00:00
|
|
|
if (pixmaps_created)
|
2001-07-16 06:53:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
pixmaps_created = true;
|
|
|
|
|
|
|
|
bool highcolor = QPixmap::defaultDepth() > 8;
|
|
|
|
|
2006-05-08 08:14:01 +00:00
|
|
|
btnPix1 = new QPixmap;
|
|
|
|
btnDownPix1 = new QPixmap;
|
|
|
|
iBtnPix1 = new QPixmap;
|
|
|
|
iBtnDownPix1 = new QPixmap;
|
|
|
|
miniBtnPix1 = new QPixmap;
|
|
|
|
miniBtnDownPix1 = new QPixmap;
|
|
|
|
iMiniBtnPix1 = new QPixmap;
|
|
|
|
iMiniBtnDownPix1 = new QPixmap;
|
|
|
|
defaultMenuPix = new QPixmap(kdelogo);
|
2001-07-16 06:53:11 +00:00
|
|
|
|
|
|
|
// buttons (active/inactive, sunken/unsunken)
|
2006-03-04 22:27:27 +00:00
|
|
|
QColorGroup g = options()->palette(KDecoration::ColorButtonBg, true).active();
|
2001-07-16 06:53:11 +00:00
|
|
|
QColor c = g.background();
|
2006-04-26 16:05:58 +00:00
|
|
|
*btnPix1 = QPixmap(normalTitleHeight, normalTitleHeight-2);
|
|
|
|
*btnDownPix1 = QPixmap(normalTitleHeight, normalTitleHeight-2);
|
|
|
|
*iBtnPix1 = QPixmap(normalTitleHeight, normalTitleHeight-2);
|
|
|
|
*iBtnDownPix1 = QPixmap(normalTitleHeight, normalTitleHeight-2);
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2006-04-26 16:05:58 +00:00
|
|
|
*miniBtnPix1 = QPixmap(toolTitleHeight, toolTitleHeight);
|
|
|
|
*miniBtnDownPix1 = QPixmap(toolTitleHeight, toolTitleHeight);
|
|
|
|
*iMiniBtnPix1 = QPixmap(toolTitleHeight, toolTitleHeight);
|
|
|
|
*iMiniBtnDownPix1 = QPixmap(toolTitleHeight, toolTitleHeight);
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
if (highcolor && false) {
|
2001-07-16 06:53:11 +00:00
|
|
|
KPixmapEffect::gradient(*btnPix1, c.light(130), c.dark(130),
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
KPixmapEffect::gradient(*btnDownPix1, c.dark(130), c.light(130),
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
|
|
|
|
KPixmapEffect::gradient(*miniBtnPix1, c.light(130), c.dark(130),
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
KPixmapEffect::gradient(*miniBtnDownPix1, c.dark(130), c.light(130),
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
g = options()->palette(KDecoration::ColorButtonBg, false);
|
|
|
|
g.setCurrentColorGroup( QPalette::Active );
|
2001-07-16 06:53:11 +00:00
|
|
|
c = g.background();
|
|
|
|
KPixmapEffect::gradient(*iBtnPix1, c.light(130), c.dark(130),
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
KPixmapEffect::gradient(*iBtnDownPix1, c.dark(130), c.light(130),
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
KPixmapEffect::gradient(*iMiniBtnPix1, c.light(130), c.dark(130),
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
KPixmapEffect::gradient(*iMiniBtnDownPix1, c.dark(130), c.light(130),
|
|
|
|
KPixmapEffect::VerticalGradient);
|
2003-09-17 08:27:26 +00:00
|
|
|
} else {
|
2001-07-16 06:53:11 +00:00
|
|
|
btnPix1->fill(c.rgb());
|
|
|
|
btnDownPix1->fill(c.rgb());
|
|
|
|
miniBtnPix1->fill(c.rgb());
|
|
|
|
miniBtnDownPix1->fill(c.rgb());
|
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
g = options()->palette(KDecoration::ColorButtonBg, false);
|
|
|
|
g.setCurrentColorGroup( QPalette::Active );
|
2001-07-16 06:53:11 +00:00
|
|
|
c = g.background();
|
|
|
|
iBtnPix1->fill(c.rgb());
|
|
|
|
iBtnDownPix1->fill(c.rgb());
|
|
|
|
iMiniBtnPix1->fill(c.rgb());
|
|
|
|
iMiniBtnDownPix1->fill(c.rgb());
|
|
|
|
}
|
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
g = options()->palette(KDecoration::ColorButtonBg, true);
|
|
|
|
g.setCurrentColorGroup( QPalette::Active );
|
2001-07-16 06:53:11 +00:00
|
|
|
drawButtonFrame(btnPix1, g, false);
|
|
|
|
drawButtonFrame(btnDownPix1, g, true);
|
|
|
|
drawButtonFrame(miniBtnPix1, g, false);
|
|
|
|
drawButtonFrame(miniBtnDownPix1, g, true);
|
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
g = options()->palette(KDecoration::ColorButtonBg, false);
|
|
|
|
g.setCurrentColorGroup( QPalette::Active );
|
2001-07-16 06:53:11 +00:00
|
|
|
drawButtonFrame(iBtnPix1, g, false);
|
|
|
|
drawButtonFrame(iBtnDownPix1, g, true);
|
|
|
|
drawButtonFrame(iMiniBtnPix1, g, false);
|
|
|
|
drawButtonFrame(iMiniBtnDownPix1, g, true);
|
|
|
|
|
|
|
|
// Make sure button pixmaps contrast with the current colour scheme.
|
2003-09-17 08:27:26 +00:00
|
|
|
if (qGray(options()->color(KDecoration::ColorButtonBg, true).rgb()) > 127)
|
2001-07-16 06:53:11 +00:00
|
|
|
btnForeground = new QColor(Qt::black);
|
|
|
|
else
|
|
|
|
btnForeground = new QColor(Qt::white);
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_pixmaps()
|
|
|
|
{
|
|
|
|
delete btnPix1;
|
|
|
|
delete btnDownPix1;
|
|
|
|
delete iBtnPix1;
|
|
|
|
delete iBtnDownPix1;
|
|
|
|
delete miniBtnPix1;
|
|
|
|
delete miniBtnDownPix1;
|
|
|
|
delete iMiniBtnPix1;
|
|
|
|
delete iMiniBtnDownPix1;
|
|
|
|
delete defaultMenuPix;
|
2003-11-02 11:03:41 +00:00
|
|
|
delete btnForeground;
|
2001-07-16 06:53:11 +00:00
|
|
|
pixmaps_created = false;
|
|
|
|
}
|
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
RedmondButton::RedmondButton(ButtonType type, RedmondDeco *parent, const char *name)
|
2006-03-04 22:27:27 +00:00
|
|
|
: KCommonDecorationButton(type, parent)
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2003-09-17 08:27:26 +00:00
|
|
|
// Eliminate background flicker
|
2006-04-30 09:16:13 +00:00
|
|
|
setAttribute(Qt::WA_NoSystemBackground, true);
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
miniBtn = decoration()->isToolWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RedmondButton::reset(unsigned long changed)
|
|
|
|
{
|
|
|
|
if (changed&DecorationReset || changed&ManualReset || changed&SizeChange || changed&StateChange) {
|
|
|
|
switch (type() ) {
|
|
|
|
case CloseButton:
|
|
|
|
setBitmap(close_bits);
|
|
|
|
break;
|
|
|
|
case HelpButton:
|
|
|
|
setBitmap(question_bits);
|
|
|
|
break;
|
|
|
|
case MinButton:
|
|
|
|
setBitmap(iconify_bits);
|
|
|
|
break;
|
|
|
|
case MaxButton:
|
2006-02-22 09:52:11 +00:00
|
|
|
setBitmap( isChecked() ? minmax_bits : maximize_bits );
|
2005-03-25 23:31:21 +00:00
|
|
|
break;
|
|
|
|
case MenuButton:
|
|
|
|
{
|
2005-07-28 14:59:42 +00:00
|
|
|
QPixmap miniIcon = decoration()->icon().pixmap(QIcon::Small, QIcon::Normal);
|
2005-03-25 23:31:21 +00:00
|
|
|
if (!miniIcon.isNull()) {
|
|
|
|
setPixmap(miniIcon);
|
|
|
|
} else {
|
|
|
|
setPixmap(*defaultMenuPix);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
setBitmap(0);
|
|
|
|
break;
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
this->update();
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
void RedmondButton::setBitmap(const unsigned char *bitmap)
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2006-04-26 16:05:58 +00:00
|
|
|
pix = QPixmap();
|
2005-03-25 23:31:21 +00:00
|
|
|
|
|
|
|
if (bitmap)
|
2006-07-19 06:49:37 +00:00
|
|
|
deco = QBitmap::fromData( QSize(10, 10), bitmap);
|
2005-03-25 23:31:21 +00:00
|
|
|
else {
|
|
|
|
deco = QBitmap(10,10);
|
|
|
|
deco.fill(Qt::color0);
|
|
|
|
}
|
2003-09-17 08:27:26 +00:00
|
|
|
deco.setMask(deco);
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
void RedmondButton::setPixmap( const QPixmap &p )
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2006-04-26 16:05:58 +00:00
|
|
|
deco = QPixmap();
|
2003-09-17 08:27:26 +00:00
|
|
|
pix = p;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2006-05-03 06:50:08 +00:00
|
|
|
repaint();
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
2005-08-17 09:15:59 +00:00
|
|
|
void RedmondButton::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QPainter p(this);
|
|
|
|
drawButton(&p);
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
void RedmondButton::drawButton(QPainter *p)
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2005-03-25 23:31:21 +00:00
|
|
|
if ( pix.isNull() ) {
|
|
|
|
if ( decoration()->isActive() ) {
|
|
|
|
if ( isDown() )
|
|
|
|
p->drawPixmap(0, 0, miniBtn ? *miniBtnDownPix1 : *btnDownPix1);
|
|
|
|
else
|
|
|
|
p->drawPixmap(0, 0, miniBtn ? *miniBtnPix1 : *btnPix1);
|
|
|
|
} else {
|
|
|
|
if ( isDown() )
|
|
|
|
p->drawPixmap(0, 0, miniBtn ? *iMiniBtnDownPix1 : *iBtnDownPix1);
|
|
|
|
else
|
|
|
|
p->drawPixmap(0, 0, miniBtn ? *iMiniBtnPix1 : *iBtnPix1);
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
p->setPen( *btnForeground );
|
|
|
|
int xOff = (width()-10)/2;
|
|
|
|
int yOff = (height()-10)/2;
|
|
|
|
p->drawPixmap(isDown() ? xOff+1: xOff, isDown() ? yOff+1 : yOff, deco);
|
|
|
|
} else {
|
|
|
|
if (isLeft() ) {
|
|
|
|
p->fillRect(0, 0, width(), height(),
|
|
|
|
options()->color(KDecoration::ColorTitleBar, decoration()->isActive()));
|
|
|
|
} else {
|
|
|
|
p->fillRect(0, 0, width(), height(),
|
|
|
|
options()->color(KDecoration::ColorTitleBlend, decoration()->isActive()));
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
if ( type()==MenuButton && height() < 16) {
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2006-04-26 16:05:58 +00:00
|
|
|
// Smooth scale the menu button pixmap
|
|
|
|
QPixmap tmpPix = QPixmap::fromImage(
|
|
|
|
pix.toImage().scaled( height(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ));
|
2005-03-25 23:31:21 +00:00
|
|
|
|
|
|
|
p->drawPixmap( 0, 0, tmpPix );
|
|
|
|
} else {
|
|
|
|
int xOff = (width() -pix.width() )/2;
|
|
|
|
int yOff = (height()-pix.height())/2;
|
|
|
|
p->drawPixmap(xOff, yOff, pix );
|
|
|
|
}
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
RedmondDeco::RedmondDeco(KDecorationBridge *b, KDecorationFactory *f)
|
2005-03-25 23:31:21 +00:00
|
|
|
: KCommonDecoration(b, f)
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2003-09-17 08:27:26 +00:00
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
QString RedmondDeco::visibleName() const
|
2003-09-17 08:27:26 +00:00
|
|
|
{
|
2005-03-25 23:31:21 +00:00
|
|
|
return i18n("Redmond");
|
|
|
|
}
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
QString RedmondDeco::defaultButtonsLeft() const
|
|
|
|
{
|
|
|
|
return "M";
|
|
|
|
}
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
QString RedmondDeco::defaultButtonsRight() const
|
|
|
|
{
|
|
|
|
return "HIA_X";
|
|
|
|
}
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
bool RedmondDeco::decorationBehaviour(DecorationBehaviour behaviour) const
|
|
|
|
{
|
|
|
|
switch (behaviour) {
|
|
|
|
case DB_MenuClose:
|
|
|
|
return true;
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case DB_WindowMask:
|
|
|
|
return false;
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case DB_ButtonHide:
|
|
|
|
return true;
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
default:
|
|
|
|
return KCommonDecoration::decorationBehaviour(behaviour);
|
|
|
|
}
|
|
|
|
}
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
int RedmondDeco::layoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
|
|
|
|
{
|
2005-05-26 11:18:36 +00:00
|
|
|
bool border = !(maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows());
|
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
switch (lm) {
|
|
|
|
case LM_BorderLeft:
|
|
|
|
case LM_BorderRight:
|
|
|
|
case LM_BorderBottom:
|
2005-05-26 11:18:36 +00:00
|
|
|
return border ? borderWidth : 0;
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case LM_TitleEdgeLeft:
|
|
|
|
case LM_TitleEdgeRight:
|
2005-05-26 11:18:36 +00:00
|
|
|
return border ? borderWidth+2 : 2;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case LM_TitleEdgeTop:
|
2005-05-26 11:18:36 +00:00
|
|
|
return border ? borderWidth+2 : 2;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case LM_TitleEdgeBottom:
|
2005-05-26 11:18:36 +00:00
|
|
|
return border ? 1 : 0;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case LM_TitleBorderLeft:
|
|
|
|
case LM_TitleBorderRight:
|
2005-05-26 11:18:36 +00:00
|
|
|
return border ? 1 : 0;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case LM_TitleHeight:
|
|
|
|
return titleHeight-2;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case LM_ButtonWidth:
|
|
|
|
return titleHeight-2;
|
|
|
|
case LM_ButtonHeight:
|
|
|
|
if (isToolWindow() || (btn && btn->type()==MenuButton) ) {
|
|
|
|
return titleHeight-2;
|
|
|
|
} else {
|
|
|
|
return titleHeight-2-2;
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case LM_ButtonSpacing:
|
|
|
|
return 0;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
case LM_ExplicitButtonSpacer:
|
|
|
|
return 2;
|
2003-09-17 08:27:26 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
default:
|
2005-03-26 13:18:32 +00:00
|
|
|
return KCommonDecoration::layoutMetric(lm, respectWindowState, btn);
|
2005-03-25 23:31:21 +00:00
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
KCommonDecorationButton *RedmondDeco::createButton(ButtonType type)
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2005-03-25 23:31:21 +00:00
|
|
|
switch (type) {
|
|
|
|
case MenuButton:
|
|
|
|
return new RedmondButton(MenuButton, this, "menu");
|
|
|
|
case HelpButton:
|
|
|
|
return new RedmondButton(HelpButton, this, "help");
|
|
|
|
case MinButton:
|
|
|
|
return new RedmondButton(MinButton, this, "minimize");
|
|
|
|
case MaxButton:
|
|
|
|
return new RedmondButton(MaxButton, this, "maximize");
|
|
|
|
case CloseButton:
|
|
|
|
return new RedmondButton(CloseButton, this, "close");
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
2004-07-25 11:43:57 +00:00
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
void RedmondDeco::init()
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2005-03-25 23:31:21 +00:00
|
|
|
// Finally, toolwindows look small
|
|
|
|
if ( isToolWindow() ) {
|
|
|
|
titleHeight = toolTitleHeight+2;
|
|
|
|
} else {
|
|
|
|
titleHeight = normalTitleHeight+2;
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
KCommonDecoration::init();
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
void RedmondDeco::reset( unsigned long changed )
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2005-03-25 23:31:21 +00:00
|
|
|
KCommonDecoration::reset(changed);
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
void RedmondDeco::paintEvent( QPaintEvent* )
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
|
|
|
bool hicolor = QPixmap::defaultDepth() > 8;
|
|
|
|
int fontoffset = 1;
|
|
|
|
|
2005-05-26 11:18:36 +00:00
|
|
|
// Modify borderWith used by titlebar to 0, when maximized and not move or resize able
|
|
|
|
bool border = !(maximizeMode()==MaximizeFull && !options()->moveResizeMaximizedWindows());
|
|
|
|
int modBorderWidth = border ? borderWidth : 0;
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
QPainter p(widget());
|
2001-07-16 06:53:11 +00:00
|
|
|
|
|
|
|
// Obtain widget bounds.
|
2003-09-17 08:27:26 +00:00
|
|
|
QRect r(widget()->rect());
|
2001-07-16 06:53:11 +00:00
|
|
|
int x = r.x();
|
|
|
|
int y = r.y();
|
|
|
|
int x2 = r.width()-1;
|
|
|
|
int y2 = r.height()-1;
|
|
|
|
int w = r.width();
|
|
|
|
int h = r.height();
|
|
|
|
|
|
|
|
// Draw part of the frame that is the frame color
|
|
|
|
// ==============================================
|
2006-04-30 09:16:13 +00:00
|
|
|
QPalette g = options()->palette(KDecoration::ColorFrame, isActive());
|
|
|
|
g.setCurrentColorGroup( QPalette::Active );
|
2006-05-19 11:06:32 +00:00
|
|
|
p.setPen( g.background().color() );
|
2001-07-16 06:53:11 +00:00
|
|
|
p.drawLine( x, y, x2-1, y );
|
|
|
|
p.drawLine( x, y, x, y2-1 );
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2001-07-16 06:53:11 +00:00
|
|
|
// Draw line under title bar
|
2003-09-26 12:06:58 +00:00
|
|
|
p.drawLine( x+borderWidth, y+titleHeight+borderWidth, x2-borderWidth, y+titleHeight+borderWidth );
|
2001-07-16 06:53:11 +00:00
|
|
|
// Draw a hidden line that appears during shading
|
2003-09-26 12:06:58 +00:00
|
|
|
p.drawLine( x+borderWidth, y2-borderWidth, x2-borderWidth, y2-borderWidth );
|
2001-07-16 06:53:11 +00:00
|
|
|
|
|
|
|
// Fill out the border edges
|
2003-09-26 12:06:58 +00:00
|
|
|
for (int i = 1; i < borderWidth; i++)
|
|
|
|
p.drawRect( x+i, y+i, w-2*i, h-2*i );
|
2001-07-16 06:53:11 +00:00
|
|
|
|
|
|
|
// Draw highlights and lowlights
|
2006-04-30 17:09:09 +00:00
|
|
|
p.setPen(g.color( QPalette::Light ));
|
2003-09-26 12:06:58 +00:00
|
|
|
for (int i = 1; i <= borderWidth/3; i++) {
|
|
|
|
p.drawLine( x+i, y+i, x2-i-1, y+i);
|
|
|
|
p.drawLine( x+i, y+i, x+i, y2-i-1);
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2006-04-30 09:16:13 +00:00
|
|
|
p.setPen(g.color(QPalette::Dark).dark(135));
|
2003-09-26 12:06:58 +00:00
|
|
|
for (int i = 1; i <= borderWidth/3; i++) {
|
|
|
|
p.drawLine( x2-i, y+i+1, x2-i, y2-i);
|
|
|
|
p.drawLine( x+i+1, y2-i, x2-i, y2-i);
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
|
|
|
// Draw black edges
|
2006-04-30 09:16:13 +00:00
|
|
|
p.setPen( g.color(QPalette::Dark).dark(155) );
|
2001-07-16 06:53:11 +00:00
|
|
|
p.drawLine(x2, y, x2, y2);
|
|
|
|
p.drawLine(x, y2, x2, y2);
|
|
|
|
|
|
|
|
// Draw the title bar.
|
|
|
|
// ===================
|
2005-03-25 23:31:21 +00:00
|
|
|
r = titleRect();
|
|
|
|
// QFontMetrics fm(options()->font(true));
|
2001-07-16 06:53:11 +00:00
|
|
|
|
|
|
|
// Obtain blend colours.
|
2003-09-17 08:27:26 +00:00
|
|
|
QColor c1 = options()->color(KDecoration::ColorTitleBar, isActive() );
|
|
|
|
QColor c2 = options()->color(KDecoration::ColorTitleBlend, isActive() );
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-03-25 23:31:21 +00:00
|
|
|
QFont fnt = options()->font(true, isToolWindow() );
|
|
|
|
if (isToolWindow() ) {
|
|
|
|
fnt.setWeight( QFont::Normal );
|
|
|
|
fontoffset = 0;
|
|
|
|
}
|
|
|
|
|
2001-07-16 06:53:11 +00:00
|
|
|
// Paint without a buffer if the colours are the same to
|
|
|
|
// improve performance, and only draw gradients on hicolor displays.
|
2003-09-17 08:27:26 +00:00
|
|
|
if ((c1 != c2) && hicolor) {
|
2001-07-16 06:53:11 +00:00
|
|
|
// KS - Add gradient caching if needed at a later stage.
|
|
|
|
|
|
|
|
// Create a disposable pixmap buffer for the title blend
|
2006-05-08 08:28:37 +00:00
|
|
|
QPixmap* titleBuffer = new QPixmap;
|
2006-04-26 16:05:58 +00:00
|
|
|
*titleBuffer = QPixmap(w-2*modBorderWidth, titleHeight);
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
if (titleBuffer->depth() > 16) {
|
2002-07-04 02:43:54 +00:00
|
|
|
KPixmapEffect::gradient(*titleBuffer, c1, c2,
|
|
|
|
KPixmapEffect::HorizontalGradient);
|
2003-09-17 08:27:26 +00:00
|
|
|
} else {
|
2002-07-04 02:43:54 +00:00
|
|
|
// This enables dithering on 15 and 16bit displays, preventing
|
|
|
|
// some pretty horrible banding effects
|
|
|
|
QImage image = KImageEffect::gradient(titleBuffer->size(), c1, c2,
|
|
|
|
KImageEffect::HorizontalGradient);
|
|
|
|
|
|
|
|
titleBuffer->convertFromImage(image, Qt::OrderedDither);
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
QPainter p2( titleBuffer );
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
// Since drawing the gradient is (relatively) slow, it is best
|
2001-07-16 06:53:11 +00:00
|
|
|
// to draw the title text on the pixmap.
|
|
|
|
|
|
|
|
p2.setFont( fnt );
|
2003-09-17 08:27:26 +00:00
|
|
|
p2.setPen( options()->color(KDecoration::ColorFont, isActive() ));
|
2005-03-25 23:31:21 +00:00
|
|
|
p2.drawText( r.x(), fontoffset, r.width()-3, r.height()-1,
|
2005-07-28 14:59:42 +00:00
|
|
|
Qt::AlignLeft | Qt::AlignVCenter, caption() );
|
2001-07-16 06:53:11 +00:00
|
|
|
p2.end();
|
|
|
|
|
2005-05-26 11:18:36 +00:00
|
|
|
p.drawPixmap( modBorderWidth, modBorderWidth, *titleBuffer );
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
delete titleBuffer;
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
} else {
|
2001-07-16 06:53:11 +00:00
|
|
|
// Assume lower ended hardware, so don't use buffers.
|
|
|
|
// Don't draw a gradient either.
|
2005-05-26 11:18:36 +00:00
|
|
|
p.fillRect( modBorderWidth, modBorderWidth, w-2*modBorderWidth, titleHeight, c1 );
|
2003-11-02 11:03:41 +00:00
|
|
|
|
2001-07-16 06:53:11 +00:00
|
|
|
// Draw the title text.
|
|
|
|
p.setFont( fnt );
|
2003-09-17 08:27:26 +00:00
|
|
|
p.setPen(options()->color(KDecoration::ColorFont, isActive() ));
|
2005-03-25 23:31:21 +00:00
|
|
|
p.drawText(r.x()+4, r.y()+fontoffset-2, r.width()-3, r.height()-1,
|
2005-07-28 14:59:42 +00:00
|
|
|
Qt::AlignLeft | Qt::AlignVCenter, caption() );
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-09-26 12:06:58 +00:00
|
|
|
void RedmondDecoFactory::readConfig() {
|
|
|
|
normalTitleHeight = QFontMetrics(options()->font(true)).height();
|
2005-03-25 23:31:21 +00:00
|
|
|
QFont toolFont = options()->font(true, true);
|
|
|
|
toolFont.setWeight(QFont::Normal);
|
|
|
|
toolTitleHeight = QFontMetrics(toolFont).height();
|
2003-09-26 12:06:58 +00:00
|
|
|
switch(options()->preferredBorderSize(this)) {
|
|
|
|
case BorderLarge:
|
|
|
|
borderWidth = 8;
|
|
|
|
if (normalTitleHeight < 20) normalTitleHeight = 20;
|
|
|
|
if (toolTitleHeight < 20) toolTitleHeight = 20;
|
|
|
|
break;
|
|
|
|
case BorderVeryLarge:
|
|
|
|
borderWidth = 12;
|
|
|
|
if (normalTitleHeight < 24) normalTitleHeight = 24;
|
|
|
|
if (toolTitleHeight < 24) toolTitleHeight = 24;
|
|
|
|
break;
|
|
|
|
case BorderHuge:
|
|
|
|
borderWidth = 18;
|
|
|
|
if (normalTitleHeight < 28) normalTitleHeight = 28;
|
|
|
|
if (toolTitleHeight < 28) toolTitleHeight = 28;
|
|
|
|
break;
|
|
|
|
case BorderVeryHuge:
|
|
|
|
borderWidth = 27;
|
|
|
|
if (normalTitleHeight < 33) normalTitleHeight = 33;
|
|
|
|
if (toolTitleHeight < 33) toolTitleHeight = 33;
|
|
|
|
break;
|
|
|
|
case BorderOversized:
|
|
|
|
borderWidth = 40;
|
|
|
|
if (normalTitleHeight < 40) normalTitleHeight = 40;
|
|
|
|
if (toolTitleHeight < 40) toolTitleHeight = 40;
|
|
|
|
break;
|
|
|
|
case BorderTiny:
|
|
|
|
case BorderNormal:
|
|
|
|
default:
|
|
|
|
borderWidth = 4;
|
|
|
|
if (normalTitleHeight < 16) normalTitleHeight = 16;
|
|
|
|
if (toolTitleHeight < 16) toolTitleHeight = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
RedmondDecoFactory::RedmondDecoFactory()
|
2003-07-04 18:32:29 +00:00
|
|
|
{
|
2003-09-26 12:06:58 +00:00
|
|
|
readConfig();
|
2003-09-17 08:27:26 +00:00
|
|
|
create_pixmaps();
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
RedmondDecoFactory::~RedmondDecoFactory()
|
|
|
|
{
|
|
|
|
Redmond::delete_pixmaps();
|
2003-07-26 10:41:28 +00:00
|
|
|
}
|
2002-08-27 18:08:20 +00:00
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
KDecoration *RedmondDecoFactory::createDecoration( KDecorationBridge *b )
|
2001-07-16 06:53:11 +00:00
|
|
|
{
|
2003-09-17 08:27:26 +00:00
|
|
|
return new RedmondDeco(b, this);
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
bool RedmondDecoFactory::reset( unsigned long changed )
|
|
|
|
{
|
2005-03-25 23:31:21 +00:00
|
|
|
// SettingButtons is handled by KCommonDecoration
|
|
|
|
if ( changed & ( SettingFont | SettingBorder | SettingColors | SettingButtons ) ) {
|
2003-09-26 12:06:58 +00:00
|
|
|
delete_pixmaps();
|
|
|
|
readConfig();
|
|
|
|
create_pixmaps();
|
|
|
|
resetDecorations(changed);
|
2003-09-17 08:27:26 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
resetDecorations(changed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2004-11-05 15:33:09 +00:00
|
|
|
bool RedmondDecoFactory::supports( Ability ability )
|
|
|
|
{
|
2005-03-25 23:31:21 +00:00
|
|
|
switch( ability )
|
|
|
|
{
|
|
|
|
case AbilityAnnounceButtons:
|
|
|
|
case AbilityButtonMenu:
|
|
|
|
case AbilityButtonHelp:
|
|
|
|
case AbilityButtonMinimize:
|
|
|
|
case AbilityButtonMaximize:
|
|
|
|
case AbilityButtonClose:
|
|
|
|
case AbilityButtonSpacer:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2004-11-05 15:33:09 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
QList< RedmondDecoFactory::BorderSize > RedmondDecoFactory::borderSizes() const
|
2003-09-26 12:06:58 +00:00
|
|
|
{ // the list must be sorted
|
2005-07-28 14:59:42 +00:00
|
|
|
return QList< BorderSize >() << BorderNormal << BorderLarge <<
|
2003-09-26 12:06:58 +00:00
|
|
|
BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
|
|
|
|
}
|
|
|
|
|
2003-09-17 08:27:26 +00:00
|
|
|
}
|
2001-07-16 06:53:11 +00:00
|
|
|
|
2004-11-21 16:19:09 +00:00
|
|
|
extern "C" KDE_EXPORT KDecorationFactory *create_factory()
|
2003-09-17 08:27:26 +00:00
|
|
|
{
|
|
|
|
return new Redmond::RedmondDecoFactory();
|
2001-07-16 06:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-02 11:03:41 +00:00
|
|
|
#include "redmond.moc"
|
2001-07-16 06:53:11 +00:00
|
|
|
// vim: ts=4
|
2005-03-25 23:31:21 +00:00
|
|
|
// kate: space-indent off; tab-width 4;
|