Qt 4.8
Public Functions | List of all members
QDecorationStyled Class Reference

#include <qdecorationstyled_qws.h>

Inheritance diagram for QDecorationStyled:
QDecorationDefault QDecoration

Public Functions

bool paint (QPainter *painter, const QWidget *widget, int decorationRegion=All, DecorationState state=Normal)
 Paints the border and title decoration for the top-level widget using the painter provided and the decoration state. More...
 
 QDecorationStyled ()
 
QRegion region (const QWidget *widget, const QRect &rect, int decorationRegion=All)
 Returns the region specified by decorationRegion for the top-level widget. More...
 
int titleBarHeight (const QWidget *widget)
 Returns the title bar height in pixels for the given widget. More...
 
virtual ~QDecorationStyled ()
 
- Public Functions inherited from QDecorationDefault
 QDecorationDefault ()
 Default constructor. More...
 
virtual ~QDecorationDefault ()
 The constructor deletes the static pixmaps. More...
 
- Public Functions inherited from QDecoration
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...
 
 QDecoration ()
 Constructs a decoration object. 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...
 

Additional Inherited Members

- Public Types inherited from QDecoration
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...
 
- Static Public Functions inherited from QDecoration
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...
 
- Protected Functions inherited from QDecorationDefault
virtual void paintButton (QPainter *painter, const QWidget *widget, int buttonRegion, DecorationState state, const QPalette &pal)
 Paints a region of the top-level widget. More...
 
virtual QPixmap pixmapFor (const QWidget *widget, int decorationRegion, int &xoff, int &yoff)
 Returns a pointer to the QPixmap for the widget specified by widget and decorationRegion. More...
 
QString windowTitleFor (const QWidget *widget) const
 
virtual const char ** xpmForRegion (int region)
 Returns a pointer to the X pixmap for the icon specified by region. More...
 
- Protected Variables inherited from QDecorationDefault
int close_width
 
int help_width
 
int maximize_width
 
int menu_width
 
int minimize_width
 
int normalize_width
 

Detailed Description

Definition at line 55 of file qdecorationstyled_qws.h.

Constructors and Destructors

◆ QDecorationStyled()

QDecorationStyled::QDecorationStyled ( )

Definition at line 55 of file qdecorationstyled_qws.cpp.

57 {
58 }
QDecorationDefault()
Default constructor.

◆ ~QDecorationStyled()

QDecorationStyled::~QDecorationStyled ( )
virtual

Definition at line 60 of file qdecorationstyled_qws.cpp.

61 {
62 }

Functions

◆ paint()

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

Paints the border and title decoration for the top-level widget using the painter provided and the decoration state.

The value of decorationRegion is a combination of the bitmask values of enum DecorationRegion.

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

Reimplemented from QDecorationDefault.

Definition at line 87 of file qdecorationstyled_qws.cpp.

89 {
90  if (decorationRegion == None)
91  return false;
92 
93  bool isActive = (widget == qApp->activeWindow());
94  QPalette pal = qApp->palette();
95  //ideally, the difference between Active and Inactive should be enough, so we shouldn't need to test this
96  if (!isActive) {
97  //pal.setCurrentColorGroup(QPalette::Disabled); //Can't do this either, because of palette limitations
98  //copied from Q3TitleBar:
105  }
106 
107  Qt::WindowFlags flags = widget->windowFlags();
108  bool hasBorder = !widget->isMaximized();
109  bool hasTitle = flags & Qt::WindowTitleHint;
110  bool hasSysMenu = flags & Qt::WindowSystemMenuHint;
111  bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint;
112  bool hasMinimize = flags & Qt::WindowMinimizeButtonHint;
113  bool hasMaximize = flags & Qt::WindowMaximizeButtonHint;
114 
115  bool paintAll = (DecorationRegion(decorationRegion) == All);
116  bool handled = false;
117 
118  QStyle *style = QApplication::style();
119 
120  // In the case of a borderless title bar, the title bar must be expanded one
121  // borderWidth to the left, right and up.
122  bool noTitleBorder = style->styleHint(QStyle::SH_TitleBar_NoBorder, 0, widget);
123  int borderWidth = style->pixelMetric(QStyle::PM_MDIFrameWidth, 0, 0);
124  int titleHeight = titleBarHeight(widget) + (noTitleBorder ? borderWidth : 0);
125  int titleExtra = noTitleBorder ? borderWidth : 0;
126 
127  if ((paintAll || decorationRegion & Borders) && state == Normal && hasBorder) {
128  QRegion newClip = painter->clipRegion();
129  if (hasTitle) { // reduce flicker
130  QRect rect(widget->rect());
131  QRect r(rect.left() - titleExtra, rect.top() - titleHeight,
132  rect.width() + 2 * titleExtra, titleHeight);
133  newClip -= r;
134  }
135  if (!newClip.isEmpty()) {
136  QRect br = QDecoration::region(widget).boundingRect();
137  painter->save();
138  painter->setClipRegion(newClip);
139 
140  QStyleOptionFrame opt;
141  opt.palette = pal;
142  opt.rect = br;
143  opt.lineWidth = borderWidth;
144 
145  if (isActive)
147  bool porterDuff = painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff);
148  if (porterDuff)
150  painter->fillRect(br, pal.window());
151  if (porterDuff)
153  style->drawPrimitive(QStyle::PE_FrameWindow, &opt, painter, 0);
154  painter->restore();
155 
156  decorationRegion &= (~Borders);
157  handled |= true;
158  }
159  }
160 
161  if (hasTitle) {
162  painter->save();
163 
165  opt.subControls = (decorationRegion & Title
167  | (decorationRegion & Menu
169  | (decorationRegion & Help
171  | (decorationRegion & Minimize
173  | (decorationRegion & Maximize
175  | (decorationRegion & (Minimize | Maximize)
177  | (decorationRegion & Close
179  opt.titleBarFlags = widget->windowFlags();
180  opt.titleBarState = widget->windowState();
181  if (isActive)
183  opt.text = windowTitleFor(widget);
184  opt.icon = widget->windowIcon();
185  opt.palette = pal;
186  opt.rect = QRect(widget->rect().x() - titleExtra, -titleHeight,
187  widget->rect().width() + 2 * titleExtra, titleHeight);
188 
189  if (paintAll) {
190  painter->setClipRegion(opt.rect);
191  } else {
192  const QRect widgetRect = widget->rect();
193  QRegion newClip = opt.rect;
194  if (!(decorationRegion & Menu) && hasSysMenu)
195  newClip -= region(widget, widgetRect, Menu);
196  if (!(decorationRegion & Title) && hasTitle)
197  newClip -= region(widget, widgetRect, Title);
198  if (!(decorationRegion & Help) && hasContextHelp)
199  newClip -= region(widget, widgetRect, Help);
200  if (!(decorationRegion & Minimize) && hasMinimize)
201  newClip -= region(widget, widgetRect, Minimize);
202  if (!(decorationRegion & Maximize) && hasMaximize)
203  newClip -= region(widget, widgetRect, Maximize);
204  if (!(decorationRegion & (Minimize | Maximize)) && (hasMaximize | hasMinimize))
205  newClip -= region(widget, widgetRect, Normal);
206  if (!(decorationRegion & Close))
207  newClip -= region(widget, widgetRect, Close);
208  painter->setClipRegion(newClip);
209  }
210 
211  if (state == Pressed)
212  opt.activeSubControls = opt.subControls;
213 
214  style->drawComplexControl(QStyle::CC_TitleBar, &opt, painter, 0);
215  painter->restore();
216 
217  decorationRegion &= ~(Title | Menu | Help | Normalize | Minimize | Maximize | Close);
218  handled |= true;
219  }
220 
221  return handled;
222 }
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
QIcon icon
the icon for the title bar
Definition: qstyleoption.h:823
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QString text
the text of the title bar
Definition: qstyleoption.h:822
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
static QStyle * style()
Returns the application&#39;s style object.
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
QIcon windowIcon
the widget&#39;s icon
Definition: qwidget.h:199
int titleBarHeight(const QWidget *widget)
Returns the title bar height in pixels for the given widget.
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
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...
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
QRegion clipRegion() const
Returns the currently set clip region.
Definition: qpainter.cpp:2562
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
#define qApp
QRegion region(const QWidget *widget, const QRect &rect, int decorationRegion=All)
Returns the region specified by decorationRegion for the top-level widget.
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget=0) const =0
Draws the given control using the provided painter with the style options specified by option...
bool isMaximized() const
Definition: qwidget.cpp:3074
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
QString windowTitleFor(const QWidget *widget) const
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
Definition: qpainter.cpp:2422
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Qt::WindowFlags titleBarFlags
the widget flags for the title bar
Definition: qstyleoption.h:825
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
int titleBarState
the state of the title bar
Definition: qstyleoption.h:824
const QBrush & window() const
Returns the window (general background) brush of the current color group.
Definition: qpalette.h:135
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
DecorationRegion
This enum describes the various regions of the window decoration.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
bool hasFeature(PaintEngineFeatures feature) const
Returns true if the paint engine supports the specified feature; otherwise returns false...
Definition: qpaintengine.h:229
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61

◆ region()

QRegion QDecorationStyled::region ( const QWidget widget,
const QRect rect,
int  decorationRegion = All 
)
virtual

Returns the region specified by decorationRegion for the top-level widget.

rect specifies the rectangle the decoration wraps. The value of decorationRegion is a combination of the bitmask values of enum DecorationRegion.

Reimplemented from QDecorationDefault.

Definition at line 224 of file qdecorationstyled_qws.cpp.

Referenced by paint().

225 {
226  QStyle *style = QApplication::style();
227 
228  // In the case of a borderless title bar, the title bar must be expanded one
229  // borderWidth to the left, right and up.
230  bool noTitleBorder = style->styleHint(QStyle::SH_TitleBar_NoBorder, 0, widget);
231  int borderWidth = style->pixelMetric(QStyle::PM_MDIFrameWidth, 0, 0);
232  int titleHeight = titleBarHeight(widget) + (noTitleBorder ? borderWidth : 0);
233  int titleExtra = noTitleBorder ? borderWidth : 0;
234 
235  QRect inside = QRect(rect.x() - titleExtra, rect.top() - titleHeight,
236  rect.width() + 2 * titleExtra, titleHeight);
237 
238  Qt::WindowFlags flags = widget->windowFlags();
239  bool hasSysMenu = flags & Qt::WindowSystemMenuHint;
240  bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint;
241  bool hasMinimize = flags & Qt::WindowMinimizeButtonHint;
242  bool hasMaximize = flags & Qt::WindowMaximizeButtonHint;
243 
251  opt.titleBarFlags = widget->windowFlags();
253  opt.text = windowTitleFor(widget);
254  opt.icon = widget->windowIcon();
255  opt.rect = inside;
256 
257  QRegion region;
258  switch (decorationRegion) {
259  case Title:
260  region = style->subControlRect(QStyle::CC_TitleBar, &opt,
262  break;
263  case Menu:
264  if (hasSysMenu)
265  region = style->subControlRect(QStyle::CC_TitleBar, &opt,
267  break;
268  case Help:
269  if (hasContextHelp)
270  region = style->subControlRect(QStyle::CC_TitleBar, &opt,
272  0);
273  break;
274  case Normalize:
275  if (hasMaximize | hasMinimize)
276  region = style->subControlRect(QStyle::CC_TitleBar, &opt,
278  0);
279  break;
280  case Minimize:
281  if (hasMinimize)
282  region = style->subControlRect(QStyle::CC_TitleBar, &opt,
284  0);
285  break;
286  case Maximize:
287  if (hasMaximize)
288  region = style->subControlRect(QStyle::CC_TitleBar, &opt,
290  0);
291  break;
292  case Close:
293  region = style->subControlRect(QStyle::CC_TitleBar, &opt,
295  break;
296 
297  default:
298  region = QDecorationDefault::region(widget, rect, decorationRegion);
299  }
300 
301  opt.rect = QRect(rect.x() - titleExtra, rect.top() - titleHeight,
302  rect.width() + 2 * titleExtra,
303  rect.height() + titleHeight + titleExtra);
304 
306  style->styleHint(QStyle::SH_WindowFrame_Mask, &opt, 0, &mask);
307 
308  return (mask.region.isEmpty() ? region : (region & mask.region));
309 }
static Qt::LayoutDirection layoutDirection()
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
QIcon icon
the icon for the title bar
Definition: qstyleoption.h:823
virtual QRegion region(const QWidget *widget, const QRect &rect, int decorationRegion=All)
Returns the region specified by decorationRegion for the top-level widget.
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QString text
the text of the title bar
Definition: qstyleoption.h:822
static QStyle * style()
Returns the application&#39;s style object.
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QIcon windowIcon
the widget&#39;s icon
Definition: qwidget.h:199
int titleBarHeight(const QWidget *widget)
Returns the title bar height in pixels for the given widget.
QRegion region(const QWidget *widget, const QRect &rect, int decorationRegion=All)
Returns the region specified by decorationRegion for the top-level widget.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QStyleHintReturnMask class provides style hints that return a QRegion.
Definition: qstyleoption.h:923
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QString windowTitleFor(const QWidget *widget) const
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Qt::WindowFlags titleBarFlags
the widget flags for the title bar
Definition: qstyleoption.h:825
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693

◆ titleBarHeight()

int QDecorationStyled::titleBarHeight ( const QWidget widget)
virtual

Returns the title bar height in pixels for the given widget.

It is the greater of 20, or the sum of the application font's line spacing value plus a border width fudge factor.

Reimplemented from QDecorationDefault.

Definition at line 64 of file qdecorationstyled_qws.cpp.

Referenced by paint(), and region().

65 {
74  opt.titleBarFlags = widget->windowFlags();
76  opt.text = windowTitleFor(widget);
77  opt.icon = widget->windowIcon();
78  opt.rect = widget->rect();
79 
80  QStyle *style = QApplication::style();
81  if (!style)
82  return 18;
83 
84  return style->pixelMetric(QStyle::PM_TitleBarHeight, &opt, 0);
85 }
static Qt::LayoutDirection layoutDirection()
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
QIcon icon
the icon for the title bar
Definition: qstyleoption.h:823
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
QString text
the text of the title bar
Definition: qstyleoption.h:822
static QStyle * style()
Returns the application&#39;s style object.
QIcon windowIcon
the widget&#39;s icon
Definition: qwidget.h:199
QString windowTitleFor(const QWidget *widget) const
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
Qt::WindowFlags titleBarFlags
the widget flags for the title bar
Definition: qstyleoption.h:825
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693

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