1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
/*
This file is part of the KDE project.
Copyright (C) 2005 Sandro Giessl <sandro@giessl.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#ifndef KCOMMONDECORATION_H
#define KCOMMONDECORATION_H
#include <qbutton.h>
#include <qvaluevector.h>
#include "kdecoration.h"
class KDecorationBridge;
class KDecorationFactory;
enum ButtonType {
HelpButton=0,
MaxButton,
MinButton,
CloseButton,
MenuButton,
OnAllDesktopsButton,
AboveButton,
BelowButton,
ShadeButton,
NumButtons
};
class KCommonDecorationButton;
class KCommonDecorationButtonPrivate;
class KCommonDecorationPrivate;
/**
* This class eases development of decorations by implementing parts of KDecoration
* which are error prone and common for most decorations.
* It takes care of the window layout, button/action handling, and window mask creation.
*/
class KWIN_EXPORT KCommonDecoration : public KDecoration
{
Q_OBJECT
public:
KCommonDecoration(KDecorationBridge* bridge, KDecorationFactory* factory);
virtual ~KCommonDecoration();
/**
* Used to calculate the decoration layout. The basic layout looks like this:
*
* Window:
* _______________________________________________________________
* | LM_TitleEdgeTop |
* |_______________________________________________________________|
* | LM_TitleEdgeLeft | [title] | LM_TitleEdgeRight |
* |__________________|________________________|___________________|
* | LM_TitleEdgeBottom |
* |_______________________________________________________________|
* | | | |
* | | | |
* | | | |
* |LM_BorderLeft LM_BorderRight|
* |_|___________________________________________________________|_|
* | LM_BorderBottom |
* |_______________________________________________________________|
*
* Title:
* ___________________________________________________________________________________
* | LM_ButtonMarginTop | | LM_ButtonMarginTop |
* |________________________________| |_________________________________|
* | [Buttons] | LM_TitleBorderLeft | LM_TitleHeight | LM_TitleBorderRight | [Buttons] |
* |___________|____________________|________________|_____________________|___________|
*
* Buttons:
* _____________________________________________________________________________________________
* | button | spacing | button | spacing | explicit spacer | spacing | ... | spacing | button |
* |________|_________|________|_________|_________________|_________|________|_________|________|
*
* @see layoutMetric()
*/
enum LayoutMetric
{
LM_BorderLeft,
LM_BorderRight,
LM_BorderBottom,
LM_TitleHeight,
LM_TitleBorderLeft,
LM_TitleBorderRight,
LM_TitleEdgeLeft,
LM_TitleEdgeRight,
LM_TitleEdgeTop,
LM_TitleEdgeBottom,
LM_ButtonWidth,
LM_ButtonHeight,
LM_ButtonSpacing,
LM_ExplicitButtonSpacer,
LM_ButtonMarginTop
};
enum DecorationBehaviour
{
DB_MenuClose, ///< Close window on double clicking the menu
DB_WindowMask, ///< Set a mask on the window
DB_ButtonHide ///< Hide buttons when there is not enough space in the titlebar
};
enum WindowCorner
{
WC_TopLeft,
WC_TopRight,
WC_BottomLeft,
WC_BottomRight
};
/**
* The name of the decoration used in the decoration preview.
*/
virtual QString visibleName() const = 0;
/**
* The default title button order on the left.
* @see KDecoration::titleButtonsLeft()
* @see KDecoration::titleButtonsRight()
*/
virtual QString defaultButtonsLeft() const = 0;
/**
* The default title button order on the left.
* @see KDecoration::titleButtonsLeft()
* @see KDecoration::titleButtonsRight()
*/
virtual QString defaultButtonsRight() const = 0;
/**
* This controls whether some specific behaviour should be enabled or not.
* @see DecorationBehaviour
*/
virtual bool decorationBehaviour(DecorationBehaviour behaviour) const;
/**
* This controls the layout of the decoration in various ways. It is
* possible to have a different layout for different window states.
* @param lm The layout element.
* @param respectWindowState Whether window states should be taken into account or a "default" state should be assumed.
* @param button For LM_ButtonWidth and LM_ButtonHeight, the button.
*/
virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton *button = 0) const;
/**
* Create a new title bar button. KCommonDecoration takes care of memory management.
* @return a pointer to the button, or 0 if the button should not be created.
*/
virtual KCommonDecorationButton *createButton(ButtonType type) = 0;
/**
* @return the mask for the specific window corner.
*/
virtual QRegion cornerShape(WindowCorner corner);
/**
* This updates the window mask using the information provided by
* cornerShape(). Edges which are aligned to screen corners are not
* shaped for better usability (remember to paint these areas in paintEvent(), too).
* You normally don't want/need to reimplement updateWindowShape().
* @see cornerShape()
*/
virtual void updateWindowShape();
/**
* Draw the window decoration.
*/
virtual void paintEvent(QPaintEvent *e) = 0;
/**
* This is used to update the painting of the title bar after the caption has been changed.
* Reimplement for a more efficient implementation (default calls update() on the whole decoration).
*/
virtual void updateCaption();
int buttonsLeftWidth() const;
int buttonsRightWidth() const;
/**
* TODO: remove?
*/
void updateLayout() const;
/**
* Makes sure all buttons are repainted.
*/
void updateButtons() const;
/**
* Manually call reset() on each button.
*/
void resetButtons() const;
/**
* Convenience method.
* @returns true if the window type is NET::Toolbar, NET::Utility, or NET::Menu
*/
bool isToolWindow() const;
/**
* Convenience method.
* @returns the title rect.
*/
QRect titleRect() const;
public:
/**
* Handles widget and layout creation, call the base implementation when subclassing this member.
*/
virtual void init();
/**
* Handles SettingButtons, call the base implementation when subclassing this member.
*/
virtual void reset( unsigned long changed );
virtual void borders( int& left, int& right, int& top, int& bottom ) const;
virtual void show();
virtual void resize(const QSize& s);
virtual QSize minimumSize() const;
virtual void maximizeChange();
virtual void desktopChange();
virtual void shadeChange();
virtual void iconChange();
virtual void activeChange();
virtual void captionChange();
public slots:
void keepAboveChange(bool above);
void keepBelowChange(bool below);
void slotMaximize();
void slotShade();
void slotKeepAbove();
void slotKeepBelow();
void menuButtonPressed();
void menuButtonReleased();
public:
virtual Position mousePosition(const QPoint &point) const;
virtual bool eventFilter( QObject* o, QEvent* e );
virtual void resizeEvent(QResizeEvent *e);
virtual void mouseDoubleClickEvent(QMouseEvent *e);
virtual void wheelEvent(QWheelEvent *e);
private:
void resetLayout();
void moveWidget(int x, int y, QWidget *widget) const;
void resizeWidget(int w, int h, QWidget *widget) const;
typedef QValueVector <KCommonDecorationButton*> ButtonContainer; ///< If the entry is 0, it's a spacer.
int buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden = false) const;
void addButtons(ButtonContainer &btnContainer, const QString& buttons, bool isLeft);
KCommonDecorationButton *m_button[NumButtons];
ButtonContainer m_buttonsLeft;
ButtonContainer m_buttonsRight;
QWidget *m_previewWidget;
// button hiding for small windows
void calcHiddenButtons();
int btnHideMinWidth;
int btnHideLastWidth;
bool closing; // for menu doubleclick closing...
KCommonDecorationPrivate *d;
};
/**
* Title bar buttons of KCommonDecoration need to inherit this class.
*/
class KWIN_EXPORT KCommonDecorationButton : public QButton
{
friend class KCommonDecoration;
public:
KCommonDecorationButton(ButtonType type, KCommonDecoration *parent, const char *name);
virtual ~KCommonDecorationButton();
/**
* These flags specify what has changed, e.g. the reason for a reset().
*/
enum
{
ManualReset = 1 << 0, ///< The button might want to do a full reset for some reason...
SizeChange = 1 << 1, ///< The button size changed @see setSize()
ToggleChange = 1 << 2, ///< The button toggle state has changed @see setToggleButton()
StateChange = 1 << 3, ///< The button has been set pressed or not... @see setOn()
IconChange = 1 << 4, ///< The window icon has been changed
DecorationReset = 1 << 5 ///< E.g. when decoration colors have changed
};
/**
* Initialize the button after size change etc.
*/
virtual void reset(unsigned long changed) = 0;
/**
* @returns the KCommonDecoration the button belongs to.
*/
KCommonDecoration *decoration() const;
/**
* @returns the button type.
* @see ButtonType
*/
ButtonType type() const;
/**
* Whether the button is left of the titlebar or not.
*/
bool isLeft() const;
/**
* Set which mouse buttons the button should honor. Used e.g. to prevent accidental right mouse clicks.
*/
void setRealizeButtons(int btns);
/**
* Set the button size.
*/
void setSize(const QSize &s);
/**
* Set/update the button's tool tip
*/
void setTipText(const QString &tip);
/**
* The mouse button that has been clicked last time.
*/
ButtonState lastMousePress() const { return m_lastMouse; }
QSize sizeHint() const;
protected:
void setToggleButton(bool toggle);
void setOn(bool on);
void setLeft(bool left);
void mousePressEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private:
KCommonDecoration *m_decoration;
ButtonType m_type;
int m_realizeButtons;
QSize m_size;
ButtonState m_lastMouse;
bool m_isLeft;
KCommonDecorationButtonPrivate *d;
};
#endif // KCOMMONDECORATION_H
|