2
This file is part of the KDE project.
4
Copyright (C) 2005 Sandro Giessl <sandro@giessl.com>
6
Permission is hereby granted, free of charge, to any person obtaining a
7
copy of this software and associated documentation files (the "Software"),
8
to deal in the Software without restriction, including without limitation
9
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
and/or sell copies of the Software, and to permit persons to whom the
11
Software is furnished to do so, subject to the following conditions:
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
25
#ifndef KCOMMONDECORATION_H
26
#define KCOMMONDECORATION_H
28
#include <QtGui/QAbstractButton>
29
#include "kdecoration.h"
31
class KDecorationBridge;
32
class KDecorationFactory;
47
class KCommonDecorationButton;
49
class KCommonDecorationButtonPrivate;
50
class KCommonDecorationPrivate;
53
* This class eases development of decorations by implementing parts of KDecoration
54
* which are error prone and common for most decorations.
55
* It takes care of the window layout, button/action handling, and window mask creation.
57
class KWIN_EXPORT KCommonDecoration : public KDecoration
62
KCommonDecoration(KDecorationBridge* bridge, KDecorationFactory* factory);
63
virtual ~KCommonDecoration();
66
* Used to calculate the decoration layout. The basic layout looks like this:
69
* _______________________________________________________________
71
* |_______________________________________________________________|
72
* | LM_TitleEdgeLeft | [title] | LM_TitleEdgeRight |
73
* |__________________|________________________|___________________|
74
* | LM_TitleEdgeBottom |
75
* |_______________________________________________________________|
79
* |LM_BorderLeft LM_BorderRight|
80
* |_|___________________________________________________________|_|
82
* |_______________________________________________________________|
85
* ___________________________________________________________________________________
86
* | LM_ButtonMarginTop | | LM_ButtonMarginTop |
87
* |________________________________| |_________________________________|
88
* | [Buttons] | LM_TitleBorderLeft | LM_TitleHeight | LM_TitleBorderRight | [Buttons] |
89
* |___________|____________________|________________|_____________________|___________|
92
* _____________________________________________________________________________________________
93
* | button | spacing | button | spacing | explicit spacer | spacing | ... | spacing | button |
94
* |________|_________|________|_________|_________________|_________|________|_________|________|
113
LM_ExplicitButtonSpacer,
117
enum DecorationBehaviour
119
DB_MenuClose, ///< Close window on double clicking the menu
120
DB_WindowMask, ///< Set a mask on the window
121
DB_ButtonHide ///< Hide buttons when there is not enough space in the titlebar
133
* The name of the decoration used in the decoration preview.
135
virtual QString visibleName() const = 0;
137
* The default title button order on the left.
138
* @see KDecoration::titleButtonsLeft()
139
* @see KDecoration::titleButtonsRight()
141
virtual QString defaultButtonsLeft() const = 0;
143
* The default title button order on the left.
144
* @see KDecoration::titleButtonsLeft()
145
* @see KDecoration::titleButtonsRight()
147
virtual QString defaultButtonsRight() const = 0;
150
* This controls whether some specific behaviour should be enabled or not.
151
* @see DecorationBehaviour
153
virtual bool decorationBehaviour(DecorationBehaviour behaviour) const;
156
* This controls the layout of the decoration in various ways. It is
157
* possible to have a different layout for different window states.
158
* @param lm The layout element.
159
* @param respectWindowState Whether window states should be taken into account or a "default" state should be assumed.
160
* @param button For LM_ButtonWidth and LM_ButtonHeight, the button.
162
virtual int layoutMetric(LayoutMetric lm, bool respectWindowState = true, const KCommonDecorationButton *button = 0) const;
165
* Create a new title bar button. KCommonDecoration takes care of memory management.
166
* @return a pointer to the button, or 0 if the button should not be created.
168
virtual KCommonDecorationButton *createButton(ButtonType type) = 0;
171
* @return the mask for the specific window corner.
173
virtual QRegion cornerShape(WindowCorner corner);
176
* This updates the window mask using the information provided by
177
* cornerShape(). Edges which are aligned to screen corners are not
178
* shaped for better usability (remember to paint these areas in paintEvent(), too).
179
* You normally don't want/need to reimplement updateWindowShape().
182
virtual void updateWindowShape();
185
* Draw the window decoration.
187
virtual void paintEvent(QPaintEvent *e) = 0;
190
* This is used to update the painting of the title bar after the caption has been changed.
191
* Reimplement for a more efficient implementation (default calls update() on the whole decoration).
193
virtual void updateCaption();
195
int buttonsLeftWidth() const;
196
int buttonsRightWidth() const;
201
void updateLayout() const;
203
* Makes sure all buttons are repainted.
205
void updateButtons() const;
207
* Manually call reset() on each button.
209
void resetButtons() const;
212
* Convenience method.
213
* @returns true if the window type is NET::Toolbar, NET::Utility, or NET::Menu
215
bool isToolWindow() const;
217
* Convenience method.
218
* @returns the title rect.
220
QRect titleRect() const;
224
* Handles widget and layout creation, call the base implementation when subclassing this member.
228
* Handles SettingButtons, call the base implementation when subclassing this member.
230
virtual void reset( unsigned long changed );
231
virtual void borders( int& left, int& right, int& top, int& bottom ) const;
233
virtual void resize(const QSize& s);
234
virtual QSize minimumSize() const;
235
virtual void maximizeChange();
236
virtual void desktopChange();
237
virtual void shadeChange();
238
virtual void iconChange();
239
virtual void activeChange();
240
virtual void captionChange();
242
void keepAboveChange(bool above);
243
void keepBelowChange(bool below);
246
void slotKeepAbove();
247
void slotKeepBelow();
248
void menuButtonPressed();
249
void menuButtonReleased();
251
virtual Position mousePosition(const QPoint &point) const;
253
virtual bool eventFilter( QObject* o, QEvent* e );
254
virtual void resizeEvent(QResizeEvent *e);
255
virtual void mouseDoubleClickEvent(QMouseEvent *e);
256
virtual void wheelEvent(QWheelEvent *e);
261
void moveWidget(int x, int y, QWidget *widget) const;
262
void resizeWidget(int w, int h, QWidget *widget) const;
264
typedef QVector <KCommonDecorationButton*> ButtonContainer; ///< If the entry is 0, it's a spacer.
265
int buttonContainerWidth(const ButtonContainer &btnContainer, bool countHidden = false) const;
266
void addButtons(ButtonContainer &btnContainer, const QString& buttons, bool isLeft);
268
KCommonDecorationButton *m_button[NumButtons];
270
ButtonContainer m_buttonsLeft;
271
ButtonContainer m_buttonsRight;
273
QWidget *m_previewWidget;
275
// button hiding for small windows
276
void calcHiddenButtons();
278
int btnHideLastWidth;
280
bool closing; // for menu doubleclick closing...
282
KCommonDecorationPrivate *d;
286
* Title bar buttons of KCommonDecoration need to inherit this class.
288
class KWIN_EXPORT KCommonDecorationButton : public QAbstractButton
292
friend class KCommonDecoration;
295
KCommonDecorationButton(ButtonType type, KCommonDecoration *parent);
296
virtual ~KCommonDecorationButton();
299
* These flags specify what has changed, e.g. the reason for a reset().
303
ManualReset = 1 << 0, ///< The button might want to do a full reset for some reason...
304
SizeChange = 1 << 1, ///< The button size changed @see setSize()
305
ToggleChange = 1 << 2, ///< The button toggle state has changed @see setToggleButton()
306
StateChange = 1 << 3, ///< The button has been set pressed or not... @see setOn()
307
IconChange = 1 << 4, ///< The window icon has been changed
308
DecorationReset = 1 << 5 ///< E.g. when decoration colors have changed
311
* Initialize the button after size change etc.
313
virtual void reset(unsigned long changed) = 0;
315
* @returns the KCommonDecoration the button belongs to.
317
KCommonDecoration *decoration() const;
319
* @returns the button type.
322
ButtonType type() const;
325
* Whether the button is left of the titlebar or not.
330
* Set which mouse buttons the button should honor. Used e.g. to prevent accidental right mouse clicks.
332
void setRealizeButtons(int btns);
334
* Set the button size.
336
void setSize(const QSize &s);
338
* Set/update the button's tool tip
340
void setTipText(const QString &tip);
342
* The mouse button that has been clicked last time.
344
Qt::MouseButtons lastMousePress() const { return m_lastMouse; }
346
QSize sizeHint() const;
349
void setToggleButton(bool toggle);
351
void setLeft(bool left);
352
void mousePressEvent(QMouseEvent *e);
353
void mouseReleaseEvent(QMouseEvent *e);
356
KCommonDecoration *m_decoration;
358
int m_realizeButtons;
360
Qt::MouseButtons m_lastMouse;
364
KCommonDecorationButtonPrivate *d;
367
#endif // KCOMMONDECORATION_H
369
// kate: space-indent on; indent-width 4; mixedindent off; indent-mode cstyle;