Qt 4.8
Public Types | Public Functions | Static Public Functions | List of all members
QDecoration Class Referenceabstract

The QDecoration class is a base class for window decorations in Qt for Embedded Linux. More...

#include <qdecoration_qws.h>

Inheritance diagram for QDecoration:
QDecorationDefault QDecorationStyled QDecorationWindows

Public Types

enum  DecorationRegion {
  None = 0x0000000000, All = 0x7fffffff, TopLeft = 0x0000000001, Top = 0x0000000002,
  TopRight = 0x0000000004, Left = 0x0000000008, Right = 0x0000000010, BottomLeft = 0x0000000020,
  Bottom = 0x0000000040, BottomRight = 0x0000000080, Borders = 0x00000000ff, Menu = 0x0000000100,
  Title = 0x0000000200, Help = 0x0000000400, Minimize = 0x0000000800, Maximize = 0x0000001000,
  Normalize = 0x0000002000, Close = 0x0000004000, Move = 0x0000008000, Resize = 0x0000010000
}
 This enum describes the various regions of the window decoration. More...
 
enum  DecorationState { Normal = 0x04, Disabled = 0x08, Hover = 0x01, Pressed = 0x02 }
 This enum describes the various states of a decoration region. More...
 

Public Functions

virtual void buildSysMenu (QWidget *widget, QMenu *menu)
 Builds the system menu for the given top level widget, adding Restore, Move, Size, Minimize, Maximize and Close actions to the given menu. More...
 
void menuTriggered (QWidget *widget, QAction *action)
 This function is called whenever an action in a top level widget's menu is triggered, and simply calls the regionClicked() function passing the widget and action parameters as arguments. More...
 
virtual bool paint (QPainter *p, const QWidget *w, int decorationRegion=All, DecorationState state=Normal)=0
 Implement this function to paint the border and title decoration for the specified top level widget using the given painter and decoration state. More...
 
 QDecoration ()
 Constructs a decoration object. More...
 
virtual QRegion region (const QWidget *w, const QRect &rect, int decorationRegion=All)=0
 Implement this function to return the region specified by decorationRegion for the given top level widget. More...
 
QRegion region (const QWidget *w, int decorationRegion=All)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
virtual int regionAt (const QWidget *w, const QPoint &point)
 Returns the type of the first region of the specified top level widget containing the given point. More...
 
virtual void regionClicked (QWidget *widget, int region)
 Handles the event that the specified region in the given top level widget is activated by a single click (the region parameter is described using the DecorationRegion enum). More...
 
virtual void regionDoubleClicked (QWidget *widget, int region)
 Handles the event that the specified region in the given top level widget is activated by a double click (the region parameter is described using the DecorationRegion enum). More...
 
virtual ~QDecoration ()
 Destroys this decoration object. More...
 

Static Public Functions

static void startMove (QWidget *widget)
 Starts to move the given top level widget by making its Title region active and grabbing the mouse input. More...
 
static void startResize (QWidget *widget)
 Starts to resize the given top level widget by making its BottomRight region active and grabbing the mouse input. More...
 

Detailed Description

The QDecoration class is a base class for window decorations in Qt for Embedded Linux.

Note that this class is non-portable and only available in Qt for Embedded Linux.

Qt for Embedded Linux provides window management of top level windows and several ready made decorations (i.e., Default, Styled and Windows). Custom decorations can be implemented by subclassing the QDecoration class and creating a decoration plugin (derived from QDecorationPlugin). The default implementation of the QDecorationFactory class will automatically detect the plugin, and load the decoration into the application at run-time using Qt's How to Create Qt Plugins. To actually apply a decoration, use the QApplication::qwsSetDecoration() function.

When creating a custom decoration, implement the paint() function to paint the border and title decoration, and the region() function to return the regions the decoration occupies. Reimplement the regionClicked() and regionDoubleClicked() functions to respond to mouse clicks (the default implementations responds to (single) clicks on items in a widget's system menu and double clicks on a widget's title).

QDecoration provides the DecorationRegion enum that describes the various regions of the window decoration, and the regionAt() function to determine the region containing a given point. The QDecoration class also provides the DecorationState enum describing the state of a given region, e.g. whether it is active or not.

In addition, it is possible to build the system menu for a given top level widget using the buildSysMenu() function; whenever an action in this menu is triggered, the menuTriggered() function is called automatically.

Finally, the QDecoration class provides a couple of static functions, startMove() and startResize(), which start a move or resize action by making the appropriate decoration region active and grabbing the mouse input.

See also
QDecorationFactory, QDecorationPlugin, {Qt for Embedded Linux Architecture}

Definition at line 71 of file qdecoration_qws.h.

Enumerations

◆ DecorationRegion

This enum describes the various regions of the window decoration.

  • All The entire region used by the window decoration.
  • Top The top border used to vertically resize the window.
  • Bottom The bottom border used to vertically resize the window.
  • Left The left border used to horizontally resize the window.
  • Right The right border used to horizontally resize the window.
  • TopLeft The top-left corner of the window used to resize the window both horizontally and vertically.
  • TopRight The top-right corner of the window used to resize the window both horizontally and vertically.
  • BottomLeft The bottom-left corner of the window used to resize the window both horizontally and vertically.
  • BottomRight The bottom-right corner of the window used to resize the window both horizontally and vertically.
  • Borders All the regions used to describe the window's borders.
  • Title The region containing the window title, used to move the window by dragging with the mouse cursor.
  • Close The region occupied by the close button. Clicking in this region closes the window.
  • Minimize The region occupied by the minimize button. Clicking in this region minimizes the window.
  • Maximize The region occupied by the maximize button. Clicking in this region maximizes the window.
  • Normalize The region occupied by a button used to restore a window's normal size. Clicking in this region restores a maximized window to its previous size. The region used for this button is often also the Maximize region.
  • Menu The region occupied by the window's menu button. Clicking in this region opens the window operations (system) menu.
  • Help The region occupied by the window's help button. Clicking in this region causes the context-sensitive help function to be enabled.
  • Resize The region used to resize the window.
  • Move The region used to move the window.
  • None No region.
See also
region(), regionAt(), DecorationState
Enumerator
None 
All 
TopLeft 
Top 
TopRight 
Left 
Right 
BottomLeft 
Bottom 
BottomRight 
Borders 
Menu 
Title 
Help 
Minimize 
Maximize 
Normalize 
Close 
Move 
Resize 

Definition at line 87 of file qdecoration_qws.h.

87  {
88  None = 0x0000000000, All = 0x7fffffff,
89  TopLeft = 0x0000000001, Top = 0x0000000002, TopRight = 0x0000000004,
90  Left = 0x0000000008, Right = 0x0000000010,
91  BottomLeft = 0x0000000020, Bottom = 0x0000000040, BottomRight = 0x0000000080,
92  Borders = 0x00000000ff,
93  Menu = 0x0000000100, Title = 0x0000000200, Help = 0x0000000400,
94  Minimize = 0x0000000800, Maximize = 0x0000001000, Normalize = 0x0000002000,
95  Close = 0x0000004000, Move = 0x0000008000, Resize = 0x0000010000
96  };

◆ DecorationState

This enum describes the various states of a decoration region.

  • Normal The region is active
  • Disabled The region is inactive.
  • Hover The cursor is hovering over the region.
  • Pressed The region is pressed.
See also
paint(), DecorationRegion
Enumerator
Normal 
Disabled 
Hover 
Pressed 

Definition at line 98 of file qdecoration_qws.h.

Constructors and Destructors

◆ QDecoration()

QDecoration::QDecoration ( )
inline

Constructs a decoration object.

Definition at line 74 of file qdecoration_qws.h.

74 {}

◆ ~QDecoration()

QDecoration::~QDecoration ( )
inlinevirtual

Destroys this decoration object.

Definition at line 75 of file qdecoration_qws.h.

75 {}

Functions

◆ buildSysMenu()

void QDecoration::buildSysMenu ( QWidget widget,
QMenu menu 
)
virtual

Builds the system menu for the given top level widget, adding Restore, Move, Size, Minimize, Maximize and Close actions to the given menu.

See also
menuTriggered()

Definition at line 276 of file qdecoration_qws.cpp.

277 {
278  QDecorationAction *act = new QDecorationAction(QLatin1String("Restore"),
279  menu, Maximize);
280  act->setEnabled(widget->windowState() & Qt::WindowMaximized);
281  menu->addAction(act);
282  act = new QDecorationAction(QLatin1String("Move"), menu, Move);
283  act->setEnabled(!(widget->windowState() & Qt::WindowMaximized));
284  menu->addAction(act);
285  menu->addAction(new QDecorationAction(QLatin1String("Size"), menu, Resize));
286  act = new QDecorationAction(QLatin1String("Minimize"), menu, Minimize);
287  menu->addAction(act);
288  act = new QDecorationAction(QLatin1String("Maximize"), menu, Maximize);
289  act->setDisabled(widget->windowState() & Qt::WindowMaximized);
290  menu->addAction(act);
291  menu->addSeparator();
292  menu->addAction(new QDecorationAction(QLatin1String("Close"), menu, Close));
293 }
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
void setDisabled(bool b)
This is a convenience function for the enabled property, that is useful for signals–slots connection...
Definition: qaction.h:223
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
void setEnabled(bool)
Definition: qaction.cpp:1192
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583

◆ menuTriggered()

void QDecoration::menuTriggered ( QWidget widget,
QAction action 
)

This function is called whenever an action in a top level widget's menu is triggered, and simply calls the regionClicked() function passing the widget and action parameters as arguments.

See also
buildSysMenu()

Definition at line 302 of file qdecoration_qws.cpp.

303 {
304  QDecorationAction *decAction = static_cast<QDecorationAction *>(action);
305  regionClicked(widget, decAction->reg);
306 }
virtual void regionClicked(QWidget *widget, int region)
Handles the event that the specified region in the given top level widget is activated by a single cl...

◆ paint()

bool QDecoration::paint ( QPainter painter,
const QWidget widget,
int  decorationRegion = All,
DecorationState  state = Normal 
)
pure virtual

Implement this function to paint the border and title decoration for the specified top level widget using the given painter and decoration state.

The specified decorationRegion is a bitmask of the values described by the DecorationRegion enum.

Note that Qt for Embedded Linux expects this function to return true if any of the widget's decorations are repainted; otherwise it should return false.

See also
region()

Implemented in QDecorationDefault, QDecorationStyled, and QDecorationWindows.

Referenced by QWidgetBackingStore::removeDirtyWidget().

◆ region() [1/2]

QRegion QDecoration::region ( const QWidget widget,
const QRect rectangle,
int  decorationRegion = All 
)
pure virtual

Implement this function to return the region specified by decorationRegion for the given top level widget.

The rectangle parameter specifies the rectangle the decoration is wrapped around. The decorationRegion is a bitmask of the values described by the DecorationRegion enum.

See also
regionAt(), paint()

Implemented in QDecorationDefault, QDecorationStyled, and QDecorationWindows.

Referenced by QDecorationStyled::paint(), QDecorationWindows::paint(), QDecorationDefault::paint(), QDecorationWindows::paintButton(), QDecorationDefault::paintButton(), regionAt(), and QWidgetBackingStore::removeDirtyWidget().

◆ region() [2/2]

QRegion QDecoration::region ( const QWidget w,
int  decorationRegion = All 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 101 of file qdecoration_qws.h.

102  { return region(w, w->rect(), decorationRegion); }
virtual QRegion region(const QWidget *w, const QRect &rect, int decorationRegion=All)=0
Implement this function to return the region specified by decorationRegion for the given top level wi...
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168

◆ regionAt()

int QDecoration::regionAt ( const QWidget widget,
const QPoint point 
)
virtual

Returns the type of the first region of the specified top level widget containing the given point.

The return value is one of the DecorationRegion enum's values. Use the region() function to retrieve the actual region. If none of the widget's regions contain the point, this function returns None .

See also
region()

Definition at line 236 of file qdecoration_qws.cpp.

237 {
238  int regions[] = {
239  TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight, // Borders first
240  Menu, Title, Help, Minimize, Normalize, Maximize, Close, // then buttons
241  None
242  };
243 
244 // char *regions_str[] = {
245 // "TopLeft", "Top", "TopRight", "Left", "Right", "BottomLeft", "Bottom", "BottomRight",
246 // "Menu", "Title", "Help", "Minimize", "Normalize", "Maximize", "Close",
247 // "None"
248 // };
249 
250  // First check to see if within all regions at all
251  QRegion reg = region(w, w->geometry(), All);
252  if (!reg.contains(point)) {
253  return None;
254  }
255 
256  int i = 0;
257  while (regions[i]) {
258  reg = region(w, w->geometry(), regions[i]);
259  if (reg.contains(point)) {
260 // qDebug("In region %s", regions_str[i]);
261  return regions[i];
262  }
263  ++i;
264  }
265  return None;
266 }
virtual QRegion region(const QWidget *w, const QRect &rect, int decorationRegion=All)=0
Implement this function to return the region specified by decorationRegion for the given top level wi...
bool contains(const QPoint &p) const
Returns true if the region contains the point p; otherwise returns false.
Definition: qregion.cpp:4104
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68

◆ regionClicked()

void QDecoration::regionClicked ( QWidget widget,
int  region 
)
virtual

Handles the event that the specified region in the given top level widget is activated by a single click (the region parameter is described using the DecorationRegion enum).

This function is called whenever a region in a top level widget is clicked; the default implementation responds to clicks on items in the system menu, performing the requested actions.

See also
regionDoubleClicked(), region()

Definition at line 322 of file qdecoration_qws.cpp.

Referenced by menuTriggered().

323 {
324  switch(reg) {
325  case Move:
326  startMove(widget);
327  break;
328  case Resize:
329  startResize(widget);
330  break;
331  case Help:
332 #ifndef QT_NO_WHATSTHIS
335  else
337 #endif
338  break;
339  case Close:
340  widget->close();
341  break;
342  case Normalize:
343  widget->showNormal();
344  break;
345  case Maximize:
346  if (widget->windowState() & Qt::WindowMaximized)
347  widget->showNormal();
348  else
349  widget->showMaximized();
350  break;
351  }
352 }
void showMaximized()
Shows the widget maximized.
Definition: qwidget.cpp:3218
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
static void startMove(QWidget *widget)
Starts to move the given top level widget by making its Title region active and grabbing the mouse in...
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition: qwidget.cpp:3250
static void startResize(QWidget *widget)
Starts to resize the given top level widget by making its BottomRight region active and grabbing the ...
static bool inWhatsThisMode()
Returns true if the user interface is in "What&#39;s This?" mode; otherwise returns false.
Definition: qwhatsthis.cpp:648
bool close()
Closes this widget.
Definition: qwidget.cpp:8305
static void enterWhatsThisMode()
This function switches the user interface into "What&#39;s This?" mode.
Definition: qwhatsthis.cpp:633
static void leaveWhatsThisMode()
If the user interface is in "What&#39;s This?" mode, this function switches back to normal mode; otherwis...
Definition: qwhatsthis.cpp:662

◆ regionDoubleClicked()

void QDecoration::regionDoubleClicked ( QWidget widget,
int  region 
)
virtual

Handles the event that the specified region in the given top level widget is activated by a double click (the region parameter is described using the DecorationRegion enum).

This function is called whenever a region in a top level widget is double clicked; the default implementation responds to a double click on the widget's title, toggling its size between the maximum and its normal size.

See also
regionClicked(), region()

Definition at line 368 of file qdecoration_qws.cpp.

369 {
370  switch(reg)
371  {
372  case Title: {
373  if (widget->windowState() & Qt::WindowMaximized)
374  widget->showNormal();
375  else
376  widget->showMaximized();
377  break;
378  }
379  }
380 }
void showMaximized()
Shows the widget maximized.
Definition: qwidget.cpp:3218
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition: qwidget.cpp:3250

◆ startMove()

void QDecoration::startMove ( QWidget widget)
static

Starts to move the given top level widget by making its Title region active and grabbing the mouse input.

See also
startResize()

Definition at line 387 of file qdecoration_qws.cpp.

Referenced by regionClicked().

388 {
389 #ifdef QT_NO_QWS_MANAGER
390  Q_UNUSED(widget);
391 #else
392  QWSManager *manager = widget->d_func()->topData()->qwsManager;
393  if (manager)
394  manager->startMove();
395 #endif
396 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ startResize()

void QDecoration::startResize ( QWidget widget)
static

Starts to resize the given top level widget by making its BottomRight region active and grabbing the mouse input.

See also
startMove()

Definition at line 403 of file qdecoration_qws.cpp.

Referenced by regionClicked().

404 {
405 #ifdef QT_NO_QWS_MANAGER
406  Q_UNUSED(widget);
407 #else
408  QWSManager *manager = widget->d_func()->topData()->qwsManager;
409  if (manager)
410  manager->startResize();
411 #endif
412 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

The documentation for this class was generated from the following files: