2000-04-25 01:00:31 +00:00
|
|
|
#include "mwmclient.h"
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qcursor.h>
|
|
|
|
#include <qabstractlayout.h>
|
|
|
|
#include <qlayout.h>
|
|
|
|
#include <qtoolbutton.h>
|
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qdrawutil.h>
|
2001-05-04 23:45:52 +00:00
|
|
|
#include <qdatetime.h>
|
2000-04-25 01:00:31 +00:00
|
|
|
#include <kpixmapeffect.h>
|
|
|
|
#include "../../workspace.h"
|
|
|
|
#include "../../options.h"
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
#include <kdebug.h>
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
using namespace KWinInternal;
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
const int s_frameWidth = 5;
|
|
|
|
const int s_buttonSize = 18;
|
2000-04-25 01:00:31 +00:00
|
|
|
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
MwmButton::MwmButton( MwmClient* parent, const char* name, int btnType )
|
|
|
|
: QButton( parent, name , WStyle_Customize | WStyle_NoBorder | WRepaintNoErase
|
|
|
|
| WResizeNoErase ), m_parent(parent), m_btnType(btnType)
|
2000-04-25 01:00:31 +00:00
|
|
|
{
|
2001-05-04 23:45:52 +00:00
|
|
|
setBackgroundMode( QWidget::NoBackground );
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
setFixedSize( s_buttonSize, s_buttonSize );
|
|
|
|
resize( s_buttonSize, s_buttonSize );
|
2001-04-22 05:39:17 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
void MwmButton::reset()
|
2001-04-22 05:39:17 +00:00
|
|
|
{
|
2001-05-04 23:45:52 +00:00
|
|
|
repaint( false );
|
2000-04-25 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
void MwmButton::drawButton( QPainter* p )
|
2000-04-25 01:00:31 +00:00
|
|
|
{
|
2001-05-04 23:45:52 +00:00
|
|
|
p->setBrush( options->color( Options::TitleBar, m_parent->isActive() ) );
|
|
|
|
p->drawRect( 0, 0, s_buttonSize, s_buttonSize );
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
qDrawShadePanel( p, 0, 0, s_buttonSize, s_buttonSize,
|
|
|
|
options->colorGroup( Options::TitleBar, m_parent->isActive() ), isDown() );
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
switch ( m_btnType )
|
|
|
|
{
|
|
|
|
case (BtnMenu):
|
|
|
|
qDrawShadePanel( p, 4, 6, 10, 4, options->colorGroup( Options::TitleBar, m_parent->isActive() ) );
|
|
|
|
break;
|
|
|
|
case (BtnIconify):
|
|
|
|
qDrawShadePanel( p, 6, 7, 5, 5, options->colorGroup( Options::TitleBar, m_parent->isActive() ) );
|
|
|
|
break;
|
|
|
|
case (BtnMax):
|
|
|
|
qDrawShadePanel( p, 4, 4, 10, 10, options->colorGroup( Options::TitleBar, m_parent->isActive() ) );
|
|
|
|
break;
|
|
|
|
}
|
2000-04-25 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
|
|
|
|
MwmClient::MwmClient( Workspace *ws, WId w, QWidget *parent,
|
|
|
|
const char *name )
|
|
|
|
: Client( ws, w, parent, name, WNorthWestGravity | WResizeNoErase | WRepaintNoErase )
|
2000-04-25 01:00:31 +00:00
|
|
|
{
|
2001-05-04 23:45:52 +00:00
|
|
|
setBackgroundMode( QWidget::NoBackground );
|
|
|
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout( this );
|
|
|
|
QHBoxLayout *titleLayout = new QHBoxLayout();
|
|
|
|
QHBoxLayout *windowLayout = new QHBoxLayout();
|
|
|
|
|
|
|
|
mainLayout->addSpacing( s_frameWidth+1 );
|
|
|
|
mainLayout->addLayout( titleLayout );
|
|
|
|
mainLayout->addLayout( windowLayout, 1 );
|
|
|
|
mainLayout->addSpacing( s_frameWidth+1 );
|
|
|
|
|
|
|
|
windowLayout->addSpacing( s_frameWidth+1 );
|
|
|
|
windowLayout->addWidget( windowWrapper(), 1 );
|
|
|
|
windowLayout->addSpacing( s_frameWidth+1 );
|
|
|
|
|
|
|
|
button[BtnMenu] = new MwmButton( this, "menu", BtnMenu );
|
|
|
|
button[BtnIconify] = new MwmButton( this, "iconify", BtnIconify );
|
|
|
|
button[BtnMax] = new MwmButton( this, "maximize", BtnMax );
|
|
|
|
|
|
|
|
connect( button[BtnMenu], SIGNAL( pressed() ), this, ( SLOT( menuButtonPressed() ) ) );
|
|
|
|
connect( button[BtnIconify], SIGNAL( clicked() ), this, ( SLOT( iconify() ) ) );
|
|
|
|
connect( button[BtnMax], SIGNAL( clicked() ), this, ( SLOT( slotMaximize() ) ) );
|
|
|
|
connect( options, SIGNAL( resetClients() ), this, ( SLOT( slotReset() ) ) );
|
|
|
|
|
|
|
|
titleLayout->addSpacing( s_frameWidth+1 );
|
|
|
|
titleLayout->addWidget( button[BtnMenu] );
|
|
|
|
titlebar = new QSpacerItem( 10, 16, QSizePolicy::Expanding,
|
|
|
|
QSizePolicy::Minimum );
|
|
|
|
titleLayout->addItem( titlebar );
|
|
|
|
titleLayout->addWidget( button[BtnIconify] );
|
|
|
|
titleLayout->addWidget( button[BtnMax] );
|
|
|
|
titleLayout->addSpacing( s_frameWidth+1 );
|
2000-04-25 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
void MwmClient::captionChange( const QString& )
|
2000-04-25 01:00:31 +00:00
|
|
|
{
|
2001-05-04 23:45:52 +00:00
|
|
|
repaint( titlebar->geometry(), false );
|
2000-04-25 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
void MwmClient::activeChange( bool )
|
2000-04-25 01:00:31 +00:00
|
|
|
{
|
2001-05-04 23:45:52 +00:00
|
|
|
button[BtnMenu]->reset();
|
|
|
|
button[BtnIconify]->reset();
|
|
|
|
button[BtnMax]->reset();
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
repaint( false );
|
2000-04-25 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
void MwmClient::slotReset()
|
2000-04-25 01:00:31 +00:00
|
|
|
{
|
2001-05-04 23:45:52 +00:00
|
|
|
button[BtnMenu]->reset();
|
|
|
|
button[BtnIconify]->reset();
|
|
|
|
button[BtnMax]->reset();
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
repaint( false );
|
|
|
|
}
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
void MwmClient::slotMaximize()
|
|
|
|
{
|
|
|
|
/* if ( button[BtnMax]->last_button == MidButton )
|
|
|
|
maximize( MaximizeVertical );
|
|
|
|
else if ( button[BtnMax]->last_button == RightButton )
|
|
|
|
maximize( MaximizeHorizontal );
|
2000-04-25 01:00:31 +00:00
|
|
|
else
|
2001-05-04 23:45:52 +00:00
|
|
|
*/ maximize();
|
|
|
|
}
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
void MwmClient::menuButtonPressed()
|
|
|
|
{
|
|
|
|
workspace()->clientPopup(this)->
|
|
|
|
popup(button[BtnMenu]->mapToGlobal(button[BtnMenu]->rect().bottomLeft()));
|
2000-04-25 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MwmClient::resizeEvent( QResizeEvent* e)
|
|
|
|
{
|
|
|
|
Client::resizeEvent( e );
|
|
|
|
|
2001-05-04 23:45:52 +00:00
|
|
|
if ( isVisibleToTLW() )
|
|
|
|
{
|
|
|
|
update( rect() );
|
|
|
|
int dx = 0;
|
|
|
|
int dy = 0;
|
|
|
|
|
|
|
|
if ( e->oldSize().width() != width() )
|
|
|
|
dx = 32 + QABS( e->oldSize().width() - width() );
|
|
|
|
|
|
|
|
if ( e->oldSize().height() != height() )
|
|
|
|
dy = 8 + QABS( e->oldSize().height() - height() );
|
|
|
|
|
|
|
|
if ( dy )
|
|
|
|
update( 0, height() - dy + 1, width(), dy );
|
|
|
|
|
|
|
|
if ( dx )
|
|
|
|
{
|
|
|
|
update( width() - dx + 1, 0, dx, height() );
|
|
|
|
update( QRect( QPoint(4,4), titlebar->geometry().bottomLeft() - QPoint(1,0) ) );
|
|
|
|
update( QRect( titlebar->geometry().topRight(), QPoint( width() - 4, titlebar->geometry().bottom() ) ) );
|
|
|
|
// Titlebar needs no paint event
|
|
|
|
QApplication::postEvent( this, new QPaintEvent( titlebar->geometry(), false ) );
|
|
|
|
}
|
|
|
|
}
|
2000-04-25 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MwmClient::paintEvent( QPaintEvent* )
|
|
|
|
{
|
|
|
|
QPainter p( this );
|
2001-05-04 23:45:52 +00:00
|
|
|
|
|
|
|
QRect trect = titlebar->geometry();
|
|
|
|
QRect wrect = windowWrapper()->geometry();
|
|
|
|
QRect mrect = this->geometry();
|
|
|
|
|
|
|
|
// draw black frame:
|
|
|
|
p.setPen( Qt::black );
|
|
|
|
p.drawRect( mrect );
|
|
|
|
p.setPen( Qt::NoPen );
|
|
|
|
|
|
|
|
p.setBrush( options->color( Options::TitleBar, isActive() ) );
|
|
|
|
|
|
|
|
// draw frame-background:
|
|
|
|
p.drawRect( 1, 1, 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:
|
|
|
|
qDrawShadePanel( &p, 1, wrect.y(), s_frameWidth, wrect.height()-s_buttonSize,
|
|
|
|
options->colorGroup( Options::TitleBar, isActive() ) );
|
|
|
|
|
|
|
|
// draw right border:
|
|
|
|
qDrawShadePanel( &p, mrect.width()-s_frameWidth-1, wrect.y(), s_frameWidth, wrect.height()-s_buttonSize,
|
|
|
|
options->colorGroup( Options::TitleBar, isActive() ) );
|
|
|
|
|
|
|
|
// draw top border:
|
|
|
|
qDrawShadePanel( &p, s_frameWidth+s_buttonSize+1, 1, wrect.width()-2*s_buttonSize, s_frameWidth,
|
|
|
|
options->colorGroup( Options::TitleBar, isActive() ) );
|
|
|
|
|
|
|
|
// draw bottom border:
|
|
|
|
qDrawShadePanel( &p, 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:
|
|
|
|
p.setPen( options->colorGroup( Options::TitleBar, isActive() ).light() );
|
|
|
|
// tl corner:
|
|
|
|
p.drawLine( 1, 1, s_frameWidth+s_buttonSize-1, 1 );
|
|
|
|
p.drawLine( 1, 1, 1, s_frameWidth+s_buttonSize-1 );
|
|
|
|
// tr corner:
|
|
|
|
p.drawLine( mrect.width()-3, 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:
|
|
|
|
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( 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:
|
|
|
|
p.drawLine( s_frameWidth-1, mrect.height()-s_frameWidth-s_buttonSize-1, 1, mrect.height()-s_frameWidth-s_buttonSize-1 );
|
|
|
|
p.drawLine( 1, mrect.height()-s_frameWidth-s_buttonSize-2, 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 );
|
|
|
|
|
|
|
|
// draw dark corner parts:
|
|
|
|
p.setPen( options->colorGroup( Options::TitleBar, isActive() ).dark() );
|
|
|
|
// tl corner:
|
|
|
|
p.drawLine( 1, s_frameWidth+s_buttonSize, 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:
|
|
|
|
p.drawLine( mrect.width()-s_frameWidth-s_buttonSize-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:
|
|
|
|
p.drawLine( 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:
|
|
|
|
p.drawLine( 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 );
|
|
|
|
|
|
|
|
// draw titlebar:
|
|
|
|
p.drawRect( trect );
|
|
|
|
qDrawShadePanel( &p, trect,
|
|
|
|
options->colorGroup( Options::TitleBar, isActive() ) );
|
|
|
|
|
|
|
|
// draw caption:
|
|
|
|
p.setFont( options->font(true) );
|
|
|
|
p.setPen( options->color( Options::Font, isActive() ) );
|
|
|
|
p.drawText( trect.x()+3, trect.y()-1, trect.width()-6, trect.height(),
|
|
|
|
AlignHCenter | AlignVCenter, caption() );
|
2000-04-25 01:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MwmClient::mouseDoubleClickEvent( QMouseEvent * e )
|
|
|
|
{
|
2001-05-04 23:45:52 +00:00
|
|
|
if ( titlebar->geometry().contains( e->pos() ) )
|
2000-04-25 01:00:31 +00:00
|
|
|
setShade( !isShade() );
|
|
|
|
workspace()->requestFocus( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MwmClient::init()
|
|
|
|
{
|
|
|
|
Client::init();
|
|
|
|
}
|
|
|
|
|
2001-04-22 05:39:17 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
Client *allocate(Workspace *ws, WId w)
|
|
|
|
{
|
|
|
|
return(new MwmClient(ws, w));
|
|
|
|
}
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void deinit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2000-04-25 01:00:31 +00:00
|
|
|
|
2000-06-29 21:36:40 +00:00
|
|
|
#include "mwmclient.moc"
|