kwin Library API Documentation

keramik.h

00001 /*
00002  *
00003  * Keramik KWin client (version 0.8)
00004  *
00005  * Copyright (C) 2002 Fredrik Höglund <fredrik@kde.org>
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the license, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 #ifndef __KERAMIK_H
00025 #define __KERAMIK_H
00026 
00027 #include <qbutton.h>
00028 #include <kdecoration.h>
00029 #include <kdecorationfactory.h>
00030 
00031 #include "tiles.h"
00032 
00033 class QSpacerItem;
00034 
00035 namespace Keramik {
00036 
00037     enum TilePixmap  { TitleLeft=0, TitleCenter, TitleRight,
00038                        CaptionSmallLeft, CaptionSmallCenter, CaptionSmallRight,
00039                        CaptionLargeLeft, CaptionLargeCenter, CaptionLargeRight,
00040                        GrabBarLeft, GrabBarCenter, GrabBarRight,
00041                        BorderLeft, BorderRight, NumTiles };
00042 
00043     enum Button      { MenuButton=0, OnAllDesktopsButton, HelpButton, MinButton,
00044                        MaxButton, CloseButton, AboveButton, BelowButton, ShadeButton,
00045                        NumButtons };
00046 
00047     enum ButtonDeco  { Menu=0, OnAllDesktops, NotOnAllDesktops, Help, Minimize, Maximize,
00048                        Restore, Close, AboveOn, AboveOff, BelowOn, BelowOff, ShadeOn, ShadeOff,
00049                            NumButtonDecos };
00050 
00051     struct SettingsCache
00052     {
00053         bool largeGrabBars:1;
00054         bool smallCaptionBubbles:1;
00055     };
00056 
00057     class KeramikHandler : public KDecorationFactory
00058     {
00059         public:
00060             KeramikHandler();
00061             ~KeramikHandler();
00062 
00063             virtual QValueList< BorderSize > borderSizes() const;
00064             virtual bool reset( unsigned long changed );
00065                         virtual KDecoration* createDecoration( KDecorationBridge* );
00066             virtual bool supports( Ability ability );
00067 
00068             bool showAppIcons() const        { return showIcons; }
00069             bool useShadowedText() const     { return shadowedText; }
00070             bool largeCaptionBubbles() const { return !smallCaptionBubbles; }
00071 
00072             int titleBarHeight( bool large ) const {
00073                 return ( large ? activeTiles[CaptionLargeCenter]->height()
00074                         : activeTiles[CaptionSmallCenter]->height() );
00075             }
00076 
00077             int grabBarHeight() const
00078                 { return activeTiles[GrabBarCenter]->height(); }
00079 
00080             const QPixmap *roundButton() const  { return titleButtonRound; }
00081             const QPixmap *squareButton() const { return titleButtonSquare; }
00082             const QBitmap *buttonDeco( ButtonDeco deco ) const
00083                 { return buttonDecos[ deco ]; }
00084 
00085             inline const QPixmap *tile( TilePixmap tilePix, bool active ) const;
00086 
00087         private:
00088             void readConfig();
00089             void createPixmaps();
00090             void destroyPixmaps();
00091 
00092             void addWidth  (int width,  QPixmap *&pix, bool left, QPixmap *bottomPix);
00093             void addHeight (int height, QPixmap *&pix);
00094             void flip( QPixmap *&, QPixmap *& );
00095             void flip( QPixmap *& );
00096             void pretile( QPixmap *&, int, Qt::Orientation );
00097             QPixmap *composite( QImage *, QImage * );
00098             QImage  *loadImage( const QString &, const QColor & );
00099             QPixmap *loadPixmap( const QString &, const QColor & );
00100 
00101             bool showIcons:1, shadowedText:1,
00102                 smallCaptionBubbles:1, largeGrabBars:1;
00103             SettingsCache *settings_cache;
00104             KeramikImageDb *imageDb;
00105 
00106             QPixmap *activeTiles[ NumTiles ];
00107             QPixmap *inactiveTiles[ NumTiles ];
00108             QBitmap *buttonDecos[ NumButtonDecos ];
00109 
00110             QPixmap *titleButtonRound, *titleButtonSquare;
00111 
00112     }; // class KeramikHandler
00113 
00114     class KeramikClient;
00115     class KeramikButton : public QButton
00116     {
00117         public:
00118             KeramikButton( KeramikClient *, const char *, Button, const QString &, const int realizeBtns = LeftButton );
00119             ~KeramikButton();
00120 
00121             ButtonState lastButton() const { return lastbutton; }
00122 
00123         private:
00124             void enterEvent( QEvent * );
00125             void leaveEvent( QEvent * );
00126             void mousePressEvent( QMouseEvent * );
00127             void mouseReleaseEvent( QMouseEvent * );
00128             void drawButton( QPainter * );
00129 
00130         private:
00131             KeramikClient *client;
00132             Button button;
00133             bool hover;
00134             ButtonState lastbutton;
00135             int realizeButtons;
00136     }; // class KeramikButton
00137 
00138 
00139     class KeramikClient : public KDecoration
00140     {
00141         Q_OBJECT
00142 
00143         public:
00144 
00145             KeramikClient( KDecorationBridge* bridge, KDecorationFactory* factory );
00146             ~KeramikClient();
00147                         virtual void init();
00148             virtual void reset( unsigned long changed );
00149             virtual Position mousePosition( const QPoint& p ) const;
00150                 virtual void borders( int& left, int& right, int& top, int& bottom ) const;
00151             virtual void resize( const QSize& s );
00152             virtual QSize minimumSize() const;
00153             virtual bool eventFilter( QObject* o, QEvent* e );
00154             virtual void activeChange();
00155             virtual void captionChange();
00156                         virtual void maximizeChange();
00157                         virtual void desktopChange();
00158                         virtual void shadeChange();
00159 
00160         private:
00161             void createLayout();
00162             void addButtons( QBoxLayout*, const QString & );
00163             void updateMask(); // FRAME
00164             void updateCaptionBuffer();
00165             void iconChange();
00166             void resizeEvent( QResizeEvent *); // FRAME
00167             void paintEvent( QPaintEvent *); // FRAME
00168             void mouseDoubleClickEvent( QMouseEvent * ); // FRAME
00169             int width() const { return widget()->width(); }
00170             int height() const { return widget()->height(); }
00171 
00172             void calculateCaptionRect();
00173 
00174             inline bool maximizedVertical() const {
00175                 return ( maximizeMode() & MaximizeVertical );
00176             }
00177 
00178         private slots:
00179             void menuButtonPressed();
00180             void slotMaximize();
00181             void slotAbove();
00182             void slotBelow();
00183             void slotShade();
00184             void keepAboveChange( bool );
00185             void keepBelowChange( bool );
00186 
00187         private:
00188             QSpacerItem   *topSpacer, *titlebar;
00189             KeramikButton *button[ NumButtons ];
00190             QRect          captionRect;
00191             QPixmap        captionBuffer;
00192             QPixmap       *activeIcon, *inactiveIcon;
00193             bool           captionBufferDirty:1, maskDirty:1;
00194             bool           largeCaption:1, largeTitlebar:1;
00195     }; // class KeramikClient
00196 
00197 } // namespace Keramik
00198 
00199 #endif // ___KERAMIK_H
00200 
00201 // vim: set noet ts=4 sw=4:
KDE Logo
This file is part of the documentation for kwin Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jun 14 16:47:03 2006 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003