Make titlebar buttons only react on left-click, if they have one function

only.

CCMAIL: 58220-done@bugs.kde.org

svn path=/trunk/kdebase/kwin/; revision=263874
icc-effect-5.14.5
Sandro Giessl 2003-11-02 11:03:41 +00:00
parent 7008c02051
commit 69f858427e
14 changed files with 226 additions and 204 deletions

View File

@ -1,13 +1,13 @@
/* /*
* B-II KWin Client * B-II KWin Client
* *
* Changes: * Changes:
* Customizable button positions by Karol Szwed <gallium@kde.org> * Customizable button positions by Karol Szwed <gallium@kde.org>
* *
* Thin frame in fixed size windows, titlebar gradient support and * Thin frame in fixed size windows, titlebar gradient support and
* accessibility improvements are * accessibility improvements are
* Copyright (c) 2003 Luciano Montanaro <mikelima@virgilio.it> * Copyright (c) 2003 Luciano Montanaro <mikelima@virgilio.it>
*/ */
#include "b2client.h" #include "b2client.h"
#include <qlayout.h> #include <qlayout.h>
@ -145,17 +145,17 @@ static void create_pixmaps()
int i; int i;
int bsize = buttonSize - 2; int bsize = buttonSize - 2;
if (bsize < 16) bsize = 16; if (bsize < 16) bsize = 16;
for (i = 0; i < NUM_PIXMAPS; i++) { for (i = 0; i < NUM_PIXMAPS; i++) {
pixmap[i] = new KPixmap; pixmap[i] = new KPixmap;
switch (i / 4) { switch (i / 4) {
case P_MAX: // will be initialized by copying P_CLOSE case P_MAX: // will be initialized by copying P_CLOSE
break; break;
case P_ICONIFY: case P_ICONIFY:
pixmap[i]->resize(10, 10); break; pixmap[i]->resize(10, 10); break;
case P_CLOSE: case P_CLOSE:
pixmap[i]->resize(bsize, bsize); break; pixmap[i]->resize(bsize, bsize); break;
default: default:
pixmap[i]->resize(16, 16); break; pixmap[i]->resize(16, 16); break;
} }
} }
@ -174,17 +174,17 @@ static void create_pixmaps()
QBitmap helpMask(16, 16, help_mask_bits, true); QBitmap helpMask(16, 16, help_mask_bits, true);
for (i = 0; i < 4; i++) pixmap[P_HELP * 4 + i]->setMask(helpMask); for (i = 0; i < 4; i++) pixmap[P_HELP * 4 + i]->setMask(helpMask);
QBitmap normalizeMask(16, 16, true); QBitmap normalizeMask(16, 16, true);
// draw normalize icon mask // draw normalize icon mask
QPainter mask(&normalizeMask); QPainter mask(&normalizeMask);
QBrush one(Qt::color1); QBrush one(Qt::color1);
mask.fillRect(3, 3, 12, 12, one); mask.fillRect(3, 3, 12, 12, one);
mask.fillRect(0, 0, 10, 10, one); mask.fillRect(0, 0, 10, 10, one);
for (i = 0; i < 4; i++) pixmap[P_NORMALIZE * 4 + i]->setMask(normalizeMask); for (i = 0; i < 4; i++) pixmap[P_NORMALIZE * 4 + i]->setMask(normalizeMask);
titleGradient[0] = 0; titleGradient[0] = 0;
titleGradient[1] = 0; titleGradient[1] = 0;
@ -239,9 +239,9 @@ bool B2ClientFactory::reset(unsigned long changed)
} }
QValueList< B2ClientFactory::BorderSize > B2ClientFactory::borderSizes() const QValueList< B2ClientFactory::BorderSize > B2ClientFactory::borderSizes() const
{ {
// the list must be sorted // the list must be sorted
return QValueList< BorderSize >() << BorderTiny << BorderNormal << return QValueList< BorderSize >() << BorderTiny << BorderNormal <<
BorderLarge << BorderVeryLarge << BorderHuge; BorderLarge << BorderVeryLarge << BorderHuge;
} }
@ -250,27 +250,27 @@ QValueList< B2ClientFactory::BorderSize > B2ClientFactory::borderSizes() const
void B2Client::maxButtonClicked( ) void B2Client::maxButtonClicked( )
{ {
switch ( button[BtnMax]->last_button ) { switch ( button[BtnMax]->last_button ) {
case MidButton: case MidButton:
maximize(maximizeMode() ^ MaximizeVertical); maximize(maximizeMode() ^ MaximizeVertical);
break; break;
case RightButton: case RightButton:
maximize(maximizeMode() ^ MaximizeHorizontal); maximize(maximizeMode() ^ MaximizeHorizontal);
break; break;
case LeftButton: case LeftButton:
default: default:
maximize(maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull); maximize(maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull);
break; break;
} }
} }
B2Client::B2Client(KDecorationBridge *b, KDecorationFactory *f) B2Client::B2Client(KDecorationBridge *b, KDecorationFactory *f)
: KDecoration(b, f), bar_x_ofs(0), in_unobs(0) : KDecoration(b, f), bar_x_ofs(0), in_unobs(0)
{ {
} }
void B2Client::init() void B2Client::init()
{ {
const QString tips[]= {i18n("Menu"), i18n("On All desktops"), const QString tips[]= {i18n("Menu"), i18n("On All desktops"),
i18n("Minimize"), i18n("Maximize"), i18n("Minimize"), i18n("Maximize"),
i18n("Close"), i18n("Help") }; i18n("Close"), i18n("Help") };
@ -281,22 +281,22 @@ void B2Client::init()
// Set button pointers to NULL so we know what has been created // Set button pointers to NULL so we know what has been created
for (int i = 0; i < BtnCount; i++) for (int i = 0; i < BtnCount; i++)
button[i] = NULL; button[i] = NULL;
g = new QGridLayout(widget(), 0, 0); g = new QGridLayout(widget(), 0, 0);
if (isPreview()) { if (isPreview()) {
g->addMultiCellWidget( g->addMultiCellWidget(
new QLabel(i18n( "<b><center>B II preview</center></b>"), new QLabel(i18n( "<b><center>B II preview</center></b>"),
widget()), widget()),
1, 1, 1, 2); 1, 1, 1, 2);
} else { } else {
g->addMultiCell( new QSpacerItem( 0, 0 ), 1, 1, 1, 2); g->addMultiCell( new QSpacerItem( 0, 0 ), 1, 1, 1, 2);
} }
// Left and right border width // Left and right border width
leftSpacer = new QSpacerItem(thickness, 16, leftSpacer = new QSpacerItem(thickness, 16,
QSizePolicy::Minimum, QSizePolicy::Expanding); QSizePolicy::Minimum, QSizePolicy::Expanding);
rightSpacer = new QSpacerItem(thickness, 16, rightSpacer = new QSpacerItem(thickness, 16,
QSizePolicy::Minimum, QSizePolicy::Expanding); QSizePolicy::Minimum, QSizePolicy::Expanding);
g->addItem(leftSpacer, 1, 0); g->addItem(leftSpacer, 1, 0);
@ -306,7 +306,7 @@ void B2Client::init()
g->addItem(rightSpacer, 1, 3); g->addItem(rightSpacer, 1, 3);
// Bottom border height // Bottom border height
spacer = new QSpacerItem(10, thickness + (isResizable() ? 4 : 0), spacer = new QSpacerItem(10, thickness + (isResizable() ? 4 : 0),
QSizePolicy::Expanding, QSizePolicy::Minimum); QSizePolicy::Expanding, QSizePolicy::Minimum);
g->addItem(spacer, 3, 1); g->addItem(spacer, 3, 1);
@ -332,7 +332,7 @@ void B2Client::init()
} }
titleLayout->addSpacing(3); titleLayout->addSpacing(3);
QColor c = options()->colorGroup(KDecoration::ColorTitleBar, isActive()). QColor c = options()->colorGroup(KDecoration::ColorTitleBar, isActive()).
color(QColorGroup::Button); color(QColorGroup::Button);
@ -355,7 +355,7 @@ void B2Client::addButtons(const QString& s, const QString tips[],
switch (s[i].latin1()) { switch (s[i].latin1()) {
case 'M': // Menu button case 'M': // Menu button
if (!button[BtnMenu]) { if (!button[BtnMenu]) {
button[BtnMenu] = new B2Button(this, tb, tips[BtnMenu]); button[BtnMenu] = new B2Button(this, tb, tips[BtnMenu], LeftButton|RightButton);
button[BtnMenu]->setPixmaps(P_MENU); button[BtnMenu]->setPixmaps(P_MENU);
button[BtnMenu]->setUseMiniIcon(); button[BtnMenu]->setUseMiniIcon();
connect(button[BtnMenu], SIGNAL(clicked()), connect(button[BtnMenu], SIGNAL(clicked()),
@ -394,8 +394,8 @@ void B2Client::addButtons(const QString& s, const QString tips[],
break; break;
case 'A': // Maximize button case 'A': // Maximize button
if (isMaximizable() && (!button[BtnMax])) { if (isMaximizable() && (!button[BtnMax])) {
button[BtnMax]= new B2Button(this, tb, tips[BtnMax]); button[BtnMax]= new B2Button(this, tb, tips[BtnMax], LeftButton|MidButton|RightButton);
button[BtnMax]->setPixmaps(maximizeMode() == MaximizeFull ? button[BtnMax]->setPixmaps(maximizeMode() == MaximizeFull ?
P_NORMALIZE : P_MAX); P_NORMALIZE : P_MAX);
connect(button[BtnMax], SIGNAL(clicked()), connect(button[BtnMax], SIGNAL(clicked()),
this, SLOT(maxButtonClicked())); this, SLOT(maxButtonClicked()));
@ -415,13 +415,13 @@ void B2Client::addButtons(const QString& s, const QString tips[],
titleLayout->addSpacing(4); titleLayout->addSpacing(4);
break; break;
} }
} }
} }
void B2Client::iconChange() void B2Client::iconChange()
{ {
if (button[BtnMenu]) if (button[BtnMenu])
button[BtnMenu]->repaint(false); button[BtnMenu]->repaint(false);
} }
@ -434,7 +434,7 @@ void B2Client::calcHiddenButtons()
B2Button* btnArray[] = { button[BtnSticky], button[BtnHelp], B2Button* btnArray[] = { button[BtnSticky], button[BtnHelp],
button[BtnMax], button[BtnIconify], button[BtnMax], button[BtnIconify],
button[BtnClose], button[BtnMenu] }; button[BtnClose], button[BtnMenu] };
int minWidth = 120; int minWidth = 120;
int currentWidth = width(); int currentWidth = width();
int count = 0; int count = 0;
int i; int i;
@ -485,10 +485,10 @@ void B2Client::captionChange()
void B2Client::paintEvent( QPaintEvent* e) void B2Client::paintEvent( QPaintEvent* e)
{ {
QPainter p(widget()); QPainter p(widget());
KDecoration::ColorType frameColorGroup = colored_frame ? KDecoration::ColorType frameColorGroup = colored_frame ?
KDecoration::ColorTitleBar : KDecoration::ColorFrame; KDecoration::ColorTitleBar : KDecoration::ColorFrame;
QRect t = titlebar->geometry(); QRect t = titlebar->geometry();
// Frame height, this is used a lot of times // Frame height, this is used a lot of times
@ -506,28 +506,28 @@ void B2Client::paintEvent( QPaintEvent* e)
if (thickness >= 2) { if (thickness >= 2) {
// inner window rect // inner window rect
p.drawRect(thickness - 1, t.bottom(), width() - 2 * (thickness - 1), p.drawRect(thickness - 1, t.bottom(), width() - 2 * (thickness - 1),
fHeight - bDepth + 2); fHeight - bDepth + 2);
if (thickness >= 3) { if (thickness >= 3) {
// frame shade panel // frame shade panel
qDrawShadePanel(&p, 1, t.bottom() - thickness + 2, qDrawShadePanel(&p, 1, t.bottom() - thickness + 2,
width() - 2, fHeight - 2 - bb + thickness, fillColor, false); width() - 2, fHeight - 2 - bb + thickness, fillColor, false);
if (thickness == 4) { if (thickness == 4) {
p.setPen(fillColor.background()); p.setPen(fillColor.background());
p.drawRect(thickness - 2, t.bottom() - 1, p.drawRect(thickness - 2, t.bottom() - 1,
width() - 2 * (thickness - 2), fHeight + 4 - bDepth); width() - 2 * (thickness - 2), fHeight + 4 - bDepth);
} else if (thickness > 4) { } else if (thickness > 4) {
qDrawShadePanel(&p, thickness - 2, qDrawShadePanel(&p, thickness - 2,
t.bottom() - 1, width() - 2 * (thickness - 2), t.bottom() - 1, width() - 2 * (thickness - 2),
fHeight + 4 - bDepth, fillColor, true); fHeight + 4 - bDepth, fillColor, true);
if (thickness >= 5) { if (thickness >= 5) {
// draw frame interior // draw frame interior
p.fillRect(2, t.bottom() - thickness + 3, p.fillRect(2, t.bottom() - thickness + 3,
width() - 4, thickness - 4, fillBrush); width() - 4, thickness - 4, fillBrush);
p.fillRect(2, height() - bDepth + 2, p.fillRect(2, height() - bDepth + 2,
width() - 4, thickness - 4, fillBrush); width() - 4, thickness - 4, fillBrush);
p.fillRect(2, t.bottom() - 1, p.fillRect(2, t.bottom() - 1,
thickness - 4, fHeight - bDepth + 4, fillBrush); thickness - 4, fHeight - bDepth + 4, fillBrush);
p.fillRect(width() - thickness + 2, t.bottom() - 1, p.fillRect(width() - thickness + 2, t.bottom() - 1,
thickness - 4, fHeight - bDepth + 4, fillBrush); thickness - 4, fHeight - bDepth + 4, fillBrush);
@ -542,25 +542,25 @@ void B2Client::paintEvent( QPaintEvent* e)
int hx = width() - 40; int hx = width() - 40;
int hw = 40; int hw = 40;
p.drawLine(width() - 1, height() - thickness - 4, p.drawLine(width() - 1, height() - thickness - 4,
width() - 1, height() - 1); width() - 1, height() - 1);
p.drawLine(hx, height() - 1, width() - 1, height() - 1); p.drawLine(hx, height() - 1, width() - 1, height() - 1);
p.drawLine(hx, height() - 4, hx, height() - 1); p.drawLine(hx, height() - 4, hx, height() - 1);
p.fillRect(hx + 1, height() - thickness - 3, p.fillRect(hx + 1, height() - thickness - 3,
hw - 2, thickness + 2, fillBrush); hw - 2, thickness + 2, fillBrush);
p.setPen(fillColor.dark()); p.setPen(fillColor.dark());
p.drawLine(width() - 2, height() - thickness - 4, p.drawLine(width() - 2, height() - thickness - 4,
width() - 2, height() - 2); width() - 2, height() - 2);
p.drawLine(hx + 1, height() - 2, width() - 2, height() - 2); p.drawLine(hx + 1, height() - 2, width() - 2, height() - 2);
p.setPen(fillColor.light()); p.setPen(fillColor.light());
p.drawLine(hx + 1, height() - thickness - 2, p.drawLine(hx + 1, height() - thickness - 2,
hx + 1, height() - 3); hx + 1, height() - 3);
p.drawLine(hx + 1, height() - thickness - 3, p.drawLine(hx + 1, height() - thickness - 3,
width() - 3, height() - thickness - 3); width() - 3, height() - thickness - 3);
} }
/* OK, we got a paint event, which means parts of us are now visible /* OK, we got a paint event, which means parts of us are now visible
which were not before. We try the titlebar if it is currently fully which were not before. We try the titlebar if it is currently fully
@ -592,9 +592,9 @@ void B2Client::doShape()
mask -= QRect(0, t.height() - thickness, 1, 1); //top left point mask -= QRect(0, t.height() - thickness, 1, 1); //top left point
} }
if (t.right() < width() - 1) { if (t.right() < width() - 1) {
mask -= QRect(width() - 1, mask -= QRect(width() - 1,
t.height() - thickness, 1, 1); //top right point t.height() - thickness, 1, 1); //top right point
mask -= QRect(t.right() + 1, 0, mask -= QRect(t.right() + 1, 0,
width() - t.right() - 1, t.height() - thickness); width() - t.right() - 1, t.height() - thickness);
} }
mask -= QRect(width() - 1, height() - 1, 1, 1); //bottom right point mask -= QRect(width() - 1, height() - 1, 1, 1); //bottom right point
@ -638,7 +638,7 @@ KDecoration::MousePosition B2Client::mousePosition( const QPoint& p ) const
else if ( p.y() <= ly + thickness ) else if ( p.y() <= ly + thickness )
return Top; return Top;
} else if ( p.y() < ly ) { } else if ( p.y() < ly ) {
if (p.x() > bar_x_ofs + thickness && if (p.x() > bar_x_ofs + thickness &&
p.x() < lx - thickness && p.y() > thickness) p.x() < lx - thickness && p.y() > thickness)
return KDecoration::mousePosition(p); return KDecoration::mousePosition(p);
if (p.x() > bar_x_ofs + range && p.x() < lx - range) if (p.x() > bar_x_ofs + range && p.x() < lx - range)
@ -702,10 +702,10 @@ void B2Client::maximizeChange()
button[BtnMax]->setPixmaps( m ? P_NORMALIZE : P_MAX ); button[BtnMax]->setPixmaps( m ? P_NORMALIZE : P_MAX );
button[BtnMax]->repaint(); button[BtnMax]->repaint();
QToolTip::remove(button[BtnMax]); QToolTip::remove(button[BtnMax]);
QToolTip::add(button[BtnMax], QToolTip::add(button[BtnMax],
m ? i18n("Restore") : i18n("Maximize")); m ? i18n("Restore") : i18n("Maximize"));
} }
spacer->changeSize(10, thickness + (isResizable() ? 4 : 0), spacer->changeSize(10, thickness + (isResizable() ? 4 : 0),
QSizePolicy::Expanding, QSizePolicy::Minimum); QSizePolicy::Expanding, QSizePolicy::Minimum);
g->activate(); g->activate();
@ -730,7 +730,7 @@ void B2Client::activeChange()
void B2Client::shadeChange() void B2Client::shadeChange()
{ {
spacer->changeSize(10, thickness + (isResizable() ? 4 : 0), spacer->changeSize(10, thickness + (isResizable() ? 4 : 0),
QSizePolicy::Expanding, QSizePolicy::Minimum); QSizePolicy::Expanding, QSizePolicy::Minimum);
g->activate(); g->activate();
doShape(); doShape();
@ -738,7 +738,7 @@ void B2Client::shadeChange()
QSize B2Client::minimumSize() const QSize B2Client::minimumSize() const
{ {
return QSize(64, 48); return QSize(64, 48);
} }
void B2Client::resize(const QSize& s) void B2Client::resize(const QSize& s)
@ -747,7 +747,7 @@ void B2Client::resize(const QSize& s)
} }
void B2Client::borders(int &left, int &right, int &top, int &bottom) const void B2Client::borders(int &left, int &right, int &top, int &bottom) const
{ {
left = right = thickness + 1; left = right = thickness + 1;
top = buttonSize + 4; top = buttonSize + 4;
bottom = thickness + (isResizable() ? 4 : 0); bottom = thickness + (isResizable() ? 4 : 0);
@ -837,11 +837,11 @@ static void redraw_pixmaps()
drawB2Rect(&smallBox, is_act ? aGrp.button() : iGrp.button(), is_down); drawB2Rect(&smallBox, is_act ? aGrp.button() : iGrp.button(), is_down);
drawB2Rect(&largeBox, is_act ? aGrp.button() : iGrp.button(), is_down); drawB2Rect(&largeBox, is_act ? aGrp.button() : iGrp.button(), is_down);
pix->fill(options()->color(KDecoration::ColorTitleBar, is_act)); pix->fill(options()->color(KDecoration::ColorTitleBar, is_act));
bitBlt(pix, pix->width() - 12, pix->width() - 12, &largeBox, bitBlt(pix, pix->width() - 12, pix->width() - 12, &largeBox,
0, 0, 12, 12, Qt::CopyROP, true); 0, 0, 12, 12, Qt::CopyROP, true);
bitBlt(pix, 0, 0, &smallBox, 0, 0, 10, 10, Qt::CopyROP, true); bitBlt(pix, 0, 0, &smallBox, 0, 0, 10, 10, Qt::CopyROP, true);
bitBlt(pixmap[P_ICONIFY * 4 + i], 0, 0, bitBlt(pixmap[P_ICONIFY * 4 + i], 0, 0,
&smallBox, 0, 0, 10, 10, Qt::CopyROP, true); &smallBox, 0, 0, 10, 10, Qt::CopyROP, true);
} }
@ -859,9 +859,9 @@ static void redraw_pixmaps()
} }
// x for close + menu + help // x for close + menu + help
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
switch (j) { switch (j) {
case 1: case 1:
pix = P_MENU; light = menu_white_bits; dark = menu_dgray_bits; pix = P_MENU; light = menu_white_bits; dark = menu_dgray_bits;
break; break;
default: default:
pix = P_HELP; light = help_light_bits; dark = help_dark_bits; pix = P_HELP; light = help_light_bits; dark = help_dark_bits;
@ -885,7 +885,7 @@ static void redraw_pixmaps()
gray, NULL, dgray, NULL, NULL); gray, NULL, dgray, NULL, NULL);
p.end(); p.end();
} }
// Create the titlebar gradients // Create the titlebar gradients
if (QPixmap::defaultDepth() > 8) { if (QPixmap::defaultDepth() > 8) {
QColor titleColor[4] = { QColor titleColor[4] = {
@ -900,18 +900,18 @@ static void redraw_pixmaps()
titleColor[0] = options()->color(KDecoration::ColorTitleBlend, true); titleColor[0] = options()->color(KDecoration::ColorTitleBlend, true);
titleColor[1] = options()->color(KDecoration::ColorTitleBar, true); titleColor[1] = options()->color(KDecoration::ColorTitleBar, true);
} }
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (titleColor[2 * i] != titleColor[2 * i + 1]) { if (titleColor[2 * i] != titleColor[2 * i + 1]) {
if (!titleGradient[i]) { if (!titleGradient[i]) {
titleGradient[i] = new KPixmap; titleGradient[i] = new KPixmap;
} }
titleGradient[i]->resize(64, buttonSize + 3); titleGradient[i]->resize(64, buttonSize + 3);
KPixmapEffect::gradient(*titleGradient[i], KPixmapEffect::gradient(*titleGradient[i],
titleColor[2 * i], titleColor[2 * i + 1], titleColor[2 * i], titleColor[2 * i + 1],
KPixmapEffect::VerticalGradient); KPixmapEffect::VerticalGradient);
} else { } else {
delete titleGradient[i]; delete titleGradient[i];
titleGradient[i] = 0; titleGradient[i] = 0;
} }
} }
@ -950,9 +950,9 @@ bool B2Client::drawbound(const QRect& geom, bool clear)
QRect t = titlebar->geometry(); QRect t = titlebar->geometry();
int frameTop = geom.top() + t.bottom(); int frameTop = geom.top() + t.bottom();
int barLeft = geom.left() + bar_x_ofs; int barLeft = geom.left() + bar_x_ofs;
int barRight = barLeft + t.width() - 1; int barRight = barLeft + t.width() - 1;
if (barRight > geom.right()) barRight = geom.right(); if (barRight > geom.right()) barRight = geom.right();
bound_shape.putPoints(0, 8, bound_shape.putPoints(0, 8,
geom.left(), frameTop, geom.left(), frameTop,
barLeft, frameTop, barLeft, frameTop,
@ -1005,13 +1005,14 @@ bool B2Client::eventFilter(QObject *o, QEvent *e)
// ===================================== // =====================================
B2Button::B2Button(B2Client *_client, QWidget *parent, const QString& tip) B2Button::B2Button(B2Client *_client, QWidget *parent, const QString& tip, const int realizeBtns)
: QButton(parent, 0) : QButton(parent, 0)
{ {
setBackgroundMode(NoBackground); setBackgroundMode(NoBackground);
realizeButtons = realizeBtns;
client = _client; client = _client;
useMiniIcon = false; useMiniIcon = false;
setFixedSize(buttonSize, buttonSize); setFixedSize(buttonSize, buttonSize);
QToolTip::add(this, tip); QToolTip::add(this, tip);
} }
@ -1029,9 +1030,9 @@ QSizePolicy B2Button::sizePolicy() const
void B2Button::drawButton(QPainter *p) void B2Button::drawButton(QPainter *p)
{ {
KPixmap* gradient = titleGradient[client->isActive() ? 0 : 1]; KPixmap* gradient = titleGradient[client->isActive() ? 0 : 1];
if (gradient) { if (gradient) {
p->drawTiledPixmap(0, 0, buttonSize, buttonSize, *gradient, 0, 2); p->drawTiledPixmap(0, 0, buttonSize, buttonSize, *gradient, 0, 2);
} else { } else {
p->fillRect(rect(), bg); p->fillRect(rect(), bg);
} }
if (useMiniIcon) { if (useMiniIcon) {
@ -1081,7 +1082,7 @@ void B2Button::mousePressEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me(e->type(), e->pos(), e->globalPos(), QMouseEvent me(e->type(), e->pos(), e->globalPos(),
LeftButton, e->state()); (e->button()&realizeButtons)?LeftButton:NoButton, e->state());
QButton::mousePressEvent(&me); QButton::mousePressEvent(&me);
} }
@ -1089,7 +1090,7 @@ void B2Button::mouseReleaseEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me(e->type(), e->pos(), e->globalPos(), QMouseEvent me(e->type(), e->pos(), e->globalPos(),
LeftButton, e->state()); (e->button()&realizeButtons)?LeftButton:NoButton, e->state());
QButton::mouseReleaseEvent(&me); QButton::mouseReleaseEvent(&me);
} }
@ -1101,7 +1102,7 @@ B2Titlebar::B2Titlebar(B2Client *parent)
set_x11mask(false), isfullyobscured(false), shift_move(false) set_x11mask(false), isfullyobscured(false), shift_move(false)
{ {
setBackgroundMode(NoBackground); setBackgroundMode(NoBackground);
captionSpacer = new QSpacerItem(10, buttonSize + 4, captionSpacer = new QSpacerItem(10, buttonSize + 4,
QSizePolicy::Expanding, QSizePolicy::Fixed); QSizePolicy::Expanding, QSizePolicy::Fixed);
} }
@ -1138,7 +1139,7 @@ bool B2Titlebar::x11Event(XEvent *e)
void B2Titlebar::drawTitlebar(QPainter &p, bool state) void B2Titlebar::drawTitlebar(QPainter &p, bool state)
{ {
KPixmap* gradient = titleGradient[state ? 0 : 1]; KPixmap* gradient = titleGradient[state ? 0 : 1];
QRect t = rect(); QRect t = rect();
// black titlebar frame // black titlebar frame
p.setPen(Qt::black); p.setPen(Qt::black);
@ -1147,11 +1148,11 @@ void B2Titlebar::drawTitlebar(QPainter &p, bool state)
p.drawLine(t.right(), 0, t.right(), t.bottom()); p.drawLine(t.right(), 0, t.right(), t.bottom());
// titlebar fill // titlebar fill
const QColorGroup cg = const QColorGroup cg =
options()->colorGroup(KDecoration::ColorTitleBar, state); options()->colorGroup(KDecoration::ColorTitleBar, state);
QBrush brush(cg.background()); QBrush brush(cg.background());
if (gradient) brush.setPixmap(*gradient); if (gradient) brush.setPixmap(*gradient);
qDrawShadeRect(&p, 1, 1, t.right() - 1, t.height() - 1, qDrawShadeRect(&p, 1, 1, t.right() - 1, t.height() - 1,
cg, false, 1, 0, &brush); cg, false, 1, 0, &brush);
// and the caption // and the caption
@ -1221,7 +1222,7 @@ void B2Titlebar::mouseMoveEvent( QMouseEvent * e )
} }
} else { } else {
e->ignore(); e->ignore();
} }
} }
} // namespace B2 } // namespace B2

View File

@ -1,10 +1,10 @@
/* /*
* B-II KWin Client * B-II KWin Client
* *
* Changes: * Changes:
* Customizable button positions by Karol Szwed <gallium@kde.org> * Customizable button positions by Karol Szwed <gallium@kde.org>
* Ported to the kde3.2 API by Luciano Montanaro <mikelima@virgilio.it> * Ported to the kde3.2 API by Luciano Montanaro <mikelima@virgilio.it>
*/ */
#ifndef __B2CLIENT_H #ifndef __B2CLIENT_H
#define __B2CLIENT_H #define __B2CLIENT_H
@ -27,7 +27,7 @@ class B2Client;
class B2Button : public QButton class B2Button : public QButton
{ {
public: public:
B2Button(B2Client *_client=0, QWidget *parent=0, const QString& tip=NULL); B2Button(B2Client *_client=0, QWidget *parent=0, const QString& tip=NULL, const int realizeBtns = LeftButton);
~B2Button() {}; ~B2Button() {};
void setBg(const QColor &c){bg = c;} void setBg(const QColor &c){bg = c;}
@ -42,17 +42,18 @@ public:
protected: protected:
virtual void drawButton(QPainter *p); virtual void drawButton(QPainter *p);
void drawButtonLabel(QPainter *){;} void drawButtonLabel(QPainter *){;}
bool useMiniIcon; bool useMiniIcon;
KPixmap *pNorm, *pDown, *iNorm, *iDown; KPixmap *pNorm, *pDown, *iNorm, *iDown;
QColor bg; //only use one color (the rest is pixmap) so forget QPalette ;) QColor bg; //only use one color (the rest is pixmap) so forget QPalette ;)
void mousePressEvent( QMouseEvent* e ); void mousePressEvent( QMouseEvent* e );
void mouseReleaseEvent( QMouseEvent* e ); void mouseReleaseEvent( QMouseEvent* e );
public: public:
B2Client* client; B2Client* client;
int last_button; int last_button;
int realizeButtons;
}; };
class B2Titlebar : public QWidget class B2Titlebar : public QWidget
@ -74,7 +75,7 @@ protected:
void resizeEvent(QResizeEvent *ev); void resizeEvent(QResizeEvent *ev);
private: private:
void drawTitlebar(QPainter &p, bool state); void drawTitlebar(QPainter &p, bool state);
B2Client *client; B2Client *client;
QString oldTitle; QString oldTitle;
KPixmap titleBuffer; KPixmap titleBuffer;
@ -119,7 +120,7 @@ private slots:
//void slotReset(); //void slotReset();
void maxButtonClicked(); void maxButtonClicked();
private: private:
void addButtons(const QString& s, const QString tips[], void addButtons(const QString& s, const QString tips[],
B2Titlebar* tb, QBoxLayout* titleLayout); B2Titlebar* tb, QBoxLayout* titleLayout);
void positionButtons(); void positionButtons();
void calcHiddenButtons(); void calcHiddenButtons();

View File

@ -204,7 +204,7 @@ unsigned long KDEDefaultHandler::readConfig( bool update )
if (new_titleHeight < new_borderWidth) new_titleHeight = new_borderWidth; if (new_titleHeight < new_borderWidth) new_titleHeight = new_borderWidth;
if (new_toolTitleHeight < 12) new_toolTitleHeight = 12; if (new_toolTitleHeight < 12) new_toolTitleHeight = 12;
if (new_toolTitleHeight < new_borderWidth) new_toolTitleHeight = new_borderWidth; if (new_toolTitleHeight < new_borderWidth) new_toolTitleHeight = new_borderWidth;
if( update ) if( update )
{ {
if( new_showGrabBar != showGrabBar if( new_showGrabBar != showGrabBar
@ -218,7 +218,7 @@ unsigned long KDEDefaultHandler::readConfig( bool update )
|| new_toolTitleHeight != toolTitleHeight ) || new_toolTitleHeight != toolTitleHeight )
changed |= SettingColors; // just recreate the pixmaps and repaint changed |= SettingColors; // just recreate the pixmaps and repaint
} }
showGrabBar = new_showGrabBar; showGrabBar = new_showGrabBar;
showTitleBarStipple = new_showTitleBarStipple; showTitleBarStipple = new_showTitleBarStipple;
useGradients = new_useGradients; useGradients = new_useGradients;
@ -515,9 +515,11 @@ QValueList< KDEDefaultHandler::BorderSize > KDEDefaultHandler::borderSizes() con
KDEDefaultButton::KDEDefaultButton(KDEDefaultClient *parent, const char *name, KDEDefaultButton::KDEDefaultButton(KDEDefaultClient *parent, const char *name,
bool largeButton, bool isLeftButton, bool isStickyButton, bool largeButton, bool isLeftButton, bool isStickyButton,
const unsigned char *bitmap, const QString& tip ) const unsigned char *bitmap, const QString& tip, const int realizeBtns )
: QButton(parent->widget(), name) : QButton(parent->widget(), name)
{ {
realizeButtons = realizeBtns;
QToolTip::add( this, tip ); QToolTip::add( this, tip );
setCursor( arrowCursor ); setCursor( arrowCursor );
setBackgroundMode( QWidget::NoBackground ); setBackgroundMode( QWidget::NoBackground );
@ -685,7 +687,7 @@ void KDEDefaultButton::mousePressEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me( e->type(), e->pos(), e->globalPos(), QMouseEvent me( e->type(), e->pos(), e->globalPos(),
LeftButton, e->state() ); (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mousePressEvent( &me ); QButton::mousePressEvent( &me );
} }
@ -694,7 +696,7 @@ void KDEDefaultButton::mouseReleaseEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me( e->type(), e->pos(), e->globalPos(), QMouseEvent me( e->type(), e->pos(), e->globalPos(),
LeftButton, e->state() ); (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mouseReleaseEvent( &me ); QButton::mouseReleaseEvent( &me );
} }
@ -745,8 +747,8 @@ void KDEDefaultClient::init()
g->setRowStretch(3, 10); // Wrapped window g->setRowStretch(3, 10); // Wrapped window
// Determine the size of the lower grab bar // Determine the size of the lower grab bar
spacer = new QSpacerItem(10, spacer = new QSpacerItem(10,
showGrabBar && isResizable() ? grabBorderWidth : borderWidth, showGrabBar && isResizable() ? grabBorderWidth : borderWidth,
QSizePolicy::Expanding, QSizePolicy::Minimum); QSizePolicy::Expanding, QSizePolicy::Minimum);
g->addItem(spacer, 4, 1); g->addItem(spacer, 4, 1);
@ -778,7 +780,7 @@ void KDEDefaultClient::addClientButtons( const QString& s, bool isLeft )
if (!button[BtnMenu]) if (!button[BtnMenu])
{ {
button[BtnMenu] = new KDEDefaultButton(this, "menu", button[BtnMenu] = new KDEDefaultButton(this, "menu",
largeButtons, isLeft, false, NULL, i18n("Menu")); largeButtons, isLeft, false, NULL, i18n("Menu"), LeftButton|RightButton);
connect( button[BtnMenu], SIGNAL(pressed()), connect( button[BtnMenu], SIGNAL(pressed()),
this, SLOT(menuButtonPressed()) ); this, SLOT(menuButtonPressed()) );
connect( button[BtnMenu], SIGNAL(released()), connect( button[BtnMenu], SIGNAL(released()),
@ -832,7 +834,7 @@ void KDEDefaultClient::addClientButtons( const QString& s, bool isLeft )
{ {
button[BtnMax] = new KDEDefaultButton(this, "maximize", button[BtnMax] = new KDEDefaultButton(this, "maximize",
largeButtons, isLeft, true, maximize_bits, largeButtons, isLeft, true, maximize_bits,
i18n("Maximize")); i18n("Maximize"), LeftButton|MidButton|RightButton);
connect( button[BtnMax], SIGNAL( clicked()), connect( button[BtnMax], SIGNAL( clicked()),
this, SLOT(slotMaximize()) ); this, SLOT(slotMaximize()) );
hb->addWidget( button[BtnMax] ); hb->addWidget( button[BtnMax] );
@ -1095,7 +1097,7 @@ void KDEDefaultClient::paintEvent( QPaintEvent* )
p2.end(); p2.end();
// Ensure a shaded window has no unpainted areas // Ensure a shaded window has no unpainted areas
// Is this still needed? // Is this still needed?
#if 1 #if 1
p.setPen(c2); p.setPen(c2);
p.drawLine(x+borderWidth, y+titleHeight+4, x2-borderWidth, y+titleHeight+4); p.drawLine(x+borderWidth, y+titleHeight+4, x2-borderWidth, y+titleHeight+4);
@ -1218,7 +1220,7 @@ KDecoration::MousePosition KDEDefaultClient::mousePosition( const QPoint& p ) co
MousePosition m = Nowhere; MousePosition m = Nowhere;
int bottomSize = (showGrabBar && isResizable()) ? grabBorderWidth : borderWidth; int bottomSize = (showGrabBar && isResizable()) ? grabBorderWidth : borderWidth;
const int range = 14 + 3*borderWidth/2; const int range = 14 + 3*borderWidth/2;
if ( ( p.x() > borderWidth && p.x() < width() - borderWidth ) if ( ( p.x() > borderWidth && p.x() < width() - borderWidth )

View File

@ -53,7 +53,7 @@ class KDEDefaultButton : public QButton, public KDecorationDefines
KDEDefaultButton(KDEDefaultClient *parent=0, const char *name=0, KDEDefaultButton(KDEDefaultClient *parent=0, const char *name=0,
bool largeButton=true, bool isLeftButton=true, bool largeButton=true, bool isLeftButton=true,
bool isStickyButton=false, const unsigned char *bitmap=NULL, bool isStickyButton=false, const unsigned char *bitmap=NULL,
const QString& tip=NULL); const QString& tip=NULL, const int realizeBtns = LeftButton);
~KDEDefaultButton(); ~KDEDefaultButton();
int last_button; int last_button;
@ -75,6 +75,8 @@ class KDEDefaultButton : public QButton, public KDecorationDefines
bool isSticky; bool isSticky;
bool isMouseOver; bool isMouseOver;
KDEDefaultClient* client; KDEDefaultClient* client;
int realizeButtons;
}; };

View File

@ -685,10 +685,12 @@ QValueList< KeramikHandler::BorderSize > KeramikHandler::borderSizes() const
KeramikButton::KeramikButton( KeramikClient* c, const char *name, Button btn, const QString &tip ) KeramikButton::KeramikButton( KeramikClient* c, const char *name, Button btn, const QString &tip, const int realizeBtns )
: QButton( c->widget(), name ), : QButton( c->widget(), name ),
client( c ), button( btn ), hover( false ), lastbutton( 0 ) client( c ), button( btn ), hover( false ), lastbutton( 0 )
{ {
realizeButtons = realizeBtns;
QToolTip::add( this, tip ); // FRAME QToolTip::add( this, tip ); // FRAME
setBackgroundMode( NoBackground ); setBackgroundMode( NoBackground );
setCursor( arrowCursor ); setCursor( arrowCursor );
@ -726,7 +728,7 @@ void KeramikButton::leaveEvent( QEvent *e )
void KeramikButton::mousePressEvent( QMouseEvent *e ) void KeramikButton::mousePressEvent( QMouseEvent *e )
{ {
lastbutton = e->button(); lastbutton = e->button();
QMouseEvent me( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); QMouseEvent me( e->type(), e->pos(), e->globalPos(), (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mousePressEvent( &me ); QButton::mousePressEvent( &me );
} }
@ -734,7 +736,7 @@ void KeramikButton::mousePressEvent( QMouseEvent *e )
void KeramikButton::mouseReleaseEvent( QMouseEvent *e ) void KeramikButton::mouseReleaseEvent( QMouseEvent *e )
{ {
lastbutton = e->button(); lastbutton = e->button();
QMouseEvent me( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); QMouseEvent me( e->type(), e->pos(), e->globalPos(), (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mouseReleaseEvent( &me ); QButton::mouseReleaseEvent( &me );
} }
@ -945,7 +947,7 @@ void KeramikClient::addButtons( QBoxLayout *layout, const QString &s )
// Menu button // Menu button
case 'M' : case 'M' :
if ( !button[MenuButton] ) { if ( !button[MenuButton] ) {
button[MenuButton] = new KeramikButton( this, "menu", MenuButton, i18n("Menu") ); button[MenuButton] = new KeramikButton( this, "menu", MenuButton, i18n("Menu"), LeftButton|RightButton );
connect( button[MenuButton], SIGNAL( pressed() ), SLOT( menuButtonPressed() ) ); connect( button[MenuButton], SIGNAL( pressed() ), SLOT( menuButtonPressed() ) );
layout->addWidget( button[MenuButton] ); layout->addWidget( button[MenuButton] );
} }
@ -982,7 +984,7 @@ void KeramikClient::addButtons( QBoxLayout *layout, const QString &s )
// Maximize button // Maximize button
case 'A' : case 'A' :
if ( !button[MaxButton] && isMaximizable() ) { if ( !button[MaxButton] && isMaximizable() ) {
button[MaxButton] = new KeramikButton( this, "maximize", MaxButton, i18n("Maximize") ); button[MaxButton] = new KeramikButton( this, "maximize", MaxButton, i18n("Maximize"), LeftButton|MidButton|RightButton );
connect( button[MaxButton], SIGNAL( clicked() ), SLOT( slotMaximize() ) ); connect( button[MaxButton], SIGNAL( clicked() ), SLOT( slotMaximize() ) );
layout->addWidget( button[MaxButton] ); layout->addWidget( button[MaxButton] );
} }

View File

@ -113,7 +113,7 @@ namespace Keramik {
class KeramikButton : public QButton class KeramikButton : public QButton
{ {
public: public:
KeramikButton( KeramikClient *, const char *, Button, const QString & ); KeramikButton( KeramikClient *, const char *, Button, const QString &, const int realizeBtns = LeftButton );
~KeramikButton(); ~KeramikButton();
int lastButton() const { return lastbutton; } int lastButton() const { return lastbutton; }
@ -130,6 +130,7 @@ namespace Keramik {
Button button; Button button;
bool hover; bool hover;
int lastbutton; int lastbutton;
int realizeButtons;
}; // class KeramikButton }; // class KeramikButton

View File

@ -1,7 +1,7 @@
/* /*
* Laptop KWin Decoration * Laptop KWin Decoration
* *
* Port of this decoration to KDE 3.2, accessibility enhancement are * Port of this decoration to KDE 3.2, accessibility enhancement are
* Copyright (c) 2003 Luciano Montanaro <mikelima@virgilio.it> * Copyright (c) 2003 Luciano Montanaro <mikelima@virgilio.it>
*/ */
@ -55,7 +55,7 @@ static KPixmap *iBtnPix2;
static KPixmap *iBtnDownPix2; static KPixmap *iBtnDownPix2;
static QColor btnForeground; static QColor btnForeground;
static int titleHeight = 14; static int titleHeight = 14;
static int btnWidth1 = 17; static int btnWidth1 = 17;
static int btnWidth2 = 27; static int btnWidth2 = 27;
@ -111,10 +111,10 @@ static void create_pixmaps()
if (titleHeight < handleSize) titleHeight = handleSize; if (titleHeight < handleSize) titleHeight = handleSize;
titleHeight &= ~1; // Make title height even titleHeight &= ~1; // Make title height even
if (titleHeight < 14) titleHeight = 14; if (titleHeight < 14) titleHeight = 14;
btnWidth1 = titleHeight + 3; btnWidth1 = titleHeight + 3;
btnWidth2 = 3*titleHeight/2 + 6; btnWidth2 = 3*titleHeight/2 + 6;
// titlebar // titlebar
QPainter p; QPainter p;
QPainter maskPainter; QPainter maskPainter;
@ -246,11 +246,13 @@ static void delete_pixmaps()
// ===================================== // =====================================
LaptopButton::LaptopButton(int w, int h, LaptopClient *parent, LaptopButton::LaptopButton(int w, int h, LaptopClient *parent,
const char *name, const unsigned char *bitmap, const char *name, const unsigned char *bitmap,
const QString& tip) const QString& tip, const int realizeBtns)
: QButton(parent->widget(), name), client(parent) : QButton(parent->widget(), name), client(parent)
{ {
realizeButtons = realizeBtns;
setCursor( arrowCursor ); setCursor( arrowCursor );
defaultSize = QSize(w, h); defaultSize = QSize(w, h);
setFixedHeight(h); setFixedHeight(h);
@ -329,7 +331,7 @@ void LaptopClient::reset(unsigned long)
} }
LaptopClient::LaptopClient(KDecorationBridge *b, KDecorationFactory *f) LaptopClient::LaptopClient(KDecorationBridge *b, KDecorationFactory *f)
: KDecoration(b, f) : KDecoration(b, f)
{ {
} }
@ -337,7 +339,7 @@ void LaptopClient::init()
{ {
createMainWidget(WResizeNoErase | WStaticContents); createMainWidget(WResizeNoErase | WStaticContents);
widget()->installEventFilter(this); widget()->installEventFilter(this);
lastButtonWidth = 0; lastButtonWidth = 0;
lastBufferWidth = 0; lastBufferWidth = 0;
@ -350,13 +352,13 @@ void LaptopClient::init()
g->addRowSpacing(0, 3); g->addRowSpacing(0, 3);
g->addRowSpacing(2, 1); g->addRowSpacing(2, 1);
if (isPreview()) if (isPreview())
g->addWidget(new QLabel(i18n("<center><b></b>Laptop preview</center>"), g->addWidget(new QLabel(i18n("<center><b></b>Laptop preview</center>"),
widget()), 3, 1); widget()), 3, 1);
else else
g->addItem( new QSpacerItem( 0, 0 ), 3, 1); // no widget in the middle g->addItem( new QSpacerItem( 0, 0 ), 3, 1); // no widget in the middle
g->setRowStretch(3, 10); g->setRowStretch(3, 10);
spacer = new QSpacerItem(10, isResizable() ? handleSize : 4, spacer = new QSpacerItem(10, isResizable() ? handleSize : 4,
QSizePolicy::Expanding, QSizePolicy::Minimum); QSizePolicy::Expanding, QSizePolicy::Minimum);
g->addItem(spacer, 4, 1); g->addItem(spacer, 4, 1);
g->addColSpacing(0, 4); g->addColSpacing(0, 4);
@ -366,7 +368,7 @@ void LaptopClient::init()
if ( isTool() ) if ( isTool() )
th -= 2; th -= 2;
button[BtnClose] = new LaptopButton(btnWidth2, th, this, "close", button[BtnClose] = new LaptopButton(btnWidth2, th, this, "close",
close_bits, i18n("Close")); close_bits, i18n("Close"));
button[BtnSticky] = new LaptopButton(btnWidth1, th, this, "sticky", button[BtnSticky] = new LaptopButton(btnWidth1, th, this, "sticky",
NULL, i18n("Sticky")); NULL, i18n("Sticky"));
@ -377,7 +379,7 @@ void LaptopClient::init()
button[BtnIconify] = new LaptopButton(btnWidth2, th, this, "iconify", button[BtnIconify] = new LaptopButton(btnWidth2, th, this, "iconify",
iconify_bits, i18n("Minimize")); iconify_bits, i18n("Minimize"));
button[BtnMax] = new LaptopButton(btnWidth2, th, this, "maximize", button[BtnMax] = new LaptopButton(btnWidth2, th, this, "maximize",
maximize_bits, i18n("Maximize")); maximize_bits, i18n("Maximize"), LeftButton|MidButton|RightButton);
if (help) { if (help) {
button[BtnHelp] = new LaptopButton(btnWidth1, th, this, "help", button[BtnHelp] = new LaptopButton(btnWidth1, th, this, "help",
question_bits, i18n("Help")); question_bits, i18n("Help"));
@ -430,7 +432,7 @@ void LaptopClient::slotMaximize()
maximize( maximizeMode() ^ MaximizeHorizontal ); maximize( maximizeMode() ^ MaximizeHorizontal );
break; break;
case LeftButton: case LeftButton:
default: default:
maximize(maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull); maximize(maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull);
break; break;
} }
@ -446,15 +448,15 @@ void LaptopClient::resizeEvent(QResizeEvent* e)
if ( e->oldSize().width() != width() ) if ( e->oldSize().width() != width() )
dx = 32 + QABS( e->oldSize().width() - width() ); dx = 32 + QABS( e->oldSize().width() - width() );
if ( e->oldSize().height() != height() ) if ( e->oldSize().height() != height() )
dy = isResizable() ? handleSize : 4 + dy = isResizable() ? handleSize : 4 +
QABS( e->oldSize().height() - height() ); QABS( e->oldSize().height() - height() );
if ( dy ) if ( dy )
widget()->update( 0, height() - dy + 1, width(), dy ); widget()->update( 0, height() - dy + 1, width(), dy );
if ( dx ) { if ( dx ) {
widget()->update( width() - dx + 1, 0, dx, height() ); widget()->update( width() - dx + 1, 0, dx, height() );
widget()->update( QRect( QPoint(4,4), widget()->update( QRect( QPoint(4,4),
titlebar->geometry().bottomLeft() - QPoint(1,0) ) ); titlebar->geometry().bottomLeft() - QPoint(1,0) ) );
widget()->update( QRect( titlebar->geometry().topRight(), widget()->update( QRect( titlebar->geometry().topRight(),
QPoint( width() - 4, titlebar->geometry().bottom() ) ) ); QPoint( width() - 4, titlebar->geometry().bottom() ) ) );
widget()->update(titlebar->geometry()); widget()->update(titlebar->geometry());
} }
@ -495,24 +497,24 @@ void LaptopClient::paintEvent( QPaintEvent* )
// inner rect // inner rect
p.drawRect(r.x() + 3, r.y() + th + 3, r.width() - 6, r.height() - th - bb); p.drawRect(r.x() + 3, r.y() + th + 3, r.width() - 6, r.height() - th - bb);
// handles // handles
if (!isResizable()) { if (!isResizable()) {
} else if (r.width() > 3*handleSize + 20) { } else if (r.width() > 3*handleSize + 20) {
int range = 8 + 3*handleSize/2; int range = 8 + 3*handleSize/2;
qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs, range, qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs, range,
handleSize - 2, g, false, 1, &g.brush(QColorGroup::Mid)); handleSize - 2, g, false, 1, &g.brush(QColorGroup::Mid));
qDrawShadePanel(&p, r.x() + range + 1, r.bottom() - bs, qDrawShadePanel(&p, r.x() + range + 1, r.bottom() - bs,
r.width() - 2*range - 2, handleSize - 2, g, false, 1, r.width() - 2*range - 2, handleSize - 2, g, false, 1,
isActive() ? &g.brush(QColorGroup::Background) : isActive() ? &g.brush(QColorGroup::Background) :
&g.brush(QColorGroup::Mid)); &g.brush(QColorGroup::Mid));
qDrawShadePanel(&p, r.right() - range, r.bottom() - bs, qDrawShadePanel(&p, r.right() - range, r.bottom() - bs,
range, bs, g, false, 1, &g.brush(QColorGroup::Mid)); range, bs, g, false, 1, &g.brush(QColorGroup::Mid));
} }
else else
qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs, qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs,
r.width() - 2, bs, g, false, 1, r.width() - 2, bs, g, false, 1,
isActive() ? &g.brush(QColorGroup::Background) : isActive() ? &g.brush(QColorGroup::Background) :
&g.brush(QColorGroup::Mid)); &g.brush(QColorGroup::Mid));
r = titlebar->geometry(); r = titlebar->geometry();
@ -593,7 +595,7 @@ void LaptopClient::desktopChange()
bool on = isOnAllDesktops(); bool on = isOnAllDesktops();
button[BtnSticky]->setBitmap(on ? unsticky_bits : sticky_bits); button[BtnSticky]->setBitmap(on ? unsticky_bits : sticky_bits);
QToolTip::remove(button[BtnSticky]); QToolTip::remove(button[BtnSticky]);
QToolTip::add(button[BtnSticky], QToolTip::add(button[BtnSticky],
on ? i18n("Not On All Desktops") : i18n("On All Desktops")); on ? i18n("Not On All Desktops") : i18n("On All Desktops"));
} }
@ -603,7 +605,7 @@ void LaptopClient::maximizeChange()
button[BtnMax]->setBitmap(m ? minmax_bits : maximize_bits); button[BtnMax]->setBitmap(m ? minmax_bits : maximize_bits);
QToolTip::remove(button[BtnMax]); QToolTip::remove(button[BtnMax]);
QToolTip::add(button[BtnMax], m ? i18n("Restore") : i18n("Maximize")); QToolTip::add(button[BtnMax], m ? i18n("Restore") : i18n("Maximize"));
spacer->changeSize(10, isResizable() ? handleSize : 4, spacer->changeSize(10, isResizable() ? handleSize : 4,
QSizePolicy::Expanding, QSizePolicy::Minimum); QSizePolicy::Expanding, QSizePolicy::Minimum);
g->activate(); g->activate();
doShape(); doShape();
@ -657,7 +659,7 @@ void LaptopClient::calcHiddenButtons()
( !isTransient() || i != BtnSticky ) && ( !isTransient() || i != BtnSticky ) &&
( isMinimizable() || i != BtnIconify ) && ( isMinimizable() || i != BtnIconify ) &&
( isMaximizable() || ( i != BtnIconify && i != BtnSticky && i != BtnMax ) ) ( isMaximizable() || ( i != BtnIconify && i != BtnSticky && i != BtnMax ) )
) { ) {
button[i]->resize(button[i]->sizeHint()); button[i]->resize(button[i]->sizeHint());
button[i]->show(); button[i]->show();
@ -758,7 +760,7 @@ void LaptopClient::shadeChange()
QSize LaptopClient::minimumSize() const QSize LaptopClient::minimumSize() const
{ {
return QSize(4 * handleSize, handleSize); return QSize(4 * handleSize, handleSize);
} }
void LaptopClient::resize(const QSize& s) void LaptopClient::resize(const QSize& s)
@ -767,11 +769,11 @@ void LaptopClient::resize(const QSize& s)
widget()->repaint(); //there is some strange wrong repaint of the frame without widget()->repaint(); //there is some strange wrong repaint of the frame without
} }
static const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | static const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask |
NET::DesktopMask | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DesktopMask | NET::DockMask | NET::ToolbarMask | NET::MenuMask |
NET::DialogMask | NET::OverrideMask | NET::TopMenuMask | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask |
NET::UtilityMask | NET::SplashMask; NET::UtilityMask | NET::SplashMask;
bool LaptopClient::isTransient() const bool LaptopClient::isTransient() const
{ {
NET::WindowType type = windowType(SUPPORTED_WINDOW_TYPES_MASK); NET::WindowType type = windowType(SUPPORTED_WINDOW_TYPES_MASK);
@ -829,7 +831,7 @@ KDecoration *LaptopClientFactory::createDecoration(KDecorationBridge *b)
} }
bool LaptopClientFactory::reset(unsigned long /*changed*/) bool LaptopClientFactory::reset(unsigned long /*changed*/)
{ {
findPreferredHandleSize(); findPreferredHandleSize();
// TODO Do not recreate decorations if it is not needed. Look at // TODO Do not recreate decorations if it is not needed. Look at
@ -840,11 +842,11 @@ bool LaptopClientFactory::reset(unsigned long /*changed*/)
return true; return true;
} }
QValueList< LaptopClientFactory::BorderSize > QValueList< LaptopClientFactory::BorderSize >
LaptopClientFactory::borderSizes() const LaptopClientFactory::borderSizes() const
{ {
// the list must be sorted // the list must be sorted
return QValueList< BorderSize >() << BorderNormal << BorderLarge << return QValueList< BorderSize >() << BorderNormal << BorderLarge <<
BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized; BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
} }

View File

@ -25,7 +25,7 @@ class LaptopButton : public QButton
{ {
public: public:
LaptopButton(int w, int h, LaptopClient *parent=0, const char *name=0, LaptopButton(int w, int h, LaptopClient *parent=0, const char *name=0,
const unsigned char *bitmap=NULL, const QString& tip=NULL); const unsigned char *bitmap=NULL, const QString& tip=NULL, const int realizeBtns = LeftButton);
void setBitmap(const unsigned char *bitmap); void setBitmap(const unsigned char *bitmap);
void reset(); void reset();
QSize sizeHint() const; QSize sizeHint() const;
@ -35,13 +35,13 @@ protected:
void mousePressEvent( QMouseEvent* e ) void mousePressEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); QMouseEvent me ( e->type(), e->pos(), e->globalPos(), (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mousePressEvent( &me ); QButton::mousePressEvent( &me );
} }
void mouseReleaseEvent( QMouseEvent* e ) void mouseReleaseEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); QMouseEvent me ( e->type(), e->pos(), e->globalPos(), (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mouseReleaseEvent( &me ); QButton::mouseReleaseEvent( &me );
} }
virtual void drawButton(QPainter *p); virtual void drawButton(QPainter *p);
@ -49,6 +49,7 @@ protected:
LaptopClient *client; LaptopClient *client;
QSize defaultSize; QSize defaultSize;
QBitmap deco; QBitmap deco;
int realizeButtons;
}; };
class LaptopClient : public KDecoration class LaptopClient : public KDecoration

View File

@ -247,7 +247,7 @@ bool ModernSysFactory::read_config()
theight = 16; theight = 16;
if (theight < bwidth) if (theight < bwidth)
theight = bwidth; theight = bwidth;
if (options()->customButtonPositions()) { if (options()->customButtonPositions()) {
bpatt = "2" + options()->titleButtonsLeft() + "3t3" bpatt = "2" + options()->titleButtonsLeft() + "3t3"
+ options()->titleButtonsRight() + "2"; + options()->titleButtonsRight() + "2";
@ -259,7 +259,7 @@ bool ModernSysFactory::read_config()
&& bwidth == border_width && theight == title_height && bwidth == border_width && theight == title_height
&& bpatt == *button_pattern) && bpatt == *button_pattern)
return false; return false;
show_handle = showh; show_handle = showh;
handle_width = hwidth; handle_width = hwidth;
handle_size = hsize; handle_size = hsize;
@ -278,11 +278,12 @@ QValueList< ModernSysFactory::BorderSize > ModernSysFactory::borderSizes() const
} }
ModernButton::ModernButton(ModernSys *parent, const char *name, ModernButton::ModernButton(ModernSys *parent, const char *name,
const unsigned char *bitmap, const QString& tip) const unsigned char *bitmap, const QString& tip, const int realizeBtns)
: QButton(parent->widget(), name) : QButton(parent->widget(), name)
{ {
setBackgroundMode( NoBackground ); setBackgroundMode( NoBackground );
setCursor( arrowCursor ); setCursor( arrowCursor );
realizeButtons = realizeBtns;
QBitmap mask(14, 15, QPixmap::defaultDepth() > 8 ? QBitmap mask(14, 15, QPixmap::defaultDepth() > 8 ?
btnhighcolor_mask_bits : lowcolor_mask_bits, true); btnhighcolor_mask_bits : lowcolor_mask_bits, true);
resize(14, 15); resize(14, 15);
@ -293,7 +294,7 @@ ModernButton::ModernButton(ModernSys *parent, const char *name,
hide(); hide();
client = parent; client = parent;
QToolTip::add( this, tip ); QToolTip::add( this, tip );
} }
QSize ModernButton::sizeHint() const QSize ModernButton::sizeHint() const
@ -332,13 +333,13 @@ void ModernButton::drawButton(QPainter *p)
void ModernButton::mousePressEvent( QMouseEvent* e ) void ModernButton::mousePressEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); QMouseEvent me ( e->type(), e->pos(), e->globalPos(), (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mousePressEvent( &me ); QButton::mousePressEvent( &me );
} }
void ModernButton::mouseReleaseEvent( QMouseEvent* e ) void ModernButton::mouseReleaseEvent( QMouseEvent* e )
{ {
QMouseEvent me ( e->type(), e->pos(), e->globalPos(), LeftButton, e->state() ); QMouseEvent me ( e->type(), e->pos(), e->globalPos(), (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mouseReleaseEvent( &me ); QButton::mouseReleaseEvent( &me );
} }
@ -385,7 +386,7 @@ void ModernSys::init()
button[BtnClose] = new ModernButton(this, "close", close_bits, i18n("Close")); button[BtnClose] = new ModernButton(this, "close", close_bits, i18n("Close"));
button[BtnSticky] = new ModernButton(this, "sticky", NULL, i18n("Sticky")); button[BtnSticky] = new ModernButton(this, "sticky", NULL, i18n("Sticky"));
button[BtnMinimize] = new ModernButton(this, "iconify", iconify_bits, i18n("Minimize")); button[BtnMinimize] = new ModernButton(this, "iconify", iconify_bits, i18n("Minimize"));
button[BtnMaximize] = new ModernButton(this, "maximize", maximize_bits, i18n("Maximize")); button[BtnMaximize] = new ModernButton(this, "maximize", maximize_bits, i18n("Maximize"), LeftButton|MidButton|RightButton);
button[BtnHelp] = new ModernButton(this, "help", question_bits, i18n("Help")); button[BtnHelp] = new ModernButton(this, "help", question_bits, i18n("Help"));
connect( button[BtnClose], SIGNAL(clicked()), this, SLOT( closeWindow() ) ); connect( button[BtnClose], SIGNAL(clicked()), this, SLOT( closeWindow() ) );

View File

@ -22,7 +22,7 @@ class ModernButton : public QButton
public: public:
ModernButton( ModernSys *parent=0, const char *name=0, ModernButton( ModernSys *parent=0, const char *name=0,
const unsigned char *bitmap=NULL, const unsigned char *bitmap=NULL,
const QString& tip=NULL); const QString& tip=NULL, const int realizeBtns = LeftButton);
void setBitmap(const unsigned char *bitmap); void setBitmap(const unsigned char *bitmap);
void reset(); void reset();
QSize sizeHint() const; QSize sizeHint() const;
@ -34,6 +34,8 @@ protected:
void drawButtonLabel(QPainter *){;} void drawButtonLabel(QPainter *){;}
QBitmap deco; QBitmap deco;
ModernSys* client; ModernSys* client;
int realizeButtons;
public: public:
int last_button; int last_button;
}; };

View File

@ -160,7 +160,7 @@ void QuartzHandler::readConfig()
// A small hack to make the on all desktops button look nicer // A small hack to make the on all desktops button look nicer
onAllDesktopsButtonOnLeft = KDecoration::options()->titleButtonsLeft().contains( 'S' ); onAllDesktopsButtonOnLeft = KDecoration::options()->titleButtonsLeft().contains( 'S' );
switch(options()->preferredBorderSize(this)) { switch(options()->preferredBorderSize(this)) {
case BorderLarge: case BorderLarge:
borderWidth = 8; borderWidth = 8;
@ -186,7 +186,7 @@ void QuartzHandler::readConfig()
normalTitleHeight = QFontMetrics(options()->font(true)).height(); normalTitleHeight = QFontMetrics(options()->font(true)).height();
if (normalTitleHeight < 18) normalTitleHeight = 18; if (normalTitleHeight < 18) normalTitleHeight = 18;
if (normalTitleHeight < borderWidth) normalTitleHeight = borderWidth; if (normalTitleHeight < borderWidth) normalTitleHeight = borderWidth;
toolTitleHeight = QFontMetrics(options()->font(true, true)).height(); toolTitleHeight = QFontMetrics(options()->font(true, true)).height();
if (toolTitleHeight < 12) toolTitleHeight = 12; if (toolTitleHeight < 12) toolTitleHeight = 12;
if (toolTitleHeight < borderWidth) toolTitleHeight = borderWidth; if (toolTitleHeight < borderWidth) toolTitleHeight = borderWidth;
@ -203,10 +203,10 @@ void QuartzHandler::drawBlocks( KPixmap *pi, KPixmap &p, const QColor &c1, const
// Draw a background gradient first // Draw a background gradient first
KPixmapEffect::gradient(p, c1, c2, KPixmapEffect::HorizontalGradient); KPixmapEffect::gradient(p, c1, c2, KPixmapEffect::HorizontalGradient);
int factor = (pi->height()-2)/4; int factor = (pi->height()-2)/4;
int square = factor - (factor+2)/4; int square = factor - (factor+2)/4;
int x = pi->width() - 5*factor - square; int x = pi->width() - 5*factor - square;
int y = (pi->height() - 4*factor)/2; int y = (pi->height() - 4*factor)/2;
@ -335,7 +335,7 @@ QValueList< QuartzHandler::BorderSize > QuartzHandler::borderSizes() const
QuartzButton::QuartzButton(QuartzClient *parent, const char *name, bool largeButton, QuartzButton::QuartzButton(QuartzClient *parent, const char *name, bool largeButton,
bool isLeftButton, bool isOnAllDesktopsButton, const unsigned char *bitmap, bool isLeftButton, bool isOnAllDesktopsButton, const unsigned char *bitmap,
const QString& tip) const QString& tip, const int realizeBtns)
: QButton(parent->widget(), name) : QButton(parent->widget(), name)
{ {
setTipText(tip); setTipText(tip);
@ -345,6 +345,8 @@ QuartzButton::QuartzButton(QuartzClient *parent, const char *name, bool largeBut
setBackgroundMode( QWidget::NoBackground ); setBackgroundMode( QWidget::NoBackground );
setToggleButton( isOnAllDesktopsButton ); setToggleButton( isOnAllDesktopsButton );
realizeButtons = realizeBtns;
deco = NULL; deco = NULL;
large = largeButton; large = largeButton;
isLeft = isLeftButton; isLeft = isLeftButton;
@ -469,7 +471,7 @@ void QuartzButton::mousePressEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me( e->type(), e->pos(), e->globalPos(), QMouseEvent me( e->type(), e->pos(), e->globalPos(),
LeftButton, e->state() ); (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mousePressEvent( &me ); QButton::mousePressEvent( &me );
} }
@ -478,7 +480,7 @@ void QuartzButton::mouseReleaseEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me( e->type(), e->pos(), e->globalPos(), QMouseEvent me( e->type(), e->pos(), e->globalPos(),
LeftButton, e->state() ); (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mouseReleaseEvent( &me ); QButton::mouseReleaseEvent( &me );
} }
@ -578,7 +580,7 @@ void QuartzClient::addClientButtons( const QString& s, bool isLeft )
if (!button[BtnMenu]) if (!button[BtnMenu])
{ {
button[BtnMenu] = new QuartzButton(this, "menu", button[BtnMenu] = new QuartzButton(this, "menu",
largeButtons, isLeft, false, NULL, i18n("Menu")); largeButtons, isLeft, false, NULL, i18n("Menu"), LeftButton|RightButton);
connect( button[BtnMenu], SIGNAL(pressed()), connect( button[BtnMenu], SIGNAL(pressed()),
this, SLOT(menuButtonPressed()) ); this, SLOT(menuButtonPressed()) );
hb->addWidget( button[BtnMenu] ); hb->addWidget( button[BtnMenu] );
@ -629,7 +631,7 @@ void QuartzClient::addClientButtons( const QString& s, bool isLeft )
if ( (!button[BtnMax]) && isMaximizable()) if ( (!button[BtnMax]) && isMaximizable())
{ {
button[BtnMax] = new QuartzButton(this, "maximize", button[BtnMax] = new QuartzButton(this, "maximize",
largeButtons, isLeft, true, maximize_bits, i18n("Maximize")); largeButtons, isLeft, true, maximize_bits, i18n("Maximize"), LeftButton|MidButton|RightButton);
connect( button[BtnMax], SIGNAL( clicked()), connect( button[BtnMax], SIGNAL( clicked()),
this, SLOT(slotMaximize()) ); this, SLOT(slotMaximize()) );
hb->addWidget( button[BtnMax] ); hb->addWidget( button[BtnMax] );

View File

@ -54,7 +54,7 @@ class QuartzButton : public QButton
public: public:
QuartzButton(QuartzClient *parent=0, const char *name=0, bool largeButton=true, QuartzButton(QuartzClient *parent=0, const char *name=0, bool largeButton=true,
bool isLeftButton=true, bool isOnAllDesktopsButton=false, bool isLeftButton=true, bool isOnAllDesktopsButton=false,
const unsigned char *bitmap=NULL, const QString& tip=NULL); const unsigned char *bitmap=NULL, const QString& tip=NULL, const int realizeBtns = LeftButton);
~QuartzButton(); ~QuartzButton();
void setBitmap(const unsigned char *bitmap); void setBitmap(const unsigned char *bitmap);
void setTipText(const QString &tip); void setTipText(const QString &tip);
@ -73,6 +73,8 @@ class QuartzButton : public QButton
bool isLeft; bool isLeft;
bool isOnAllDesktops; bool isOnAllDesktops;
QuartzClient* client; QuartzClient* client;
int realizeButtons;
}; };

View File

@ -13,7 +13,7 @@
* *
*/ */
#include "redmond.h" #include "redmond.h"
#include <qlayout.h> #include <qlayout.h>
#include <qdrawutil.h> #include <qdrawutil.h>
@ -81,12 +81,12 @@ static unsigned char question_bits[] = {
// Up / Down titlebar button images // Up / Down titlebar button images
static KPixmap *btnPix1; static KPixmap *btnPix1;
static KPixmap *iBtnPix1; static KPixmap *iBtnPix1;
static KPixmap *btnDownPix1; static KPixmap *btnDownPix1;
static KPixmap *iBtnDownPix1; static KPixmap *iBtnDownPix1;
static KPixmap *miniBtnPix1; static KPixmap *miniBtnPix1;
static KPixmap *iMiniBtnPix1; static KPixmap *iMiniBtnPix1;
static KPixmap *miniBtnDownPix1; static KPixmap *miniBtnDownPix1;
static KPixmap *iMiniBtnDownPix1; static KPixmap *iMiniBtnDownPix1;
@ -200,13 +200,13 @@ static void create_pixmaps ()
iMiniBtnDownPix1->fill(c.rgb()); iMiniBtnDownPix1->fill(c.rgb());
} }
g = options()->colorGroup(KDecoration::ColorButtonBg, true); g = options()->colorGroup(KDecoration::ColorButtonBg, true);
drawButtonFrame(btnPix1, g, false); drawButtonFrame(btnPix1, g, false);
drawButtonFrame(btnDownPix1, g, true); drawButtonFrame(btnDownPix1, g, true);
drawButtonFrame(miniBtnPix1, g, false); drawButtonFrame(miniBtnPix1, g, false);
drawButtonFrame(miniBtnDownPix1, g, true); drawButtonFrame(miniBtnDownPix1, g, true);
g = options()->colorGroup(KDecoration::ColorButtonBg, false); g = options()->colorGroup(KDecoration::ColorButtonBg, false);
drawButtonFrame(iBtnPix1, g, false); drawButtonFrame(iBtnPix1, g, false);
drawButtonFrame(iBtnDownPix1, g, true); drawButtonFrame(iBtnDownPix1, g, true);
drawButtonFrame(iMiniBtnPix1, g, false); drawButtonFrame(iMiniBtnPix1, g, false);
@ -230,23 +230,24 @@ void delete_pixmaps()
delete iMiniBtnPix1; delete iMiniBtnPix1;
delete iMiniBtnDownPix1; delete iMiniBtnDownPix1;
delete defaultMenuPix; delete defaultMenuPix;
delete btnForeground; delete btnForeground;
pixmaps_created = false; pixmaps_created = false;
} }
RedmondButton::RedmondButton(RedmondDeco *parent, const char *name, RedmondButton::RedmondButton(RedmondDeco *parent, const char *name,
const unsigned char *bitmap, bool menuButton, bool isMini, int size, const QString& tip) const unsigned char *bitmap, bool menuButton, bool isMini, int size, const QString& tip, const int realizeBtns)
: QButton(parent->widget(), name) : QButton(parent->widget(), name)
{ {
// Eliminate background flicker // Eliminate background flicker
setBackgroundMode( NoBackground ); setBackgroundMode( NoBackground );
setCursor( arrowCursor ); setCursor( arrowCursor );
menuBtn = menuButton; menuBtn = menuButton;
miniBtn = isMini; miniBtn = isMini;
client = parent; client = parent;
this->size = size; this->size = size;
realizeButtons = realizeBtns;
// Use larger button for the menu, or mini-buttons for toolwindows. // Use larger button for the menu, or mini-buttons for toolwindows.
if ( isMini || menuButton ) { if ( isMini || menuButton ) {
@ -285,7 +286,7 @@ void RedmondButton::setBitmap(const unsigned char *bitmap)
pix.resize(0, 0); pix.resize(0, 0);
deco = QBitmap(10, 10, bitmap, true); deco = QBitmap(10, 10, bitmap, true);
deco.setMask(deco); deco.setMask(deco);
repaint( false ); repaint( false );
} }
@ -307,7 +308,7 @@ void RedmondButton::mousePressEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me(e->type(), e->pos(), e->globalPos(), QMouseEvent me(e->type(), e->pos(), e->globalPos(),
LeftButton, e->state()); (e->button()&realizeButtons)?LeftButton:NoButton, e->state());
QButton::mousePressEvent( &me ); QButton::mousePressEvent( &me );
} }
@ -316,7 +317,7 @@ void RedmondButton::mouseReleaseEvent( QMouseEvent* e )
{ {
last_button = e->button(); last_button = e->button();
QMouseEvent me ( e->type(), e->pos(), e->globalPos(), QMouseEvent me ( e->type(), e->pos(), e->globalPos(),
LeftButton, e->state() ); (e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mouseReleaseEvent( &me ); QButton::mouseReleaseEvent( &me );
} }
@ -345,13 +346,13 @@ void RedmondButton::drawButton(QPainter *p)
options()->color(KDecoration::ColorTitleBar, client->isActive())); options()->color(KDecoration::ColorTitleBar, client->isActive()));
if ( menuBtn && size < 16) { if ( menuBtn && size < 16) {
QPixmap tmpPix; QPixmap tmpPix;
// Smooth scale the menu button pixmap // Smooth scale the menu button pixmap
tmpPix.convertFromImage( tmpPix.convertFromImage(
pix.convertToImage().smoothScale(size, size)); pix.convertToImage().smoothScale(size, size));
p->drawPixmap( 0, 0, tmpPix ); p->drawPixmap( 0, 0, tmpPix );
} else { } else {
int xOff = (width() -pix.width() )/2; int xOff = (width() -pix.width() )/2;
int yOff = (height()-pix.height())/2; int yOff = (height()-pix.height())/2;
@ -393,7 +394,7 @@ void RedmondDeco::init()
g->addItem(new QSpacerItem( 0, 0 ), 3, 1); // no widget in the middle g->addItem(new QSpacerItem( 0, 0 ), 3, 1); // no widget in the middle
} }
g->addRowSpacing(0, borderWidth); // Top grab bar g->addRowSpacing(0, borderWidth); // Top grab bar
// without the next line, unshade flickers // without the next line, unshade flickers
g->addItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding)); g->addItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding));
g->setRowStretch(3, 10); // Wrapped window g->setRowStretch(3, 10); // Wrapped window
@ -402,10 +403,10 @@ void RedmondDeco::init()
g->addColSpacing(0, borderWidth); g->addColSpacing(0, borderWidth);
g->addColSpacing(2, borderWidth); g->addColSpacing(2, borderWidth);
button[BtnMenu] = new RedmondButton(this, "menu", NULL, true, smallButtons, titleHeight-2, i18n("Menu")); button[BtnMenu] = new RedmondButton(this, "menu", NULL, true, smallButtons, titleHeight-2, i18n("Menu"), LeftButton|RightButton);
button[BtnClose] = new RedmondButton(this, "close", close_bits, false, smallButtons, titleHeight-2, i18n("Close")); button[BtnClose] = new RedmondButton(this, "close", close_bits, false, smallButtons, titleHeight-2, i18n("Close"));
button[BtnMin] = new RedmondButton(this, "iconify", iconify_bits, false, smallButtons, titleHeight-2, i18n("Minimize")); button[BtnMin] = new RedmondButton(this, "iconify", iconify_bits, false, smallButtons, titleHeight-2, i18n("Minimize"));
button[BtnMax] = new RedmondButton(this, "maximize", maximize_bits, false, smallButtons, titleHeight-2, i18n("Maximize")); button[BtnMax] = new RedmondButton(this, "maximize", maximize_bits, false, smallButtons, titleHeight-2, i18n("Maximize"), LeftButton|MidButton|RightButton);
// Connect required stuff together // Connect required stuff together
connect(button[BtnMenu], SIGNAL(pressed()), this, SLOT(menuButtonPressed())); connect(button[BtnMenu], SIGNAL(pressed()), this, SLOT(menuButtonPressed()));
@ -417,7 +418,7 @@ void RedmondDeco::init()
hb = new QBoxLayout(0, QBoxLayout::LeftToRight, 0, 0, 0); hb = new QBoxLayout(0, QBoxLayout::LeftToRight, 0, 0, 0);
hb->setResizeMode(QLayout::FreeResize); hb->setResizeMode(QLayout::FreeResize);
hb->addSpacing(2); hb->addSpacing(2);
hb->addWidget(button[BtnMenu]); hb->addWidget(button[BtnMenu]);
titlebar = new QSpacerItem(10, titleHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); titlebar = new QSpacerItem(10, titleHeight, QSizePolicy::Expanding, QSizePolicy::Minimum);
hb->addItem(titlebar); hb->addItem(titlebar);
hb->addSpacing(borderWidth/2); hb->addSpacing(borderWidth/2);
@ -464,7 +465,7 @@ void RedmondDeco::slotReset()
// The menu is reset by iconChange() // The menu is reset by iconChange()
widget()->repaint( false ); widget()->repaint( false );
} }
@ -511,7 +512,7 @@ void RedmondDeco::resizeEvent(QResizeEvent *)
if ( dy ) if ( dy )
update( 0, height() - dy + 1, width(), dy ); update( 0, height() - dy + 1, width(), dy );
if ( dx ) if ( dx )
{ {
update( width() - dx + 1, 0, dx, height() ); update( width() - dx + 1, 0, dx, height() );
update( QRect( QPoint(4,4), titlebar->geometry().bottomLeft() - QPoint(1,0) ) ); update( QRect( QPoint(4,4), titlebar->geometry().bottomLeft() - QPoint(1,0) ) );
@ -519,7 +520,7 @@ void RedmondDeco::resizeEvent(QResizeEvent *)
// Titlebar needs no paint event // Titlebar needs no paint event
QApplication::postEvent( this, new QPaintEvent( titlebar->geometry(), FALSE ) ); QApplication::postEvent( this, new QPaintEvent( titlebar->geometry(), FALSE ) );
} }
} }
*/ */
} }
@ -552,7 +553,7 @@ void RedmondDeco::paintEvent( QPaintEvent* )
p.setPen( g.background() ); p.setPen( g.background() );
p.drawLine( x, y, x2-1, y ); p.drawLine( x, y, x2-1, y );
p.drawLine( x, y, x, y2-1 ); p.drawLine( x, y, x, y2-1 );
// Draw line under title bar // Draw line under title bar
p.drawLine( x+borderWidth, y+titleHeight+borderWidth, x2-borderWidth, y+titleHeight+borderWidth ); p.drawLine( x+borderWidth, y+titleHeight+borderWidth, x2-borderWidth, y+titleHeight+borderWidth );
// Draw a hidden line that appears during shading // Draw a hidden line that appears during shading
@ -612,14 +613,14 @@ void RedmondDeco::paintEvent( QPaintEvent* )
QPainter p2( titleBuffer, this ); QPainter p2( titleBuffer, this );
// Since drawing the gradient is (relatively) slow, it is best // Since drawing the gradient is (relatively) slow, it is best
// to draw the title text on the pixmap. // to draw the title text on the pixmap.
// Reduce the font size and weight for toolwindows. // Reduce the font size and weight for toolwindows.
QFont fnt = options()->font(true); QFont fnt = options()->font(true);
if ( smallButtons ) { if ( smallButtons ) {
fnt.setPointSize( fnt.pointSize() - 2 ); // Shrink font by 2 pt. fnt.setPointSize( fnt.pointSize() - 2 ); // Shrink font by 2 pt.
fnt.setWeight( QFont::Normal ); fnt.setWeight( QFont::Normal );
fontoffset = 0; fontoffset = 0;
} }
p2.setFont( fnt ); p2.setFont( fnt );
@ -630,19 +631,19 @@ void RedmondDeco::paintEvent( QPaintEvent* )
p.drawPixmap( borderWidth, borderWidth, *titleBuffer ); p.drawPixmap( borderWidth, borderWidth, *titleBuffer );
delete titleBuffer; delete titleBuffer;
} else { } else {
// Assume lower ended hardware, so don't use buffers. // Assume lower ended hardware, so don't use buffers.
// Don't draw a gradient either. // Don't draw a gradient either.
p.fillRect( borderWidth, borderWidth, w-2*borderWidth, titleHeight, c1 ); p.fillRect( borderWidth, borderWidth, w-2*borderWidth, titleHeight, c1 );
// Draw the title text. // Draw the title text.
QFont fnt = options()->font(true); QFont fnt = options()->font(true);
if ( smallButtons ) if ( smallButtons )
{ {
fnt.setPointSize( fnt.pointSize() - 2 ); // Shrink font by 2 pt. fnt.setPointSize( fnt.pointSize() - 2 ); // Shrink font by 2 pt.
fnt.setWeight( QFont::Normal ); fnt.setWeight( QFont::Normal );
fontoffset = 0; fontoffset = 0;
} }
p.setFont( fnt ); p.setFont( fnt );
@ -655,7 +656,7 @@ void RedmondDeco::paintEvent( QPaintEvent* )
void RedmondDeco::showEvent(QShowEvent *) void RedmondDeco::showEvent(QShowEvent *)
{ {
calcHiddenButtons(); calcHiddenButtons();
widget()->show(); widget()->show();
} }
@ -774,7 +775,7 @@ void RedmondDeco::activeChange()
QPixmap *miniIcon = new QPixmap(icon().pixmap(QIconSet::Small, QIconSet::Normal)); QPixmap *miniIcon = new QPixmap(icon().pixmap(QIconSet::Small, QIconSet::Normal));
if (!miniIcon->isNull()) { if (!miniIcon->isNull()) {
button[BtnMenu]->setPixmap(*miniIcon); button[BtnMenu]->setPixmap(*miniIcon);
} else { } else {
button[BtnMenu]->setPixmap(kdelogo); button[BtnMenu]->setPixmap(kdelogo);
} }
@ -817,7 +818,7 @@ void RedmondDeco::menuButtonPressed()
lastClient = this; lastClient = this;
t->start(); t->start();
if (!dbl) { if (!dbl) {
QPoint menupoint(button[BtnMenu]->rect().bottomLeft().x()-3, QPoint menupoint(button[BtnMenu]->rect().bottomLeft().x()-3,
button[BtnMenu]->rect().bottomLeft().y()+4); button[BtnMenu]->rect().bottomLeft().y()+4);
KDecorationFactory* f = factory(); KDecorationFactory* f = factory();
showWindowMenu(button[BtnMenu]->mapToGlobal(menupoint)); showWindowMenu(button[BtnMenu]->mapToGlobal(menupoint));
@ -943,5 +944,5 @@ extern "C" KDecorationFactory *create_factory()
} }
#include "redmond.moc" #include "redmond.moc"
// vim: ts=4 // vim: ts=4

View File

@ -38,10 +38,10 @@ class RedmondButton : public QButton
{ {
Q_OBJECT Q_OBJECT
public: public:
RedmondButton(RedmondDeco *parent=0, const char *name=0, RedmondButton(RedmondDeco *parent=0, const char *name=0,
const unsigned char *bitmap=NULL, const unsigned char *bitmap=NULL,
bool menuButton=false, bool isMini=false, int size = 16, bool menuButton=false, bool isMini=false, int size = 16,
const QString& tip=NULL); const QString& tip=NULL, const int realizeBtns = LeftButton);
void setBitmap(const unsigned char *bitmap); void setBitmap(const unsigned char *bitmap);
void setPixmap(const QPixmap &p); void setPixmap(const QPixmap &p);
void reset(); void reset();
@ -61,6 +61,8 @@ protected:
bool miniBtn; bool miniBtn;
RedmondDeco *client; RedmondDeco *client;
int size; int size;
int realizeButtons;
}; };