add more spacing
[personal-kdebase.git] / workspace / kwin / clients / keramik / keramik.h
blob9cf1b9321f2baafa186ccb15edeb6c0ba401a420
1 /*
3 * Keramik KWin client (version 0.8)
5 * Copyright (C) 2002 Fredrik Höglund <fredrik@kde.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the license, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef __KERAMIK_H
25 #define __KERAMIK_H
27 #include <QAbstractButton>
28 #include <kdecoration.h>
29 #include <kdecorationfactory.h>
31 class QSpacerItem;
32 class QBoxLayout;
34 namespace Keramik {
36 enum TilePixmap { TitleLeft=0, TitleCenter, TitleRight,
37 CaptionSmallLeft, CaptionSmallCenter, CaptionSmallRight,
38 CaptionLargeLeft, CaptionLargeCenter, CaptionLargeRight,
39 GrabBarLeft, GrabBarCenter, GrabBarRight,
40 BorderLeft, BorderRight, NumTiles };
42 enum Button { MenuButton=0, OnAllDesktopsButton, HelpButton, MinButton,
43 MaxButton, CloseButton, AboveButton, BelowButton, ShadeButton,
44 NumButtons };
46 enum ButtonDeco { Menu=0, OnAllDesktops, NotOnAllDesktops, Help, Minimize, Maximize,
47 Restore, Close, AboveOn, AboveOff, BelowOn, BelowOff, ShadeOn, ShadeOff,
48 NumButtonDecos };
50 struct SettingsCache
52 bool largeGrabBars:1;
53 bool smallCaptionBubbles:1;
56 class KeramikHandler : public KDecorationFactory
58 public:
59 KeramikHandler();
60 ~KeramikHandler();
62 virtual QList< BorderSize > borderSizes() const;
63 virtual bool reset( unsigned long changed );
64 virtual KDecoration* createDecoration( KDecorationBridge* );
65 virtual bool supports( Ability ability ) const;
67 bool showAppIcons() const { return showIcons; }
68 bool useShadowedText() const { return shadowedText; }
69 bool largeCaptionBubbles() const { return !smallCaptionBubbles; }
71 int titleBarHeight( bool large ) const {
72 return ( large ? activeTiles[CaptionLargeCenter]->height()
73 : activeTiles[CaptionSmallCenter]->height() );
76 int grabBarHeight() const
77 { return activeTiles[GrabBarCenter]->height(); }
79 const QPixmap *roundButton() const { return titleButtonRound; }
80 const QPixmap *squareButton() const { return titleButtonSquare; }
81 const QBitmap *buttonDeco( ButtonDeco deco ) const
82 { return buttonDecos[ deco ]; }
84 inline const QPixmap *tile( TilePixmap tilePix, bool active ) const;
86 private:
87 void readConfig();
88 void createPixmaps();
89 void destroyPixmaps();
91 void addWidth (int width, QPixmap *&pix, bool left, QPixmap *bottomPix);
92 void addHeight (int height, QPixmap *&pix);
93 void flip( QPixmap *&, QPixmap *& );
94 void pretile( QPixmap *&, int, Qt::Orientation );
95 QPixmap *composite( QImage *, QImage * );
96 QImage *loadImage( const QString &, const QColor & );
97 QPixmap *loadPixmap( const QString &, const QColor & );
99 bool showIcons:1, shadowedText:1,
100 smallCaptionBubbles:1, largeGrabBars:1;
101 SettingsCache *settings_cache;
103 QPixmap *activeTiles[ NumTiles ];
104 QPixmap *inactiveTiles[ NumTiles ];
105 QBitmap *buttonDecos[ NumButtonDecos ];
107 QPixmap *titleButtonRound, *titleButtonSquare;
109 }; // class KeramikHandler
111 class KeramikClient;
112 class KeramikButton : public QAbstractButton
114 public:
115 KeramikButton( KeramikClient *, Button, const QString &, const int realizeBtns = Qt::LeftButton );
116 ~KeramikButton();
118 Qt::MouseButtons lastButton() const { return lastbutton; }
120 private:
121 void enterEvent( QEvent * );
122 void leaveEvent( QEvent * );
123 void mousePressEvent( QMouseEvent * );
124 void mouseReleaseEvent( QMouseEvent * );
125 void paintEvent( QPaintEvent * );
127 private:
128 KeramikClient *client;
129 Button button;
130 bool hover;
131 Qt::MouseButtons lastbutton;
132 int realizeButtons;
133 }; // class KeramikButton
136 class KeramikClient : public KDecoration
138 Q_OBJECT
140 public:
142 KeramikClient( KDecorationBridge* bridge, KDecorationFactory* factory );
143 ~KeramikClient();
144 virtual void init();
145 virtual void reset( unsigned long changed );
146 virtual Position mousePosition( const QPoint& p ) const;
147 virtual void borders( int& left, int& right, int& top, int& bottom ) const;
148 virtual void resize( const QSize& s );
149 virtual QSize minimumSize() const;
150 virtual bool eventFilter( QObject* o, QEvent* e );
151 virtual void activeChange();
152 virtual void captionChange();
153 virtual void maximizeChange();
154 virtual void desktopChange();
155 virtual void shadeChange();
157 private:
158 void createLayout();
159 void addButtons( QBoxLayout*, const QString & );
160 void updateMask(); // FRAME
161 void updateCaptionBuffer();
162 void iconChange();
163 void resizeEvent( QResizeEvent *); // FRAME
164 void paintEvent( QPaintEvent *); // FRAME
165 void mouseDoubleClickEvent( QMouseEvent * ); // FRAME
166 int width() const { return widget()->width(); }
167 int height() const { return widget()->height(); }
169 void calculateCaptionRect();
171 inline bool maximizedVertical() const {
172 return ( maximizeMode() & MaximizeVertical );
175 private slots:
176 void menuButtonPressed();
177 void slotMaximize();
178 void slotAbove();
179 void slotBelow();
180 void slotShade();
181 void keepAboveChange( bool );
182 void keepBelowChange( bool );
184 private:
185 QSpacerItem *topSpacer, *titlebar;
186 KeramikButton *button[ NumButtons ];
187 QRect captionRect;
188 QPixmap captionBuffer;
189 QPixmap *activeIcon, *inactiveIcon;
190 bool captionBufferDirty:1, maskDirty:1;
191 bool largeCaption:1, largeTitlebar:1;
192 }; // class KeramikClient
194 } // namespace Keramik
196 #endif // ___KERAMIK_H
198 // vim: set noet ts=4 sw=4: