00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00067 bool showAppIcons() const { return showIcons; }
00068 bool useShadowedText() const { return shadowedText; }
00069 bool largeCaptionBubbles() const { return !smallCaptionBubbles; }
00070
00071 int titleBarHeight( bool large ) const {
00072 return ( large ? activeTiles[CaptionLargeCenter]->height()
00073 : activeTiles[CaptionSmallCenter]->height() );
00074 }
00075
00076 int grabBarHeight() const
00077 { return activeTiles[GrabBarCenter]->height(); }
00078
00079 const QPixmap *roundButton() const { return titleButtonRound; }
00080 const QPixmap *squareButton() const { return titleButtonSquare; }
00081 const QBitmap *buttonDeco( ButtonDeco deco ) const
00082 { return buttonDecos[ deco ]; }
00083
00084 inline const QPixmap *tile( TilePixmap tilePix, bool active ) const;
00085
00086 private:
00087 void readConfig();
00088 void createPixmaps();
00089 void destroyPixmaps();
00090
00091 void addWidth (int width, QPixmap *&pix, bool left, QPixmap *bottomPix);
00092 void addHeight (int height, QPixmap *&pix);
00093 void flip( QPixmap *&, QPixmap *& );
00094 void flip( QPixmap *& );
00095 void pretile( QPixmap *&, int, Qt::Orientation );
00096 QPixmap *composite( QImage *, QImage * );
00097 QImage *loadImage( const QString &, const QColor & );
00098 QPixmap *loadPixmap( const QString &, const QColor & );
00099
00100 bool showIcons:1, shadowedText:1,
00101 smallCaptionBubbles:1, largeGrabBars:1;
00102 SettingsCache *settings_cache;
00103 KeramikImageDb *imageDb;
00104
00105 QPixmap *activeTiles[ NumTiles ];
00106 QPixmap *inactiveTiles[ NumTiles ];
00107 QBitmap *buttonDecos[ NumButtonDecos ];
00108
00109 QPixmap *titleButtonRound, *titleButtonSquare;
00110
00111 };
00112
00113 class KeramikClient;
00114 class KeramikButton : public QButton
00115 {
00116 public:
00117 KeramikButton( KeramikClient *, const char *, Button, const QString &, const int realizeBtns = LeftButton );
00118 ~KeramikButton();
00119
00120 ButtonState lastButton() const { return lastbutton; }
00121
00122 private:
00123 void enterEvent( QEvent * );
00124 void leaveEvent( QEvent * );
00125 void mousePressEvent( QMouseEvent * );
00126 void mouseReleaseEvent( QMouseEvent * );
00127 void drawButton( QPainter * );
00128
00129 private:
00130 KeramikClient *client;
00131 Button button;
00132 bool hover;
00133 ButtonState lastbutton;
00134 int realizeButtons;
00135 };
00136
00137
00138 class KeramikClient : public KDecoration
00139 {
00140 Q_OBJECT
00141
00142 public:
00143
00144 KeramikClient( KDecorationBridge* bridge, KDecorationFactory* factory );
00145 ~KeramikClient();
00146 virtual void init();
00147 virtual void reset( unsigned long changed );
00148 virtual Position mousePosition( const QPoint& p ) const;
00149 virtual void borders( int& left, int& right, int& top, int& bottom ) const;
00150 virtual void resize( const QSize& s );
00151 virtual QSize minimumSize() const;
00152 virtual bool eventFilter( QObject* o, QEvent* e );
00153 virtual void activeChange();
00154 virtual void captionChange();
00155 virtual void maximizeChange();
00156 virtual void desktopChange();
00157 virtual void shadeChange();
00158
00159 private:
00160 void createLayout();
00161 void addButtons( QBoxLayout*, const QString & );
00162 void updateMask();
00163 void updateCaptionBuffer();
00164 void iconChange();
00165 void resizeEvent( QResizeEvent *);
00166 void paintEvent( QPaintEvent *);
00167 void mouseDoubleClickEvent( QMouseEvent * );
00168 int width() const { return widget()->width(); }
00169 int height() const { return widget()->height(); }
00170
00171 void calculateCaptionRect();
00172
00173 inline bool maximizedVertical() const {
00174 return ( maximizeMode() & MaximizeVertical );
00175 }
00176
00177 private slots:
00178 void menuButtonPressed();
00179 void slotMaximize();
00180 void slotAbove();
00181 void slotBelow();
00182 void slotShade();
00183 void keepAboveChange( bool );
00184 void keepBelowChange( bool );
00185
00186 private:
00187 QSpacerItem *topSpacer, *titlebar;
00188 KeramikButton *button[ NumButtons ];
00189 QRect captionRect;
00190 QPixmap captionBuffer;
00191 QPixmap *activeIcon, *inactiveIcon;
00192 bool captionBufferDirty:1, maskDirty:1;
00193 bool largeCaption:1, largeTitlebar:1;
00194 };
00195
00196 }
00197
00198 #endif // ___KERAMIK_H
00199
00200