Add support for above, below and shade titlebar buttons. If somebody

doesn't like the buttons bitmaps, they can indeed try to do better.

svn path=/trunk/kdebase/kwin/; revision=331723
This commit is contained in:
Luboš Luňák 2004-07-22 11:22:44 +00:00
parent a35e5cad28
commit 5f2d4c57de
2 changed files with 125 additions and 6 deletions

View file

@ -50,6 +50,30 @@ static const unsigned char question_bits[] = {
0x00, 0x00, 0x78, 0x00, 0xcc, 0x00, 0xc0, 0x00, 0x60, 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0xcc, 0x00, 0xc0, 0x00, 0x60, 0x00, 0x30, 0x00,
0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00}; 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00};
static const unsigned char above_on_bits[] = {
0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0x30, 0x00, 0xfc, 0x00, 0x78, 0x00,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char above_off_bits[] = {
0x30, 0x00, 0x78, 0x00, 0xfc, 0x00, 0x30, 0x00, 0xfe, 0x01, 0xfe, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char below_on_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x78, 0x00, 0xfc, 0x00,
0x30, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0x00, 0x00 };
static const unsigned char below_off_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01,
0x30, 0x00, 0xfc, 0x00, 0x78, 0x00, 0x30, 0x00 };
static const unsigned char shade_on_bits[] = {
0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0xfe, 0x01, 0x02, 0x01, 0x02, 0x01,
0x02, 0x01, 0x02, 0x01, 0xfe, 0x01, 0x00, 0x00 };
static const unsigned char shade_off_bits[] = {
0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char pindown_white_bits[] = { static const unsigned char pindown_white_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x1f, 0xa0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x1f, 0xa0, 0x03,
0xb0, 0x01, 0x30, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x20, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x30, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x20, 0x00, 0x00, 0x00,
@ -710,6 +734,9 @@ KDEDefaultClient::KDEDefaultClient( KDecorationBridge* b, KDecorationFactory* f
void KDEDefaultClient::init() void KDEDefaultClient::init()
{ {
connect( this, SIGNAL( keepAboveChanged( bool )), SLOT( keepAboveChange( bool )));
connect( this, SIGNAL( keepBelowChanged( bool )), SLOT( keepBelowChange( bool )));
createMainWidget( WResizeNoErase | WStaticContents | WRepaintNoErase ); createMainWidget( WResizeNoErase | WStaticContents | WRepaintNoErase );
widget()->installEventFilter( this ); widget()->installEventFilter( this );
@ -854,6 +881,48 @@ void KDEDefaultClient::addClientButtons( const QString& s, bool isLeft )
} }
break; break;
// Above button
case 'F':
if ( (!button[BtnAbove]))
{
button[BtnAbove] = new KDEDefaultButton(this, "above",
largeButtons, isLeft, true,
keepAbove() ? above_on_bits : above_off_bits,
i18n("Keep Above Others"));
connect( button[BtnAbove], SIGNAL( clicked()),
this, SLOT(slotAbove()) );
hb->addWidget( button[BtnAbove] );
}
break;
// Below button
case 'B':
if ( (!button[BtnBelow]))
{
button[BtnBelow] = new KDEDefaultButton(this, "below",
largeButtons, isLeft, true,
keepBelow() ? below_on_bits : below_off_bits,
i18n("Keep Below Others"));
connect( button[BtnBelow], SIGNAL( clicked()),
this, SLOT(slotBelow()) );
hb->addWidget( button[BtnBelow] );
}
break;
// Shade button
case 'L':
if ( (!button[BtnShade]) && isShadeable())
{
button[BtnShade] = new KDEDefaultButton(this, "shade",
largeButtons, isLeft, true,
isSetShade() ? shade_on_bits : shade_off_bits,
isSetShade() ? i18n( "Unshade" ) : i18n("Shade"));
connect( button[BtnShade], SIGNAL( clicked()),
this, SLOT(slotShade()) );
hb->addWidget( button[BtnShade] );
}
break;
// Spacer item (only for non-tool windows) // Spacer item (only for non-tool windows)
case '_': case '_':
if ( !isTool() ) if ( !isTool() )
@ -884,6 +953,22 @@ void KDEDefaultClient::desktopChange()
} }
} }
void KDEDefaultClient::keepAboveChange( bool above )
{
if (button[BtnAbove]) {
button[BtnAbove]->setBitmap( above ? above_on_bits : above_off_bits );
button[BtnAbove]->repaint(false);
}
}
void KDEDefaultClient::keepBelowChange( bool below )
{
if (button[BtnBelow]) {
button[BtnBelow]->setBitmap( below ? below_on_bits : below_off_bits );
button[BtnBelow]->repaint(false);
}
}
void KDEDefaultClient::slotMaximize() void KDEDefaultClient::slotMaximize()
{ {
if ( button[BtnMax]->last_button == MidButton ) if ( button[BtnMax]->last_button == MidButton )
@ -894,6 +979,26 @@ void KDEDefaultClient::slotMaximize()
maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull ); maximize( maximizeMode() == MaximizeFull ? MaximizeRestore : MaximizeFull );
} }
void KDEDefaultClient::slotAbove()
{
setKeepAbove( !keepAbove());
button[BtnAbove]->turnOn(keepAbove());
button[BtnAbove]->repaint(true);
}
void KDEDefaultClient::slotBelow()
{
setKeepBelow( !keepBelow());
button[BtnBelow]->turnOn(keepBelow());
button[BtnBelow]->repaint(true);
}
void KDEDefaultClient::slotShade()
{
setShade( !isSetShade());
button[BtnShade]->setBitmap(isSetShade() ? shade_on_bits : shade_off_bits );
button[BtnShade]->repaint(true);
}
void KDEDefaultClient::resizeEvent( QResizeEvent* e) void KDEDefaultClient::resizeEvent( QResizeEvent* e)
{ {
@ -1154,6 +1259,13 @@ void KDEDefaultClient::activeChange()
void KDEDefaultClient::shadeChange() void KDEDefaultClient::shadeChange()
{ {
if (button[BtnShade]) {
bool on = isShade();
button[BtnShade]->turnOn(on);
button[BtnShade]->repaint(false);
QToolTip::remove( button[BtnShade] );
QToolTip::add( button[BtnShade], on ? i18n("Unshade") : i18n("Shade"));
}
} }
QSize KDEDefaultClient::minimumSize() const QSize KDEDefaultClient::minimumSize() const
@ -1178,10 +1290,12 @@ void KDEDefaultClient::borders( int& left, int& right, int& top, int& bottom ) c
void KDEDefaultClient::calcHiddenButtons() void KDEDefaultClient::calcHiddenButtons()
{ {
// Hide buttons in this order: // Hide buttons in this order:
// Sticky, Help, Maximize, Minimize, Close, Menu. // Shade, Below, Above, Sticky, Help, Maximize, Minimize, Close, Menu.
KDEDefaultButton* btnArray[] = { button[BtnSticky], button[BtnHelp], KDEDefaultButton* btnArray[] = { button[ BtnShade ], button[ BtnBelow ],
button[ BtnAbove ], button[BtnSticky], button[BtnHelp],
button[BtnMax], button[BtnIconify], button[BtnClose], button[BtnMax], button[BtnIconify], button[BtnClose],
button[BtnMenu] }; button[BtnMenu] };
const int buttons_cnt = sizeof( btnArray ) / sizeof( btnArray[ 0 ] );
int minwidth = largeButtons ? 10 * normalTitleHeight : 10 * toolTitleHeight; // Start hiding at this width int minwidth = largeButtons ? 10 * normalTitleHeight : 10 * toolTitleHeight; // Start hiding at this width
int btn_width = largeButtons ? normalTitleHeight : toolTitleHeight; int btn_width = largeButtons ? normalTitleHeight : toolTitleHeight;
@ -1197,7 +1311,7 @@ void KDEDefaultClient::calcHiddenButtons()
} }
// Bound the number of buttons to hide // Bound the number of buttons to hide
if (count > 6) count = 6; if (count > buttons_cnt) count = buttons_cnt;
// Hide the required buttons... // Hide the required buttons...
for(i = 0; i < count; i++) for(i = 0; i < count; i++)
@ -1207,7 +1321,7 @@ void KDEDefaultClient::calcHiddenButtons()
} }
// Show the rest of the buttons... // Show the rest of the buttons...
for(i = count; i < 6; i++) for(i = count; i < buttons_cnt; i++)
{ {
if (btnArray[i] && (!btnArray[i]->isVisible()) ) if (btnArray[i] && (!btnArray[i]->isVisible()) )
btnArray[i]->show(); btnArray[i]->show();

View file

@ -108,8 +108,13 @@ class KDEDefaultClient : public KDecoration
protected slots: protected slots:
void slotMaximize(); void slotMaximize();
void slotAbove();
void slotBelow();
void slotShade();
void menuButtonPressed(); void menuButtonPressed();
void menuButtonReleased(); void menuButtonReleased();
void keepAboveChange( bool );
void keepBelowChange( bool );
private: private:
void doShape(); void doShape();
@ -118,7 +123,7 @@ class KDEDefaultClient : public KDecoration
bool isTool() const; bool isTool() const;
enum Buttons{ BtnHelp=0, BtnMax, BtnIconify, BtnClose, enum Buttons{ BtnHelp=0, BtnMax, BtnIconify, BtnClose,
BtnMenu, BtnSticky, BtnCount }; BtnMenu, BtnSticky, BtnAbove, BtnBelow, BtnShade, BtnCount };
KDEDefaultButton* button[ KDEDefaultClient::BtnCount ]; KDEDefaultButton* button[ KDEDefaultClient::BtnCount ];
int lastButtonWidth; int lastButtonWidth;
int titleHeight; int titleHeight;