this commit is dedicated to rikkus :P

svn path=/trunk/kdebase/kwin/; revision=95367
This commit is contained in:
Lennart Kudling 2001-05-05 23:16:27 +00:00
parent c0d943b01a
commit 4ca78790ee

View file

@ -1,30 +1,27 @@
#include "mwmclient.h"
#include <qapplication.h> #include <qapplication.h>
#include <qcursor.h>
#include <qabstractlayout.h>
#include <qlayout.h>
#include <qtoolbutton.h>
#include <qlabel.h>
#include <qdrawutil.h>
#include <qdatetime.h> #include <qdatetime.h>
#include <kpixmapeffect.h>
#include <qlayout.h>
#include <qbutton.h>
#include <qdrawutil.h>
#include "../../workspace.h" #include "../../workspace.h"
#include "../../options.h" #include "../../options.h"
#include "mwmclient.h"
#include <kdebug.h> #include <kdebug.h>
using namespace KWinInternal; using namespace KWinInternal;
const int s_frameWidth = 5; const int s_frameWidth = 5;
const int s_buttonSize = 18; const int s_buttonSize = 19;
MwmButton::MwmButton( MwmClient* parent, const char* name, int btnType ) MwmButton::MwmButton( MwmClient* parent, const char* name, int btnType )
: QButton( parent, name , WStyle_Customize | WStyle_NoBorder | WRepaintNoErase : QButton( parent, name , WStyle_Customize | WStyle_NoBorder
| WResizeNoErase ), m_parent(parent), m_btnType(btnType) | WRepaintNoErase | WResizeNoErase ), m_parent(parent), m_btnType(btnType)
{ {
setBackgroundMode( QWidget::NoBackground ); setBackgroundMode( QWidget::NoBackground );
setFixedSize( s_buttonSize, s_buttonSize ); setFixedSize( s_buttonSize, s_buttonSize );
resize( s_buttonSize, s_buttonSize ); resize( s_buttonSize, s_buttonSize );
} }
@ -45,27 +42,30 @@ void MwmButton::drawButton( QPainter* p )
switch ( m_btnType ) switch ( m_btnType )
{ {
case (BtnMenu): case (BtnMenu):
qDrawShadePanel( p, 4, 6, 10, 4, options->colorGroup( Options::TitleBar, m_parent->isActive() ) ); qDrawShadePanel( p, 4, 7, 11, 4,
options->colorGroup( Options::TitleBar, m_parent->isActive() ) );
break; break;
case (BtnIconify): case (BtnIconify):
qDrawShadePanel( p, 6, 7, 5, 5, options->colorGroup( Options::TitleBar, m_parent->isActive() ) ); qDrawShadePanel( p, 7, 7, 5, 5,
options->colorGroup( Options::TitleBar, m_parent->isActive() ) );
break; break;
case (BtnMax): case (BtnMax):
qDrawShadePanel( p, 4, 4, 10, 10, options->colorGroup( Options::TitleBar, m_parent->isActive() ) ); qDrawShadePanel( p, 4, 4, 11, 11,
options->colorGroup( Options::TitleBar, m_parent->isActive() ) );
break; break;
} }
} }
MwmClient::MwmClient( Workspace *ws, WId w, QWidget *parent, MwmClient::MwmClient( Workspace* ws, WId w, QWidget* parent, const char* name )
const char *name ) : Client( ws, w, parent, name, WNorthWestGravity | WResizeNoErase
: Client( ws, w, parent, name, WNorthWestGravity | WResizeNoErase | WRepaintNoErase ) | WRepaintNoErase )
{ {
setBackgroundMode( QWidget::NoBackground ); setBackgroundMode( QWidget::NoBackground );
QVBoxLayout *mainLayout = new QVBoxLayout( this ); QVBoxLayout* mainLayout = new QVBoxLayout( this );
QHBoxLayout *titleLayout = new QHBoxLayout(); QHBoxLayout* titleLayout = new QHBoxLayout();
QHBoxLayout *windowLayout = new QHBoxLayout(); QHBoxLayout* windowLayout = new QHBoxLayout();
mainLayout->addSpacing( s_frameWidth+1 ); mainLayout->addSpacing( s_frameWidth+1 );
mainLayout->addLayout( titleLayout ); mainLayout->addLayout( titleLayout );
@ -80,19 +80,25 @@ MwmClient::MwmClient( Workspace *ws, WId w, QWidget *parent,
button[BtnIconify] = new MwmButton( this, "iconify", BtnIconify ); button[BtnIconify] = new MwmButton( this, "iconify", BtnIconify );
button[BtnMax] = new MwmButton( this, "maximize", BtnMax ); button[BtnMax] = new MwmButton( this, "maximize", BtnMax );
connect( button[BtnMenu], SIGNAL( pressed() ), this, ( SLOT( menuButtonPressed() ) ) ); connect( button[BtnMenu], SIGNAL( pressed() ),
connect( button[BtnIconify], SIGNAL( clicked() ), this, ( SLOT( iconify() ) ) ); this, ( SLOT( menuButtonPressed() ) ) );
connect( button[BtnMax], SIGNAL( clicked() ), this, ( SLOT( slotMaximize() ) ) ); connect( button[BtnIconify], SIGNAL( clicked() ),
connect( options, SIGNAL( resetClients() ), this, ( SLOT( slotReset() ) ) ); this, ( SLOT( iconify() ) ) );
connect( button[BtnMax], SIGNAL( clicked() ),
this, ( SLOT( slotMaximize() ) ) );
connect( options, SIGNAL( resetClients() ),
this, ( SLOT( slotReset() ) ) );
titleLayout->addSpacing( s_frameWidth+1 ); titleLayout->addSpacing( s_frameWidth+1 );
titleLayout->addWidget( button[BtnMenu] ); titleLayout->addWidget( button[BtnMenu] );
titlebar = new QSpacerItem( 10, 16, QSizePolicy::Expanding, titlebar = new QSpacerItem( 10, 16, QSizePolicy::Expanding,
QSizePolicy::Minimum ); QSizePolicy::Minimum );
titleLayout->addItem( titlebar ); titleLayout->addItem( titlebar );
titleLayout->addWidget( button[BtnIconify] ); titleLayout->addWidget( button[BtnIconify] );
titleLayout->addWidget( button[BtnMax] ); titleLayout->addWidget( button[BtnMax] );
titleLayout->addSpacing( s_frameWidth+1 ); titleLayout->addSpacing( s_frameWidth + 1 );
} }
void MwmClient::captionChange( const QString& ) void MwmClient::captionChange( const QString& )
@ -120,18 +126,25 @@ void MwmClient::slotReset()
void MwmClient::slotMaximize() void MwmClient::slotMaximize()
{ {
/* if ( button[BtnMax]->last_button == MidButton ) maximize();
maximize( MaximizeVertical );
else if ( button[BtnMax]->last_button == RightButton )
maximize( MaximizeHorizontal );
else
*/ maximize();
} }
void MwmClient::menuButtonPressed() void MwmClient::menuButtonPressed()
{ {
workspace()->clientPopup(this)-> static QTime* t = 0;
popup(button[BtnMenu]->mapToGlobal(button[BtnMenu]->rect().bottomLeft())); static MwmClient* tc = 0;
if ( !t )
t = new QTime;
if ( tc != this || t->elapsed() > QApplication::doubleClickInterval() )
workspace()->clientPopup( this )->popup(
button[BtnMenu]->mapToGlobal(
button[BtnMenu]->rect().bottomLeft() ) );
else
closeWindow();
t->start();
tc = this;
} }
void MwmClient::resizeEvent( QResizeEvent* e) void MwmClient::resizeEvent( QResizeEvent* e)
@ -155,12 +168,15 @@ void MwmClient::resizeEvent( QResizeEvent* e)
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),
update( QRect( titlebar->geometry().topRight(), QPoint( width() - 4, titlebar->geometry().bottom() ) ) ); titlebar->geometry().bottomLeft() - QPoint(1,0) ) );
// Titlebar needs no paint event update( QRect( titlebar->geometry().topRight(),
QApplication::postEvent( this, new QPaintEvent( titlebar->geometry(), false ) ); QPoint( width() - 4, titlebar->geometry().bottom() ) ) );
} // Titlebar needs no paint event
QApplication::postEvent( this,
new QPaintEvent( titlebar->geometry(), false ) );
}
} }
} }
@ -170,7 +186,7 @@ void MwmClient::paintEvent( QPaintEvent* )
QRect trect = titlebar->geometry(); QRect trect = titlebar->geometry();
QRect wrect = windowWrapper()->geometry(); QRect wrect = windowWrapper()->geometry();
QRect mrect = this->geometry(); QRect mrect = rect();
// draw black frame: // draw black frame:
p.setPen( Qt::black ); p.setPen( Qt::black );
@ -180,66 +196,194 @@ void MwmClient::paintEvent( QPaintEvent* )
p.setBrush( options->color( Options::TitleBar, isActive() ) ); p.setBrush( options->color( Options::TitleBar, isActive() ) );
// draw frame-background: // draw frame-background:
p.drawRect( 1, 1, mrect.width()-2, s_frameWidth ); p.drawRect(
p.drawRect( 1, mrect.height()-s_frameWidth-1, mrect.width()-2, s_frameWidth ); 1,
p.drawRect( 1, s_frameWidth+1, s_frameWidth, mrect.height()-2*s_frameWidth-2 ); 1,
p.drawRect( mrect.width()-s_frameWidth-1, s_frameWidth+1, s_frameWidth, mrect.height()-2*s_frameWidth-2 ); mrect.width() - 2,
s_frameWidth );
p.drawRect(
1,
mrect.height() - s_frameWidth - 1,
mrect.width() - 2,
s_frameWidth );
p.drawRect(
1,
s_frameWidth + 1,
s_frameWidth,
mrect.height() - 2*s_frameWidth - 2 );
p.drawRect(
mrect.width() - s_frameWidth - 1,
s_frameWidth + 1,
s_frameWidth,
mrect.height() - 2*s_frameWidth - 2 );
// draw left border: // draw left frame:
qDrawShadePanel( &p, 1, wrect.y(), s_frameWidth, wrect.height()-s_buttonSize, qDrawShadePanel( &p,
options->colorGroup( Options::TitleBar, isActive() ) ); 1,
wrect.y(),
s_frameWidth,
wrect.height() - s_buttonSize,
options->colorGroup( Options::TitleBar, isActive() ) );
// draw right border: // draw right frame:
qDrawShadePanel( &p, mrect.width()-s_frameWidth-1, wrect.y(), s_frameWidth, wrect.height()-s_buttonSize, qDrawShadePanel( &p,
options->colorGroup( Options::TitleBar, isActive() ) ); mrect.width() - s_frameWidth - 1,
wrect.y(),
s_frameWidth,
wrect.height() - s_buttonSize,
options->colorGroup( Options::TitleBar, isActive() ) );
// draw top border: // draw top frame:
qDrawShadePanel( &p, s_frameWidth+s_buttonSize+1, 1, wrect.width()-2*s_buttonSize, s_frameWidth, qDrawShadePanel( &p,
options->colorGroup( Options::TitleBar, isActive() ) ); s_frameWidth + s_buttonSize + 1,
1,
wrect.width() - 2*s_buttonSize,
s_frameWidth,
options->colorGroup( Options::TitleBar, isActive() ) );
// draw bottom border: // draw bottom frame:
qDrawShadePanel( &p, s_frameWidth+s_buttonSize+1, mrect.height()-s_frameWidth-1, wrect.width()-2*s_buttonSize, s_frameWidth, qDrawShadePanel( &p,
options->colorGroup( Options::TitleBar, isActive() ) ); s_frameWidth + s_buttonSize + 1,
mrect.height() - s_frameWidth - 1,
wrect.width() - 2*s_buttonSize,
s_frameWidth,
options->colorGroup( Options::TitleBar, isActive() ) );
// draw light corner parts: // draw light corner parts:
p.setPen( options->colorGroup( Options::TitleBar, isActive() ).light() ); p.setPen( options->colorGroup( Options::TitleBar, isActive() ).light() );
// tl corner: // tl corner:
p.drawLine( 1, 1, s_frameWidth+s_buttonSize-1, 1 ); p.drawLine(
p.drawLine( 1, 1, 1, s_frameWidth+s_buttonSize-1 ); 1,
1,
s_frameWidth + s_buttonSize - 1,
1 );
p.drawLine(
1,
1,
1,
s_frameWidth + s_buttonSize - 1 );
// tr corner: // tr corner:
p.drawLine( mrect.width()-3, 1, mrect.width()-s_frameWidth-s_buttonSize-1, 1 ); p.drawLine(
p.drawLine( mrect.width()-s_frameWidth-s_buttonSize-1, 1, mrect.width()-s_frameWidth-s_buttonSize-1, s_frameWidth-1 ); mrect.width() - 3,
p.drawLine( mrect.width()-s_frameWidth-1, s_frameWidth, mrect.width()-s_frameWidth-1, s_frameWidth+s_buttonSize-1 ); 1,
mrect.width() - s_frameWidth - s_buttonSize - 1,
1 );
p.drawLine(
mrect.width() - s_frameWidth - s_buttonSize - 1,
1,
mrect.width() - s_frameWidth - s_buttonSize - 1,
s_frameWidth - 1 );
p.drawLine(
mrect.width() - s_frameWidth - 1,
s_frameWidth,
mrect.width() - s_frameWidth - 1,
s_frameWidth + s_buttonSize - 1 );
// br corner: // br corner:
p.drawLine( mrect.width()-3, mrect.height()-s_frameWidth-s_buttonSize-1, mrect.width()-s_frameWidth-1, mrect.height()-s_frameWidth-s_buttonSize-1 ); p.drawLine(
p.drawLine( mrect.width()-s_frameWidth-1, mrect.height()-s_frameWidth-s_buttonSize, mrect.width()-s_frameWidth-1, mrect.height()-s_frameWidth-1 ); mrect.width() - 3,
p.drawLine( mrect.width()-s_frameWidth-2, mrect.height()-s_frameWidth-1, mrect.width()-s_frameWidth-s_buttonSize-1, mrect.height()-s_frameWidth-1 ); mrect.height() - s_frameWidth - s_buttonSize - 1,
p.drawLine( mrect.width()-s_frameWidth-s_buttonSize-1, mrect.height()-s_frameWidth, mrect.width()-s_frameWidth-s_buttonSize-1, mrect.height()-2 ); mrect.width() - s_frameWidth - 1,
mrect.height() - s_frameWidth - s_buttonSize - 1 );
p.drawLine(
mrect.width() - s_frameWidth - 1,
mrect.height() - s_frameWidth - s_buttonSize,
mrect.width() - s_frameWidth - 1,
mrect.height() - s_frameWidth - 1 );
p.drawLine(
mrect.width() - s_frameWidth - 2,
mrect.height() - s_frameWidth - 1,
mrect.width() - s_frameWidth - s_buttonSize - 1,
mrect.height() - s_frameWidth - 1 );
p.drawLine(
mrect.width() - s_frameWidth - s_buttonSize - 1,
mrect.height() - s_frameWidth,
mrect.width() - s_frameWidth - s_buttonSize - 1,
mrect.height() - 2 );
// bl corner: // bl corner:
p.drawLine( s_frameWidth-1, mrect.height()-s_frameWidth-s_buttonSize-1, 1, mrect.height()-s_frameWidth-s_buttonSize-1 ); p.drawLine(
p.drawLine( 1, mrect.height()-s_frameWidth-s_buttonSize-2, 1, mrect.height()-3 ); s_frameWidth-1,
p.drawLine( s_frameWidth+s_buttonSize-1, mrect.height()-s_frameWidth-1, s_frameWidth+1, mrect.height()-s_frameWidth-1 ); mrect.height() - s_frameWidth - s_buttonSize - 1,
2,
mrect.height() - s_frameWidth - s_buttonSize - 1 );
p.drawLine(
1,
mrect.height() - s_frameWidth - s_buttonSize - 1,
1,
mrect.height() - 3 );
p.drawLine(
s_frameWidth + s_buttonSize - 1,
mrect.height() - s_frameWidth - 1,
s_frameWidth + 1,
mrect.height() - s_frameWidth - 1 );
p.setPen( Qt::NoPen ); // p.setPen( Qt::NoPen );
// draw dark corner parts: // draw dark corner parts:
p.setPen( options->colorGroup( Options::TitleBar, isActive() ).dark() ); p.setPen( options->colorGroup( Options::TitleBar, isActive() ).dark() );
// tl corner: // tl corner:
p.drawLine( 1, s_frameWidth+s_buttonSize, s_frameWidth, s_frameWidth+s_buttonSize ); p.drawLine(
p.drawLine( s_frameWidth, s_frameWidth+s_buttonSize-1, s_frameWidth, s_frameWidth ); 1,
p.drawLine( s_frameWidth+1, s_frameWidth, s_frameWidth+s_buttonSize, s_frameWidth ); s_frameWidth + s_buttonSize,
p.drawLine( s_frameWidth+s_buttonSize, s_frameWidth, s_frameWidth+s_buttonSize, 1 ); s_frameWidth,
s_frameWidth + s_buttonSize );
p.drawLine(
s_frameWidth,
s_frameWidth + s_buttonSize - 1,
s_frameWidth,
s_frameWidth );
p.drawLine(
s_frameWidth + 1,
s_frameWidth,
s_frameWidth + s_buttonSize,
s_frameWidth );
p.drawLine(
s_frameWidth + s_buttonSize,
s_frameWidth,
s_frameWidth + s_buttonSize,
1 );
// tr corner: // tr corner:
p.drawLine( mrect.width()-s_frameWidth-s_buttonSize-1, s_frameWidth, mrect.width()-s_frameWidth-2, s_frameWidth ); p.drawLine(
p.drawLine( mrect.width()-s_frameWidth-1, s_frameWidth+s_buttonSize, mrect.width()-2, s_frameWidth+s_buttonSize ); mrect.width() - s_frameWidth - s_buttonSize - 1,
p.drawLine( mrect.width()-2, s_frameWidth+s_buttonSize, mrect.width()-2, 1 ); s_frameWidth,
mrect.width() - s_frameWidth - 2,
s_frameWidth );
p.drawLine(
mrect.width() - s_frameWidth - 1,
s_frameWidth + s_buttonSize,
mrect.width() - 2,
s_frameWidth + s_buttonSize );
p.drawLine(
mrect.width() - 2,
s_frameWidth + s_buttonSize,
mrect.width() - 2,
1 );
// br corner: // br corner:
p.drawLine( mrect.width()-s_frameWidth-s_buttonSize-1, mrect.height()-2, mrect.width()-3, mrect.height()-2 ); p.drawLine(
p.drawLine( mrect.width()-2, mrect.height()-2, mrect.width()-2, mrect.height()-s_frameWidth-s_buttonSize-2 ); mrect.width() - s_frameWidth - s_buttonSize - 1,
mrect.height() - 2,
mrect.width() - 3,
mrect.height() - 2 );
p.drawLine(
mrect.width() - 2,
mrect.height() - 2,
mrect.width() - 2,
mrect.height() - s_frameWidth - s_buttonSize - 2 );
// bl corner: // bl corner:
p.drawLine( 1, mrect.height()-2, s_frameWidth+s_buttonSize, mrect.height()-2 ); p.drawLine(
p.drawLine( s_frameWidth+s_buttonSize, mrect.height()-3, s_frameWidth+s_buttonSize, mrect.height()-s_frameWidth-1 ); 1,
p.drawLine( s_frameWidth, mrect.height()-s_frameWidth-1, s_frameWidth, mrect.height()-s_frameWidth-s_buttonSize-1 ); mrect.height() - 2,
s_frameWidth + s_buttonSize,
mrect.height() - 2 );
p.drawLine(
s_frameWidth + s_buttonSize,
mrect.height() - 3,
s_frameWidth + s_buttonSize,
mrect.height() - s_frameWidth - 1 );
p.drawLine(
s_frameWidth,
mrect.height() - s_frameWidth - 1,
s_frameWidth,
mrect.height() - s_frameWidth - s_buttonSize - 1 );
p.setPen( Qt::NoPen ); p.setPen( Qt::NoPen );
@ -249,17 +393,23 @@ void MwmClient::paintEvent( QPaintEvent* )
options->colorGroup( Options::TitleBar, isActive() ) ); options->colorGroup( Options::TitleBar, isActive() ) );
// draw caption: // draw caption:
p.setFont( options->font(true) ); p.setFont( options->font( true ) );
p.setPen( options->color( Options::Font, isActive() ) ); p.setPen( options->color( Options::Font, isActive() ) );
p.drawText( trect.x()+3, trect.y()-1, trect.width()-6, trect.height(), p.drawText(
trect.x() + 3,
trect.y() - 1,
trect.width() - 6,
trect.height(),
AlignHCenter | AlignVCenter, caption() ); AlignHCenter | AlignVCenter, caption() );
} }
void MwmClient::mouseDoubleClickEvent( QMouseEvent * e ) void MwmClient::mouseDoubleClickEvent( QMouseEvent * e )
{ {
if ( titlebar->geometry().contains( e->pos() ) ) if ( titlebar->geometry().contains( e->pos() ) )
setShade( !isShade() ); {
workspace()->requestFocus( this ); workspace()->lowerClient( this );
workspace()->requestFocus( workspace()->topClientOnDesktop() );
}
} }
void MwmClient::init() void MwmClient::init()
@ -269,9 +419,9 @@ void MwmClient::init()
extern "C" extern "C"
{ {
Client *allocate(Workspace *ws, WId w) Client* allocate( Workspace* ws, WId w )
{ {
return(new MwmClient(ws, w)); return( new MwmClient( ws, w ) );
} }
void init() void init()
{ {