2003-08-29 22:49:03 +00:00
/* Plastik KWin window decoration
Copyright ( C ) 2003 Sandro Giessl < ceebx @ users . sourceforge . net >
based on the window decoration " Web " :
Copyright ( C ) 2001 Rik Hemsley ( rikkus ) < rik @ kde . org >
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation ; either
version 2 of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; see the file COPYING . If not , write to
the Free Software Foundation , Inc . , 59 Temple Place - Suite 330 ,
Boston , MA 02111 - 1307 , USA .
*/
# include <klocale.h>
# include <kpixmap.h>
# include <kpixmapeffect.h>
# include <qbitmap.h>
# include <qdatetime.h>
# include <qfontmetrics.h>
# include <qimage.h>
2003-09-17 18:43:17 +00:00
# include <qlabel.h>
2003-08-29 22:49:03 +00:00
# include <qlayout.h>
# include <qpainter.h>
# include <qpixmap.h>
# include "plastikclient.h"
# include "plastikclient.moc"
# include "plastikbutton.h"
# include "misc.h"
# include "shadow.h"
// global constants
static const int TOPMARGIN = 4 ; // do not change
static const int DECOHEIGHT = 2 ; // do not change
static const int SIDETITLEMARGIN = 6 ;
// Default button layout
const char default_left [ ] = " M " ;
const char default_right [ ] = " HIAX " ;
2003-09-17 18:43:17 +00:00
namespace KWinPlastik
{
PlastikClient : : PlastikClient ( KDecorationBridge * bridge , KDecorationFactory * factory )
: KDecoration ( bridge , factory ) ,
2003-08-29 22:49:03 +00:00
mainLayout_ ( 0 ) ,
2003-09-17 18:43:17 +00:00
topSpacer_ ( 0 ) , titleSpacer_ ( 0 ) , leftTitleSpacer_ ( 0 ) , rightTitleSpacer_ ( 0 ) ,
decoSpacer_ ( 0 ) , leftSpacer_ ( 0 ) , rightSpacer_ ( 0 ) , bottomSpacer_ ( 0 ) ,
2003-08-29 22:49:03 +00:00
aCaptionBuffer ( 0 ) , iCaptionBuffer ( 0 ) ,
aTitleBarTile ( 0 ) , iTitleBarTile ( 0 ) , aTitleBarTopTile ( 0 ) , iTitleBarTopTile ( 0 ) ,
pixmaps_created ( false ) ,
captionBufferDirty ( true ) ,
2003-09-23 20:39:13 +00:00
closing ( false ) ,
2003-08-29 22:49:03 +00:00
s_titleHeight ( 0 ) ,
s_titleFont ( QFont ( ) )
2003-09-17 18:43:17 +00:00
{ }
PlastikClient : : ~ PlastikClient ( )
{
delete_pixmaps ( ) ;
delete aCaptionBuffer ;
delete iCaptionBuffer ;
for ( int n = 0 ; n < NumButtons ; n + + ) {
if ( m_button [ n ] ) delete m_button [ n ] ;
}
}
void PlastikClient : : init ( )
2003-08-29 22:49:03 +00:00
{
2003-09-17 18:43:17 +00:00
s_titleHeight = isTool ( ) ?
PlastikHandler : : titleHeightTool ( )
: PlastikHandler : : titleHeight ( ) ;
s_titleFont = isTool ( ) ?
PlastikHandler : : titleFontTool ( )
: PlastikHandler : : titleFont ( ) ;
2003-10-25 13:57:28 +00:00
createMainWidget ( WNoAutoErase ) ;
2003-09-17 18:43:17 +00:00
widget ( ) - > installEventFilter ( this ) ;
2003-08-29 22:49:03 +00:00
// for flicker-free redraws
2003-09-17 18:43:17 +00:00
widget ( ) - > setBackgroundMode ( NoBackground ) ;
2003-08-29 22:49:03 +00:00
_resetLayout ( ) ;
create_pixmaps ( ) ;
aCaptionBuffer = new QPixmap ( ) ;
iCaptionBuffer = new QPixmap ( ) ;
captionBufferDirty = true ;
2003-10-25 13:57:28 +00:00
widget ( ) - > update ( titleSpacer_ - > geometry ( ) ) ;
2003-08-29 22:49:03 +00:00
}
2004-01-06 10:13:20 +00:00
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 ;
2003-09-17 18:43:17 +00:00
bool PlastikClient : : isTool ( )
2003-08-29 22:49:03 +00:00
{
2004-01-06 10:13:20 +00:00
NET : : WindowType type = windowType ( SUPPORTED_WINDOW_TYPES_MASK ) ;
2003-09-17 18:43:17 +00:00
return ( ( type = = NET : : Toolbar ) | | ( type = = NET : : NET : : Utility ) | | ( type = = NET : : Menu ) ) ;
2003-08-29 22:49:03 +00:00
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : resizeEvent ( )
2003-08-29 22:49:03 +00:00
{
doShape ( ) ;
2003-10-25 13:57:28 +00:00
widget ( ) - > update ( ) ;
2003-08-29 22:49:03 +00:00
}
void PlastikClient : : paintEvent ( QPaintEvent * )
{
if ( ! PlastikHandler : : initialized ( ) ) return ;
if ( captionBufferDirty )
update_captionBuffer ( ) ;
bool active = isActive ( ) ;
2003-09-17 18:43:17 +00:00
QPainter painter ( widget ( ) ) ;
2003-08-29 22:49:03 +00:00
QRegion mask ;
// colors...
const QColor windowContour = PlastikHandler : : getColor ( WindowContour , active ) ;
const QColor deco = PlastikHandler : : getColor ( TitleGradientTo , active ) ;
const QColor border = PlastikHandler : : getColor ( Border , active ) ;
const QColor highlightTop = PlastikHandler : : getColor ( TitleHighlightTop , active ) ;
const QColor highlightTitleLeft = alphaBlendColors ( deco ,
PlastikHandler : : getColor ( SideHighlightLeft , active ) , 150 ) ;
const QColor highlightTitleRight = alphaBlendColors ( deco ,
PlastikHandler : : getColor ( SideHighlightRight , active ) , 150 ) ;
const QColor highlightLeft = alphaBlendColors ( border ,
PlastikHandler : : getColor ( SideHighlightLeft , active ) , 150 ) ;
const QColor highlightRight = alphaBlendColors ( border ,
PlastikHandler : : getColor ( SideHighlightRight , active ) , 150 ) ;
const QColor highlightBottom = alphaBlendColors ( border ,
PlastikHandler : : getColor ( SideHighlightBottom , active ) , 150 ) ;
QRect Rtop ( topSpacer_ - > geometry ( ) ) ;
QRect Rtitle ( titleSpacer_ - > geometry ( ) ) ;
QRect Rltitle ( leftTitleSpacer_ - > geometry ( ) ) ;
QRect Rrtitle ( rightTitleSpacer_ - > geometry ( ) ) ;
QRect Rdeco ( decoSpacer_ - > geometry ( ) ) ;
QRect Rleft ( leftSpacer_ - > geometry ( ) ) ;
QRect Rright ( rightSpacer_ - > geometry ( ) ) ;
QRect Rbottom ( bottomSpacer_ - > geometry ( ) ) ;
QRect tempRect ;
// topSpacer
if ( Rtop . height ( ) > 0 )
{
painter . setPen ( windowContour ) ;
painter . drawLine ( Rtop . left ( ) + 2 , Rtop . top ( ) , Rtop . right ( ) - 2 , Rtop . top ( ) ) ;
painter . drawPoint ( Rtop . left ( ) + 1 , Rtop . top ( ) + 1 ) ;
painter . drawPoint ( Rtop . right ( ) - 1 , Rtop . top ( ) + 1 ) ;
painter . drawLine ( Rtop . left ( ) , Rtop . top ( ) + 2 , Rtop . left ( ) , Rtop . bottom ( ) ) ;
painter . drawLine ( Rtop . right ( ) , Rtop . top ( ) + 2 , Rtop . right ( ) , Rtop . bottom ( ) ) ;
painter . setPen ( highlightTop ) ;
painter . drawLine ( Rtop . left ( ) + 3 , Rtop . top ( ) + 1 , Rtop . right ( ) - 3 , Rtop . top ( ) + 1 ) ;
// a bit anti-aliasing for the window contour...
painter . setPen ( alphaBlendColors ( highlightTop , windowContour , 150 ) ) ;
painter . drawPoint ( Rtop . left ( ) + 2 , Rtop . top ( ) + 1 ) ;
painter . drawPoint ( Rtop . right ( ) - 2 , Rtop . top ( ) + 1 ) ;
painter . setPen ( alphaBlendColors ( highlightTitleLeft , windowContour , 150 ) ) ;
painter . drawPoint ( Rtop . left ( ) + 1 , Rtop . top ( ) + 2 ) ;
painter . setPen ( alphaBlendColors ( highlightTitleRight , windowContour , 150 ) ) ;
painter . drawPoint ( Rtop . right ( ) - 1 , Rtop . top ( ) + 2 ) ;
// highlight...
painter . setPen ( highlightTitleLeft ) ;
painter . drawLine ( Rtop . left ( ) + 1 , Rtop . top ( ) + 3 , Rtop . left ( ) + 1 , Rtop . bottom ( ) ) ;
painter . setPen ( highlightTitleRight ) ;
painter . drawLine ( Rtop . right ( ) - 1 , Rtop . top ( ) + 3 , Rtop . right ( ) - 1 , Rtop . bottom ( ) ) ;
painter . drawTiledPixmap ( Rtop . left ( ) + 2 , Rtop . top ( ) + 2 ,
Rtop . width ( ) - 2 * 2 , Rtop . height ( ) - 2 ,
active ? * aTitleBarTopTile : * iTitleBarTopTile ) ;
}
// leftTitleSpacer
if ( Rltitle . width ( ) > 0 )
{
painter . setPen ( windowContour ) ;
painter . drawLine ( Rltitle . left ( ) , Rltitle . top ( ) ,
Rltitle . left ( ) , Rltitle . bottom ( ) ) ;
painter . setPen ( highlightTitleLeft ) ;
painter . drawLine ( Rltitle . left ( ) + 1 , Rltitle . top ( ) ,
Rltitle . left ( ) + 1 , Rltitle . bottom ( ) ) ;
painter . drawTiledPixmap ( Rltitle . left ( ) + 2 , Rltitle . top ( ) , Rltitle . width ( ) - 2 , Rltitle . height ( ) ,
active ? * aTitleBarTile : * iTitleBarTile ) ;
}
// Space under the left button group
painter . drawTiledPixmap ( Rltitle . right ( ) + 1 , Rtitle . top ( ) ,
( Rtitle . left ( ) - 1 ) - Rltitle . right ( ) , Rtitle . height ( ) ,
active ? * aTitleBarTile : * iTitleBarTile ) ;
// rightTitleSpacer
if ( Rrtitle . width ( ) > 0 )
{
painter . setPen ( windowContour ) ;
painter . drawLine ( Rrtitle . right ( ) , Rrtitle . top ( ) ,
Rrtitle . right ( ) , Rrtitle . bottom ( ) ) ;
painter . setPen ( highlightTitleRight ) ;
painter . drawLine ( Rrtitle . right ( ) - 1 , Rrtitle . top ( ) ,
Rrtitle . right ( ) - 1 , Rrtitle . bottom ( ) ) ;
painter . drawTiledPixmap ( Rrtitle . left ( ) , Rrtitle . top ( ) , Rrtitle . width ( ) - 2 , Rrtitle . height ( ) ,
active ? * aTitleBarTile : * iTitleBarTile ) ;
}
// Space under the right button group
painter . drawTiledPixmap ( Rtitle . right ( ) + 1 , Rtitle . top ( ) ,
( Rrtitle . left ( ) - 1 ) - Rtitle . right ( ) , Rtitle . height ( ) ,
active ? * aTitleBarTile : * iTitleBarTile ) ;
// titleSpacer
QPixmap * titleBfrPtr = active ? aCaptionBuffer : iCaptionBuffer ;
if ( Rtitle . width ( ) > 0 & & titleBfrPtr ! = 0 )
{
const int titleMargin = 5 ; // 5 px betwee title and buttons
int tX , tW ;
switch ( PlastikHandler : : titleAlign ( ) )
{
// AlignCenter
case Qt : : AlignHCenter :
tX = ( titleBfrPtr - > width ( ) > Rtitle . width ( ) - 2 * titleMargin ) ?
( Rtitle . left ( ) + titleMargin )
: Rtitle . left ( ) + ( Rtitle . width ( ) - titleBfrPtr - > width ( ) ) / 2 ;
tW = ( titleBfrPtr - > width ( ) > Rtitle . width ( ) - 2 * titleMargin ) ?
( Rtitle . width ( ) - 2 * titleMargin )
: titleBfrPtr - > width ( ) ;
break ;
// AlignRight
case Qt : : AlignRight :
tX = ( titleBfrPtr - > width ( ) > Rtitle . width ( ) - 2 * titleMargin ) ?
( Rtitle . left ( ) + titleMargin )
: Rtitle . right ( ) - titleMargin - titleBfrPtr - > width ( ) ;
tW = ( titleBfrPtr - > width ( ) > Rtitle . width ( ) - 2 * titleMargin ) ?
( Rtitle . width ( ) - 2 * titleMargin )
: titleBfrPtr - > width ( ) ;
break ;
// AlignLeft
default :
tX = ( Rtitle . left ( ) + titleMargin ) ;
tW = ( titleBfrPtr - > width ( ) > Rtitle . width ( ) - 2 * titleMargin ) ?
( Rtitle . width ( ) - 2 * titleMargin )
: titleBfrPtr - > width ( ) ;
}
if ( tW > 0 )
{
painter . drawTiledPixmap ( tX , Rtitle . top ( ) ,
tW , Rtitle . height ( ) ,
* titleBfrPtr ) ;
}
painter . drawTiledPixmap ( Rtitle . left ( ) , Rtitle . top ( ) ,
tX - Rtitle . left ( ) , Rtitle . height ( ) ,
active ? * aTitleBarTile : * iTitleBarTile ) ;
painter . drawTiledPixmap ( tX + tW , Rtitle . top ( ) ,
Rtitle . right ( ) - ( tX + tW ) + 1 , Rtitle . height ( ) ,
active ? * aTitleBarTile : * iTitleBarTile ) ;
}
titleBfrPtr = 0 ;
// decoSpacer
if ( Rdeco . height ( ) > 0 )
{
int l ;
if ( Rleft . width ( ) ! = 0 )
l = Rdeco . left ( ) + 2 ;
else
l = Rdeco . left ( ) ;
int r ;
if ( Rright . width ( ) ! = 0 )
r = Rdeco . right ( ) - 2 ;
else
r = Rdeco . right ( ) ;
painter . setPen ( deco ) ;
painter . drawLine ( l , Rdeco . bottom ( ) , r , Rdeco . bottom ( ) ) ;
painter . drawLine ( l , Rdeco . top ( ) , r , Rdeco . top ( ) ) ;
if ( Rleft . width ( ) ! = 0 ) {
painter . setPen ( windowContour ) ;
painter . drawLine ( Rdeco . left ( ) , Rdeco . top ( ) , Rdeco . left ( ) , Rdeco . bottom ( ) ) ;
painter . setPen ( highlightTitleLeft ) ;
painter . drawLine ( Rdeco . left ( ) + 1 , Rdeco . top ( ) ,
Rdeco . left ( ) + 1 , Rdeco . bottom ( ) ) ;
}
if ( Rright . width ( ) ! = 0 ) {
painter . setPen ( windowContour ) ;
painter . drawLine ( Rdeco . right ( ) , Rdeco . top ( ) , Rdeco . right ( ) , Rdeco . bottom ( ) ) ;
painter . setPen ( highlightTitleRight ) ;
painter . drawLine ( Rdeco . right ( ) - 1 , Rdeco . top ( ) ,
Rdeco . right ( ) - 1 , Rdeco . bottom ( ) ) ;
}
}
if ( Rleft . height ( ) = = 1 & & Rright . height ( ) = = 1 ) // the window is shaded... hopefully
{
// let's orient on the bottomSpacer which should have the prper x coords...
painter . setPen ( windowContour ) ;
painter . drawPoint ( Rbottom . left ( ) , Rleft . top ( ) ) ;
painter . drawPoint ( Rbottom . right ( ) , Rright . top ( ) ) ;
painter . setPen ( border ) ;
painter . drawLine ( Rbottom . left ( ) + 1 , Rleft . top ( ) , Rbottom . right ( ) - 1 , Rright . top ( ) ) ;
}
else
{
// leftSpacer
if ( Rleft . width ( ) > 0 & & Rleft . height ( ) > 0 )
{
painter . setPen ( windowContour ) ;
painter . drawLine ( Rleft . left ( ) , Rleft . top ( ) ,
Rleft . left ( ) , Rleft . bottom ( ) ) ;
painter . setPen ( highlightLeft ) ;
painter . drawLine ( Rleft . left ( ) + 1 , Rleft . top ( ) ,
Rleft . left ( ) + 1 , Rleft . bottom ( ) ) ;
if ( Rleft . width ( ) > 2 ) {
tempRect . setCoords ( Rleft . left ( ) + 2 , Rleft . top ( ) ,
Rleft . right ( ) , Rleft . bottom ( ) ) ;
painter . fillRect ( tempRect , border ) ;
}
}
// rightSpacer
if ( Rright . width ( ) > 0 & & Rright . height ( ) > 0 )
{
painter . setPen ( windowContour ) ;
painter . drawLine ( Rright . right ( ) , Rright . top ( ) ,
Rright . right ( ) , Rright . bottom ( ) ) ;
painter . setPen ( highlightRight ) ;
painter . drawLine ( Rright . right ( ) - 1 , Rright . top ( ) ,
Rright . right ( ) - 1 , Rright . bottom ( ) ) ;
if ( Rright . width ( ) > 2 ) {
tempRect . setCoords ( Rright . left ( ) , Rright . top ( ) ,
Rright . right ( ) - 2 , Rright . bottom ( ) ) ;
painter . fillRect ( tempRect , border ) ;
}
}
}
// bottomSpacer
if ( Rbottom . height ( ) > 0 )
{
painter . setPen ( windowContour ) ;
painter . drawLine ( Rbottom . left ( ) + 1 , Rbottom . bottom ( ) ,
Rbottom . right ( ) - 1 , Rbottom . bottom ( ) ) ;
if ( Rleft . width ( ) ! = 0 ) {
painter . setPen ( windowContour ) ;
painter . drawLine ( Rbottom . left ( ) , Rbottom . top ( ) ,
Rbottom . left ( ) , Rbottom . bottom ( ) - 1 ) ;
painter . setPen ( highlightLeft ) ;
painter . drawLine ( Rbottom . left ( ) + 1 , Rbottom . top ( ) ,
Rbottom . left ( ) + 1 , Rbottom . bottom ( ) - 2 ) ;
// anti-alias for the window contour...
painter . setPen ( alphaBlendColors ( border , windowContour , 110 ) ) ;
painter . drawPoint ( Rbottom . left ( ) + 1 , Rbottom . bottom ( ) - 1 ) ;
}
if ( Rright . width ( ) ! = 0 ) {
painter . setPen ( windowContour ) ;
painter . drawLine ( Rbottom . right ( ) , Rbottom . top ( ) ,
Rbottom . right ( ) , Rbottom . bottom ( ) - 1 ) ;
painter . setPen ( highlightRight ) ;
painter . drawLine ( Rbottom . right ( ) - 1 , Rbottom . top ( ) ,
Rbottom . right ( ) - 1 , Rbottom . bottom ( ) - 2 ) ;
// anti-alias for the window contour...
painter . setPen ( alphaBlendColors ( border , windowContour , 110 ) ) ;
painter . drawPoint ( Rbottom . right ( ) - 1 , Rbottom . bottom ( ) - 1 ) ;
}
int l ;
if ( Rleft . width ( ) ! = 0 )
l = Rbottom . left ( ) + 2 ;
else
l = Rbottom . left ( ) ;
int r ;
if ( Rright . width ( ) ! = 0 )
r = Rbottom . right ( ) - 2 ;
else
r = Rbottom . right ( ) ;
painter . setPen ( highlightBottom ) ;
painter . drawLine ( l , Rbottom . bottom ( ) - 1 ,
r , Rbottom . bottom ( ) - 1 ) ;
tempRect . setCoords ( l , Rbottom . top ( ) , r , Rbottom . bottom ( ) - 2 ) ;
painter . fillRect ( tempRect , border ) ;
}
}
void PlastikClient : : showEvent ( QShowEvent * )
{
doShape ( ) ;
2003-10-25 13:57:28 +00:00
widget ( ) - > update ( ) ;
2003-08-29 22:49:03 +00:00
}
void PlastikClient : : windowWrapperShowEvent ( QShowEvent * )
{
doShape ( ) ;
2003-10-25 13:57:28 +00:00
widget ( ) - > update ( ) ;
2003-08-29 22:49:03 +00:00
}
void PlastikClient : : mouseDoubleClickEvent ( QMouseEvent * e )
{
if ( titleSpacer_ - > geometry ( ) . contains ( e - > pos ( ) ) )
2003-09-17 18:43:17 +00:00
titlebarDblClickOperation ( ) ;
2003-08-29 22:49:03 +00:00
}
void PlastikClient : : doShape ( )
{
2003-09-17 18:43:17 +00:00
int w = widget ( ) - > width ( ) ;
int h = widget ( ) - > height ( ) ;
int r ( w ) ;
int b ( h ) ;
2003-08-29 22:49:03 +00:00
2003-09-17 18:43:17 +00:00
QRegion mask ( 0 , 0 , w , h ) ;
2003-08-29 22:49:03 +00:00
if ( topSpacer_ - > geometry ( ) . height ( ) > 0 )
{
// Remove top-left corner.
if ( leftTitleSpacer_ - > geometry ( ) . width ( ) > 0 )
{
mask - = QRegion ( 0 , 0 , 1 , 2 ) ;
mask - = QRegion ( 1 , 0 , 1 , 1 ) ;
}
// Remove top-right corner.
if ( rightTitleSpacer_ - > geometry ( ) . width ( ) > 0 )
{
mask - = QRegion ( r - 1 , 0 , 1 , 2 ) ;
mask - = QRegion ( r - 2 , 0 , 1 , 1 ) ;
}
}
// Remove bottom-left corner and bottom-right corner.
if ( bottomSpacer_ - > geometry ( ) . height ( ) > 0 )
{
mask - = QRegion ( 0 , b - 1 , 1 , 1 ) ;
mask - = QRegion ( r - 1 , b - 1 , 1 , 1 ) ;
}
2003-09-17 18:43:17 +00:00
setMask ( mask ) ;
// widget()->setMask(mask);
2003-08-29 22:49:03 +00:00
}
void PlastikClient : : _resetLayout ( )
{
// basic layout:
// _______________________________________________________________
// | topSpacer |
// |_______________________________________________________________|
// | leftTitleSpacer | btns | titleSpacer | bts | rightTitleSpacer |
// |_________________|______|_____________|_____|__________________|
// | decoSpacer |
// |_______________________________________________________________|
// | | | |
2003-09-17 18:43:17 +00:00
// | | contentsFake | |
2003-08-29 22:49:03 +00:00
// | | | |
// |leftSpacer rightSpacer|
// |_|___________________________________________________________|_|
// | bottomSpacer |
// |_______________________________________________________________|
//
if ( ! PlastikHandler : : initialized ( ) ) return ;
delete mainLayout_ ;
delete topSpacer_ ;
delete titleSpacer_ ;
delete leftTitleSpacer_ ;
delete rightTitleSpacer_ ;
delete decoSpacer_ ;
delete leftSpacer_ ;
delete rightSpacer_ ;
delete bottomSpacer_ ;
2003-09-17 18:43:17 +00:00
mainLayout_ = new QVBoxLayout ( widget ( ) , 0 , 0 ) ;
2003-08-29 22:49:03 +00:00
topSpacer_ = new QSpacerItem ( 1 , TOPMARGIN , QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
titleSpacer_ = new QSpacerItem ( 1 , s_titleHeight ,
QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
leftTitleSpacer_ = new QSpacerItem ( SIDETITLEMARGIN , s_titleHeight ,
QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
rightTitleSpacer_ = new QSpacerItem ( SIDETITLEMARGIN , s_titleHeight ,
QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
decoSpacer_ = new QSpacerItem ( 1 , DECOHEIGHT , QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
leftSpacer_ = new QSpacerItem ( PlastikHandler : : borderSize ( ) , 1 ,
QSizePolicy : : Fixed , QSizePolicy : : Expanding ) ;
rightSpacer_ = new QSpacerItem ( PlastikHandler : : borderSize ( ) , 1 ,
QSizePolicy : : Fixed , QSizePolicy : : Expanding ) ;
bottomSpacer_ = new QSpacerItem ( 1 , PlastikHandler : : borderSize ( ) ,
QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
// top
mainLayout_ - > addItem ( topSpacer_ ) ;
// title
QHBoxLayout * titleLayout_ = new QHBoxLayout ( mainLayout_ , 0 , 0 ) ;
// sizeof(...) is calculated at compile time
2003-09-17 18:43:17 +00:00
memset ( m_button , 0 , sizeof ( PlastikButton * ) * NumButtons ) ;
2003-08-29 22:49:03 +00:00
2003-09-23 20:39:13 +00:00
titleLayout_ - > addItem ( PlastikHandler : : reverseLayout ( ) ? rightTitleSpacer_ : leftTitleSpacer_ ) ;
2003-08-29 22:49:03 +00:00
addButtons ( titleLayout_ ,
2003-09-17 18:43:17 +00:00
options ( ) - > customButtonPositions ( ) ? options ( ) - > titleButtonsLeft ( ) : QString ( default_left ) ,
2003-08-29 22:49:03 +00:00
s_titleHeight - 1 ) ;
titleLayout_ - > addItem ( titleSpacer_ ) ;
addButtons ( titleLayout_ ,
2003-09-17 18:43:17 +00:00
options ( ) - > customButtonPositions ( ) ? options ( ) - > titleButtonsRight ( ) : QString ( default_right ) ,
2003-08-29 22:49:03 +00:00
s_titleHeight - 1 ) ;
2003-09-23 20:39:13 +00:00
titleLayout_ - > addItem ( PlastikHandler : : reverseLayout ( ) ? leftTitleSpacer_ : rightTitleSpacer_ ) ;
2003-08-29 22:49:03 +00:00
// deco
mainLayout_ - > addItem ( decoSpacer_ ) ;
//Mid
QHBoxLayout * midLayout = new QHBoxLayout ( mainLayout_ , 0 , 0 ) ;
2003-09-23 20:39:13 +00:00
midLayout - > addItem ( PlastikHandler : : reverseLayout ( ) ? rightSpacer_ : leftSpacer_ ) ;
2003-10-30 18:25:43 +00:00
if ( isPreview ( ) )
midLayout - > addWidget ( new QLabel ( i18n ( " <center><b>Plastik</b></center> " ) , widget ( ) ) ) ;
else
midLayout - > addItem ( new QSpacerItem ( 0 , 0 ) ) ;
2003-09-23 20:39:13 +00:00
midLayout - > addItem ( PlastikHandler : : reverseLayout ( ) ? leftSpacer_ : rightSpacer_ ) ;
2003-08-29 22:49:03 +00:00
//Bottom
mainLayout_ - > addItem ( bottomSpacer_ ) ;
}
void PlastikClient : : addButtons ( QBoxLayout * layout , const QString & s , int buttonSize )
{
if ( s . length ( ) > 0 ) {
for ( unsigned n = 0 ; n < s . length ( ) ; n + + ) {
switch ( s [ n ] ) {
case ' M ' : // Menu button
2003-09-17 18:43:17 +00:00
if ( ! m_button [ MenuButton ] ) {
2003-11-01 23:58:05 +00:00
m_button [ MenuButton ] = new PlastikButton ( this , " menu " , i18n ( " Menu " ) , MenuButton , buttonSize , LeftButton | RightButton ) ;
2003-09-17 18:43:17 +00:00
connect ( m_button [ MenuButton ] , SIGNAL ( pressed ( ) ) , SLOT ( menuButtonPressed ( ) ) ) ;
2003-09-23 20:39:13 +00:00
connect ( m_button [ MenuButton ] , SIGNAL ( released ( ) ) , this , SLOT ( menuButtonReleased ( ) ) ) ;
2003-09-17 18:43:17 +00:00
layout - > addWidget ( m_button [ MenuButton ] , 0 , Qt : : AlignHCenter | Qt : : AlignTop ) ;
2003-08-29 22:49:03 +00:00
}
break ;
2003-09-17 18:43:17 +00:00
case ' S ' : // OnAllDesktops button
if ( ! m_button [ OnAllDesktopsButton ] ) {
2004-01-09 16:38:08 +00:00
const bool oad = isOnAllDesktops ( ) ;
m_button [ OnAllDesktopsButton ] = new PlastikButton ( this , " on_all_desktops " , oad ? i18n ( " Not On All Desktops " ) : i18n ( " On All Desktops " ) , OnAllDesktopsButton , buttonSize ) ;
m_button [ OnAllDesktopsButton ] - > setOnAllDesktops ( oad ) ;
m_button [ OnAllDesktopsButton ] - > setDeco ( ) ; // update deco...
2003-09-17 18:43:17 +00:00
connect ( m_button [ OnAllDesktopsButton ] , SIGNAL ( clicked ( ) ) , SLOT ( toggleOnAllDesktops ( ) ) ) ;
layout - > addWidget ( m_button [ OnAllDesktopsButton ] , 0 , Qt : : AlignHCenter | Qt : : AlignTop ) ;
2003-08-29 22:49:03 +00:00
}
break ;
case ' H ' : // Help button
2003-09-17 18:43:17 +00:00
if ( ( ! m_button [ HelpButton ] ) & & providesContextHelp ( ) ) {
m_button [ HelpButton ] = new PlastikButton ( this , " help " , i18n ( " Help " ) , HelpButton , buttonSize ) ;
connect ( m_button [ HelpButton ] , SIGNAL ( clicked ( ) ) , SLOT ( showContextHelp ( ) ) ) ;
layout - > addWidget ( m_button [ HelpButton ] , 0 , Qt : : AlignHCenter | Qt : : AlignTop ) ;
2003-08-29 22:49:03 +00:00
}
break ;
case ' I ' : // Minimize button
2003-09-17 18:43:17 +00:00
if ( ( ! m_button [ MinButton ] ) & & isMinimizable ( ) ) {
m_button [ MinButton ] = new PlastikButton ( this , " minimize " , i18n ( " Minimize " ) , MinButton , buttonSize ) ;
connect ( m_button [ MinButton ] , SIGNAL ( clicked ( ) ) , SLOT ( minimize ( ) ) ) ;
layout - > addWidget ( m_button [ MinButton ] , 0 , Qt : : AlignHCenter | Qt : : AlignTop ) ;
2003-08-29 22:49:03 +00:00
}
break ;
case ' A ' : // Maximize button
2003-09-17 18:43:17 +00:00
if ( ( ! m_button [ MaxButton ] ) & & isMaximizable ( ) ) {
2004-01-09 16:38:08 +00:00
const bool max = maximizeMode ( ) ! = MaximizeRestore ;
m_button [ MaxButton ] = new PlastikButton ( this , " maximize " , max ? i18n ( " Restore " ) : i18n ( " Maximize " ) , MaxButton , buttonSize , LeftButton | MidButton | RightButton ) ;
m_button [ OnAllDesktopsButton ] - > setMaximized ( max ) ;
m_button [ OnAllDesktopsButton ] - > setDeco ( ) ; // update deco...
m_button [ MaxButton ] - > setOnAllDesktops ( isOnAllDesktops ( ) ) ;
2003-09-17 18:43:17 +00:00
connect ( m_button [ MaxButton ] , SIGNAL ( clicked ( ) ) , SLOT ( slotMaximize ( ) ) ) ;
layout - > addWidget ( m_button [ MaxButton ] , 0 , Qt : : AlignHCenter | Qt : : AlignTop ) ;
2003-08-29 22:49:03 +00:00
}
break ;
case ' X ' : // Close button
2003-09-17 18:43:17 +00:00
if ( ( ! m_button [ CloseButton ] ) & & isCloseable ( ) ) {
m_button [ CloseButton ] = new PlastikButton ( this , " close " , i18n ( " Close " ) , CloseButton , buttonSize ) ;
connect ( m_button [ CloseButton ] , SIGNAL ( clicked ( ) ) , SLOT ( closeWindow ( ) ) ) ;
layout - > addWidget ( m_button [ CloseButton ] , 0 , Qt : : AlignHCenter | Qt : : AlignTop ) ;
2003-08-29 22:49:03 +00:00
}
break ;
case ' _ ' : // Spacer item
layout - > addSpacing ( 3 ) ; // add a 3 px spacing...
}
// add 2 px spacing between buttons
2003-09-17 18:43:17 +00:00
if ( n < ( s . length ( ) - 1 ) ) // and only between them!
2003-08-29 22:49:03 +00:00
layout - > addSpacing ( 1 ) ;
}
}
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : captionChange ( )
2003-08-29 22:49:03 +00:00
{
captionBufferDirty = true ;
2003-10-25 13:57:28 +00:00
widget ( ) - > update ( titleSpacer_ - > geometry ( ) ) ;
2003-08-29 22:49:03 +00:00
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : reset ( unsigned long changed )
{
if ( changed & SettingColors )
{
// repaint the whole thing
delete_pixmaps ( ) ;
create_pixmaps ( ) ;
captionBufferDirty = true ;
2003-10-25 13:57:28 +00:00
widget ( ) - > update ( ) ;
for ( int n = 0 ; n < NumButtons ; n + + ) {
if ( m_button [ n ] ) m_button [ n ] - > update ( ) ;
}
2003-09-17 18:43:17 +00:00
} else if ( changed & SettingFont ) {
// font has changed -- update title height and font
s_titleHeight = isTool ( ) ?
PlastikHandler : : titleHeightTool ( )
: PlastikHandler : : titleHeight ( ) ;
s_titleFont = isTool ( ) ?
PlastikHandler : : titleFontTool ( )
: PlastikHandler : : titleFont ( ) ;
// update buttons
for ( int n = 0 ; n < NumButtons ; n + + ) {
if ( m_button [ n ] ) m_button [ n ] - > setSize ( s_titleHeight - 1 ) ;
}
// update the spacer
titleSpacer_ - > changeSize ( 1 , s_titleHeight ,
QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
// then repaint
delete_pixmaps ( ) ;
create_pixmaps ( ) ;
captionBufferDirty = true ;
2003-10-25 13:57:28 +00:00
widget ( ) - > update ( ) ;
2003-09-17 18:43:17 +00:00
}
}
2003-12-15 15:14:45 +00:00
PlastikClient : : Position PlastikClient : : mousePosition ( const QPoint & point ) const
2003-08-29 22:49:03 +00:00
{
2003-09-23 14:45:56 +00:00
const int corner = 18 + 3 * PlastikHandler : : borderSize ( ) / 2 ;
2003-12-15 15:14:45 +00:00
Position pos = PositionCenter ;
2003-08-29 22:49:03 +00:00
// often needed coords..
QRect topRect ( topSpacer_ - > geometry ( ) ) ;
QRect decoRect ( decoSpacer_ - > geometry ( ) ) ;
QRect leftRect ( leftSpacer_ - > geometry ( ) ) ;
QRect leftTitleRect ( leftTitleSpacer_ - > geometry ( ) ) ;
QRect rightRect ( rightSpacer_ - > geometry ( ) ) ;
QRect rightTitleRect ( rightTitleSpacer_ - > geometry ( ) ) ;
QRect bottomRect ( bottomSpacer_ - > geometry ( ) ) ;
if ( bottomRect . contains ( point ) ) {
2003-12-15 15:14:45 +00:00
if ( point . x ( ) < = bottomRect . left ( ) + corner ) pos = PositionBottomLeft ;
else if ( point . x ( ) > = bottomRect . right ( ) - corner ) pos = PositionBottomRight ;
else pos = PositionBottom ;
2003-08-29 22:49:03 +00:00
}
else if ( leftRect . contains ( point ) ) {
2003-12-15 15:14:45 +00:00
if ( point . y ( ) < = topRect . top ( ) + corner ) pos = PositionTopLeft ;
else if ( point . y ( ) > = bottomRect . bottom ( ) - corner ) pos = PositionBottomLeft ;
else pos = PositionLeft ;
2003-08-29 22:49:03 +00:00
}
else if ( leftTitleRect . contains ( point ) ) {
2003-12-15 15:14:45 +00:00
if ( point . y ( ) < = topRect . top ( ) + corner ) pos = PositionTopLeft ;
else pos = PositionLeft ;
2003-08-29 22:49:03 +00:00
}
else if ( rightRect . contains ( point ) ) {
2003-12-15 15:14:45 +00:00
if ( point . y ( ) < = topRect . top ( ) + corner ) pos = PositionTopRight ;
else if ( point . y ( ) > = bottomRect . bottom ( ) - corner ) pos = PositionBottomRight ;
else pos = PositionRight ;
2003-08-29 22:49:03 +00:00
}
else if ( rightTitleRect . contains ( point ) ) {
2003-12-15 15:14:45 +00:00
if ( point . y ( ) < = topRect . top ( ) + corner ) pos = PositionTopRight ;
else pos = PositionRight ;
2003-08-29 22:49:03 +00:00
}
else if ( topRect . contains ( point ) ) {
2003-12-15 15:14:45 +00:00
if ( point . x ( ) < = topRect . left ( ) + corner ) pos = PositionTopLeft ;
else if ( point . x ( ) > = topRect . right ( ) - corner ) pos = PositionTopRight ;
else pos = PositionTop ;
2003-08-29 22:49:03 +00:00
}
else if ( decoRect . contains ( point ) ) {
if ( point . x ( ) < = leftTitleRect . right ( ) ) {
2003-12-15 15:14:45 +00:00
if ( point . y ( ) < = topRect . top ( ) + corner ) pos = PositionTopLeft ;
else pos = PositionLeft ;
2003-08-29 22:49:03 +00:00
}
else if ( point . x ( ) > = rightTitleRect . left ( ) ) {
2003-12-15 15:14:45 +00:00
if ( point . y ( ) < = topRect . top ( ) + corner ) pos = PositionTopRight ;
else pos = PositionRight ;
2003-08-29 22:49:03 +00:00
}
}
return pos ;
}
void PlastikClient : : iconChange ( )
{
2003-09-17 18:43:17 +00:00
if ( m_button [ MenuButton ] )
2003-08-29 22:49:03 +00:00
{
2003-10-25 13:57:28 +00:00
m_button [ MenuButton ] - > update ( ) ;
2003-08-29 22:49:03 +00:00
}
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : activeChange ( )
2003-08-29 22:49:03 +00:00
{
2003-09-17 18:43:17 +00:00
for ( int n = 0 ; n < NumButtons ; n + + )
2003-10-25 13:57:28 +00:00
if ( m_button [ n ] ) m_button [ n ] - > update ( ) ;
widget ( ) - > update ( ) ;
2003-08-29 22:49:03 +00:00
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : maximizeChange ( )
2003-08-29 22:49:03 +00:00
{
if ( ! PlastikHandler : : initialized ( ) ) return ;
2003-11-09 18:47:08 +00:00
if ( m_button [ MaxButton ] ) {
m_button [ MaxButton ] - > setMaximized ( maximizeMode ( ) ! = MaximizeRestore ) ;
m_button [ MaxButton ] - > setTipText ( ( maximizeMode ( ) = = MaximizeRestore ) ?
i18n ( " Maximize " )
: i18n ( " Restore " ) ) ;
m_button [ MaxButton ] - > setDeco ( ) ; // update the button icon...
}
2003-08-29 22:49:03 +00:00
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : desktopChange ( )
2003-08-29 22:49:03 +00:00
{
2003-09-17 18:43:17 +00:00
if ( m_button [ OnAllDesktopsButton ] ) {
m_button [ OnAllDesktopsButton ] - > setOnAllDesktops ( isOnAllDesktops ( ) ) ;
m_button [ OnAllDesktopsButton ] - > setTipText ( isOnAllDesktops ( ) ?
i18n ( " Not On All Desktops " )
: i18n ( " On All Desktops " ) ) ;
m_button [ OnAllDesktopsButton ] - > setDeco ( ) ; // update icon/deco
2003-08-29 22:49:03 +00:00
}
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : slotMaximize ( )
2003-08-29 22:49:03 +00:00
{
2003-09-17 18:43:17 +00:00
if ( m_button [ MaxButton ] )
2003-08-29 22:49:03 +00:00
{
2003-09-17 18:43:17 +00:00
switch ( m_button [ MaxButton ] - > lastMousePress ( ) )
2003-08-29 22:49:03 +00:00
{
2003-09-17 18:43:17 +00:00
case MidButton :
maximize ( maximizeMode ( ) ^ MaximizeVertical ) ;
break ;
case RightButton :
maximize ( maximizeMode ( ) ^ MaximizeHorizontal ) ;
break ;
default :
maximize ( maximizeMode ( ) = = MaximizeFull ? MaximizeRestore : MaximizeFull ) ;
2003-08-29 22:49:03 +00:00
}
2003-09-17 18:43:17 +00:00
doShape ( ) ;
2003-08-29 22:49:03 +00:00
}
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : menuButtonPressed ( )
2003-08-29 22:49:03 +00:00
{
2003-09-23 20:39:13 +00:00
static QTime * t = NULL ;
static PlastikClient * lastClient = NULL ;
if ( t = = NULL )
t = new QTime ;
bool dbl = ( lastClient = = this & & t - > elapsed ( ) < = QApplication : : doubleClickInterval ( ) ) ;
lastClient = this ;
t - > start ( ) ;
if ( ! dbl | | ! PlastikHandler : : menuClose ( ) ) {
QPoint pos = m_button [ MenuButton ] - > mapToGlobal ( m_button [ MenuButton ] - > rect ( ) . bottomLeft ( ) ) ;
2003-10-22 08:47:32 +00:00
KDecorationFactory * f = factory ( ) ;
2003-09-23 20:39:13 +00:00
showWindowMenu ( pos ) ;
2003-10-22 08:47:32 +00:00
if ( ! f - > exists ( this ) ) // 'this' was deleted
return ;
2003-09-23 20:39:13 +00:00
m_button [ MenuButton ] - > setDown ( false ) ;
}
else
closing = true ;
}
void PlastikClient : : menuButtonReleased ( )
{
if ( closing )
closeWindow ( ) ;
2003-08-29 22:49:03 +00:00
}
void PlastikClient : : create_pixmaps ( )
{
if ( pixmaps_created )
return ;
KPixmap tempPixmap ;
QPainter painter ;
// aTitleBarTopTile
tempPixmap . resize ( 1 , TOPMARGIN - 1 - 1 ) ;
KPixmapEffect : : gradient ( tempPixmap ,
PlastikHandler : : getColor ( TitleGradientToTop , true ) ,
PlastikHandler : : getColor ( TitleGradientFrom , true ) ,
KPixmapEffect : : VerticalGradient ) ;
aTitleBarTopTile = new QPixmap ( 1 , TOPMARGIN - 1 - 1 ) ;
painter . begin ( aTitleBarTopTile ) ;
painter . drawPixmap ( 0 , 0 , tempPixmap ) ;
painter . end ( ) ;
// aTitleBarTile
tempPixmap . resize ( 1 , s_titleHeight ) ;
KPixmapEffect : : gradient ( tempPixmap ,
PlastikHandler : : getColor ( TitleGradientFrom , true ) ,
PlastikHandler : : getColor ( TitleGradientTo , true ) ,
KPixmapEffect : : VerticalGradient ) ;
aTitleBarTile = new QPixmap ( 1 , s_titleHeight ) ;
painter . begin ( aTitleBarTile ) ;
painter . drawPixmap ( 0 , 0 , tempPixmap ) ;
painter . end ( ) ;
// iTitleBarTopTile
tempPixmap . resize ( 1 , TOPMARGIN - 1 - 1 ) ;
KPixmapEffect : : gradient ( tempPixmap ,
PlastikHandler : : getColor ( TitleGradientToTop , false ) ,
PlastikHandler : : getColor ( TitleGradientFrom , false ) ,
KPixmapEffect : : VerticalGradient ) ;
iTitleBarTopTile = new QPixmap ( 1 , TOPMARGIN - 1 - 1 ) ;
painter . begin ( iTitleBarTopTile ) ;
painter . drawPixmap ( 0 , 0 , tempPixmap ) ;
painter . end ( ) ;
// iTitleBarTile
tempPixmap . resize ( 1 , s_titleHeight ) ;
KPixmapEffect : : gradient ( tempPixmap ,
PlastikHandler : : getColor ( TitleGradientFrom , false ) ,
PlastikHandler : : getColor ( TitleGradientTo , false ) ,
KPixmapEffect : : VerticalGradient ) ;
iTitleBarTile = new QPixmap ( 1 , s_titleHeight ) ;
painter . begin ( iTitleBarTile ) ;
painter . drawPixmap ( 0 , 0 , tempPixmap ) ;
painter . end ( ) ;
pixmaps_created = true ;
}
void PlastikClient : : delete_pixmaps ( )
{
delete aTitleBarTopTile ;
aTitleBarTopTile = 0 ;
delete iTitleBarTopTile ;
iTitleBarTopTile = 0 ;
delete aTitleBarTile ;
aTitleBarTile = 0 ;
delete iTitleBarTile ;
iTitleBarTile = 0 ;
pixmaps_created = false ;
}
void PlastikClient : : update_captionBuffer ( )
{
if ( ! PlastikHandler : : initialized ( ) ) return ;
const uint maxCaptionLength = 300 ; // truncate captions longer than this!
2003-09-10 17:58:07 +00:00
QString c ( caption ( ) ) ;
if ( c . length ( ) > maxCaptionLength ) {
c . truncate ( maxCaptionLength ) ;
c . append ( " [...] " ) ;
2003-08-29 22:49:03 +00:00
}
QFontMetrics fm ( s_titleFont ) ;
2003-09-10 17:58:07 +00:00
int captionWidth = fm . width ( c ) ;
2003-08-29 22:49:03 +00:00
QPixmap textPixmap ;
QPainter painter ;
if ( PlastikHandler : : titleShadow ( ) )
{
// prepare the shadow
textPixmap = QPixmap ( captionWidth + 2 * 2 , s_titleHeight ) ; // 2*2 px shadow space
textPixmap . fill ( QColor ( 0 , 0 , 0 ) ) ;
textPixmap . setMask ( textPixmap . createHeuristicMask ( TRUE ) ) ;
painter . begin ( & textPixmap ) ;
painter . setFont ( s_titleFont ) ;
painter . setPen ( white ) ;
2003-09-10 17:58:07 +00:00
painter . drawText ( textPixmap . rect ( ) , AlignCenter , c ) ;
2003-08-29 22:49:03 +00:00
painter . end ( ) ;
}
QImage shadow ;
ShadowEngine se ;
// active
aCaptionBuffer - > resize ( captionWidth + 4 , s_titleHeight ) ; // 4 px shadow
painter . begin ( aCaptionBuffer ) ;
painter . drawTiledPixmap ( aCaptionBuffer - > rect ( ) , * aTitleBarTile ) ;
if ( PlastikHandler : : titleShadow ( ) )
{
shadow = se . makeShadow ( textPixmap , QColor ( 0 , 0 , 0 ) ) ;
painter . drawImage ( 1 , 1 , shadow ) ;
}
painter . setFont ( s_titleFont ) ;
painter . setPen ( PlastikHandler : : getColor ( TitleFont , true ) ) ;
2003-09-10 17:58:07 +00:00
painter . drawText ( aCaptionBuffer - > rect ( ) , AlignCenter , c ) ;
2003-08-29 22:49:03 +00:00
painter . end ( ) ;
// inactive
iCaptionBuffer - > resize ( captionWidth + 4 , s_titleHeight ) ;
painter . begin ( iCaptionBuffer ) ;
painter . drawTiledPixmap ( iCaptionBuffer - > rect ( ) , * iTitleBarTile ) ;
if ( PlastikHandler : : titleShadow ( ) )
{
painter . drawImage ( 1 , 1 , shadow ) ;
}
painter . setFont ( s_titleFont ) ;
painter . setPen ( PlastikHandler : : getColor ( TitleFont , false ) ) ;
2003-09-10 17:58:07 +00:00
painter . drawText ( iCaptionBuffer - > rect ( ) , AlignCenter , c ) ;
2003-08-29 22:49:03 +00:00
painter . end ( ) ;
captionBufferDirty = false ;
}
2003-09-17 18:43:17 +00:00
void PlastikClient : : borders ( int & left , int & right , int & top , int & bottom ) const
{
if ( ( maximizeMode ( ) = = MaximizeFull ) & & ! options ( ) - > moveResizeMaximizedWindows ( ) ) {
left = right = bottom = 0 ;
top = s_titleHeight + DECOHEIGHT ;
// update layout etc.
topSpacer_ - > changeSize ( 1 , 0 , QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
leftSpacer_ - > changeSize ( left , 1 , QSizePolicy : : Fixed , QSizePolicy : : Expanding ) ;
leftTitleSpacer_ - > changeSize ( left , s_titleHeight , QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
rightSpacer_ - > changeSize ( right , 1 , QSizePolicy : : Fixed , QSizePolicy : : Expanding ) ;
rightTitleSpacer_ - > changeSize ( right , s_titleHeight , QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
bottomSpacer_ - > changeSize ( 1 , bottom , QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
} else {
left = right = bottom = PlastikHandler : : borderSize ( ) ;
top = s_titleHeight + DECOHEIGHT + TOPMARGIN ;
// update layout etc.
topSpacer_ - > changeSize ( 1 , TOPMARGIN , QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
leftSpacer_ - > changeSize ( left , 1 , QSizePolicy : : Fixed , QSizePolicy : : Expanding ) ;
leftTitleSpacer_ - > changeSize ( SIDETITLEMARGIN , s_titleHeight ,
QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
rightSpacer_ - > changeSize ( right , 1 , QSizePolicy : : Fixed , QSizePolicy : : Expanding ) ;
rightTitleSpacer_ - > changeSize ( SIDETITLEMARGIN , s_titleHeight ,
QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ;
bottomSpacer_ - > changeSize ( 1 , bottom , QSizePolicy : : Expanding , QSizePolicy : : Fixed ) ;
}
// activate updated layout
widget ( ) - > layout ( ) - > activate ( ) ;
}
QSize PlastikClient : : minimumSize ( ) const
{
return widget ( ) - > minimumSize ( ) ;
}
void PlastikClient : : show ( )
{
widget ( ) - > show ( ) ;
}
void PlastikClient : : resize ( const QSize & s )
{
widget ( ) - > resize ( s ) ;
}
bool PlastikClient : : eventFilter ( QObject * o , QEvent * e )
{
if ( o ! = widget ( ) )
return false ;
switch ( e - > type ( ) )
{
case QEvent : : Resize :
resizeEvent ( ) ;
return true ;
case QEvent : : Paint :
paintEvent ( static_cast < QPaintEvent * > ( e ) ) ;
return true ;
case QEvent : : MouseButtonDblClick :
mouseDoubleClickEvent ( static_cast < QMouseEvent * > ( e ) ) ;
return true ;
case QEvent : : MouseButtonPress :
processMousePressEvent ( static_cast < QMouseEvent * > ( e ) ) ;
return true ;
default :
break ;
}
return false ;
}
} // KWinPlastik