Qt 4.8
Public Functions | Protected Functions | List of all members
QDecorationWindows Class Reference

#include <qdecorationwindows_qws.h>

Inheritance diagram for QDecorationWindows:
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...
 
 QDecorationWindows ()
 
QRegion region (const QWidget *widget, const QRect &rect, int decorationRegion=All)
 Returns the region specified by decorationRegion for the top-level widget. More...
 
virtual ~QDecorationWindows ()
 
- 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...
 

Protected Functions

void paintButton (QPainter *painter, const QWidget *widget, int buttonRegion, DecorationState state, const QPalette &pal)
 Paints a region of the top-level widget. More...
 
const char ** xpmForRegion (int reg)
 Returns a pointer to the X pixmap for the icon specified by region. More...
 
- Protected Functions inherited from QDecorationDefault
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...
 
virtual int titleBarHeight (const QWidget *widget)
 Returns the title bar height in pixels for the given widget. More...
 
QString windowTitleFor (const QWidget *widget) const
 

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 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 qdecorationwindows_qws.h.

Constructors and Destructors

◆ QDecorationWindows()

QDecorationWindows::QDecorationWindows ( )

Definition at line 172 of file qdecorationwindows_qws.cpp.

◆ ~QDecorationWindows()

QDecorationWindows::~QDecorationWindows ( )
virtual

Definition at line 182 of file qdecorationwindows_qws.cpp.

183 {
184 }

Functions

◆ paint()

bool QDecorationWindows::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 319 of file qdecorationwindows_qws.cpp.

321 {
322  if (decorationRegion == None)
323  return false;
324 
325  const QRect titleRect = QDecoration::region(widget, Title).boundingRect();
326  const QPalette pal = QApplication::palette();
327  QRegion oldClipRegion = painter->clipRegion();
328 
329  bool paintAll = (decorationRegion == int(All));
330  if ((paintAll || decorationRegion & Title && titleRect.width() > 0) && state == Normal
331  && (widget->windowFlags() & Qt::WindowTitleHint) ) {
332  painter->setClipRegion(oldClipRegion);
333  QColor fromBrush, toBrush;
334  QPen titlePen;
335 
336  if (widget == qApp->activeWindow() || qApp->activeWindow() == qApp->activePopupWidget()) {
337  fromBrush = pal.color(QPalette::Highlight);
338  titlePen = pal.color(QPalette::HighlightedText);
339  } else {
340  fromBrush = pal.color(QPalette::Window);
341  titlePen = pal.color(QPalette::Text);
342  }
343  toBrush = fromBrush.lighter(300);
344 
345  painter->setPen(Qt::NoPen);
346  QPoint p1(titleRect.x(), titleRect.y() + titleRect.height()/2);
347  QPoint p2(titleRect.right(), titleRect.y() + titleRect.height()/2);
348  QLinearGradient lg(p1, p2);
349  lg.setColorAt(0, fromBrush);
350  lg.setColorAt(1, toBrush);
351  painter->fillRect(titleRect, lg);
352 
353  painter->setPen(titlePen);
354  painter->drawText(titleRect, Qt::AlignVCenter, windowTitleFor(widget));
355  decorationRegion ^= Title;
356  }
357 
358  return QDecorationDefault::paint(painter, widget, decorationRegion, state);
359 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
virtual 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 de...
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
static QPalette palette()
Returns the application palette.
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
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
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
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...
QRegion clipRegion() const
Returns the currently set clip region.
Definition: qpainter.cpp:2562
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
#define qApp
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
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
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
QColor lighter(int f=150) const
Returns a lighter (or darker) color, but does not change this object.
Definition: qcolor.h:298
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61

◆ paintButton()

void QDecorationWindows::paintButton ( QPainter painter,
const QWidget widget,
int  buttonRegion,
DecorationState  state,
const QPalette pal 
)
protectedvirtual

Paints a region of the top-level widget.

The region is painted in the specified decoration state using the painter and palette provided. The region to be painted is specified by buttonRegion, which is a combination of the bitmask values of DecorationRegion. If the value of buttonRegion is one of Help, Menu, Close, Minimize, Maximize, and Normalize, the button pixmap for that region is painted.

See also
pixmapFor()

Reimplemented from QDecorationDefault.

Definition at line 361 of file qdecorationwindows_qws.cpp.

363 {
364  QBrush fromBrush, toBrush;
365  QPen titlePen;
366 
367  if (widget == qApp->activeWindow() || qApp->activeWindow() == qApp->activePopupWidget()) {
368  fromBrush = pal.brush(QPalette::Highlight);
369  titlePen = pal.color(QPalette::HighlightedText);
370  } else {
371  fromBrush = pal.brush(QPalette::Window);
372  titlePen = pal.color(QPalette::Text);
373  }
374  toBrush = fromBrush.color().lighter(300);
375 
376  QRect brect(QDecoration::region(widget, buttonRegion).boundingRect());
377  if (buttonRegion != Close && buttonRegion != Menu)
378  painter->fillRect(brect, toBrush);
379  else
380  painter->fillRect(brect.x() - 2, brect.y(), brect.width() + 4, brect.height(),
381  buttonRegion == Menu ? fromBrush : toBrush);
382 
383  int xoff = 1;
384  int yoff = 2;
385  const QPixmap pm = pixmapFor(widget, buttonRegion, xoff, yoff);
386  if (buttonRegion != Menu) {
387  if (state & Normal) {
388  qDrawWinPanel(painter, brect.x(), brect.y() + 2, brect.width(),
389  brect.height() - 4, pal, false, &pal.brush(QPalette::Window));
390  } else if (state & Pressed) {
391  qDrawWinPanel(painter, brect.x(), brect.y() + 2, brect.width(),
392  brect.height() - 4, pal, true, &pal.brush(QPalette::Window));
393  ++xoff;
394  ++yoff;
395  }
396  } else {
397  xoff = 0;
398  yoff = 2;
399  }
400 
401  if (!pm.isNull())
402  painter->drawPixmap(brect.x() + xoff, brect.y() + yoff, pm);
403 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
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
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
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...
static const QRectF boundingRect(const QPointF *points, int pointCount)
void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill)
Definition: qdrawutil.cpp:475
#define qApp
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
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.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QColor lighter(int f=150) const
Returns a lighter (or darker) color, but does not change this object.
Definition: qcolor.h:298
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420

◆ region()

QRegion QDecorationWindows::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 210 of file qdecorationwindows_qws.cpp.

211 {
212  Qt::WindowFlags flags = widget->windowFlags();
213  bool hasTitle = flags & Qt::WindowTitleHint;
214  bool hasSysMenu = flags & Qt::WindowSystemMenuHint;
215  bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint;
216  bool hasMinimize = flags & Qt::WindowMinimizeButtonHint;
217  bool hasMaximize = flags & Qt::WindowMaximizeButtonHint;
218  const QFontMetrics fontMetrics = QApplication::fontMetrics();
219  int titleHeight = hasTitle ? qMax(20, fontMetrics.height()) : 0;
220  int state = widget->windowState();
221  bool isMinimized = state & Qt::WindowMinimized;
222  bool isMaximized = state & Qt::WindowMaximized;
223 
224  QRegion region;
225  switch (type) {
226  case Menu: {
227  if (hasSysMenu) {
228  region = QRect(rect.left() + 2, rect.top() - titleHeight,
229  menu_width, titleHeight);
230  }
231  }
232  break;
233 
234  case Title: {
235  QRect r(rect.left()
236  + (hasSysMenu ? menu_width + 4: 0),
237  rect.top() - titleHeight,
238  rect.width()
239  - (hasSysMenu ? menu_width : 0)
240  - close_width
241  - (hasMaximize ? maximize_width : 0)
242  - (hasMinimize ? minimize_width : 0)
243  - (hasContextHelp ? help_width : 0)
244  - 3,
245  titleHeight);
246  if (r.width() > 0)
247  region = r;
248  }
249  break;
250  case Help: {
251  if (hasContextHelp) {
252  QRect r(rect.right()
253  - close_width
254  - (hasMaximize ? maximize_width : 0)
255  - (hasMinimize ? minimize_width : 0)
256  - help_width - 3, rect.top() - titleHeight,
257  help_width, titleHeight);
258  if (r.left() > rect.left() + titleHeight)
259  region = r;
260  }
261  }
262  break;
263 
264  case Minimize: {
265  if (hasMinimize && !isMinimized) {
266  QRect r(rect.right() - close_width
267  - (hasMaximize ? maximize_width : 0)
268  - minimize_width - 3, rect.top() - titleHeight,
269  minimize_width, titleHeight);
270  if (r.left() > rect.left() + titleHeight)
271  region = r;
272  }
273  }
274  break;
275 
276  case Maximize: {
277  if (hasMaximize && !isMaximized) {
278  QRect r(rect.right() - close_width - maximize_width - 3,
279  rect.top() - titleHeight, maximize_width, titleHeight);
280  if (r.left() > rect.left() + titleHeight)
281  region = r;
282  }
283  }
284  break;
285 
286  case Normalize: {
287  if (hasMinimize && isMinimized) {
288  QRect r(rect.right() - close_width
289  - (hasMaximize ? maximize_width : 0)
290  - minimize_width - 3, rect.top() - titleHeight,
291  minimize_width, titleHeight);
292  if (r.left() > rect.left() + titleHeight)
293  region = r;
294  } else if (hasMaximize && isMaximized) {
295  QRect r(rect.right() - close_width - maximize_width - 3,
296  rect.top() - titleHeight, maximize_width, titleHeight);
297  if (r.left() > rect.left() + titleHeight)
298  region = r;
299  }
300  }
301  break;
302 
303  case Close: {
304  QRect r(rect.right() - close_width - 1, rect.top() - titleHeight,
305  close_width, titleHeight);
306  if (r.left() > rect.left() + titleHeight)
307  region = r;
308  }
309  break;
310 
311  default:
312  region = QDecorationDefault::region(widget, rect, type);
313  break;
314  }
315 
316  return region;
317 }
int type
Definition: qmetatype.cpp:239
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
virtual QRegion region(const QWidget *widget, const QRect &rect, int decorationRegion=All)
Returns the region specified by decorationRegion for the top-level widget.
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRegion region(const QWidget *widget, const QRect &rect, int decorationRegion=All)
Returns the region specified by decorationRegion for the top-level widget.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static QFontMetrics fontMetrics()
Returns display (screen) font metrics for the application font.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
int height() const
Returns the height of the font.

◆ xpmForRegion()

const char ** QDecorationWindows::xpmForRegion ( int  region)
protectedvirtual

Returns a pointer to the X pixmap for the icon specified by region.

An X pixmap is an ASCII-text-based image. The value of region must be one of a subset of the values of enum DecorationRegion. The supported values are Help, Menu, Close, Minimize, Maximize, and Normalize. Other values of region cause zero to be returned.

See also
QDecoration::DecorationRegion

Reimplemented from QDecorationDefault.

Definition at line 186 of file qdecorationwindows_qws.cpp.

187 {
188 #ifdef QT_NO_IMAGEFORMAT_XPM
189  Q_UNUSED(reg);
190 #else
191  switch(reg)
192  {
193  case Close:
194  return (const char **)win_close_xpm;
195  case Help:
196  return (const char **)win_help_xpm;
197  case Minimize:
198  return (const char **)win_minimize_xpm;
199  case Maximize:
200  return (const char **)win_maximize_xpm;
201  case Normalize:
202  return (const char **)win_normalize_xpm;
203  default:
205  }
206 #endif
207  return 0;
208 }
static const char *const win_help_xpm[]
virtual const char ** xpmForRegion(int region)
Returns a pointer to the X pixmap for the icon specified by region.
static const char *const win_normalize_xpm[]
static const char *const win_close_xpm[]
static const char *const win_minimize_xpm[]
#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
static const char *const win_maximize_xpm[]

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