00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __KERAMIK_H
00026 #define __KERAMIK_H
00027
00028 #include <qbutton.h>
00029 #include <kdecoration.h>
00030 #include <kdecorationfactory.h>
00031
00032 #include "tiles.h"
00033
00034 class QSpacerItem;
00035
00036 namespace Keramik {
00037
00038 enum TilePixmap { TitleLeft=0, TitleCenter, TitleRight,
00039 CaptionSmallLeft, CaptionSmallCenter, CaptionSmallRight,
00040 CaptionLargeLeft, CaptionLargeCenter, CaptionLargeRight,
00041 GrabBarLeft, GrabBarCenter, GrabBarRight,
00042 BorderLeft, BorderRight, NumTiles };
00043
00044 enum Button { MenuButton=0, OnAllDesktopsButton, HelpButton, MinButton,
00045 MaxButton, CloseButton, NumButtons };
00046
00047 enum ButtonDeco { Menu=0, OnAllDesktops, NotOnAllDesktops, Help, Minimize, Maximize,
00048 Restore, Close, NumButtonDecos };
00049
00050 struct SettingsCache
00051 {
00052 bool largeGrabBars:1;
00053 bool smallCaptionBubbles:1;
00054 };
00055
00056 class KeramikHandler : public KDecorationFactory
00057 {
00058 public:
00059 KeramikHandler();
00060 ~KeramikHandler();
00061
00062 virtual QValueList< BorderSize > borderSizes() const;
00063 virtual bool reset( unsigned long changed );
00064 virtual KDecoration* createDecoration( KDecorationBridge* );
00065
00066 bool showAppIcons() const { return showIcons; }
00067 bool useShadowedText() const { return shadowedText; }
00068 bool largeCaptionBubbles() const { return !smallCaptionBubbles; }
00069
00070 int titleBarHeight( bool large ) const {
00071 return ( large ? activeTiles[CaptionLargeCenter]->height()
00072 : activeTiles[CaptionSmallCenter]->height() );
00073 }
00074
00075 int grabBarHeight() const
00076 { return activeTiles[GrabBarCenter]->height(); }
00077
00078 const QPixmap *roundButton() const { return titleButtonRound; }
00079 const QPixmap *squareButton() const { return titleButtonSquare; }
00080 const QBitmap *buttonDeco( ButtonDeco deco ) const
00081 { return buttonDecos[ deco ]; }
00082
00083 inline const QPixmap *tile( TilePixmap tilePix, bool active ) const;
00084
00085 private:
00086 void readConfig();
00087 void createPixmaps();
00088 void destroyPixmaps();
00089
00090 void addWidth (int width, QPixmap *&pix, bool left, QPixmap *bottomPix);
00091 void addHeight (int height, QPixmap *&pix);
00092 void flip( QPixmap *&, QPixmap *& );
00093 void flip( QPixmap *& );
00094 void pretile( QPixmap *&, int, Qt::Orientation );
00095 QPixmap *composite( QImage *, QImage * );
00096 QImage *loadImage( const QString &, const QColor & );
00097 QPixmap *loadPixmap( const QString &, const QColor & );
00098
00099 bool showIcons:1, shadowedText:1,
00100 smallCaptionBubbles:1, largeGrabBars:1;
00101 SettingsCache *settings_cache;
00102 KeramikImageDb *imageDb;
00103
00104 QPixmap *activeTiles[ NumTiles ];
00105 QPixmap *inactiveTiles[ NumTiles ];
00106 QBitmap *buttonDecos[ NumButtonDecos ];
00107
00108 QPixmap *titleButtonRound, *titleButtonSquare;
00109
00110 };
00111
00112 class KeramikClient;
00113 class KeramikButton : public QButton
00114 {
00115 public:
00116 KeramikButton( KeramikClient *, const char *, Button, const QString &, const int realizeBtns = LeftButton );
00117 ~KeramikButton();
00118
00119 int lastButton() const { return lastbutton; }
00120
00121 private:
00122 void enterEvent( QEvent * );
00123 void leaveEvent( QEvent * );
00124 void mousePressEvent( QMouseEvent * );
00125 void mouseReleaseEvent( QMouseEvent * );
00126 void drawButton( QPainter * );
00127
00128 private:
00129 KeramikClient *client;
00130 Button button;
00131 bool hover;
00132 int lastbutton;
00133 int realizeButtons;
00134 };
00135
00136
00137 class KeramikClient : public KDecoration
00138 {
00139 Q_OBJECT
00140
00141 public:
00142
00143 KeramikClient( KDecorationBridge* bridge, KDecorationFactory* factory );
00144 ~KeramikClient();
00145 virtual void init();
00146 virtual void reset( unsigned long changed );
00147 virtual Position mousePosition( const QPoint& p ) const;
00148 virtual void borders( int& left, int& right, int& top, int& bottom ) const;
00149 virtual void resize( const QSize& s );
00150 virtual QSize minimumSize() const;
00151 virtual bool eventFilter( QObject* o, QEvent* e );
00152 virtual void activeChange();
00153 virtual void captionChange();
00154 virtual void maximizeChange();
00155 virtual void desktopChange();
00156 virtual void shadeChange() {};
00157
00158 private:
00159 void createLayout();
00160 void addButtons( QBoxLayout*, const QString & );
00161 void updateMask();
00162 void updateCaptionBuffer();
00163 void iconChange();
00164 void resizeEvent( QResizeEvent *);
00165 void paintEvent( QPaintEvent *);
00166 void mouseDoubleClickEvent( QMouseEvent * );
00167 int width() const { return widget()->width(); }
00168 int height() const { return widget()->height(); }
00169
00170 void calculateCaptionRect();
00171
00172 inline bool maximizedVertical() const {
00173 return ( maximizeMode() & MaximizeVertical );
00174 }
00175
00176 private slots:
00177 void menuButtonPressed();
00178 void slotMaximize();
00179
00180 private:
00181 QSpacerItem *topSpacer, *titlebar;
00182 KeramikButton *button[ NumButtons ];
00183 QRect captionRect;
00184 QPixmap captionBuffer;
00185 QPixmap *activeIcon, *inactiveIcon;
00186 bool captionBufferDirty:1, maskDirty:1;
00187 bool largeCaption:1, largeTitlebar:1;
00188 };
00189
00190 }
00191
00192 #endif // ___KERAMIK_H
00193
00194