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

View File

@ -1,10 +1,10 @@
/*
/*
* B-II KWin Client
*
* Changes:
* Customizable button positions by Karol Szwed <gallium@kde.org>
* Ported to the kde3.2 API by Luciano Montanaro <mikelima@virgilio.it>
*/
*/
#ifndef __B2CLIENT_H
#define __B2CLIENT_H
@ -27,7 +27,7 @@ class B2Client;
class B2Button : public QButton
{
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() {};
void setBg(const QColor &c){bg = c;}
@ -42,17 +42,18 @@ public:
protected:
virtual void drawButton(QPainter *p);
void drawButtonLabel(QPainter *){;}
bool useMiniIcon;
KPixmap *pNorm, *pDown, *iNorm, *iDown;
QColor bg; //only use one color (the rest is pixmap) so forget QPalette ;)
void mousePressEvent( QMouseEvent* e );
void mouseReleaseEvent( QMouseEvent* e );
public:
B2Client* client;
int last_button;
int last_button;
int realizeButtons;
};
class B2Titlebar : public QWidget
@ -74,7 +75,7 @@ protected:
void resizeEvent(QResizeEvent *ev);
private:
void drawTitlebar(QPainter &p, bool state);
B2Client *client;
QString oldTitle;
KPixmap titleBuffer;
@ -119,7 +120,7 @@ private slots:
//void slotReset();
void maxButtonClicked();
private:
void addButtons(const QString& s, const QString tips[],
void addButtons(const QString& s, const QString tips[],
B2Titlebar* tb, QBoxLayout* titleLayout);
void positionButtons();
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_toolTitleHeight < 12) new_toolTitleHeight = 12;
if (new_toolTitleHeight < new_borderWidth) new_toolTitleHeight = new_borderWidth;
if( update )
{
if( new_showGrabBar != showGrabBar
@ -218,7 +218,7 @@ unsigned long KDEDefaultHandler::readConfig( bool update )
|| new_toolTitleHeight != toolTitleHeight )
changed |= SettingColors; // just recreate the pixmaps and repaint
}
showGrabBar = new_showGrabBar;
showTitleBarStipple = new_showTitleBarStipple;
useGradients = new_useGradients;
@ -515,9 +515,11 @@ QValueList< KDEDefaultHandler::BorderSize > KDEDefaultHandler::borderSizes() con
KDEDefaultButton::KDEDefaultButton(KDEDefaultClient *parent, const char *name,
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)
{
realizeButtons = realizeBtns;
QToolTip::add( this, tip );
setCursor( arrowCursor );
setBackgroundMode( QWidget::NoBackground );
@ -685,7 +687,7 @@ void KDEDefaultButton::mousePressEvent( QMouseEvent* e )
{
last_button = e->button();
QMouseEvent me( e->type(), e->pos(), e->globalPos(),
LeftButton, e->state() );
(e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mousePressEvent( &me );
}
@ -694,7 +696,7 @@ void KDEDefaultButton::mouseReleaseEvent( QMouseEvent* e )
{
last_button = e->button();
QMouseEvent me( e->type(), e->pos(), e->globalPos(),
LeftButton, e->state() );
(e->button()&realizeButtons)?LeftButton:NoButton, e->state() );
QButton::mouseReleaseEvent( &me );
}
@ -745,8 +747,8 @@ void KDEDefaultClient::init()
g->setRowStretch(3, 10); // Wrapped window
// Determine the size of the lower grab bar
spacer = new QSpacerItem(10,
showGrabBar && isResizable() ? grabBorderWidth : borderWidth,
spacer = new QSpacerItem(10,
showGrabBar && isResizable() ? grabBorderWidth : borderWidth,
QSizePolicy::Expanding, QSizePolicy::Minimum);
g->addItem(spacer, 4, 1);
@ -778,7 +780,7 @@ void KDEDefaultClient::addClientButtons( const QString& s, bool isLeft )
if (!button[BtnMenu])
{
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()),
this, SLOT(menuButtonPressed()) );
connect( button[BtnMenu], SIGNAL(released()),
@ -832,7 +834,7 @@ void KDEDefaultClient::addClientButtons( const QString& s, bool isLeft )
{
button[BtnMax] = new KDEDefaultButton(this, "maximize",
largeButtons, isLeft, true, maximize_bits,
i18n("Maximize"));
i18n("Maximize"), LeftButton|MidButton|RightButton);
connect( button[BtnMax], SIGNAL( clicked()),
this, SLOT(slotMaximize()) );
hb->addWidget( button[BtnMax] );
@ -1095,7 +1097,7 @@ void KDEDefaultClient::paintEvent( QPaintEvent* )
p2.end();
// Ensure a shaded window has no unpainted areas
// Is this still needed?
// Is this still needed?
#if 1
p.setPen(c2);
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;
int bottomSize = (showGrabBar && isResizable()) ? grabBorderWidth : borderWidth;
const int range = 14 + 3*borderWidth/2;
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,
bool largeButton=true, bool isLeftButton=true,
bool isStickyButton=false, const unsigned char *bitmap=NULL,
const QString& tip=NULL);
const QString& tip=NULL, const int realizeBtns = LeftButton);
~KDEDefaultButton();
int last_button;
@ -75,6 +75,8 @@ class KDEDefaultButton : public QButton, public KDecorationDefines
bool isSticky;
bool isMouseOver;
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 ),
client( c ), button( btn ), hover( false ), lastbutton( 0 )
{
realizeButtons = realizeBtns;
QToolTip::add( this, tip ); // FRAME
setBackgroundMode( NoBackground );
setCursor( arrowCursor );
@ -726,7 +728,7 @@ void KeramikButton::leaveEvent( QEvent *e )
void KeramikButton::mousePressEvent( QMouseEvent *e )
{
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 );
}
@ -734,7 +736,7 @@ void KeramikButton::mousePressEvent( QMouseEvent *e )
void KeramikButton::mouseReleaseEvent( QMouseEvent *e )
{
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 );
}
@ -945,7 +947,7 @@ void KeramikClient::addButtons( QBoxLayout *layout, const QString &s )
// Menu button
case 'M' :
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() ) );
layout->addWidget( button[MenuButton] );
}
@ -982,7 +984,7 @@ void KeramikClient::addButtons( QBoxLayout *layout, const QString &s )
// Maximize button
case 'A' :
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() ) );
layout->addWidget( button[MaxButton] );
}

View File

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

View File

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

View File

@ -25,7 +25,7 @@ class LaptopButton : public QButton
{
public:
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 reset();
QSize sizeHint() const;
@ -35,13 +35,13 @@ protected:
void mousePressEvent( QMouseEvent* e )
{
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 );
}
void mouseReleaseEvent( QMouseEvent* e )
{
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 );
}
virtual void drawButton(QPainter *p);
@ -49,6 +49,7 @@ protected:
LaptopClient *client;
QSize defaultSize;
QBitmap deco;
int realizeButtons;
};
class LaptopClient : public KDecoration

View File

@ -247,7 +247,7 @@ bool ModernSysFactory::read_config()
theight = 16;
if (theight < bwidth)
theight = bwidth;
if (options()->customButtonPositions()) {
bpatt = "2" + options()->titleButtonsLeft() + "3t3"
+ options()->titleButtonsRight() + "2";
@ -259,7 +259,7 @@ bool ModernSysFactory::read_config()
&& bwidth == border_width && theight == title_height
&& bpatt == *button_pattern)
return false;
show_handle = showh;
handle_width = hwidth;
handle_size = hsize;
@ -278,11 +278,12 @@ QValueList< ModernSysFactory::BorderSize > ModernSysFactory::borderSizes() const
}
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)
{
setBackgroundMode( NoBackground );
setCursor( arrowCursor );
realizeButtons = realizeBtns;
QBitmap mask(14, 15, QPixmap::defaultDepth() > 8 ?
btnhighcolor_mask_bits : lowcolor_mask_bits, true);
resize(14, 15);
@ -293,7 +294,7 @@ ModernButton::ModernButton(ModernSys *parent, const char *name,
hide();
client = parent;
QToolTip::add( this, tip );
}
QSize ModernButton::sizeHint() const
@ -332,13 +333,13 @@ void ModernButton::drawButton(QPainter *p)
void ModernButton::mousePressEvent( QMouseEvent* e )
{
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 );
}
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 );
}
@ -385,7 +386,7 @@ void ModernSys::init()
button[BtnClose] = new ModernButton(this, "close", close_bits, i18n("Close"));
button[BtnSticky] = new ModernButton(this, "sticky", NULL, i18n("Sticky"));
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"));
connect( button[BtnClose], SIGNAL(clicked()), this, SLOT( closeWindow() ) );

View File

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

View File

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

View File

@ -54,7 +54,7 @@ class QuartzButton : public QButton
public:
QuartzButton(QuartzClient *parent=0, const char *name=0, bool largeButton=true,
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();
void setBitmap(const unsigned char *bitmap);
void setTipText(const QString &tip);
@ -73,6 +73,8 @@ class QuartzButton : public QButton
bool isLeft;
bool isOnAllDesktops;
QuartzClient* client;
int realizeButtons;
};

View File

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

View File

@ -38,10 +38,10 @@ class RedmondButton : public QButton
{
Q_OBJECT
public:
RedmondButton(RedmondDeco *parent=0, const char *name=0,
RedmondButton(RedmondDeco *parent=0, const char *name=0,
const unsigned char *bitmap=NULL,
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 setPixmap(const QPixmap &p);
void reset();
@ -61,6 +61,8 @@ protected:
bool miniBtn;
RedmondDeco *client;
int size;
int realizeButtons;
};