Qt 4.8
qstylesheetstyle.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qglobal.h>
43 
44 #ifndef QT_NO_STYLE_STYLESHEET
45 
46 #include "qstylesheetstyle_p.h"
47 #include "private/qcssutil_p.h"
48 #include <qdebug.h>
49 #include <qapplication.h>
50 #include <qmenu.h>
51 #include <qmenubar.h>
52 #include <qpainter.h>
53 #include <qstyleoption.h>
54 #include <qlineedit.h>
55 #include <qwindowsstyle.h>
56 #include <qcombobox.h>
57 #include <qwindowsstyle.h>
58 #include <qplastiquestyle.h>
59 #include "private/qcssparser_p.h"
60 #include "private/qmath_p.h"
61 #include <qabstractscrollarea.h>
62 #include "private/qabstractscrollarea_p.h"
63 #include <qtooltip.h>
64 #include <qshareddata.h>
65 #include <qradiobutton.h>
66 #include <qtoolbutton.h>
67 #include <qscrollbar.h>
68 #include <qstring.h>
69 #include <qfile.h>
70 #include <qcheckbox.h>
71 #include <qstatusbar.h>
72 #include <qheaderview.h>
73 #include <qprogressbar.h>
74 #include <private/qwindowsstyle_p.h>
75 #include <qtabbar.h>
76 #include <QMetaProperty>
77 #include <qmainwindow.h>
78 #include <qdockwidget.h>
79 #include <qmdisubwindow.h>
80 #include <qdialog.h>
81 #include <private/qwidget_p.h>
82 #include <QAbstractSpinBox>
83 #include <QLabel>
84 #include "qdrawutil.h"
85 
86 #include <limits.h>
87 #include <QtGui/qtoolbar.h>
88 
90 
91 using namespace QCss;
92 
93 
95 {
97 public:
99 };
100 
101 
103 
104 /* RECURSION_GUARD:
105  * the QStyleSheetStyle is a proxy. If used with others proxy style, we may end up with something like:
106  * QStyleSheetStyle -> ProxyStyle -> QStyleSheetStyle -> OriginalStyle
107  * Recursion may happen if the style call the widget()->style() again.
108  * Not to mention the performence penalty of having two lookup of rules.
109  *
110  * The first instance of QStyleSheetStyle will set globalStyleSheetStyle to itself. The second one
111  * will notice the globalStyleSheetStyle is not istelf and call its base style directly.
112  */
115 {
116  public:
118  : guarded(globalStyleSheetStyle == 0)
119  {
120  if (guarded) globalStyleSheetStyle = that;
121  }
122  ~QStyleSheetStyleRecursionGuard() { if (guarded) globalStyleSheetStyle = 0; }
123  bool guarded;
124 };
125 #define RECURSION_GUARD(RETURN) \
126  if (globalStyleSheetStyle != 0 && globalStyleSheetStyle != this) { RETURN; } \
127  QStyleSheetStyleRecursionGuard recursion_guard(this);
128 
129 #define ceil(x) ((int)(x) + ((x) > 0 && (x) != (int)(x)))
130 
213 };
214 
217  const char *name;
218 };
219 
221  { QStyle::SC_None, "" },
222  { QStyle::SC_None, "down-arrow" },
223  { QStyle::SC_None, "up-arrow" },
224  { QStyle::SC_None, "left-arrow" },
225  { QStyle::SC_None, "right-arrow" },
226  { QStyle::SC_None, "indicator" },
227  { QStyle::SC_None, "indicator" },
228  { QStyle::SC_None, "menu-indicator" },
229  { QStyle::SC_ComboBoxArrow, "drop-down" },
230  { QStyle::SC_ComboBoxArrow, "down-arrow" },
231  { QStyle::SC_None, "item" },
232  { QStyle::SC_SpinBoxUp, "up-button" },
233  { QStyle::SC_SpinBoxUp, "up-arrow" },
234  { QStyle::SC_SpinBoxDown, "down-button" },
235  { QStyle::SC_SpinBoxDown, "down-arrow" },
236  { QStyle::SC_GroupBoxLabel, "title" },
237  { QStyle::SC_GroupBoxCheckBox, "indicator" },
238  { QStyle::SC_ToolButtonMenu, "menu-button" },
239  { QStyle::SC_ToolButtonMenu, "menu-arrow" },
240  { QStyle::SC_None, "menu-indicator" },
241  { QStyle::SC_None, "tab" },
242  { QStyle::SC_ScrollBarSlider, "handle" },
243  { QStyle::SC_ScrollBarAddPage, "add-page" },
244  { QStyle::SC_ScrollBarSubPage, "sub-page" },
245  { QStyle::SC_ScrollBarAddLine, "add-line" },
246  { QStyle::SC_ScrollBarSubLine, "sub-line" },
247  { QStyle::SC_ScrollBarFirst, "first" },
248  { QStyle::SC_ScrollBarLast, "last" },
249  { QStyle::SC_ScrollBarSubLine, "up-arrow" },
250  { QStyle::SC_ScrollBarAddLine, "down-arrow" },
251  { QStyle::SC_ScrollBarSubLine, "left-arrow" },
252  { QStyle::SC_ScrollBarAddLine, "right-arrow" },
253  { QStyle::SC_None, "handle" },
254  { QStyle::SC_None, "handle" },
255  { QStyle::SC_None, "separator" },
256  { QStyle::SC_None, "scroller" },
257  { QStyle::SC_None, "tearoff" },
258  { QStyle::SC_None, "indicator" },
259  { QStyle::SC_None, "separator" },
260  { QStyle::SC_None, "icon" },
261  { QStyle::SC_None, "right-arrow" },
262  { QStyle::SC_None, "branch" },
263  { QStyle::SC_None, "section" },
264  { QStyle::SC_None, "down-arrow" },
265  { QStyle::SC_None, "up-arrow" },
266  { QStyle::SC_None, "chunk" },
267  { QStyle::SC_None, "tab" },
268  { QStyle::SC_None, "scroller" },
269  { QStyle::SC_None, "tear" },
270  { QStyle::SC_SliderGroove, "groove" },
271  { QStyle::SC_SliderHandle, "handle" },
272  { QStyle::SC_None, "add-page" },
273  { QStyle::SC_None, "sub-page"},
274  { QStyle::SC_SliderTickmarks, "tick-mark" },
275  { QStyle::SC_None, "pane" },
276  { QStyle::SC_None, "tab-bar" },
277  { QStyle::SC_None, "left-corner" },
278  { QStyle::SC_None, "right-corner" },
279  { QStyle::SC_None, "title" },
280  { QStyle::SC_None, "close-button" },
281  { QStyle::SC_None, "float-button" },
282  { QStyle::SC_None, "separator" },
283  { QStyle::SC_MdiCloseButton, "close-button" },
284  { QStyle::SC_MdiMinButton, "minimize-button" },
285  { QStyle::SC_MdiNormalButton, "normal-button" },
286  { QStyle::SC_TitleBarLabel, "title" },
287  { QStyle::SC_TitleBarCloseButton, "close-button" },
288  { QStyle::SC_TitleBarMinButton, "minimize-button" },
289  { QStyle::SC_TitleBarMaxButton, "maximize-button" },
290  { QStyle::SC_TitleBarShadeButton, "shade-button" },
291  { QStyle::SC_TitleBarUnshadeButton, "unshade-button" },
292  { QStyle::SC_TitleBarNormalButton, "normal-button" },
293  { QStyle::SC_TitleBarContextHelpButton, "contexthelp-button" },
294  { QStyle::SC_TitleBarSysMenu, "sys-menu" },
295  { QStyle::SC_None, "item" },
296  { QStyle::SC_None, "icon" },
297  { QStyle::SC_None, "text" },
298  { QStyle::SC_None, "indicator" },
299  { QStyle::SC_None, "corner" },
300  { QStyle::SC_None, "close-button" },
301 };
302 
303 
305 {
307  : horizStretch(QCss::TileMode_Unknown), vertStretch(QCss::TileMode_Unknown)
308  {
309  for (int i = 0; i < 4; i++)
310  cuts[i] = -1;
311  }
312  int cuts[4];
316 };
317 
319 {
321  Qt::Alignment a, QCss::Origin o, Attachment t, QCss::Origin c)
322  : brush(b), pixmap(p), repeat(r), position(a), origin(o), attachment(t), clip(c) { }
323 
324  bool isTransparent() const {
325  if (brush.style() != Qt::NoBrush)
326  return !brush.isOpaque();
327  return pixmap.isNull() ? false : pixmap.hasAlpha();
328  }
332  Qt::Alignment position;
336 };
337 
339 {
341  {
342  for (int i = 0; i < 4; i++) {
343  borders[i] = 0;
344  styles[i] = QCss::BorderStyle_None;
345  }
346  }
347 
349  {
350  for (int i = 0; i < 4; i++) {
351  borders[i] = b[i];
352  styles[i] = s[i];
353  colors[i] = c[i];
354  radii[i] = r[i];
355  }
356  }
357 
358  int borders[4];
359  QBrush colors[4];
360  QCss::BorderStyle styles[4];
361  QSize radii[4]; // topleft, topright, bottomleft, bottomright
362 
364  { return bi; }
365  bool hasBorderImage() const { return bi!=0; }
366 
368 
369  bool isOpaque() const
370  {
371  for (int i = 0; i < 4; i++) {
372  if (styles[i] == QCss::BorderStyle_Native || styles[i] == QCss::BorderStyle_None)
373  continue;
374  if (styles[i] >= QCss::BorderStyle_Dotted && styles[i] <= QCss::BorderStyle_DotDotDash
375  && styles[i] != BorderStyle_Solid)
376  return false;
377  if (!colors[i].isOpaque())
378  return false;
379  if (!radii[i].isEmpty())
380  return false;
381  }
382  if (bi != 0 && bi->pixmap.hasAlpha())
383  return false;
384  return true;
385  }
386 };
387 
388 
390 {
392  {
393  for (int i = 0; i < 4; i++) {
394  offsets[i] = 0;
395  }
396  }
397 
399  : QStyleSheetBorderData(b, c, s, r)
400  {
401  for (int i = 0; i < 4; i++) {
402  offsets[i] = o[i];
403  }
404  }
405 
406  int offsets[4];
407 };
408 
410 {
411  QStyleSheetBoxData(int *m, int *p, int s) : spacing(s)
412  {
413  for (int i = 0; i < 4; i++) {
414  margins[i] = m[i];
415  paddings[i] = p[i];
416  }
417  }
418 
419  int margins[4];
420  int paddings[4];
421 
422  int spacing;
423 };
424 
426 {
427  QStyleSheetPaletteData(const QBrush &fg, const QBrush &sfg, const QBrush &sbg,
428  const QBrush &abg)
429  : foreground(fg), selectionForeground(sfg), selectionBackground(sbg),
430  alternateBackground(abg) { }
431 
436 };
437 
439 {
440  QStyleSheetGeometryData(int w, int h, int minw, int minh, int maxw, int maxh)
441  : minWidth(minw), minHeight(minh), width(w), height(h), maxWidth(maxw), maxHeight(maxh) { }
442 
443  int minWidth, minHeight, width, height, maxWidth, maxHeight;
444 };
445 
447 {
448  QStyleSheetPositionData(int l, int t, int r, int b, Origin o, Qt::Alignment p, QCss::PositionMode m, Qt::Alignment a = 0)
449  : left(l), top(t), bottom(b), right(r), origin(o), position(p), mode(m), textAlignment(a) { }
450 
451  int left, top, bottom, right;
453  Qt::Alignment position;
455  Qt::Alignment textAlignment;
456 };
457 
459 {
460  QStyleSheetImageData(const QIcon &i, Qt::Alignment a, const QSize &sz)
461  : icon(i), alignment(a), size(sz) { }
462 
464  Qt::Alignment alignment;
466 };
467 
469 {
470 public:
471  QRenderRule() : features(0), hasFont(false), pal(0), b(0), bg(0), bd(0), ou(0), geo(0), p(0), img(0), clipset(0) { }
474 
475  QRect borderRect(const QRect &r) const;
476  QRect outlineRect(const QRect &r) const;
477  QRect paddingRect(const QRect &r) const;
478  QRect contentsRect(const QRect &r) const;
479 
480  enum { Margin = 1, Border = 2, Padding = 4, All=Margin|Border|Padding };
481  QRect boxRect(const QRect &r, int flags = All) const;
482  QSize boxSize(const QSize &s, int flags = All) const;
483  QRect originRect(const QRect &rect, Origin origin) const;
484 
485  QPainterPath borderClip(QRect rect);
486  void drawBorder(QPainter *, const QRect&);
487  void drawOutline(QPainter *, const QRect&);
488  void drawBorderImage(QPainter *, const QRect&);
489  void drawBackground(QPainter *, const QRect&, const QPoint& = QPoint(0, 0));
490  void drawBackgroundImage(QPainter *, const QRect&, QPoint = QPoint(0, 0));
491  void drawFrame(QPainter *, const QRect&);
492  void drawImage(QPainter *p, const QRect &rect);
493  void drawRule(QPainter *, const QRect&);
494  void configurePalette(QPalette *, QPalette::ColorGroup, const QWidget *, bool);
495  void configurePalette(QPalette *p, QPalette::ColorRole fr, QPalette::ColorRole br);
496 
497  const QStyleSheetPaletteData *palette() const { return pal; }
498  const QStyleSheetBoxData *box() const { return b; }
499  const QStyleSheetBackgroundData *background() const { return bg; }
500  const QStyleSheetBorderData *border() const { return bd; }
501  const QStyleSheetOutlineData *outline() const { return ou; }
502  const QStyleSheetGeometryData *geometry() const { return geo; }
503  const QStyleSheetPositionData *position() const { return p; }
504 
505  bool hasPalette() const { return pal != 0; }
506  bool hasBackground() const { return bg != 0 && (!bg->pixmap.isNull() || bg->brush.style() != Qt::NoBrush); }
507  bool hasGradientBackground() const { return bg && bg->brush.style() >= Qt::LinearGradientPattern
508  && bg->brush.style() <= Qt::ConicalGradientPattern; }
509 
510  bool hasNativeBorder() const {
511  return bd == 0
512  || (!bd->hasBorderImage() && bd->styles[0] == BorderStyle_Native);
513  }
514 
515  bool hasNativeOutline() const {
516  return (ou == 0
517  || (!ou->hasBorderImage() && ou->styles[0] == BorderStyle_Native));
518  }
519 
520  bool baseStyleCanDraw() const {
521  if (!hasBackground() || (background()->brush.style() == Qt::NoBrush && bg->pixmap.isNull()))
522  return true;
523  if (bg && !bg->pixmap.isNull())
524  return false;
525  if (hasGradientBackground())
526  return features & StyleFeature_BackgroundGradient;
527  return features & StyleFeature_BackgroundColor;
528  }
529 
530  bool hasBox() const { return b != 0; }
531  bool hasBorder() const { return bd != 0; }
532  bool hasOutline() const { return ou != 0; }
533  bool hasPosition() const { return p != 0; }
534  bool hasGeometry() const { return geo != 0; }
535  bool hasDrawable() const { return !hasNativeBorder() || hasBackground() || hasImage(); }
536  bool hasImage() const { return img != 0; }
537 
539  { return geo ? QSize(geo->minWidth, geo->minHeight) : QSize(0, 0); }
541  { return boxSize(minimumContentsSize()); }
542 
544  { return geo ? QSize(geo->width, geo->height)
545  : ((img && img->size.isValid()) ? img->size : QSize()); }
546  QSize contentsSize(const QSize &sz) const
547  {
548  QSize csz = contentsSize();
549  if (csz.width() == -1) csz.setWidth(sz.width());
550  if (csz.height() == -1) csz.setHeight(sz.height());
551  return csz;
552  }
553  bool hasContentsSize() const
554  { return (geo && (geo->width != -1 || geo->height != -1)) || (img && img->size.isValid()); }
555 
556  QSize size() const { return boxSize(contentsSize()); }
557  QSize size(const QSize &sz) const { return boxSize(contentsSize(sz)); }
558  QSize adjustSize(const QSize &sz)
559  {
560  if (!geo)
561  return sz;
562  QSize csz = contentsSize();
563  if (csz.width() == -1) csz.setWidth(sz.width());
564  if (csz.height() == -1) csz.setHeight(sz.height());
565  if (geo->maxWidth != -1 && csz.width() > geo->maxWidth) csz.setWidth(geo->maxWidth);
566  if (geo->maxHeight != -1 && csz.height() > geo->maxHeight) csz.setHeight(geo->maxHeight);
567  csz=csz.expandedTo(QSize(geo->minWidth, geo->minHeight));
568  return csz;
569  }
570 
571  int features;
574  bool hasFont;
575 
577  bool hasStyleHint(const QString& sh) const { return styleHints.contains(sh); }
578  QVariant styleHint(const QString& sh) const { return styleHints.value(sh); }
579 
580  void fixupBorder(int);
581 
590 
591  // Shouldn't be here
592  void setClip(QPainter *p, const QRect &rect);
593  void unsetClip(QPainter *);
594  int clipset;
596 };
597 
599 static const char *knownStyleHints[] = {
600  "activate-on-singleclick",
601  "alignment",
602  "arrow-keys-navigate-into-children",
603  "backward-icon",
604  "button-layout",
605  "cd-icon",
606  "combobox-list-mousetracking",
607  "combobox-popup",
608  "computer-icon",
609  "desktop-icon",
610  "dialog-apply-icon",
611  "dialog-cancel-icon",
612  "dialog-close-icon",
613  "dialog-discard-icon",
614  "dialog-help-icon",
615  "dialog-no-icon",
616  "dialog-ok-icon",
617  "dialog-open-icon",
618  "dialog-reset-icon",
619  "dialog-save-icon",
620  "dialog-yes-icon",
621  "dialogbuttonbox-buttons-have-icons",
622  "directory-closed-icon",
623  "directory-icon",
624  "directory-link-icon",
625  "directory-open-icon",
626  "dither-disable-text",
627  "dockwidget-close-icon",
628  "downarrow-icon",
629  "dvd-icon",
630  "etch-disabled-text",
631  "file-icon",
632  "file-link-icon",
633  "filedialog-backward-icon", // unused
634  "filedialog-contentsview-icon",
635  "filedialog-detailedview-icon",
636  "filedialog-end-icon",
637  "filedialog-infoview-icon",
638  "filedialog-listview-icon",
639  "filedialog-new-directory-icon",
640  "filedialog-parent-directory-icon",
641  "filedialog-start-icon",
642  "floppy-icon",
643  "forward-icon",
644  "gridline-color",
645  "harddisk-icon",
646  "home-icon",
647  "icon-size",
648  "leftarrow-icon",
649  "lineedit-password-character",
650  "mdi-fill-space-on-maximize",
651  "menu-scrollable",
652  "menubar-altkey-navigation",
653  "menubar-separator",
654  "messagebox-critical-icon",
655  "messagebox-information-icon",
656  "messagebox-question-icon",
657  "messagebox-text-interaction-flags",
658  "messagebox-warning-icon",
659  "mouse-tracking",
660  "network-icon",
661  "opacity",
662  "paint-alternating-row-colors-for-empty-area",
663  "rightarrow-icon",
664  "scrollbar-contextmenu",
665  "scrollbar-leftclick-absolute-position",
666  "scrollbar-middleclick-absolute-position",
667  "scrollbar-roll-between-buttons",
668  "scrollbar-scroll-when-pointer-leaves-control",
669  "scrollview-frame-around-contents",
670  "show-decoration-selected",
671  "spinbox-click-autorepeat-rate",
672  "spincontrol-disable-on-bounds",
673  "tabbar-elide-mode",
674  "tabbar-prefer-no-arrows",
675  "titlebar-close-icon",
676  "titlebar-contexthelp-icon",
677  "titlebar-maximize-icon",
678  "titlebar-menu-icon",
679  "titlebar-minimize-icon",
680  "titlebar-normal-icon",
681  "titlebar-shade-icon",
682  "titlebar-unshade-icon",
683  "toolbutton-popup-delay",
684  "trash-icon",
685  "uparrow-icon"
686 };
687 
688 static const int numKnownStyleHints = sizeof(knownStyleHints)/sizeof(knownStyleHints[0]);
689 
691 {
693  for (int i = 0; i < layout.count(); i++) {
694  int button = layout[i].toAscii();
695  switch (button) {
696  case 'm':
699  break;
700  case 'M':
702  break;
703  case 'X':
706  break;
707  case 'N':
710  break;
711  case 'I':
713  break;
714  case 'T':
716  break;
717  case 'H':
719  break;
720  case 'S':
722  break;
723  default:
724  buttons.append(button);
725  break;
726  }
727  }
728  return buttons;
729 }
730 
731 namespace {
732  struct ButtonInfo {
733  QRenderRule rule;
734  int element;
735  int offset;
736  int where;
737  int width;
738  };
739 }
740 
742 {
744  const bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
745  const bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
746  QRenderRule subRule = renderRule(w, tb);
747  QRect cr = subRule.contentsRect(tb->rect);
748  QList<QVariant> layout = subRule.styleHint(QLatin1String("button-layout")).toList();
749  if (layout.isEmpty())
750  layout = subControlLayout(QLatin1String("I(T)HSmMX"));
751 
752  int offsets[3] = { 0, 0, 0 };
753  enum Where { Left, Right, Center, NoWhere } where = Left;
754  QList<ButtonInfo> infos;
755  for (int i = 0; i < layout.count(); i++) {
756  ButtonInfo info;
757  info.element = layout[i].toInt();
758  if (info.element == '(') {
759  where = Center;
760  } else if (info.element == ')') {
761  where = Right;
762  } else {
763  switch (info.element) {
766  continue;
767  break;
770  continue;
771  break;
774  continue;
775  if (isMinimized)
776  info.element = PseudoElement_TitleBarNormalButton;
777  break;
780  continue;
781  if (isMaximized)
782  info.element = PseudoElement_TitleBarNormalButton;
783  break;
786  continue;
787  if (isMinimized)
789  break;
793  continue;
794  break;
795  default:
796  continue;
797  }
798  if (info.element == PseudoElement_TitleBar) {
799  info.width = tb->fontMetrics.width(tb->text) + 6;
800  subRule.geo = new QStyleSheetGeometryData(info.width, tb->fontMetrics.height(), -1, -1, -1, -1);
801  } else {
802  subRule = renderRule(w, tb, info.element);
803  info.width = subRule.size().width();
804  }
805  info.rule = subRule;
806  info.offset = offsets[where];
807  info.where = where;
808  infos.append(info);
809 
810  offsets[where] += info.width;
811  }
812  }
813 
814  for (int i = 0; i < infos.count(); i++) {
815  ButtonInfo info = infos[i];
816  QRect lr = cr;
817  switch (info.where) {
818  case Center: {
819  lr.setLeft(cr.left() + offsets[Left]);
820  lr.setRight(cr.right() - offsets[Right]);
821  QRect r(0, 0, offsets[Center], lr.height());
822  r.moveCenter(lr.center());
823  r.setLeft(r.left()+info.offset);
824  r.setWidth(info.width);
825  lr = r;
826  break; }
827  case Left:
828  lr.translate(info.offset, 0);
829  lr.setWidth(info.width);
830  break;
831  case Right:
832  lr.moveLeft(cr.right() + 1 - offsets[Right] + info.offset);
833  lr.setWidth(info.width);
834  break;
835  default:
836  break;
837  }
838  QStyle::SubControl control = knownPseudoElements[info.element].subControl;
839  layoutRects[control] = positionRect(w, info.rule, info.element, lr, tb->direction);
840  }
841 
842  return layoutRects;
843 }
844 
846 {
847  switch (pe) {
858  default: break;
859  }
860  return QStyle::SP_CustomBase;
861 }
862 
864 : features(0), hasFont(false), pal(0), b(0), bg(0), bd(0), ou(0), geo(0), p(0), img(0), clipset(0)
865 {
866  QPalette palette = QApplication::palette(); // ###: ideally widget's palette
867  ValueExtractor v(declarations, palette);
869 
870  int w = -1, h = -1, minw = -1, minh = -1, maxw = -1, maxh = -1;
871  if (v.extractGeometry(&w, &h, &minw, &minh, &maxw, &maxh))
872  geo = new QStyleSheetGeometryData(w, h, minw, minh, maxw, maxh);
873 
874  int left = 0, top = 0, right = 0, bottom = 0;
875  Origin origin = Origin_Unknown;
876  Qt::Alignment position = 0;
878  Qt::Alignment textAlignment = 0;
879  if (v.extractPosition(&left, &top, &right, &bottom, &origin, &position, &mode, &textAlignment))
880  p = new QStyleSheetPositionData(left, top, right, bottom, origin, position, mode, textAlignment);
881 
882  int margins[4], paddings[4], spacing = -1;
883  for (int i = 0; i < 4; i++)
884  margins[i] = paddings[i] = 0;
885  if (v.extractBox(margins, paddings, &spacing))
886  b = new QStyleSheetBoxData(margins, paddings, spacing);
887 
888  int borders[4];
889  QBrush colors[4];
890  QCss::BorderStyle styles[4];
891  QSize radii[4];
892  for (int i = 0; i < 4; i++) {
893  borders[i] = 0;
894  styles[i] = BorderStyle_None;
895  }
896  if (v.extractBorder(borders, colors, styles, radii))
897  bd = new QStyleSheetBorderData(borders, colors, styles, radii);
898 
899  int offsets[4];
900  for (int i = 0; i < 4; i++) {
901  borders[i] = offsets[i] = 0;
902  styles[i] = BorderStyle_None;
903  }
904  if (v.extractOutline(borders, colors, styles, radii, offsets))
905  ou = new QStyleSheetOutlineData(borders, colors, styles, radii, offsets);
906 
907  QBrush brush;
908  QString uri;
909  Repeat repeat = Repeat_XY;
910  Qt::Alignment alignment = Qt::AlignTop | Qt::AlignLeft;
911  Attachment attachment = Attachment_Scroll;
912  origin = Origin_Padding;
913  Origin clip = Origin_Border;
914  if (v.extractBackground(&brush, &uri, &repeat, &alignment, &origin, &attachment, &clip))
915  bg = new QStyleSheetBackgroundData(brush, QPixmap(uri), repeat, alignment, origin, attachment, clip);
916 
917  QBrush sfg, fg;
918  QBrush sbg, abg;
919  if (v.extractPalette(&fg, &sfg, &sbg, &abg))
920  pal = new QStyleSheetPaletteData(fg, sfg, sbg, abg);
921 
922  QIcon icon;
923  alignment = Qt::AlignCenter;
924  QSize size;
925  if (v.extractImage(&icon, &alignment, &size))
926  img = new QStyleSheetImageData(icon, alignment, size);
927 
928  int adj = -255;
929  hasFont = v.extractFont(&font, &adj);
930 
931 #ifndef QT_NO_TOOLTIP
932  if (widget && qstrcmp(widget->metaObject()->className(), "QTipLabel") == 0)
933  palette = QToolTip::palette();
934 #endif
935 
936  for (int i = 0; i < declarations.count(); i++) {
937  const Declaration& decl = declarations.at(i);
938  if (decl.d->propertyId == BorderImage) {
939  QString uri;
940  QCss::TileMode horizStretch, vertStretch;
941  int cuts[4];
942 
943  decl.borderImageValue(&uri, cuts, &horizStretch, &vertStretch);
944  if (uri.isEmpty() || uri == QLatin1String("none")) {
945  if (bd && bd->bi)
946  bd->bi->pixmap = QPixmap();
947  } else {
948  if (!bd)
950  if (!bd->bi)
952 
954  bi->pixmap = QPixmap(uri);
955  for (int i = 0; i < 4; i++)
956  bi->cuts[i] = cuts[i];
957  bi->horizStretch = horizStretch;
958  bi->vertStretch = vertStretch;
959  }
960  } else if (decl.d->propertyId == QtBackgroundRole) {
961  if (bg && bg->brush.style() != Qt::NoBrush)
962  continue;
963  int role = decl.d->values.at(0).variant.toInt();
964  if (role >= Value_FirstColorRole && role <= Value_LastColorRole)
966  } else if (decl.d->property.startsWith(QLatin1String("qproperty-"), Qt::CaseInsensitive)) {
967  // intentionally left blank...
968  } else if (decl.d->propertyId == UnknownProperty) {
969  bool knownStyleHint = false;
970  for (int i = 0; i < numKnownStyleHints; i++) {
972  if (decl.d->property.compare(styleHint) == 0) {
973  QString hintName = QString(styleHint);
974  QVariant hintValue;
975  if (hintName.endsWith(QLatin1String("alignment"))) {
976  hintValue = (int) decl.alignmentValue();
977  } else if (hintName.endsWith(QLatin1String("color"))) {
978  hintValue = (int) decl.colorValue().rgba();
979  } else if (hintName.endsWith(QLatin1String("size"))) {
980  hintValue = decl.sizeValue();
981  } else if (hintName.endsWith(QLatin1String("icon"))) {
982  hintValue = decl.iconValue();
983  } else if (hintName == QLatin1String("button-layout")
984  && decl.d->values.count() != 0 && decl.d->values.at(0).type == Value::String) {
985  hintValue = subControlLayout(decl.d->values.at(0).variant.toString());
986  } else {
987  int integer;
988  decl.intValue(&integer);
989  hintValue = integer;
990  }
991  styleHints[decl.d->property] = hintValue;
992  knownStyleHint = true;
993  break;
994  }
995  }
996  if (!knownStyleHint)
997  qDebug("Unknown property %s", qPrintable(decl.d->property));
998  }
999  }
1000 
1001  if (widget) {
1003  if (!style)
1004  style = qobject_cast<QStyleSheetStyle *>(widget->style());
1005  if (style)
1006  fixupBorder(style->nativeFrameWidth(widget));
1007 
1008  }
1009  if (hasBorder() && border()->hasBorderImage())
1011 }
1012 
1014 {
1015  if (!hasBox())
1016  return r;
1017  const int* m = box()->margins;
1018  return r.adjusted(m[LeftEdge], m[TopEdge], -m[RightEdge], -m[BottomEdge]);
1019 }
1020 
1022 {
1023  QRect br = borderRect(r);
1024  if (!hasOutline())
1025  return br;
1026  const int *b = outline()->borders;
1027  return r.adjusted(b[LeftEdge], b[TopEdge], -b[RightEdge], -b[BottomEdge]);
1028 }
1029 
1031 {
1032  QRect br = borderRect(r);
1033  if (!hasBorder())
1034  return br;
1035  const int *b = border()->borders;
1036  return br.adjusted(b[LeftEdge], b[TopEdge], -b[RightEdge], -b[BottomEdge]);
1037 }
1038 
1040 {
1041  QRect pr = paddingRect(r);
1042  if (!hasBox())
1043  return pr;
1044  const int *p = box()->paddings;
1045  return pr.adjusted(p[LeftEdge], p[TopEdge], -p[RightEdge], -p[BottomEdge]);
1046 }
1047 
1048 QRect QRenderRule::boxRect(const QRect& cr, int flags) const
1049 {
1050  QRect r = cr;
1051  if (hasBox()) {
1052  if (flags & Margin) {
1053  const int *m = box()->margins;
1054  r.adjust(-m[LeftEdge], -m[TopEdge], m[RightEdge], m[BottomEdge]);
1055  }
1056  if (flags & Padding) {
1057  const int *p = box()->paddings;
1058  r.adjust(-p[LeftEdge], -p[TopEdge], p[RightEdge], p[BottomEdge]);
1059  }
1060  }
1061  if (hasBorder() && (flags & Border)) {
1062  const int *b = border()->borders;
1063  r.adjust(-b[LeftEdge], -b[TopEdge], b[RightEdge], b[BottomEdge]);
1064  }
1065  return r;
1066 }
1067 
1068 QSize QRenderRule::boxSize(const QSize &cs, int flags) const
1069 {
1070  QSize bs = boxRect(QRect(QPoint(0, 0), cs), flags).size();
1071  if (cs.width() < 0) bs.setWidth(-1);
1072  if (cs.height() < 0) bs.setHeight(-1);
1073  return bs;
1074 }
1075 
1076 void QRenderRule::fixupBorder(int nativeWidth)
1077 {
1078  if (bd == 0)
1079  return;
1080 
1081  if (!bd->hasBorderImage() || bd->bi->pixmap.isNull()) {
1082  bd->bi = 0;
1083  // ignore the color, border of edges that have none border-style
1084  QBrush color = pal ? pal->foreground : QBrush();
1085  const bool hasRadius = bd->radii[0].isValid() || bd->radii[1].isValid()
1086  || bd->radii[2].isValid() || bd->radii[3].isValid();
1087  for (int i = 0; i < 4; i++) {
1088  if ((bd->styles[i] == BorderStyle_Native) && hasRadius)
1089  bd->styles[i] = BorderStyle_None;
1090 
1091  switch (bd->styles[i]) {
1092  case BorderStyle_None:
1093  // border-style: none forces width to be 0
1094  bd->colors[i] = QBrush();
1095  bd->borders[i] = 0;
1096  break;
1097  case BorderStyle_Native:
1098  if (bd->borders[i] == 0)
1099  bd->borders[i] = nativeWidth;
1100  // intentional fall through
1101  default:
1102  if (!bd->colors[i].style() != Qt::NoBrush) // auto-acquire 'color'
1103  bd->colors[i] = color;
1104  break;
1105  }
1106  }
1107 
1108  return;
1109  }
1110 
1111  // inspect the border image
1113  if (bi->cuts[0] == -1) {
1114  for (int i = 0; i < 4; i++) // assume, cut = border
1115  bi->cuts[i] = int(border()->borders[i]);
1116  }
1117 }
1118 
1120 {
1121  setClip(p, rect);
1122  static const Qt::TileRule tileMode2TileRule[] = {
1124 
1125  const QStyleSheetBorderImageData *borderImageData = border()->borderImage();
1126  const int *targetBorders = border()->borders;
1127  const int *sourceBorders = borderImageData->cuts;
1128  QMargins sourceMargins(sourceBorders[LeftEdge], sourceBorders[TopEdge],
1129  sourceBorders[RightEdge], sourceBorders[BottomEdge]);
1130  QMargins targetMargins(targetBorders[LeftEdge], targetBorders[TopEdge],
1131  targetBorders[RightEdge], targetBorders[BottomEdge]);
1132 
1133  bool wasSmoothPixmapTransform = p->renderHints() & QPainter::SmoothPixmapTransform;
1135  qDrawBorderPixmap(p, rect, targetMargins, borderImageData->pixmap,
1136  QRect(QPoint(), borderImageData->pixmap.size()), sourceMargins,
1137  QTileRules(tileMode2TileRule[borderImageData->horizStretch], tileMode2TileRule[borderImageData->vertStretch]));
1138  p->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothPixmapTransform);
1139  unsetClip(p);
1140 }
1141 
1142 QRect QRenderRule::originRect(const QRect &rect, Origin origin) const
1143 {
1144  switch (origin) {
1145  case Origin_Padding:
1146  return paddingRect(rect);
1147  case Origin_Border:
1148  return borderRect(rect);
1149  case Origin_Content:
1150  return contentsRect(rect);
1151  case Origin_Margin:
1152  default:
1153  return rect;
1154  }
1155 }
1156 
1158 {
1159  if (!hasBackground())
1160  return;
1161 
1162  const QPixmap& bgp = background()->pixmap;
1163  if (bgp.isNull())
1164  return;
1165 
1166  setClip(p, borderRect(rect));
1167 
1168  if (background()->origin != background()->clip) {
1169  p->save();
1170  p->setClipRect(originRect(rect, background()->clip), Qt::IntersectClip);
1171  }
1172 
1173  if (background()->attachment == Attachment_Fixed)
1174  off = QPoint(0, 0);
1175 
1176  QRect r = originRect(rect, background()->origin);
1178  QRect inter = aligned.translated(-off).intersected(r);
1179 
1180  switch (background()->repeat) {
1181  case Repeat_Y:
1182  p->drawTiledPixmap(inter.x(), r.y(), inter.width(), r.height(), bgp,
1183  inter.x() - aligned.x() + off.x(),
1184  bgp.height() - int(aligned.y() - r.y()) % bgp.height() + off.y());
1185  break;
1186  case Repeat_X:
1187  p->drawTiledPixmap(r.x(), inter.y(), r.width(), inter.height(), bgp,
1188  bgp.width() - int(aligned.x() - r.x())%bgp.width() + off.x(),
1189  inter.y() - aligned.y() + off.y());
1190  break;
1191  case Repeat_XY:
1192  p->drawTiledPixmap(r, bgp,
1193  QPoint(bgp.width() - int(aligned.x() - r.x())% bgp.width() + off.x(),
1194  bgp.height() - int(aligned.y() - r.y())%bgp.height() + off.y()));
1195  break;
1196  case Repeat_None:
1197  default:
1198  p->drawPixmap(inter.x(), inter.y(), bgp, inter.x() - aligned.x() + off.x(),
1199  inter.y() - aligned.y() + off.y(), inter.width(), inter.height());
1200  break;
1201  }
1202 
1203 
1204  if (background()->origin != background()->clip)
1205  p->restore();
1206 
1207  unsetClip(p);
1208 }
1209 
1211 {
1212  if (!hasOutline())
1213  return;
1214 
1215  bool wasAntialiased = p->renderHints() & QPainter::Antialiasing;
1217  qDrawBorder(p, rect, ou->styles, ou->borders, ou->colors, ou->radii);
1218  p->setRenderHint(QPainter::Antialiasing, wasAntialiased);
1219 }
1220 
1222 {
1223  if (!hasBorder())
1224  return;
1225 
1226  if (border()->hasBorderImage()) {
1227  drawBorderImage(p, rect);
1228  return;
1229  }
1230 
1231  bool wasAntialiased = p->renderHints() & QPainter::Antialiasing;
1233  qDrawBorder(p, rect, bd->styles, bd->borders, bd->colors, bd->radii);
1234  p->setRenderHint(QPainter::Antialiasing, wasAntialiased);
1235 }
1236 
1238 {
1239  if (!hasBorder())
1240  return QPainterPath();
1241 
1242  QSize tlr, trr, blr, brr;
1243  qNormalizeRadii(r, bd->radii, &tlr, &trr, &blr, &brr);
1244  if (tlr.isNull() && trr.isNull() && blr.isNull() && brr.isNull())
1245  return QPainterPath();
1246 
1247  const QRectF rect(r);
1248  const int *borders = border()->borders;
1249  QPainterPath path;
1250  qreal curY = rect.y() + borders[TopEdge]/qreal(2.0);
1251  path.moveTo(rect.x() + tlr.width(), curY);
1252  path.lineTo(rect.right() - trr.width(), curY);
1253  qreal curX = rect.right() - borders[RightEdge]/qreal(2.0);
1254  path.arcTo(curX - 2*trr.width() + borders[RightEdge], curY,
1255  trr.width()*2 - borders[RightEdge], trr.height()*2 - borders[TopEdge], 90, -90);
1256 
1257  path.lineTo(curX, rect.bottom() - brr.height());
1258  curY = rect.bottom() - borders[BottomEdge]/qreal(2.0);
1259  path.arcTo(curX - 2*brr.width() + borders[RightEdge], curY - 2*brr.height() + borders[BottomEdge],
1260  brr.width()*2 - borders[RightEdge], brr.height()*2 - borders[BottomEdge], 0, -90);
1261 
1262  path.lineTo(rect.x() + blr.width(), curY);
1263  curX = rect.left() + borders[LeftEdge]/qreal(2.0);
1264  path.arcTo(curX, rect.bottom() - 2*blr.height() + borders[BottomEdge]/2,
1265  blr.width()*2 - borders[LeftEdge], blr.height()*2 - borders[BottomEdge], 270, -90);
1266 
1267  path.lineTo(curX, rect.top() + tlr.height());
1268  path.arcTo(curX, rect.top() + borders[TopEdge]/2,
1269  tlr.width()*2 - borders[LeftEdge], tlr.height()*2 - borders[TopEdge], 180, -90);
1270 
1271  path.closeSubpath();
1272  return path;
1273 }
1274 
1279 {
1280  if (clipset++)
1281  return;
1282  clipPath = borderClip(rect);
1283  if (!clipPath.isEmpty()) {
1284  p->save();
1286  }
1287 }
1288 
1290 {
1291  if (--clipset)
1292  return;
1293  if (!clipPath.isEmpty())
1294  p->restore();
1295 }
1296 
1297 void QRenderRule::drawBackground(QPainter *p, const QRect& rect, const QPoint& off)
1298 {
1299  QBrush brush = hasBackground() ? background()->brush : QBrush();
1300  if (brush.style() == Qt::NoBrush)
1301  brush = defaultBackground;
1302 
1303  if (brush.style() != Qt::NoBrush) {
1304  Origin origin = hasBackground() ? background()->clip : Origin_Border;
1305  // ### fix for gradients
1306  const QPainterPath &borderPath = borderClip(originRect(rect, origin));
1307  if (!borderPath.isEmpty()) {
1308  // Drawn intead of being used as clipping path for better visual quality
1309  bool wasAntialiased = p->renderHints() & QPainter::Antialiasing;
1311  p->fillPath(borderPath, brush);
1312  p->setRenderHint(QPainter::Antialiasing, wasAntialiased);
1313  } else {
1314  p->fillRect(originRect(rect, origin), brush);
1315  }
1316  }
1317 
1318  drawBackgroundImage(p, rect, off);
1319 }
1320 
1322 {
1323  drawBackground(p, rect);
1324  if (hasBorder())
1325  drawBorder(p, borderRect(rect));
1326 }
1327 
1329 {
1330  if (!hasImage())
1331  return;
1332  img->icon.paint(p, rect, img->alignment);
1333 }
1334 
1336 {
1337  drawFrame(p, rect);
1338  drawImage(p, contentsRect(rect));
1339 }
1340 
1341 // *shudder* , *horror*, *whoa* <-- what you might feel when you see the functions below
1343 {
1344  if (bg && bg->brush.style() != Qt::NoBrush) {
1345  if (br != QPalette::NoRole)
1346  p->setBrush(br, bg->brush);
1348  if (bg->brush.style() == Qt::SolidPattern) {
1351  p->setBrush(QPalette::Dark, bg->brush.color().darker(150));
1353  }
1354  }
1355 
1356  if (!hasPalette())
1357  return;
1358 
1359  if (pal->foreground.style() != Qt::NoBrush) {
1360  if (fr != QPalette::NoRole)
1361  p->setBrush(fr, pal->foreground);
1364  }
1371 }
1372 
1374 {
1375  if (bg && bg->brush.style() != Qt::NoBrush) {
1376  p->setBrush(cg, QPalette::Base, bg->brush); // for windows, windowxp
1377  p->setBrush(cg, QPalette::Button, bg->brush); // for plastique
1378  p->setBrush(cg, w->backgroundRole(), bg->brush);
1379  p->setBrush(cg, QPalette::Window, bg->brush);
1380  }
1381 
1382  if (embedded) {
1383  /* For embedded widgets (ComboBox, SpinBox and ScrollArea) we want the embedded widget
1384  * to be transparent when we have a transparent background or border image */
1385  if ((hasBackground() && background()->isTransparent())
1386  || (hasBorder() && border()->hasBorderImage() && !border()->borderImage()->pixmap.isNull()))
1387  p->setBrush(cg, w->backgroundRole(), Qt::NoBrush);
1388  }
1389 
1390  if (!hasPalette())
1391  return;
1392 
1393  if (pal->foreground.style() != Qt::NoBrush) {
1395  p->setBrush(cg, w->foregroundRole(), pal->foreground);
1398  }
1405 }
1406 
1408 // Style rules
1409 #define WIDGET(x) (static_cast<QWidget *>(x.ptr))
1410 
1411 static inline QWidget *parentWidget(const QWidget *w)
1412 {
1413  if(qobject_cast<const QLabel *>(w) && qstrcmp(w->metaObject()->className(), "QTipLabel") == 0) {
1414  QWidget *p = qvariant_cast<QWidget *>(w->property("_q_stylesheet_parent"));
1415  if (p)
1416  return p;
1417  }
1418  return w->parentWidget();
1419 }
1420 
1422 {
1423 public:
1425 
1427  {
1428  if (isNullNode(node))
1429  return QStringList();
1430  const QMetaObject *metaObject = WIDGET(node)->metaObject();
1431 #ifndef QT_NO_TOOLTIP
1432  if (qstrcmp(metaObject->className(), "QTipLabel") == 0)
1433  return QStringList(QLatin1String("QToolTip"));
1434 #endif
1435  QStringList result;
1436  do {
1437  result += QString::fromLatin1(metaObject->className()).replace(QLatin1Char(':'), QLatin1Char('-'));
1438  metaObject = metaObject->superClass();
1439  } while (metaObject != 0);
1440  return result;
1441  }
1442  QString attribute(NodePtr node, const QString& name) const
1443  {
1444  if (isNullNode(node))
1445  return QString();
1446 
1447  QHash<QString, QString> &cache = m_attributeCache[WIDGET(node)];
1448  QHash<QString, QString>::const_iterator cacheIt = cache.constFind(name);
1449  if (cacheIt != cache.constEnd())
1450  return cacheIt.value();
1451 
1452  QVariant value = WIDGET(node)->property(name.toLatin1());
1453  if (!value.isValid()) {
1454  if (name == QLatin1String("class")) {
1455  QString className = QString::fromLatin1(WIDGET(node)->metaObject()->className());
1456  if (className.contains(QLatin1Char(':')))
1457  className.replace(QLatin1Char(':'), QLatin1Char('-'));
1458  cache[name] = className;
1459  return className;
1460  } else if (name == QLatin1String("style")) {
1461  QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(WIDGET(node)->style());
1462  if (proxy) {
1463  QString styleName = QString::fromLatin1(proxy->baseStyle()->metaObject()->className());
1464  cache[name] = styleName;
1465  return styleName;
1466  }
1467  }
1468  }
1469  QString valueStr;
1470  if(value.type() == QVariant::StringList || value.type() == QVariant::List)
1471  valueStr = value.toStringList().join(QLatin1String(" "));
1472  else
1473  valueStr = value.toString();
1474  cache[name] = valueStr;
1475  return valueStr;
1476  }
1477  bool nodeNameEquals(NodePtr node, const QString& nodeName) const
1478  {
1479  if (isNullNode(node))
1480  return false;
1481  const QMetaObject *metaObject = WIDGET(node)->metaObject();
1482 #ifndef QT_NO_TOOLTIP
1483  if (qstrcmp(metaObject->className(), "QTipLabel") == 0)
1484  return nodeName == QLatin1String("QToolTip");
1485 #endif
1486  do {
1487  const ushort *uc = (const ushort *)nodeName.constData();
1488  const ushort *e = uc + nodeName.length();
1489  const uchar *c = (uchar *)metaObject->className();
1490  while (*c && uc != e && (*uc == *c || (*c == ':' && *uc == '-'))) {
1491  ++uc;
1492  ++c;
1493  }
1494  if (uc == e && !*c)
1495  return true;
1496  metaObject = metaObject->superClass();
1497  } while (metaObject != 0);
1498  return false;
1499  }
1501  { return true; }
1503  { return isNullNode(node) ? QStringList() : QStringList(WIDGET(node)->objectName()); }
1504  bool isNullNode(NodePtr node) const
1505  { return node.ptr == 0; }
1507  { NodePtr n; n.ptr = isNullNode(node) ? 0 : parentWidget(WIDGET(node)); return n; }
1509  { NodePtr n; n.ptr = 0; return n; }
1511  { return node; }
1512  void freeNode(NodePtr) const
1513  { }
1514 
1515 private:
1517 };
1518 
1520 {
1521  QHash<const QWidget *, QVector<StyleRule> >::const_iterator cacheIt = styleSheetCaches->styleRulesCache.constFind(w);
1522  if (cacheIt != styleSheetCaches->styleRulesCache.constEnd())
1523  return cacheIt.value();
1524 
1525  if (!initWidget(w)) {
1526  return QVector<StyleRule>();
1527  }
1528 
1529  QStyleSheetStyleSelector styleSelector;
1530 
1531  StyleSheet defaultSs;
1532  QHash<const void *, StyleSheet>::const_iterator defaultCacheIt = styleSheetCaches->styleSheetCache.constFind(baseStyle());
1533  if (defaultCacheIt == styleSheetCaches->styleSheetCache.constEnd()) {
1534  defaultSs = getDefaultStyleSheet();
1535  QStyle *bs = baseStyle();
1536  styleSheetCaches->styleSheetCache.insert(bs, defaultSs);
1537  QObject::connect(bs, SIGNAL(destroyed(QObject*)), styleSheetCaches, SLOT(styleDestroyed(QObject*)), Qt::UniqueConnection);
1538  } else {
1539  defaultSs = defaultCacheIt.value();
1540  }
1541  styleSelector.styleSheets += defaultSs;
1542 
1543  if (!qApp->styleSheet().isEmpty()) {
1544  StyleSheet appSs;
1545  QHash<const void *, StyleSheet>::const_iterator appCacheIt = styleSheetCaches->styleSheetCache.constFind(qApp);
1546  if (appCacheIt == styleSheetCaches->styleSheetCache.constEnd()) {
1547  QString ss = qApp->styleSheet();
1548  if (ss.startsWith(QLatin1String("file:///")))
1549  ss.remove(0, 8);
1550  parser.init(ss, qApp->styleSheet() != ss);
1551  if (!parser.parse(&appSs))
1552  qWarning("Could not parse application stylesheet");
1554  appSs.depth = 1;
1555  styleSheetCaches->styleSheetCache.insert(qApp, appSs);
1556  } else {
1557  appSs = appCacheIt.value();
1558  }
1559  styleSelector.styleSheets += appSs;
1560  }
1561 
1562  QVector<QCss::StyleSheet> widgetSs;
1563  for (const QWidget *wid = w; wid; wid = parentWidget(wid)) {
1564  if (wid->styleSheet().isEmpty())
1565  continue;
1566  StyleSheet ss;
1567  QHash<const void *, StyleSheet>::const_iterator widCacheIt = styleSheetCaches->styleSheetCache.constFind(wid);
1568  if (widCacheIt == styleSheetCaches->styleSheetCache.constEnd()) {
1569  parser.init(wid->styleSheet());
1570  if (!parser.parse(&ss)) {
1571  parser.init(QLatin1String("* {") + wid->styleSheet() + QLatin1Char('}'));
1572  if (!parser.parse(&ss))
1573  qWarning("Could not parse stylesheet of widget %p", wid);
1574  }
1576  styleSheetCaches->styleSheetCache.insert(wid, ss);
1577  } else {
1578  ss = widCacheIt.value();
1579  }
1580  widgetSs.append(ss);
1581  }
1582 
1583  for (int i = 0; i < widgetSs.count(); i++)
1584  widgetSs[i].depth = widgetSs.count() - i + 2;
1585 
1586  styleSelector.styleSheets += widgetSs;
1587 
1589  n.ptr = (void *)w;
1590  QVector<QCss::StyleRule> rules = styleSelector.styleRulesForNode(n);
1591  styleSheetCaches->styleRulesCache.insert(w, rules);
1592  return rules;
1593 }
1594 
1596 // Rendering rules
1598 {
1599  QVector<Declaration> decls;
1600  for (int i = 0; i < styleRules.count(); i++) {
1601  const Selector& selector = styleRules.at(i).selectors.at(0);
1602  // Rules with pseudo elements don't cascade. This is an intentional
1603  // diversion for CSS
1604  if (part.compare(selector.pseudoElement(), Qt::CaseInsensitive) != 0)
1605  continue;
1606  quint64 negated = 0;
1607  quint64 cssClass = selector.pseudoClass(&negated);
1608  if ((pseudoClass == PseudoClass_Any) || (cssClass == PseudoClass_Unspecified)
1609  || ((((cssClass & pseudoClass) == cssClass)) && ((negated & pseudoClass) == 0)))
1610  decls += styleRules.at(i).declarations;
1611  }
1612  return decls;
1613 }
1614 
1616 {
1617  QStyle *base = baseStyle();
1618 
1619 #ifndef QT_NO_SPINBOX
1620  if (qobject_cast<const QAbstractSpinBox *>(w))
1621  return base->pixelMetric(QStyle::PM_SpinBoxFrameWidth, 0, w);
1622 #endif
1623 
1624 #ifndef QT_NO_COMBOBOX
1625  if (qobject_cast<const QComboBox *>(w))
1626  return base->pixelMetric(QStyle::PM_ComboBoxFrameWidth, 0, w);
1627 #endif
1628 
1629 #ifndef QT_NO_MENU
1630  if (qobject_cast<const QMenu *>(w))
1631  return base->pixelMetric(QStyle::PM_MenuPanelWidth, 0, w);
1632 #endif
1633 
1634 #ifndef QT_NO_MENUBAR
1635  if (qobject_cast<const QMenuBar *>(w))
1636  return base->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, w);
1637 #endif
1638 #ifndef QT_NO_FRAME
1639  if (const QFrame *frame = qobject_cast<const QFrame *>(w)) {
1640  if (frame->frameShape() == QFrame::NoFrame)
1641  return 0;
1642  }
1643 #endif
1644 
1645  if (qstrcmp(w->metaObject()->className(), "QTipLabel") == 0)
1646  return base->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, w);
1647 
1648  return base->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, w);
1649 }
1650 
1652 {
1653  quint64 pc = 0;
1654  if (state & QStyle::State_Enabled) {
1655  pc |= PseudoClass_Enabled;
1656  if (state & QStyle::State_MouseOver)
1657  pc |= PseudoClass_Hover;
1658  } else {
1659  pc |= PseudoClass_Disabled;
1660  }
1661  if (state & QStyle::State_Active)
1662  pc |= PseudoClass_Active;
1663  if (state & QStyle::State_Window)
1664  pc |= PseudoClass_Window;
1665  if (state & QStyle::State_Sunken)
1666  pc |= PseudoClass_Pressed;
1667  if (state & QStyle::State_HasFocus)
1668  pc |= PseudoClass_Focus;
1669  if (state & QStyle::State_On)
1671  if (state & QStyle::State_Off)
1673  if (state & QStyle::State_NoChange)
1675  if (state & QStyle::State_Selected)
1676  pc |= PseudoClass_Selected;
1677  if (state & QStyle::State_Horizontal)
1678  pc |= PseudoClass_Horizontal;
1679  else
1680  pc |= PseudoClass_Vertical;
1681  if (state & (QStyle::State_Open | QStyle::State_On | QStyle::State_Sunken))
1682  pc |= PseudoClass_Open;
1683  else
1684  pc |= PseudoClass_Closed;
1685  if (state & QStyle::State_Children)
1686  pc |= PseudoClass_Children;
1687  if (state & QStyle::State_Sibling)
1688  pc |= PseudoClass_Sibling;
1689  if (state & QStyle::State_ReadOnly)
1690  pc |= PseudoClass_ReadOnly;
1691  if (state & QStyle::State_Item)
1692  pc |= PseudoClass_Item;
1693 #ifdef QT_KEYPAD_NAVIGATION
1694  if (state & QStyle::State_HasEditFocus)
1695  pc |= PseudoClass_EditFocus;
1696 #endif
1697  return pc;
1698 }
1699 
1700 static void qt_check_if_internal_widget(const QWidget **w, int *element)
1701 {
1702 #ifdef QT_NO_DOCKWIDGET
1703  Q_UNUSED(w);
1704  Q_UNUSED(element);
1705 #else
1706  if (*w && qstrcmp((*w)->metaObject()->className(), "QDockWidgetTitleButton") == 0) {
1707  if ((*w)->objectName() == QLatin1String("qt_dockwidget_closebutton")) {
1709  } else if ((*w)->objectName() == QLatin1String("qt_dockwidget_floatbutton")) {
1711  }
1712  *w = (*w)->parentWidget();
1713  }
1714 #endif
1715 }
1716 
1717 QRenderRule QStyleSheetStyle::renderRule(const QWidget *w, int element, quint64 state) const
1718 {
1719  qt_check_if_internal_widget(&w, &element);
1720  QHash<quint64, QRenderRule> &cache = styleSheetCaches->renderRulesCache[w][element];
1722  if (cacheIt != cache.constEnd())
1723  return cacheIt.value();
1724 
1725  if (!initWidget(w))
1726  return QRenderRule();
1727 
1728  quint64 stateMask = 0;
1729  const QVector<StyleRule> rules = styleRules(w);
1730  for (int i = 0; i < rules.count(); i++) {
1731  const Selector& selector = rules.at(i).selectors.at(0);
1732  quint64 negated = 0;
1733  stateMask |= selector.pseudoClass(&negated);
1734  stateMask |= negated;
1735  }
1736 
1737  cacheIt = cache.constFind(state & stateMask);
1738  if (cacheIt != cache.constEnd()) {
1739  const QRenderRule &newRule = cacheIt.value();
1740  cache[state] = newRule;
1741  return newRule;
1742  }
1743 
1744 
1745  const QString part = QLatin1String(knownPseudoElements[element].name);
1746  QVector<Declaration> decls = declarations(rules, part, state);
1747  QRenderRule newRule(decls, w);
1748  cache[state] = newRule;
1749  if ((state & stateMask) != state)
1750  cache[state&stateMask] = newRule;
1751  return newRule;
1752 }
1753 
1754 QRenderRule QStyleSheetStyle::renderRule(const QWidget *w, const QStyleOption *opt, int pseudoElement) const
1755 {
1756  quint64 extraClass = 0;
1757  QStyle::State state = opt ? opt->state : QStyle::State(QStyle::State_None);
1758 
1759  if (const QStyleOptionComplex *complex = qstyleoption_cast<const QStyleOptionComplex *>(opt)) {
1760  if (pseudoElement != PseudoElement_None) {
1761  // if not an active subcontrol, just pass enabled/disabled
1762  QStyle::SubControl subControl = knownPseudoElements[pseudoElement].subControl;
1763 
1764  if (!(complex->activeSubControls & subControl))
1766  }
1767 
1768  switch (pseudoElement) {
1771  state |= (complex->state & (QStyle::State_On|QStyle::State_ReadOnly));
1772  break;
1777 #ifndef QT_NO_SPINBOX
1778  if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
1779  bool on = false;
1780  bool up = pseudoElement == PseudoElement_SpinBoxUpButton
1781  || pseudoElement == PseudoElement_SpinBoxUpArrow;
1782  if ((sb->stepEnabled & QAbstractSpinBox::StepUpEnabled) && up)
1783  on = true;
1784  else if ((sb->stepEnabled & QAbstractSpinBox::StepDownEnabled) && !up)
1785  on = true;
1786  state |= (on ? QStyle::State_On : QStyle::State_Off);
1787  }
1788 #endif // QT_NO_SPINBOX
1789  break;
1791  state |= (complex->state & (QStyle::State_MouseOver | QStyle::State_Sunken));
1792  break;
1796  state |= complex->state & QStyle::State_MouseOver;
1797  if (complex->state & QStyle::State_Sunken ||
1798  complex->activeSubControls & QStyle::SC_ToolButtonMenu)
1799  state |= QStyle::State_Sunken;
1800  break;
1802  state |= complex->state & QStyle::State_MouseOver;
1803  break;
1804  default:
1805  break;
1806  }
1807 
1808  if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1809  // QStyle::State_On is set when the popup is being shown
1810  // Propagate EditField Pressed state
1811  if (pseudoElement == PseudoElement_None
1812  && (complex->activeSubControls & QStyle::SC_ComboBoxEditField)
1813  && (!(state & QStyle::State_MouseOver))) {
1814  state |= QStyle::State_Sunken;
1815  }
1816 
1817  if (!combo->frame)
1818  extraClass |= PseudoClass_Frameless;
1819  if (!combo->editable)
1820  extraClass |= PseudoClass_ReadOnly;
1821  else
1822  extraClass |= PseudoClass_Editable;
1823 #ifndef QT_NO_SPINBOX
1824  } else if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
1825  if (!spin->frame)
1826  extraClass |= PseudoClass_Frameless;
1827 #endif // QT_NO_SPINBOX
1828  } else if (const QStyleOptionGroupBox *gb = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
1829  if (gb->features & QStyleOptionFrameV2::Flat)
1830  extraClass |= PseudoClass_Flat;
1831  if (gb->lineWidth == 0)
1832  extraClass |= PseudoClass_Frameless;
1833  } else if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
1834  if (tb->titleBarState & Qt::WindowMinimized) {
1835  extraClass |= PseudoClass_Minimized;
1836  }
1837  else if (tb->titleBarState & Qt::WindowMaximized)
1838  extraClass |= PseudoClass_Maximized;
1839  }
1840  } else {
1841  // handle simple style options
1842  if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1843  if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem)
1844  extraClass |= PseudoClass_Default;
1845  if (mi->checkType == QStyleOptionMenuItem::Exclusive)
1846  extraClass |= PseudoClass_Exclusive;
1847  else if (mi->checkType == QStyleOptionMenuItem::NonExclusive)
1848  extraClass |= PseudoClass_NonExclusive;
1849  if (mi->checkType != QStyleOptionMenuItem::NotCheckable)
1850  extraClass |= (mi->checked) ? (PseudoClass_On|PseudoClass_Checked)
1852  } else if (const QStyleOptionHeader *hdr = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
1853  if (hdr->position == QStyleOptionHeader::OnlyOneSection)
1854  extraClass |= PseudoClass_OnlyOne;
1855  else if (hdr->position == QStyleOptionHeader::Beginning)
1856  extraClass |= PseudoClass_First;
1857  else if (hdr->position == QStyleOptionHeader::End)
1858  extraClass |= PseudoClass_Last;
1859  else if (hdr->position == QStyleOptionHeader::Middle)
1860  extraClass |= PseudoClass_Middle;
1861 
1862  if (hdr->selectedPosition == QStyleOptionHeader::NextAndPreviousAreSelected)
1864  else if (hdr->selectedPosition == QStyleOptionHeader::NextIsSelected)
1865  extraClass |= PseudoClass_NextSelected;
1866  else if (hdr->selectedPosition == QStyleOptionHeader::PreviousIsSelected)
1867  extraClass |= PseudoClass_PreviousSelected;
1868 #ifndef QT_NO_TABWIDGET
1869  } else if (const QStyleOptionTabWidgetFrame *tab = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
1870  switch (tab->shape) {
1871  case QTabBar::RoundedNorth:
1873  extraClass |= PseudoClass_Top;
1874  break;
1875  case QTabBar::RoundedSouth:
1877  extraClass |= PseudoClass_Bottom;
1878  break;
1879  case QTabBar::RoundedEast:
1881  extraClass |= PseudoClass_Left;
1882  break;
1883  case QTabBar::RoundedWest:
1885  extraClass |= PseudoClass_Right;
1886  break;
1887  default:
1888  break;
1889  }
1890 #endif
1891 #ifndef QT_NO_TABBAR
1892  } else if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1893  if (tab->position == QStyleOptionTab::OnlyOneTab)
1894  extraClass |= PseudoClass_OnlyOne;
1895  else if (tab->position == QStyleOptionTab::Beginning)
1896  extraClass |= PseudoClass_First;
1897  else if (tab->position == QStyleOptionTab::End)
1898  extraClass |= PseudoClass_Last;
1899  else if (tab->position == QStyleOptionTab::Middle)
1900  extraClass |= PseudoClass_Middle;
1901 
1902  if (tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1903  extraClass |= PseudoClass_NextSelected;
1904  else if (tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1905  extraClass |= PseudoClass_PreviousSelected;
1906 
1907  switch (tab->shape) {
1908  case QTabBar::RoundedNorth:
1910  extraClass |= PseudoClass_Top;
1911  break;
1912  case QTabBar::RoundedSouth:
1914  extraClass |= PseudoClass_Bottom;
1915  break;
1916  case QTabBar::RoundedEast:
1918  extraClass |= PseudoClass_Left;
1919  break;
1920  case QTabBar::RoundedWest:
1922  extraClass |= PseudoClass_Right;
1923  break;
1924  default:
1925  break;
1926  }
1927 #endif // QT_NO_TABBAR
1928  } else if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1929  if (btn->features & QStyleOptionButton::Flat)
1930  extraClass |= PseudoClass_Flat;
1931  if (btn->features & QStyleOptionButton::DefaultButton)
1932  extraClass |= PseudoClass_Default;
1933  } else if (const QStyleOptionFrame *frm = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1934  if (frm->lineWidth == 0)
1935  extraClass |= PseudoClass_Frameless;
1936  if (const QStyleOptionFrameV2 *frame2 = qstyleoption_cast<const QStyleOptionFrameV2 *>(opt)) {
1937  if (frame2->features & QStyleOptionFrameV2::Flat)
1938  extraClass |= PseudoClass_Flat;
1939  }
1940  }
1941 #ifndef QT_NO_TOOLBAR
1942  else if (const QStyleOptionToolBar *tb = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
1943  if (tb->toolBarArea == Qt::LeftToolBarArea)
1944  extraClass |= PseudoClass_Left;
1945  else if (tb->toolBarArea == Qt::RightToolBarArea)
1946  extraClass |= PseudoClass_Right;
1947  else if (tb->toolBarArea == Qt::TopToolBarArea)
1948  extraClass |= PseudoClass_Top;
1949  else if (tb->toolBarArea == Qt::BottomToolBarArea)
1950  extraClass |= PseudoClass_Bottom;
1951 
1952  if (tb->positionWithinLine == QStyleOptionToolBar::Beginning)
1953  extraClass |= PseudoClass_First;
1954  else if (tb->positionWithinLine == QStyleOptionToolBar::Middle)
1955  extraClass |= PseudoClass_Middle;
1956  else if (tb->positionWithinLine == QStyleOptionToolBar::End)
1957  extraClass |= PseudoClass_Last;
1958  else if (tb->positionWithinLine == QStyleOptionToolBar::OnlyOne)
1959  extraClass |= PseudoClass_OnlyOne;
1960  }
1961 #endif // QT_NO_TOOLBAR
1962 #ifndef QT_NO_TOOLBOX
1963  else if (const QStyleOptionToolBoxV2 *tab = qstyleoption_cast<const QStyleOptionToolBoxV2 *>(opt)) {
1964  if (tab->position == QStyleOptionToolBoxV2::OnlyOneTab)
1965  extraClass |= PseudoClass_OnlyOne;
1966  else if (tab->position == QStyleOptionToolBoxV2::Beginning)
1967  extraClass |= PseudoClass_First;
1968  else if (tab->position == QStyleOptionToolBoxV2::End)
1969  extraClass |= PseudoClass_Last;
1970  else if (tab->position == QStyleOptionToolBoxV2::Middle)
1971  extraClass |= PseudoClass_Middle;
1972 
1973  if (tab->selectedPosition == QStyleOptionToolBoxV2::NextIsSelected)
1974  extraClass |= PseudoClass_NextSelected;
1975  else if (tab->selectedPosition == QStyleOptionToolBoxV2::PreviousIsSelected)
1976  extraClass |= PseudoClass_PreviousSelected;
1977  }
1978 #endif // QT_NO_TOOLBOX
1979 #ifndef QT_NO_DOCKWIDGET
1980  else if (const QStyleOptionDockWidgetV2 *dw = qstyleoption_cast<const QStyleOptionDockWidgetV2 *>(opt)) {
1981  if (dw->verticalTitleBar)
1982  extraClass |= PseudoClass_Vertical;
1983  else
1984  extraClass |= PseudoClass_Horizontal;
1985  if (dw->closable)
1986  extraClass |= PseudoClass_Closable;
1987  if (dw->floatable)
1988  extraClass |= PseudoClass_Floatable;
1989  if (dw->movable)
1990  extraClass |= PseudoClass_Movable;
1991  }
1992 #endif // QT_NO_DOCKWIDGET
1993 #ifndef QT_NO_ITEMVIEWS
1994  else if (const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(opt)) {
1995  if (v2->features & QStyleOptionViewItemV2::Alternate)
1996  extraClass |= PseudoClass_Alternate;
1997  if (const QStyleOptionViewItemV4 *v4 = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) {
1998  if (v4->viewItemPosition == QStyleOptionViewItemV4::OnlyOne)
1999  extraClass |= PseudoClass_OnlyOne;
2000  else if (v4->viewItemPosition == QStyleOptionViewItemV4::Beginning)
2001  extraClass |= PseudoClass_First;
2002  else if (v4->viewItemPosition == QStyleOptionViewItemV4::End)
2003  extraClass |= PseudoClass_Last;
2004  else if (v4->viewItemPosition == QStyleOptionViewItemV4::Middle)
2005  extraClass |= PseudoClass_Middle;
2006  }
2007  }
2008 #endif
2009 #ifndef QT_NO_LINEEDIT
2010  // LineEdit sets Sunken flag to indicate Sunken frame (argh)
2011  if (const QLineEdit *lineEdit = qobject_cast<const QLineEdit *>(w)) {
2012  state &= ~QStyle::State_Sunken;
2013  if (lineEdit->hasFrame()) {
2014  extraClass &= ~PseudoClass_Frameless;
2015  } else {
2016  extraClass |= PseudoClass_Frameless;
2017  }
2018  } else
2019 #endif
2020  if (const QFrame *frm = qobject_cast<const QFrame *>(w)) {
2021  if (frm->lineWidth() == 0)
2022  extraClass |= PseudoClass_Frameless;
2023  }
2024  }
2025 
2026  return renderRule(w, pseudoElement, pseudoClass(state) | extraClass);
2027 }
2028 
2029 bool QStyleSheetStyle::hasStyleRule(const QWidget *w, int part) const
2030 {
2031  QHash<int, bool> &cache = styleSheetCaches->hasStyleRuleCache[w];
2032  QHash<int, bool>::const_iterator cacheIt = cache.constFind(part);
2033  if (cacheIt != cache.constEnd())
2034  return cacheIt.value();
2035 
2036  if (!initWidget(w))
2037  return false;
2038 
2039 
2040  const QVector<StyleRule> &rules = styleRules(w);
2041  if (part == PseudoElement_None) {
2042  bool result = w && !rules.isEmpty();
2043  cache[part] = result;
2044  return result;
2045  }
2046 
2047  QString pseudoElement = QLatin1String(knownPseudoElements[part].name);
2049  for (int i = 0; i < rules.count(); i++) {
2050  const Selector& selector = rules.at(i).selectors.at(0);
2051  if (pseudoElement.compare(selector.pseudoElement(), Qt::CaseInsensitive) == 0) {
2052  cache[part] = true;
2053  return true;
2054  }
2055  }
2056 
2057  cache[part] = false;
2058  return false;
2059 }
2060 
2061 static Origin defaultOrigin(int pe)
2062 {
2063  switch (pe) {
2071  case PseudoElement_GroupBoxIndicator: // never used
2075  return Origin_Border;
2076 
2085  return Origin_Padding;
2086 
2102  return Origin_Content;
2103 
2104  default:
2105  return Origin_Margin;
2106  }
2107 }
2108 
2109 static Qt::Alignment defaultPosition(int pe)
2110 {
2111  switch (pe) {
2117 
2124 
2132  return Qt::AlignRight | Qt::AlignTop;
2133 
2144  return Qt::AlignCenter;
2145 
2147  case PseudoElement_GroupBoxIndicator: // never used
2148  return Qt::AlignLeft | Qt::AlignTop;
2149 
2154 
2155  default:
2156  return 0;
2157  }
2158 }
2159 
2160 QSize QStyleSheetStyle::defaultSize(const QWidget *w, QSize sz, const QRect& rect, int pe) const
2161 {
2162  QStyle *base = baseStyle();
2163 
2164  switch (pe) {
2167  if (sz.width() == -1)
2168  sz.setWidth(base->pixelMetric(PM_IndicatorWidth, 0, w));
2169  if (sz.height() == -1)
2170  sz.setHeight(base->pixelMetric(PM_IndicatorHeight, 0, w));
2171  break;
2172 
2175  if (sz.width() == -1)
2176  sz.setWidth(base->pixelMetric(PM_ExclusiveIndicatorWidth, 0, w));
2177  if (sz.height() == -1)
2178  sz.setHeight(base->pixelMetric(PM_ExclusiveIndicatorHeight, 0, w));
2179  break;
2180 
2182  int pm = base->pixelMetric(PM_MenuButtonIndicator, 0, w);
2183  if (sz.width() == -1)
2184  sz.setWidth(pm);
2185  if (sz.height() == -1)
2186  sz.setHeight(pm);
2187  }
2188  break;
2189 
2191  if (sz.width() == -1)
2192  sz.setWidth(16);
2193  break;
2194 
2200  if (sz.width() == -1)
2201  sz.setWidth(13);
2202  if (sz.height() == -1)
2203  sz.setHeight(13);
2204  break;
2205 
2208  if (sz.width() == -1)
2209  sz.setWidth(16);
2210  if (sz.height() == -1)
2211  sz.setHeight(rect.height()/2);
2212  break;
2213 
2215  if (sz.width() == -1)
2216  sz.setWidth(base->pixelMetric(PM_MenuButtonIndicator, 0, w));
2217  break;
2218 
2221  int pm = base->pixelMetric(PM_HeaderMargin, 0, w);
2222  if (sz.width() == -1)
2223  sz.setWidth(pm);
2224  if (sz.height() == 1)
2225  sz.setHeight(pm);
2226  break;
2227  }
2228 
2234  int pm = pixelMetric(QStyle::PM_ScrollBarExtent, 0, w);
2235  if (sz.width() == -1)
2236  sz.setWidth(pm);
2237  if (sz.height() == -1)
2238  sz.setHeight(pm);
2239  break;
2240  }
2241 
2244  int iconSize = pixelMetric(PM_SmallIconSize, 0, w);
2245  return QSize(iconSize, iconSize);
2246  }
2247 
2248  default:
2249  break;
2250  }
2251 
2252  // expand to rectangle
2253  if (sz.height() == -1)
2254  sz.setHeight(rect.height());
2255  if (sz.width() == -1)
2256  sz.setWidth(rect.width());
2257 
2258  return sz;
2259 }
2260 
2262 {
2263  switch (pe) {
2274  return PositionMode_Absolute;
2275  default:
2276  return PositionMode_Static;
2277  }
2278 }
2279 
2281  const QRect &originRect, Qt::LayoutDirection dir) const
2282 {
2283  const QStyleSheetPositionData *p = rule2.position();
2284  PositionMode mode = (p && p->mode != PositionMode_Unknown) ? p->mode : defaultPositionMode(pe);
2285  Qt::Alignment position = (p && p->position != 0) ? p->position : defaultPosition(pe);
2286  QRect r;
2287 
2288  if (mode != PositionMode_Absolute) {
2289  QSize sz = defaultSize(w, rule2.size(), originRect, pe);
2290  sz = sz.expandedTo(rule2.minimumContentsSize());
2291  r = QStyle::alignedRect(dir, position, sz, originRect);
2292  if (p) {
2293  int left = p->left ? p->left : -p->right;
2294  int top = p->top ? p->top : -p->bottom;
2295  r.translate(dir == Qt::LeftToRight ? left : -left, top);
2296  }
2297  } else {
2298  r = p ? originRect.adjusted(dir == Qt::LeftToRight ? p->left : p->right, p->top,
2299  dir == Qt::LeftToRight ? -p->right : -p->left, -p->bottom)
2300  : originRect;
2301  if (rule2.hasContentsSize()) {
2302  QSize sz = rule2.size().expandedTo(rule2.minimumContentsSize());
2303  if (sz.width() == -1) sz.setWidth(r.width());
2304  if (sz.height() == -1) sz.setHeight(r.height());
2305  r = QStyle::alignedRect(dir, position, sz, r);
2306  }
2307  }
2308  return r;
2309 }
2310 
2311 QRect QStyleSheetStyle::positionRect(const QWidget *w, const QRenderRule& rule1, const QRenderRule& rule2, int pe,
2312  const QRect& rect, Qt::LayoutDirection dir) const
2313 {
2314  const QStyleSheetPositionData *p = rule2.position();
2315  Origin origin = (p && p->origin != Origin_Unknown) ? p->origin : defaultOrigin(pe);
2316  QRect originRect = rule1.originRect(rect, origin);
2317  return positionRect(w, rule2, pe, originRect, dir);
2318 }
2319 
2320 
2326 {
2327 #ifndef QT_NO_COMBOBOX
2328  if (QComboBox *cmb = qobject_cast<QComboBox *>(w)) {
2329  if (cmb->isEditable())
2330  return cmb->lineEdit();
2331  else
2332  return cmb;
2333  }
2334 #endif
2335 
2336 #ifndef QT_NO_SPINBOX
2337  if (QAbstractSpinBox *sb = qobject_cast<QAbstractSpinBox *>(w))
2338  return sb->findChild<QLineEdit *>();
2339 #endif
2340 
2341 #ifndef QT_NO_SCROLLAREA
2342  if (QAbstractScrollArea *sa = qobject_cast<QAbstractScrollArea *>(w))
2343  return sa->viewport();
2344 #endif
2345 
2346  return w;
2347 }
2348 
2357 {
2358 #ifndef QT_NO_LINEEDIT
2359  if (qobject_cast<const QLineEdit *>(w)) {
2360  //if the QLineEdit is an embeddedWidget, we need the rule of the real widget
2361 #ifndef QT_NO_COMBOBOX
2362  if (qobject_cast<const QComboBox *>(w->parentWidget()))
2363  return w->parentWidget();
2364 #endif
2365 #ifndef QT_NO_SPINBOX
2366  if (qobject_cast<const QAbstractSpinBox *>(w->parentWidget()))
2367  return w->parentWidget();
2368 #endif
2369  }
2370 #endif // QT_NO_LINEEDIT
2371 
2372 #ifndef QT_NO_SCROLLAREA
2373  if (const QAbstractScrollArea *sa = qobject_cast<const QAbstractScrollArea *>(w->parentWidget())) {
2374  if (sa->viewport() == w)
2375  return w->parentWidget();
2376  }
2377 #endif
2378 
2379  return const_cast<QWidget *>(w);
2380 }
2381 
2385 static bool unstylable(const QWidget *w)
2386 {
2387  if (w->windowType() == Qt::Desktop)
2388  return true;
2389 
2390  if (!w->styleSheet().isEmpty())
2391  return false;
2392 
2393  if (containerWidget(w) != w)
2394  return true;
2395 
2396 #ifndef QT_NO_FRAME
2397  // detect QComboBoxPrivateContainer
2398  else if (qobject_cast<const QFrame *>(w)) {
2399  if (0
2400 #ifndef QT_NO_COMBOBOX
2401  || qobject_cast<const QComboBox *>(w->parentWidget())
2402 #endif
2403  )
2404  return true;
2405  }
2406 #endif
2407  return false;
2408 }
2409 
2411 {
2412  quint64 pc = w->isWindow() ? quint64(PseudoClass_Window) : 0;
2413  if (const QAbstractSlider *slider = qobject_cast<const QAbstractSlider *>(w)) {
2414  pc |= ((slider->orientation() == Qt::Vertical) ? PseudoClass_Vertical : PseudoClass_Horizontal);
2415  } else
2416 #ifndef QT_NO_COMBOBOX
2417  if (const QComboBox *combo = qobject_cast<const QComboBox *>(w)) {
2418  if (combo->isEditable())
2419  pc |= (combo->isEditable() ? PseudoClass_Editable : PseudoClass_ReadOnly);
2420  } else
2421 #endif
2422 #ifndef QT_NO_LINEEDIT
2423  if (const QLineEdit *edit = qobject_cast<const QLineEdit *>(w)) {
2424  pc |= (edit->isReadOnly() ? PseudoClass_ReadOnly : PseudoClass_Editable);
2425  } else
2426 #endif
2427  { } // required for the above ifdef'ery to work
2428  return pc;
2429 }
2430 
2431 // sets up the geometry of the widget. We set a dynamic property when
2432 // we modify the min/max size of the widget. The min/max size is restored
2433 // to their original value when a new stylesheet that does not contain
2434 // the CSS properties is set and when the widget has this dynamic property set.
2435 // This way we don't trample on users who had setup a min/max size in code and
2436 // don't use stylesheets at all.
2438 {
2440  const QStyleSheetGeometryData *geo = rule.geometry();
2441  if (w->property("_q_stylesheet_minw").toBool()
2442  && ((!rule.hasGeometry() || geo->minWidth == -1))) {
2443  w->setMinimumWidth(0);
2444  w->setProperty("_q_stylesheet_minw", QVariant());
2445  }
2446  if (w->property("_q_stylesheet_minh").toBool()
2447  && ((!rule.hasGeometry() || geo->minHeight == -1))) {
2448  w->setMinimumHeight(0);
2449  w->setProperty("_q_stylesheet_minh", QVariant());
2450  }
2451  if (w->property("_q_stylesheet_maxw").toBool()
2452  && ((!rule.hasGeometry() || geo->maxWidth == -1))) {
2454  w->setProperty("_q_stylesheet_maxw", QVariant());
2455  }
2456  if (w->property("_q_stylesheet_maxh").toBool()
2457  && ((!rule.hasGeometry() || geo->maxHeight == -1))) {
2459  w->setProperty("_q_stylesheet_maxh", QVariant());
2460  }
2461 
2462 
2463  if (rule.hasGeometry()) {
2464  if (geo->minWidth != -1) {
2465  w->setProperty("_q_stylesheet_minw", true);
2466  w->setMinimumWidth(rule.boxSize(QSize(qMax(geo->width, geo->minWidth), 0)).width());
2467  }
2468  if (geo->minHeight != -1) {
2469  w->setProperty("_q_stylesheet_minh", true);
2470  w->setMinimumHeight(rule.boxSize(QSize(0, qMax(geo->height, geo->minHeight))).height());
2471  }
2472  if (geo->maxWidth != -1) {
2473  w->setProperty("_q_stylesheet_maxw", true);
2474  w->setMaximumWidth(rule.boxSize(QSize(qMin(geo->width == -1 ? QWIDGETSIZE_MAX : geo->width,
2475  geo->maxWidth == -1 ? QWIDGETSIZE_MAX : geo->maxWidth), 0)).width());
2476  }
2477  if (geo->maxHeight != -1) {
2478  w->setProperty("_q_stylesheet_maxh", true);
2479  w->setMaximumHeight(rule.boxSize(QSize(0, qMin(geo->height == -1 ? QWIDGETSIZE_MAX : geo->height,
2480  geo->maxHeight == -1 ? QWIDGETSIZE_MAX : geo->maxHeight))).height());
2481  }
2482  }
2483 }
2484 
2486 {
2487  QHash<QString, QVariant> propertyHash;
2488  QVector<Declaration> decls = declarations(styleRules(w), QString());
2489 
2490  // run through the declarations in order
2491  for (int i = 0; i < decls.count(); i++) {
2492  const Declaration &decl = decls.at(i);
2493  QString property = decl.d->property;
2494  if (!property.startsWith(QLatin1String("qproperty-"), Qt::CaseInsensitive))
2495  continue;
2496  property.remove(0, 10); // strip "qproperty-"
2497  const QVariant value = w->property(property.toLatin1());
2498  const QMetaObject *metaObject = w->metaObject();
2499  int index = metaObject->indexOfProperty(property.toLatin1());
2500  if (index == -1) {
2501  qWarning() << w << " does not have a property named " << property;
2502  continue;
2503  }
2504  QMetaProperty metaProperty = metaObject->property(index);
2505  if (!metaProperty.isWritable() || !metaProperty.isDesignable()) {
2506  qWarning() << w << " cannot design property named " << property;
2507  continue;
2508  }
2509  QVariant v;
2510  switch (value.type()) {
2511  case QVariant::Icon: v = decl.iconValue(); break;
2512  case QVariant::Image: v = QImage(decl.uriValue()); break;
2513  case QVariant::Pixmap: v = QPixmap(decl.uriValue()); break;
2514  case QVariant::Rect: v = decl.rectValue(); break;
2515  case QVariant::Size: v = decl.sizeValue(); break;
2516  case QVariant::Color: v = decl.colorValue(); break;
2517  case QVariant::Brush: v = decl.brushValue(); break;
2518 #ifndef QT_NO_SHORTCUT
2519  case QVariant::KeySequence: v = QKeySequence(decl.d->values.at(0).variant.toString()); break;
2520 #endif
2521  default: v = decl.d->values.at(0).variant; break;
2522  }
2523  propertyHash[property] = v;
2524  }
2525  // apply the values
2526  const QList<QString> properties = propertyHash.keys();
2527  for (int i = 0; i < properties.count(); i++) {
2528  const QString &property = properties.at(i);
2529  w->setProperty(property.toLatin1(), propertyHash[property]);
2530  }
2531 }
2532 
2534 {
2535  struct RuleRoleMap {
2536  int state;
2537  QPalette::ColorGroup group;
2538  } map[3] = {
2542  };
2543 
2544  QPalette p = w->palette();
2545  QWidget *ew = embeddedWidget(w);
2546 
2547  for (int i = 0; i < 3; i++) {
2548  QRenderRule rule = renderRule(w, PseudoElement_None, map[i].state | extendedPseudoClass(w));
2549  if (i == 0) {
2550  if (!w->property("_q_styleSheetWidgetFont").isValid()) {
2551  saveWidgetFont(w, w->font());
2552  }
2553  updateStyleSheetFont(w);
2554  if (ew != w)
2555  updateStyleSheetFont(ew);
2556  }
2557 
2558  rule.configurePalette(&p, map[i].group, ew, ew != w);
2559  }
2560 
2561  styleSheetCaches->customPaletteWidgets.insert(w, w->palette());
2562  w->setPalette(p);
2563  if (ew != w)
2564  ew->setPalette(p);
2565 }
2566 
2568 {
2569  if (styleSheetCaches->customPaletteWidgets.contains(w)) {
2570  QPalette p = styleSheetCaches->customPaletteWidgets.value(w);
2571  w->setPalette(p);
2572  QWidget *ew = embeddedWidget(w);
2573  if (ew != w)
2574  ew->setPalette(p);
2575  styleSheetCaches->customPaletteWidgets.remove(w);
2576  }
2577  QVariant oldFont = w->property("_q_styleSheetWidgetFont");
2578  if (oldFont.isValid()) {
2579  w->setFont(qvariant_cast<QFont>(oldFont));
2580  }
2581  if (styleSheetCaches->autoFillDisabledWidgets.contains(w)) {
2583  styleSheetCaches->autoFillDisabledWidgets.remove(w);
2584  }
2585 }
2586 
2587 static void updateWidgets(const QList<const QWidget *>& widgets)
2588 {
2589  if (!styleSheetCaches->styleRulesCache.isEmpty() || !styleSheetCaches->hasStyleRuleCache.isEmpty() || !styleSheetCaches->renderRulesCache.isEmpty()) {
2590  for (int i = 0; i < widgets.size(); ++i) {
2591  const QWidget *widget = widgets.at(i);
2592  styleSheetCaches->styleRulesCache.remove(widget);
2593  styleSheetCaches->hasStyleRuleCache.remove(widget);
2594  styleSheetCaches->renderRulesCache.remove(widget);
2595  }
2596  }
2597  for (int i = 0; i < widgets.size(); ++i) {
2598  QWidget *widget = const_cast<QWidget *>(widgets.at(i));
2599  if (widget == 0)
2600  continue;
2601  widget->style()->polish(widget);
2603  QApplication::sendEvent(widget, &event);
2604  widget->update();
2605  widget->updateGeometry();
2606  }
2607 }
2608 
2610 // The stylesheet style
2612 
2614  : QWindowsStyle(*new QStyleSheetStylePrivate), base(base), refcount(1)
2615 {
2616  ++numinstances;
2617  if (numinstances == 1) {
2618  styleSheetCaches = new QStyleSheetStyleCaches;
2619  }
2620 }
2621 
2623 {
2624  --numinstances;
2625  if (numinstances == 0) {
2626  delete styleSheetCaches;
2627  }
2628 }
2630 {
2631  if (base)
2632  return base;
2633  if (QStyleSheetStyle *me = qobject_cast<QStyleSheetStyle *>(QApplication::style()))
2634  return me->base;
2635  return QApplication::style();
2636 }
2637 
2639 {
2640  styleRulesCache.remove((const QWidget *)o);
2641  hasStyleRuleCache.remove((const QWidget *)o);
2642  renderRulesCache.remove((const QWidget *)o);
2643  customPaletteWidgets.remove((const QWidget *)o);
2644  styleSheetCache.remove((const QWidget *)o);
2645  autoFillDisabledWidgets.remove((const QWidget *)o);
2646 }
2647 
2649 {
2650  styleSheetCache.remove(o);
2651 }
2652 
2658 {
2659  if (!w)
2660  return false;
2662  return true;
2663 
2664  if(unstylable(w))
2665  return false;
2666 
2667  const_cast<QWidget *>(w)->setAttribute(Qt::WA_StyleSheet, true);
2668  QObject::connect(w, SIGNAL(destroyed(QObject*)), styleSheetCaches, SLOT(widgetDestroyed(QObject*)), Qt::UniqueConnection);
2669  return true;
2670 }
2671 
2673 {
2674  baseStyle()->polish(w);
2675  RECURSION_GUARD(return)
2676 
2677  if (!initWidget(w))
2678  return;
2679 
2680  if (styleSheetCaches->styleRulesCache.contains(w)) {
2681  // the widget accessed its style pointer before polish (or repolish)
2682  // (exemple: the QAbstractSpinBox constructor ask for the stylehint)
2683  styleSheetCaches->styleRulesCache.remove(w);
2684  styleSheetCaches->hasStyleRuleCache.remove(w);
2685  styleSheetCaches->renderRulesCache.remove(w);
2686  }
2687  setGeometry(w);
2688  setProperties(w);
2689  unsetPalette(w);
2690  setPalette(w);
2691 
2692  //set the WA_Hover attribute if one of the selector depends of the hover state
2693  QVector<StyleRule> rules = styleRules(w);
2694  for (int i = 0; i < rules.count(); i++) {
2695  const Selector& selector = rules.at(i).selectors.at(0);
2696  quint64 negated = 0;
2697  quint64 cssClass = selector.pseudoClass(&negated);
2698  if ( cssClass & PseudoClass_Hover || negated & PseudoClass_Hover) {
2701  }
2702  }
2703 
2704 
2705 #ifndef QT_NO_SCROLLAREA
2706  if (QAbstractScrollArea *sa = qobject_cast<QAbstractScrollArea *>(w)) {
2708  if ((rule.hasBorder() && rule.border()->hasBorderImage())
2709  || (rule.hasBackground() && !rule.background()->pixmap.isNull())) {
2710  QObject::connect(sa->horizontalScrollBar(), SIGNAL(valueChanged(int)),
2711  sa, SLOT(update()), Qt::UniqueConnection);
2712  QObject::connect(sa->verticalScrollBar(), SIGNAL(valueChanged(int)),
2713  sa, SLOT(update()), Qt::UniqueConnection);
2714  }
2715  }
2716 #endif
2717 
2718 #ifndef QT_NO_PROGRESSBAR
2719  if (QProgressBar *pb = qobject_cast<QProgressBar *>(w)) {
2721  }
2722 #endif
2723 
2725  if (rule.hasDrawable() || rule.hasBox()) {
2727 #ifndef QT_NO_ITEMVIEWS
2728  || qobject_cast<QHeaderView *>(w)
2729 #endif
2730 #ifndef QT_NO_TABBAR
2731  || qobject_cast<QTabBar *>(w)
2732 #endif
2733 #ifndef QT_NO_FRAME
2734  || qobject_cast<QFrame *>(w)
2735 #endif
2736 #ifndef QT_NO_MAINWINDOW
2737  || qobject_cast<QMainWindow *>(w)
2738 #endif
2739 #ifndef QT_NO_MDIAREA
2740  || qobject_cast<QMdiSubWindow *>(w)
2741 #endif
2742 #ifndef QT_NO_MENUBAR
2743  || qobject_cast<QMenuBar *>(w)
2744 #endif
2745  || qobject_cast<QDialog *>(w)) {
2747  }
2748  QWidget *ew = embeddedWidget(w);
2749  if (ew->autoFillBackground()) {
2750  ew->setAutoFillBackground(false);
2751  styleSheetCaches->autoFillDisabledWidgets.insert(w);
2752  if (ew != w) { //eg. viewport of a scrollarea
2753  //(in order to draw the background anyway in case we don't.)
2755  }
2756  }
2757  if (!rule.hasBackground() || rule.background()->isTransparent() || rule.hasBox()
2758  || (!rule.hasNativeBorder() && !rule.border()->isOpaque()))
2760  }
2761 }
2762 
2764 {
2765  baseStyle()->polish(app);
2766 }
2767 
2769 {
2770  baseStyle()->polish(pal);
2771 }
2772 
2774 {
2776  children.append(w);
2777  styleSheetCaches->styleSheetCache.remove(w);
2778  updateWidgets(children);
2779 }
2780 
2782 {
2783  Q_UNUSED(app);
2784  const QList<const QWidget*> allWidgets = styleSheetCaches->styleRulesCache.keys();
2785  styleSheetCaches->styleSheetCache.remove(qApp);
2786  styleSheetCaches->styleRulesCache.clear();
2787  styleSheetCaches->hasStyleRuleCache.clear();
2788  styleSheetCaches->renderRulesCache.clear();
2789  updateWidgets(allWidgets);
2790 }
2791 
2793 {
2794  if (!w || !w->testAttribute(Qt::WA_StyleSheet)) {
2795  baseStyle()->unpolish(w);
2796  return;
2797  }
2798 
2799  styleSheetCaches->styleRulesCache.remove(w);
2800  styleSheetCaches->hasStyleRuleCache.remove(w);
2801  styleSheetCaches->renderRulesCache.remove(w);
2802  styleSheetCaches->styleSheetCache.remove(w);
2803  unsetPalette(w);
2804  w->setProperty("_q_stylesheet_minw", QVariant());
2805  w->setProperty("_q_stylesheet_minh", QVariant());
2806  w->setProperty("_q_stylesheet_maxw", QVariant());
2807  w->setProperty("_q_stylesheet_maxh", QVariant());
2808  w->setAttribute(Qt::WA_StyleSheet, false);
2809  QObject::disconnect(w, 0, this, 0);
2810 #ifndef QT_NO_SCROLLAREA
2811  if (QAbstractScrollArea *sa = qobject_cast<QAbstractScrollArea *>(w)) {
2812  QObject::disconnect(sa->horizontalScrollBar(), SIGNAL(valueChanged(int)),
2813  sa, SLOT(update()));
2814  QObject::disconnect(sa->verticalScrollBar(), SIGNAL(valueChanged(int)),
2815  sa, SLOT(update()));
2816  }
2817 #endif
2818 #ifndef QT_NO_PROGRESSBAR
2819  if (QProgressBar *pb = qobject_cast<QProgressBar *>(w))
2821 #endif
2822  baseStyle()->unpolish(w);
2823 }
2824 
2826 {
2827  baseStyle()->unpolish(app);
2828  RECURSION_GUARD(return)
2829  styleSheetCaches->styleRulesCache.clear();
2830  styleSheetCaches->hasStyleRuleCache.clear();
2831  styleSheetCaches->renderRulesCache.clear();
2832  styleSheetCaches->styleSheetCache.remove(qApp);
2833 }
2834 
2835 #ifndef QT_NO_TABBAR
2836 inline static bool verticalTabs(QTabBar::Shape shape)
2837 {
2838  return shape == QTabBar::RoundedWest
2839  || shape == QTabBar::RoundedEast
2840  || shape == QTabBar::TriangularWest
2841  || shape == QTabBar::TriangularEast;
2842 }
2843 #endif // QT_NO_TABBAR
2844 
2846  const QWidget *w) const
2847 {
2848  RECURSION_GUARD(baseStyle()->drawComplexControl(cc, opt, p, w); return)
2849 
2850  QRenderRule rule = renderRule(w, opt);
2851 
2852  switch (cc) {
2853  case CC_ComboBox:
2854  if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2855  QStyleOptionComboBox cmbOpt(*cmb);
2856  cmbOpt.rect = rule.borderRect(opt->rect);
2857  if (rule.hasNativeBorder()) {
2858  rule.drawBackgroundImage(p, cmbOpt.rect);
2859  rule.configurePalette(&cmbOpt.palette, QPalette::ButtonText, QPalette::Button);
2860  bool customDropDown = (opt->subControls & QStyle::SC_ComboBoxArrow)
2862  if (customDropDown)
2864  if (rule.baseStyleCanDraw()) {
2865  baseStyle()->drawComplexControl(cc, &cmbOpt, p, w);
2866  } else {
2867  QWindowsStyle::drawComplexControl(cc, &cmbOpt, p, w);
2868  }
2869  if (!customDropDown)
2870  return;
2871  } else {
2872  rule.drawRule(p, opt->rect);
2873  }
2874 
2877  if (subRule.hasDrawable()) {
2879  subRule.drawRule(p, r);
2881  r = positionRect(w, subRule, subRule2, PseudoElement_ComboBoxArrow, r, opt->direction);
2882  subRule2.drawRule(p, r);
2883  } else {
2885  QWindowsStyle::drawComplexControl(cc, &cmbOpt, p, w);
2886  }
2887  }
2888 
2889  return;
2890  }
2891  break;
2892 
2893 #ifndef QT_NO_SPINBOX
2894  case CC_SpinBox:
2895  if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
2896  QStyleOptionSpinBox spinOpt(*spin);
2897  rule.configurePalette(&spinOpt.palette, QPalette::ButtonText, QPalette::Button);
2898  rule.configurePalette(&spinOpt.palette, QPalette::Text, QPalette::Base);
2899  spinOpt.rect = rule.borderRect(opt->rect);
2900  bool customUp = true, customDown = true;
2903  bool upRuleMatch = upRule.hasGeometry() || upRule.hasPosition();
2904  bool downRuleMatch = downRule.hasGeometry() || downRule.hasPosition();
2905  if (rule.hasNativeBorder() && !upRuleMatch && !downRuleMatch) {
2906  rule.drawBackgroundImage(p, spinOpt.rect);
2907  customUp = (opt->subControls & QStyle::SC_SpinBoxUp)
2909  if (customUp)
2911  customDown = (opt->subControls & QStyle::SC_SpinBoxDown)
2913  if (customDown)
2915  if (rule.baseStyleCanDraw()) {
2916  baseStyle()->drawComplexControl(cc, &spinOpt, p, w);
2917  } else {
2918  QWindowsStyle::drawComplexControl(cc, &spinOpt, p, w);
2919  }
2920  if (!customUp && !customDown)
2921  return;
2922  } else {
2923  rule.drawRule(p, opt->rect);
2924  }
2925 
2926  if ((opt->subControls & QStyle::SC_SpinBoxUp) && customUp) {
2928  if (subRule.hasDrawable()) {
2930  subRule.drawRule(p, r);
2932  r = positionRect(w, subRule, subRule2, PseudoElement_SpinBoxUpArrow, r, opt->direction);
2933  subRule2.drawRule(p, r);
2934  } else {
2936  QWindowsStyle::drawComplexControl(cc, &spinOpt, p, w);
2937  }
2938  }
2939 
2940  if ((opt->subControls & QStyle::SC_SpinBoxDown) && customDown) {
2942  if (subRule.hasDrawable()) {
2944  subRule.drawRule(p, r);
2946  r = positionRect(w, subRule, subRule2, PseudoElement_SpinBoxDownArrow, r, opt->direction);
2947  subRule2.drawRule(p, r);
2948  } else {
2950  QWindowsStyle::drawComplexControl(cc, &spinOpt, p, w);
2951  }
2952  }
2953  return;
2954  }
2955  break;
2956 #endif // QT_NO_SPINBOX
2957 
2958  case CC_GroupBox:
2959  if (const QStyleOptionGroupBox *gb = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
2960 
2961  QRect labelRect, checkBoxRect, titleRect, frameRect;
2962  bool hasTitle = (gb->subControls & QStyle::SC_GroupBoxCheckBox) || !gb->text.isEmpty();
2963 
2964  if (!rule.hasDrawable() && (!hasTitle || !hasStyleRule(w, PseudoElement_GroupBoxTitle))
2965  && !hasStyleRule(w, PseudoElement_Indicator) && !rule.hasBox() && !rule.hasFont && !rule.hasPalette()) {
2966  // let the native style draw the combobox if there is no style for it.
2967  break;
2968  }
2969  rule.drawBackground(p, opt->rect);
2970 
2971  QRenderRule titleRule = renderRule(w, opt, PseudoElement_GroupBoxTitle);
2972  bool clipSet = false;
2973 
2974  if (hasTitle) {
2975  labelRect = subControlRect(CC_GroupBox, opt, SC_GroupBoxLabel, w);
2976  //Some native style (such as mac) may return a too small rectangle (because they use smaller fonts), so we may need to expand it a little bit.
2977  labelRect.setSize(labelRect.size().expandedTo(ParentStyle::subControlRect(CC_GroupBox, opt, SC_GroupBoxLabel, w).size()));
2978  if (gb->subControls & QStyle::SC_GroupBoxCheckBox) {
2979  checkBoxRect = subControlRect(CC_GroupBox, opt, SC_GroupBoxCheckBox, w);
2980  titleRect = titleRule.boxRect(checkBoxRect.united(labelRect));
2981  } else {
2982  titleRect = titleRule.boxRect(labelRect);
2983  }
2984  if (!titleRule.hasBackground() || !titleRule.background()->isTransparent()) {
2985  clipSet = true;
2986  p->save();
2987  p->setClipRegion(QRegion(opt->rect) - titleRect);
2988  }
2989  }
2990 
2991  frameRect = subControlRect(CC_GroupBox, opt, SC_GroupBoxFrame, w);
2992  QStyleOptionFrameV2 frame;
2993  frame.QStyleOption::operator=(*gb);
2994  frame.features = gb->features;
2995  frame.lineWidth = gb->lineWidth;
2996  frame.midLineWidth = gb->midLineWidth;
2997  frame.rect = frameRect;
2998  drawPrimitive(PE_FrameGroupBox, &frame, p, w);
2999 
3000  if (clipSet)
3001  p->restore();
3002 
3003  // draw background and frame of the title
3004  if (hasTitle)
3005  titleRule.drawRule(p, titleRect);
3006 
3007  // draw the indicator
3008  if (gb->subControls & QStyle::SC_GroupBoxCheckBox) {
3009  QStyleOptionButton box;
3010  box.QStyleOption::operator=(*gb);
3011  box.rect = checkBoxRect;
3012  drawPrimitive(PE_IndicatorCheckBox, &box, p, w);
3013  }
3014 
3015  // draw the text
3016  if (!gb->text.isEmpty()) {
3017  int alignment = int(Qt::AlignCenter | Qt::TextShowMnemonic);
3018  if (!styleHint(QStyle::SH_UnderlineShortcut, opt, w)) {
3019  alignment |= Qt::TextHideMnemonic;
3020  }
3021 
3022  QPalette pal = gb->palette;
3023  if (gb->textColor.isValid())
3024  pal.setColor(QPalette::WindowText, gb->textColor);
3026  drawItemText(p, labelRect, alignment, pal, gb->state & State_Enabled,
3027  gb->text, QPalette::WindowText);
3028 
3029  if (gb->state & State_HasFocus) {
3030  QStyleOptionFocusRect fropt;
3031  fropt.QStyleOption::operator=(*gb);
3032  fropt.rect = labelRect;
3033  drawPrimitive(PE_FrameFocusRect, &fropt, p, w);
3034  }
3035  }
3036 
3037  return;
3038  }
3039  break;
3040 
3041  case CC_ToolButton:
3042  if (const QStyleOptionToolButton *tool = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
3043  QStyleOptionToolButton toolOpt(*tool);
3044  rule.configurePalette(&toolOpt.palette, QPalette::ButtonText, QPalette::Button);
3045  toolOpt.font = rule.font.resolve(toolOpt.font);
3046  toolOpt.rect = rule.borderRect(opt->rect);
3047  bool customArrow = (tool->features & (QStyleOptionToolButton::HasMenu | QStyleOptionToolButton::MenuButtonPopup));
3048  bool customDropDown = tool->features & QStyleOptionToolButton::MenuButtonPopup;
3049  if (rule.hasNativeBorder()) {
3050  if (tool->subControls & SC_ToolButton) {
3051  //in some case (eg. the button is "auto raised") the style doesn't draw the background
3052  //so we need to draw the background.
3053  // use the same condition as in QCommonStyle
3054  State bflags = tool->state & ~State_Sunken;
3055  if (bflags & State_AutoRaise && (!(bflags & State_MouseOver) || !(bflags & State_Enabled)))
3056  bflags &= ~State_Raised;
3057  if (tool->state & State_Sunken && tool->activeSubControls & SC_ToolButton)
3058  bflags |= State_Sunken;
3059  if (!(bflags & (State_Sunken | State_On | State_Raised)))
3060  rule.drawBackground(p, toolOpt.rect);
3061  }
3062  customArrow = customArrow && hasStyleRule(w, PseudoElement_ToolButtonDownArrow);
3063  if (customArrow)
3064  toolOpt.features &= ~QStyleOptionToolButton::HasMenu;
3065  customDropDown = customDropDown && hasStyleRule(w, PseudoElement_ToolButtonMenu);
3066  if (customDropDown)
3068 
3069  if (rule.baseStyleCanDraw() && !(tool->features & QStyleOptionToolButton::Arrow)) {
3070  baseStyle()->drawComplexControl(cc, &toolOpt, p, w);
3071  } else {
3072  QWindowsStyle::drawComplexControl(cc, &toolOpt, p, w);
3073  }
3074 
3075  if (!customArrow && !customDropDown)
3076  return;
3077  } else {
3078  rule.drawRule(p, opt->rect);
3079  toolOpt.rect = rule.contentsRect(opt->rect);
3080  if (rule.hasFont)
3081  toolOpt.font = rule.font;
3082  drawControl(CE_ToolButtonLabel, &toolOpt, p, w);
3083  }
3084 
3087  if (customDropDown) {
3089  if (subRule.hasDrawable()) {
3090  subRule.drawRule(p, r);
3091  } else {
3092  toolOpt.rect = r;
3094  }
3095  }
3096  }
3097 
3098  if (customArrow) {
3099  QRenderRule subRule2 = customDropDown ? renderRule(w, opt, PseudoElement_ToolButtonMenuArrow)
3101  QRect r2 = customDropDown
3102  ? positionRect(w, subRule, subRule2, PseudoElement_ToolButtonMenuArrow, r, opt->direction)
3103  : positionRect(w, rule, subRule2, PseudoElement_ToolButtonDownArrow, opt->rect, opt->direction);
3104  if (subRule2.hasDrawable()) {
3105  subRule2.drawRule(p, r2);
3106  } else {
3107  toolOpt.rect = r2;
3109  }
3110  }
3111 
3112  return;
3113  }
3114  break;
3115 
3116 #ifndef QT_NO_SCROLLBAR
3117  case CC_ScrollBar:
3118  if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
3119  QStyleOptionSlider sbOpt(*sb);
3120  if (!rule.hasDrawable()) {
3121  sbOpt.rect = rule.borderRect(opt->rect);
3122  rule.drawBackgroundImage(p, opt->rect);
3123  baseStyle()->drawComplexControl(cc, &sbOpt, p, w);
3124  } else {
3125  rule.drawRule(p, opt->rect);
3126  QWindowsStyle::drawComplexControl(cc, opt, p, w);
3127  }
3128  return;
3129  }
3130  break;
3131 #endif // QT_NO_SCROLLBAR
3132 
3133 #ifndef QT_NO_SLIDER
3134  case CC_Slider:
3135  if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
3136  rule.drawRule(p, opt->rect);
3137 
3138  QRenderRule grooveSubRule = renderRule(w, opt, PseudoElement_SliderGroove);
3139  QRenderRule handleSubRule = renderRule(w, opt, PseudoElement_SliderHandle);
3140  if (!grooveSubRule.hasDrawable()) {
3141  QStyleOptionSlider slOpt(*slider);
3142  bool handleHasRule = handleSubRule.hasDrawable();
3143  // If the style specifies a different handler rule, draw the groove without the handler.
3144  if (handleHasRule)
3145  slOpt.subControls &= ~SC_SliderHandle;
3146  baseStyle()->drawComplexControl(cc, &slOpt, p, w);
3147  if (!handleHasRule)
3148  return;
3149  }
3150 
3151  QRect gr = subControlRect(cc, opt, SC_SliderGroove, w);
3152  if (slider->subControls & SC_SliderGroove) {
3153  grooveSubRule.drawRule(p, gr);
3154  }
3155 
3156  if (slider->subControls & SC_SliderHandle) {
3157  QRect hr = subControlRect(cc, opt, SC_SliderHandle, w);
3158 
3160  if (subRule1.hasDrawable()) {
3161  QRect r(gr.topLeft(),
3162  slider->orientation == Qt::Horizontal
3163  ? QPoint(hr.x()+hr.width()/2, gr.y()+gr.height() - 1)
3164  : QPoint(gr.x()+gr.width() - 1, hr.y()+hr.height()/2));
3165  subRule1.drawRule(p, r);
3166  }
3167 
3169  if (subRule2.hasDrawable()) {
3170  QRect r(slider->orientation == Qt::Horizontal
3171  ? QPoint(hr.x()+hr.width()/2+1, gr.y())
3172  : QPoint(gr.x(), hr.y()+hr.height()/2+1),
3173  gr.bottomRight());
3174  subRule2.drawRule(p, r);
3175  }
3176 
3177  handleSubRule.drawRule(p, handleSubRule.boxRect(hr, Margin));
3178  }
3179 
3180  if (slider->subControls & SC_SliderTickmarks) {
3181  // TODO...
3182  }
3183 
3184  return;
3185  }
3186  break;
3187 #endif // QT_NO_SLIDER
3188 
3189  case CC_MdiControls:
3193  QList<QVariant> layout = rule.styleHint(QLatin1String("button-layout")).toList();
3194  if (layout.isEmpty())
3195  layout = subControlLayout(QLatin1String("mNX"));
3196 
3197  QStyleOptionComplex optCopy(*opt);
3198  optCopy.subControls = 0;
3199  for (int i = 0; i < layout.count(); i++) {
3200  int layoutButton = layout[i].toInt();
3201  if (layoutButton < PseudoElement_MdiCloseButton
3202  || layoutButton > PseudoElement_MdiNormalButton)
3203  continue;
3204  QStyle::SubControl control = knownPseudoElements[layoutButton].subControl;
3205  if (!(opt->subControls & control))
3206  continue;
3207  QRenderRule subRule = renderRule(w, opt, layoutButton);
3208  if (subRule.hasDrawable()) {
3209  QRect rect = subRule.boxRect(subControlRect(CC_MdiControls, opt, control, w), Margin);
3210  subRule.drawRule(p, rect);
3211  QIcon icon = standardIcon(subControlIcon(layoutButton), opt);
3212  icon.paint(p, subRule.contentsRect(rect), Qt::AlignCenter);
3213  } else {
3214  optCopy.subControls |= control;
3215  }
3216  }
3217 
3218  if (optCopy.subControls)
3219  baseStyle()->drawComplexControl(CC_MdiControls, &optCopy, p, w);
3220  return;
3221  }
3222  break;
3223 
3224  case CC_TitleBar:
3225  if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
3226  QRenderRule subRule = renderRule(w, opt, PseudoElement_TitleBar);
3227  if (!subRule.hasDrawable() && !subRule.hasBox() && !subRule.hasBorder())
3228  break;
3229  subRule.drawRule(p, opt->rect);
3231 
3232  QRect ir;
3233  ir = layout[SC_TitleBarLabel];
3234  if (ir.isValid()) {
3235  if (subRule.hasPalette())
3236  p->setPen(subRule.palette()->foreground.color());
3237  p->fillRect(ir, Qt::white);
3238  p->drawText(ir.x(), ir.y(), ir.width(), ir.height(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3239  }
3240 
3241  QPixmap pm;
3242 
3243  ir = layout[SC_TitleBarSysMenu];
3244  if (ir.isValid()) {
3246  subSubRule.drawRule(p, ir);
3247  ir = subSubRule.contentsRect(ir);
3248  if (!tb->icon.isNull()) {
3249  tb->icon.paint(p, ir);
3250  } else {
3251  int iconSize = pixelMetric(PM_SmallIconSize, tb, w);
3252  pm = standardIcon(SP_TitleBarMenuButton, 0, w).pixmap(iconSize, iconSize);
3253  drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3254  }
3255  }
3256 
3257  ir = layout[SC_TitleBarCloseButton];
3258  if (ir.isValid()) {
3260  subSubRule.drawRule(p, ir);
3261 
3262  QSize sz = subSubRule.contentsRect(ir).size();
3263  if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool)
3265  else
3266  pm = standardIcon(SP_TitleBarCloseButton, 0, w).pixmap(sz);
3267  drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3268  }
3269 
3270  int pes[] = {
3277  };
3278 
3279  for (unsigned int i = 0; i < sizeof(pes)/sizeof(int); i++) {
3280  int pe = pes[i];
3281  QStyle::SubControl sc = knownPseudoElements[pe].subControl;
3282  ir = layout[sc];
3283  if (!ir.isValid())
3284  continue;
3285  QRenderRule subSubRule = renderRule(w, opt, pe);
3286  subSubRule.drawRule(p, ir);
3287  pm = standardIcon(subControlIcon(pe), 0, w).pixmap(subSubRule.contentsRect(ir).size());
3288  drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3289  }
3290 
3291  return;
3292  }
3293  break;
3294 
3295 
3296  default:
3297  break;
3298  }
3299 
3300  baseStyle()->drawComplexControl(cc, opt, p, w);
3301 }
3302 
3304  const QWidget *w) const
3305 {
3306  RECURSION_GUARD(baseStyle()->drawControl(ce, opt, p, w); return)
3307 
3308  QRenderRule rule = renderRule(w, opt);
3309  int pe1 = PseudoElement_None, pe2 = PseudoElement_None;
3310  bool fallback = false;
3311 
3312  switch (ce) {
3313  case CE_ToolButtonLabel:
3314  if (const QStyleOptionToolButton *btn = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
3315  if (rule.hasBox() || btn->features & QStyleOptionToolButton::Arrow) {
3316  QCommonStyle::drawControl(ce, opt, p, w);
3317  } else {
3318  QStyleOptionToolButton butOpt(*btn);
3319  rule.configurePalette(&butOpt.palette, QPalette::ButtonText, QPalette::Button);
3320  baseStyle()->drawControl(ce, &butOpt, p, w);
3321  }
3322  return;
3323  }
3324  break;
3325 
3326  case CE_FocusFrame:
3327  if (!rule.hasNativeBorder()) {
3328  rule.drawBorder(p, opt->rect);
3329  return;
3330  }
3331  break;
3332 
3333  case CE_PushButton:
3334  if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
3335  if (rule.hasDrawable() || rule.hasBox() || rule.hasPosition() || rule.hasPalette() ||
3337  ParentStyle::drawControl(ce, opt, p, w);
3338  return;
3339  }
3340  }
3341  break;
3342  case CE_PushButtonBevel:
3343  if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
3344  QStyleOptionButton btnOpt(*btn);
3345  btnOpt.rect = rule.borderRect(opt->rect);
3346  if (rule.hasNativeBorder()) {
3347  rule.drawBackgroundImage(p, btnOpt.rect);
3348  rule.configurePalette(&btnOpt.palette, QPalette::ButtonText, QPalette::Button);
3349  bool customMenu = (btn->features & QStyleOptionButton::HasMenu
3351  if (customMenu)
3352  btnOpt.features &= ~QStyleOptionButton::HasMenu;
3353  if (rule.baseStyleCanDraw()) {
3354  baseStyle()->drawControl(ce, &btnOpt, p, w);
3355  } else {
3356  QWindowsStyle::drawControl(ce, &btnOpt, p, w);
3357  }
3358  if (!customMenu)
3359  return;
3360  } else {
3361  rule.drawRule(p, opt->rect);
3362  }
3363 
3364  if (btn->features & QStyleOptionButton::HasMenu) {
3366  QRect ir = positionRect(w, rule, subRule, PseudoElement_PushButtonMenuIndicator, opt->rect, opt->direction);
3367  if (subRule.hasDrawable()) {
3368  subRule.drawRule(p, ir);
3369  } else {
3370  btnOpt.rect = ir;
3371  baseStyle()->drawPrimitive(PE_IndicatorArrowDown, &btnOpt, p, w);
3372  }
3373  }
3374  }
3375  return;
3376 
3377  case CE_PushButtonLabel:
3378  if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
3379  QStyleOptionButton butOpt(*button);
3380  rule.configurePalette(&butOpt.palette, QPalette::ButtonText, QPalette::Button);
3381 
3382  const QFont oldFont = p->font();
3383  if (rule.hasFont)
3384  p->setFont(rule.font);
3385 
3386  if (rule.hasPosition() && rule.position()->textAlignment != 0) {
3387  Qt::Alignment textAlignment = rule.position()->textAlignment;
3388  QRect textRect = button->rect;
3390  const uint verticalAlignMask = Qt::AlignVCenter | Qt::AlignTop | Qt::AlignLeft;
3391  tf |= (textAlignment & verticalAlignMask) ? (textAlignment & verticalAlignMask) : Qt::AlignVCenter;
3392  if (!styleHint(SH_UnderlineShortcut, button, w))
3393  tf |= Qt::TextHideMnemonic;
3394  if (!button->icon.isNull()) {
3395  //Group both icon and text
3396  QRect iconRect;
3397  QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
3398  if (mode == QIcon::Normal && button->state & State_HasFocus)
3399  mode = QIcon::Active;
3400  QIcon::State state = QIcon::Off;
3401  if (button->state & State_On)
3402  state = QIcon::On;
3403 
3404  QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
3405  int labelWidth = pixmap.width();
3406  int labelHeight = pixmap.height();
3407  int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint()
3408  int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();
3409  if (!button->text.isEmpty())
3410  labelWidth += (textWidth + iconSpacing);
3411 
3412  //Determine label alignment:
3413  if (textAlignment & Qt::AlignLeft) { /*left*/
3414  iconRect = QRect(textRect.x(), textRect.y() + (textRect.height() - labelHeight) / 2,
3415  pixmap.width(), pixmap.height());
3416  } else if (textAlignment & Qt::AlignHCenter) { /* center */
3417  iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
3418  textRect.y() + (textRect.height() - labelHeight) / 2,
3419  pixmap.width(), pixmap.height());
3420  } else { /*right*/
3421  iconRect = QRect(textRect.x() + textRect.width() - labelWidth,
3422  textRect.y() + (textRect.height() - labelHeight) / 2,
3423  pixmap.width(), pixmap.height());
3424  }
3425 
3426  iconRect = visualRect(button->direction, textRect, iconRect);
3427 
3428  tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead
3429 
3430  if (button->direction == Qt::RightToLeft)
3431  textRect.setRight(iconRect.left() - iconSpacing);
3432  else
3433  textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing);
3434 
3435  if (button->state & (State_On | State_Sunken))
3438  p->drawPixmap(iconRect, pixmap);
3439  } else {
3440  tf |= textAlignment;
3441  }
3442  if (button->state & (State_On | State_Sunken))
3445 
3446  if (button->features & QStyleOptionButton::HasMenu) {
3447  int indicatorSize = pixelMetric(PM_MenuButtonIndicator, button, w);
3448  if (button->direction == Qt::LeftToRight)
3449  textRect = textRect.adjusted(0, 0, -indicatorSize, 0);
3450  else
3451  textRect = textRect.adjusted(indicatorSize, 0, 0, 0);
3452  }
3453  drawItemText(p, textRect, tf, butOpt.palette, (button->state & State_Enabled),
3454  button->text, QPalette::ButtonText);
3455  } else {
3456  ParentStyle::drawControl(ce, &butOpt, p, w);
3457  }
3458 
3459  if (rule.hasFont)
3460  p->setFont(oldFont);
3461  }
3462  return;
3463 
3464  case CE_RadioButton:
3465  case CE_CheckBox:
3466  if (rule.hasBox() || !rule.hasNativeBorder() || rule.hasDrawable() || hasStyleRule(w, PseudoElement_Indicator)) {
3467  rule.drawRule(p, opt->rect);
3468  ParentStyle::drawControl(ce, opt, p, w);
3469  return;
3470  } else if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
3471  QStyleOptionButton butOpt(*btn);
3472  rule.configurePalette(&butOpt.palette, QPalette::ButtonText, QPalette::Button);
3473  baseStyle()->drawControl(ce, &butOpt, p, w);
3474  return;
3475  }
3476  break;
3477  case CE_RadioButtonLabel:
3478  case CE_CheckBoxLabel:
3479  if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
3480  QStyleOptionButton butOpt(*btn);
3481  rule.configurePalette(&butOpt.palette, QPalette::ButtonText, QPalette::Button);
3482  ParentStyle::drawControl(ce, &butOpt, p, w);
3483  }
3484  return;
3485 
3486  case CE_Splitter:
3488  break;
3489 
3490  case CE_ToolBar:
3491  if (rule.hasBackground()) {
3492  rule.drawBackground(p, opt->rect);
3493  }
3494  if (rule.hasBorder()) {
3495  rule.drawBorder(p, rule.borderRect(opt->rect));
3496  } else {
3497 #ifndef QT_NO_TOOLBAR
3498  if (const QStyleOptionToolBar *tb = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
3499  QStyleOptionToolBar newTb(*tb);
3500  newTb.rect = rule.borderRect(opt->rect);
3501  baseStyle()->drawControl(ce, &newTb, p, w);
3502  }
3503 #endif // QT_NO_TOOLBAR
3504  }
3505  return;
3506 
3507  case CE_MenuEmptyArea:
3508  case CE_MenuBarEmptyArea:
3509  if (rule.hasDrawable()) {
3510  // Drawn by PE_Widget
3511  return;
3512  }
3513  break;
3514 
3515  case CE_MenuTearoff:
3516  case CE_MenuScroller:
3517  if (const QStyleOptionMenuItem *m = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
3518  QStyleOptionMenuItem mi(*m);
3520  QRenderRule subRule = renderRule(w, opt, pe);
3521  mi.rect = subRule.contentsRect(opt->rect);
3522  rule.configurePalette(&mi.palette, QPalette::ButtonText, QPalette::Button);
3524 
3525  if (subRule.hasDrawable()) {
3526  subRule.drawRule(p, opt->rect);
3527  } else {
3528  baseStyle()->drawControl(ce, &mi, p, w);
3529  }
3530  }
3531  return;
3532 
3533  case CE_MenuItem:
3534  if (const QStyleOptionMenuItem *m = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
3535  QStyleOptionMenuItem mi(*m);
3536 
3538  QRenderRule subRule = renderRule(w, opt, pseudo);
3539  mi.rect = subRule.contentsRect(opt->rect);
3540  rule.configurePalette(&mi.palette, QPalette::ButtonText, QPalette::Button);
3541  rule.configurePalette(&mi.palette, QPalette::HighlightedText, QPalette::Highlight);
3544  QFont oldFont = p->font();
3545  if (subRule.hasFont)
3546  p->setFont(subRule.font.resolve(p->font()));
3547 
3548  // We fall back to drawing with the style sheet code whenever at least one of the
3549  // items are styled in an incompatible way, such as having a background image.
3551 
3552  if ((pseudo == PseudoElement_MenuSeparator) && subRule.hasDrawable()) {
3553  subRule.drawRule(p, opt->rect);
3554  } else if ((pseudo == PseudoElement_Item)
3555  && (allRules.hasBox() || allRules.hasBorder()
3556  || (allRules.background() && !allRules.background()->pixmap.isNull()))) {
3557  subRule.drawRule(p, opt->rect);
3558  if (subRule.hasBackground()) {
3561  } else {
3563  }
3565 
3566  bool checkable = mi.checkType != QStyleOptionMenuItem::NotCheckable;
3567  bool checked = checkable ? mi.checked : false;
3568 
3569  bool dis = !(opt->state & QStyle::State_Enabled),
3570  act = opt->state & QStyle::State_Selected;
3571 
3572  if (!mi.icon.isNull()) {
3573  QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
3574  if (act && !dis)
3575  mode = QIcon::Active;
3576  QPixmap pixmap;
3577  if (checked)
3578  pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
3579  else
3580  pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
3581  int pixw = pixmap.width();
3582  int pixh = pixmap.height();
3583  QRenderRule iconRule = renderRule(w, opt, PseudoElement_MenuIcon);
3584  if (!iconRule.hasGeometry()) {
3585  iconRule.geo = new QStyleSheetGeometryData(pixw, pixh, pixw, pixh, -1, -1);
3586  } else {
3587  iconRule.geo->width = pixw;
3588  iconRule.geo->height = pixh;
3589  }
3590  QRect iconRect = positionRect(w, subRule, iconRule, PseudoElement_MenuIcon, opt->rect, opt->direction);
3591  iconRule.drawRule(p, iconRect);
3592  QRect pmr(0, 0, pixw, pixh);
3593  pmr.moveCenter(iconRect.center());
3594  p->drawPixmap(pmr.topLeft(), pixmap);
3595  } else if (checkable) {
3596  QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark);
3597  if (subSubRule.hasDrawable() || checked) {
3598  QStyleOptionMenuItem newMi = mi;
3599  newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction);
3601  }
3602  }
3603 
3604  QRect textRect = subRule.contentsRect(opt->rect);
3605  textRect.setWidth(textRect.width() - mi.tabWidth);
3606  QString s = mi.text;
3607  p->setPen(mi.palette.buttonText().color());
3608  if (!s.isEmpty()) {
3610  if (!styleHint(SH_UnderlineShortcut, &mi, w))
3611  text_flags |= Qt::TextHideMnemonic;
3612  int t = s.indexOf(QLatin1Char('\t'));
3613  if (t >= 0) {
3614  QRect vShortcutRect = visualRect(opt->direction, mi.rect,
3615  QRect(textRect.topRight(), QPoint(mi.rect.right(), textRect.bottom())));
3616  p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
3617  s = s.left(t);
3618  }
3619  p->drawText(textRect, text_flags, s.left(t));
3620  }
3621 
3622  if (mi.menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
3625  mi.rect = positionRect(w, subRule, subRule2, PseudoElement_MenuRightArrow, opt->rect, mi.direction);
3626  drawPrimitive(arrow, &mi, p, w);
3627  }
3629  QWindowsStyle::drawControl(ce, &mi, p, w);
3631  // We have a style defined, but QWindowsStyle won't draw anything if not checked.
3632  // So we mimick what QWindowsStyle would do.
3633  int checkcol = qMax<int>(mi.maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
3634  QRect vCheckRect = visualRect(opt->direction, mi.rect, QRect(mi.rect.x(), mi.rect.y(), checkcol, mi.rect.height()));
3635  if (mi.state.testFlag(State_Enabled) && mi.state.testFlag(State_Selected)) {
3636  qDrawShadePanel(p, vCheckRect, mi.palette, true, 1, &mi.palette.brush(QPalette::Button));
3637  } else {
3638  QBrush fill(mi.palette.light().color(), Qt::Dense4Pattern);
3639  qDrawShadePanel(p, vCheckRect, mi.palette, true, 1, &fill);
3640  }
3641  QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark);
3642  if (subSubRule.hasDrawable()) {
3643  QStyleOptionMenuItem newMi(mi);
3649  }
3650  }
3651  } else {
3652  if (rule.hasDrawable() && !subRule.hasDrawable() && !(opt->state & QStyle::State_Selected)) {
3655  }
3656  if (rule.baseStyleCanDraw() && subRule.baseStyleCanDraw()) {
3657  baseStyle()->drawControl(ce, &mi, p, w);
3658  } else {
3659  ParentStyle::drawControl(ce, &mi, p, w);
3660  }
3661  }
3662 
3663  if (subRule.hasFont)
3664  p->setFont(oldFont);
3665 
3666  return;
3667  }
3668  return;
3669 
3670  case CE_MenuBarItem:
3671  if (const QStyleOptionMenuItem *m = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
3672  QStyleOptionMenuItem mi(*m);
3673  QRenderRule subRule = renderRule(w, opt, PseudoElement_Item);
3674  mi.rect = subRule.contentsRect(opt->rect);
3675  rule.configurePalette(&mi.palette, QPalette::ButtonText, QPalette::Button);
3677 
3678  if (subRule.hasDrawable()) {
3679  subRule.drawRule(p, opt->rect);
3680  QCommonStyle::drawControl(ce, &mi, p, w);
3681  } else {
3682  if (rule.hasDrawable() && !(opt->state & QStyle::State_Selected)) {
3683  // So that the menu bar background is not hidden by the items
3686  }
3687  baseStyle()->drawControl(ce, &mi, p, w);
3688  }
3689  }
3690  return;
3691 
3692 #ifndef QT_NO_COMBOBOX
3693  case CE_ComboBoxLabel:
3694  if (!rule.hasBox())
3695  break;
3696  if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
3698  p->save();
3699  p->setClipRect(editRect);
3700  if (!cb->currentIcon.isNull()) {
3701  int spacing = rule.hasBox() ? rule.box()->spacing : -1;
3702  if (spacing == -1)
3703  spacing = 6;
3704  QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
3705  QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode);
3706  QRect iconRect(editRect);
3707  iconRect.setWidth(cb->iconSize.width());
3708  iconRect = alignedRect(cb->direction,
3710  iconRect.size(), editRect);
3711  drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
3712 
3713  if (cb->direction == Qt::RightToLeft)
3714  editRect.translate(-spacing - cb->iconSize.width(), 0);
3715  else
3716  editRect.translate(cb->iconSize.width() + spacing, 0);
3717  }
3718  if (!cb->currentText.isEmpty() && !cb->editable) {
3719  QPalette styledPalette(cb->palette);
3720  rule.configurePalette(&styledPalette, QPalette::Text, QPalette::Base);
3721  drawItemText(p, editRect.adjusted(0, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, styledPalette,
3722  cb->state & State_Enabled, cb->currentText, QPalette::Text);
3723  }
3724  p->restore();
3725  return;
3726  }
3727  break;
3728 #endif // QT_NO_COMBOBOX
3729 
3730  case CE_Header:
3733  ParentStyle::drawControl(ce, opt, p, w);
3734  return;
3735  }
3738  if (!subRule.hasNativeBorder() || !subRule.baseStyleCanDraw()
3739  || subRule.hasBackground() || subRule.hasPalette()) {
3740  ParentStyle::drawControl(ce, opt, p, w);
3741  return;
3742  }
3743  }
3744  break;
3745  case CE_HeaderSection:
3746  if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
3748  if (subRule.hasNativeBorder()) {
3749  QStyleOptionHeader hdr(*header);
3751 
3752  if (subRule.baseStyleCanDraw()) {
3753  baseStyle()->drawControl(CE_HeaderSection, &hdr, p, w);
3754  } else {
3756  }
3757  } else {
3758  subRule.drawRule(p, opt->rect);
3759  }
3760  return;
3761  }
3762  break;
3763 
3764  case CE_HeaderLabel:
3765  if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
3766  QStyleOptionHeader hdr(*header);
3769  QFont oldFont = p->font();
3770  if (subRule.hasFont)
3771  p->setFont(subRule.font.resolve(p->font()));
3772  baseStyle()->drawControl(ce, &hdr, p, w);
3773  if (subRule.hasFont)
3774  p->setFont(oldFont);
3775  return;
3776  }
3777  break;
3778 
3779  case CE_HeaderEmptyArea:
3780  if (rule.hasDrawable()) {
3781  return;
3782  }
3783  break;
3784 
3785  case CE_ProgressBar:
3786  QWindowsStyle::drawControl(ce, opt, p, w);
3787  return;
3788 
3789  case CE_ProgressBarGroove:
3790  if (!rule.hasNativeBorder()) {
3791  rule.drawRule(p, rule.boxRect(opt->rect, Margin));
3792  return;
3793  }
3794  break;
3795 
3796  case CE_ProgressBarContents: {
3798  if (subRule.hasDrawable()) {
3799  if (const QStyleOptionProgressBarV2 *pb = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
3800  p->save();
3801  p->setClipRect(pb->rect);
3802 
3803  qint64 minimum = qint64(pb->minimum);
3804  qint64 maximum = qint64(pb->maximum);
3805  qint64 progress = qint64(pb->progress);
3806  bool vertical = (pb->orientation == Qt::Vertical);
3807  bool inverted = pb->invertedAppearance;
3808 
3809  QTransform m;
3810  QRect rect = pb->rect;
3811  if (vertical) {
3812  rect = QRect(rect.y(), rect.x(), rect.height(), rect.width());
3813  m.rotate(90);
3814  m.translate(0, -(rect.height() + rect.y()*2));
3815  }
3816 
3817  bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
3818  if (inverted)
3819  reverse = !reverse;
3820  const bool indeterminate = pb->minimum == pb->maximum;
3821  qreal fillRatio = indeterminate ? qreal(0.50) : qreal(progress - minimum)/(maximum - minimum);
3822  int fillWidth = int(rect.width() * fillRatio);
3823  int chunkWidth = fillWidth;
3824  if (subRule.hasContentsSize()) {
3825  QSize sz = subRule.size();
3826  chunkWidth = (opt->state & QStyle::State_Horizontal) ? sz.width() : sz.height();
3827  }
3828 
3829  QRect r = rect;
3830  if (pb->minimum == 0 && pb->maximum == 0) {
3831  Q_D(const QWindowsStyle);
3832  int chunkCount = fillWidth/chunkWidth;
3833  int offset = (d->animateStep*8%rect.width());
3834  int x = reverse ? r.left() + r.width() - offset - chunkWidth : r.x() + offset;
3835  while (chunkCount > 0) {
3836  r.setRect(x, rect.y(), chunkWidth, rect.height());
3837  r = m.mapRect(QRectF(r)).toRect();
3838  subRule.drawRule(p, r);
3839  x += reverse ? -chunkWidth : chunkWidth;
3840  if (reverse ? x < rect.left() : x > rect.right())
3841  break;
3842  --chunkCount;
3843  }
3844 
3845  r = rect;
3846  x = reverse ? r.right() - (r.left() - x - chunkWidth)
3847  : r.left() + (x - r.right() - chunkWidth);
3848  while (chunkCount > 0) {
3849  r.setRect(x, rect.y(), chunkWidth, rect.height());
3850  r = m.mapRect(QRectF(r)).toRect();
3851  subRule.drawRule(p, r);
3852  x += reverse ? -chunkWidth : chunkWidth;
3853  --chunkCount;
3854  };
3855  } else {
3856  int x = reverse ? r.left() + r.width() - chunkWidth : r.x();
3857 
3858  for (int i = 0; i < ceil(qreal(fillWidth)/chunkWidth); ++i) {
3859  r.setRect(x, rect.y(), chunkWidth, rect.height());
3860  r = m.mapRect(QRectF(r)).toRect();
3861  subRule.drawRule(p, r);
3862  x += reverse ? -chunkWidth : chunkWidth;
3863  }
3864  }
3865 
3866  p->restore();
3867  return;
3868  }
3869  }
3870  }
3871  break;
3872 
3873  case CE_ProgressBarLabel:
3874  if (const QStyleOptionProgressBarV2 *pb = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
3875  if (rule.hasBox() || rule.hasBorder() || hasStyleRule(w, PseudoElement_ProgressBarChunk)) {
3876  drawItemText(p, pb->rect, pb->textAlignment | Qt::TextSingleLine, pb->palette,
3877  pb->state & State_Enabled, pb->text, QPalette::Text);
3878  } else {
3879  QStyleOptionProgressBarV2 pbCopy(*pb);
3880  rule.configurePalette(&pbCopy.palette, QPalette::HighlightedText, QPalette::Highlight);
3881  baseStyle()->drawControl(ce, &pbCopy, p, w);
3882  }
3883  return;
3884  }
3885  break;
3886 
3887  case CE_SizeGrip:
3888  if (const QStyleOptionSizeGrip *sgOpt = qstyleoption_cast<const QStyleOptionSizeGrip *>(opt)) {
3889  if (rule.hasDrawable()) {
3890  rule.drawFrame(p, opt->rect);
3891  p->save();
3892  switch (sgOpt->corner) {
3893  case Qt::BottomRightCorner: break;
3894  case Qt::BottomLeftCorner: p->rotate(90); break;
3895  case Qt::TopLeftCorner: p->rotate(180); break;
3896  case Qt::TopRightCorner: p->rotate(270); break;
3897  default: break;
3898  }
3899  rule.drawImage(p, opt->rect);
3900  p->restore();
3901  } else {
3902  QStyleOptionSizeGrip sg(*sgOpt);
3903  sg.rect = rule.contentsRect(opt->rect);
3904  baseStyle()->drawControl(CE_SizeGrip, &sg, p, w);
3905  }
3906  return;
3907  }
3908  break;
3909 
3910  case CE_ToolBoxTab:
3911  QWindowsStyle::drawControl(ce, opt, p, w);
3912  return;
3913 
3914  case CE_ToolBoxTabShape: {
3915  QRenderRule subRule = renderRule(w, opt, PseudoElement_ToolBoxTab);
3916  if (subRule.hasDrawable()) {
3917  subRule.drawRule(p, opt->rect);
3918  return;
3919  }
3920  }
3921  break;
3922 
3923  case CE_ToolBoxTabLabel:
3924  if (const QStyleOptionToolBox *box = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {
3925  QStyleOptionToolBox boxCopy(*box);
3926  QRenderRule subRule = renderRule(w, opt, PseudoElement_ToolBoxTab);
3928  QFont oldFont = p->font();
3929  if (subRule.hasFont)
3930  p->setFont(subRule.font);
3931  boxCopy.rect = subRule.contentsRect(opt->rect);
3932  QWindowsStyle::drawControl(ce, &boxCopy, p , w);
3933  if (subRule.hasFont)
3934  p->setFont(oldFont);
3935  return;
3936  }
3937  break;
3938 
3939  case CE_ScrollBarAddPage:
3941  break;
3942 
3943  case CE_ScrollBarSubPage:
3945  break;
3946 
3947  case CE_ScrollBarAddLine:
3950  fallback = true;
3951  break;
3952 
3953  case CE_ScrollBarSubLine:
3956  fallback = true;
3957  break;
3958 
3959  case CE_ScrollBarFirst:
3961  break;
3962 
3963  case CE_ScrollBarLast:
3965  break;
3966 
3967  case CE_ScrollBarSlider:
3969  fallback = true;
3970  break;
3971 
3972 #ifndef QT_NO_ITEMVIEWS
3973  case CE_ItemViewItem:
3974  if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) {
3975  QRenderRule subRule = renderRule(w, opt, PseudoElement_ViewItem);
3976  if (subRule.hasDrawable() || hasStyleRule(w, PseudoElement_Indicator)) {
3977  QStyleOptionViewItemV4 optCopy(*vopt);
3980  QWindowsStyle::drawControl(ce, &optCopy, p, w);
3981  } else {
3982  QStyleOptionViewItemV4 voptCopy(*vopt);
3984  baseStyle()->drawControl(ce, &voptCopy, p, w);
3985  }
3986  return;
3987  }
3988  break;
3989 #endif // QT_NO_ITEMVIEWS
3990 
3991 #ifndef QT_NO_TABBAR
3992  case CE_TabBarTab:
3994  QWindowsStyle::drawControl(ce, opt, p, w);
3995  return;
3996  }
3997  break;
3998 
3999  case CE_TabBarTabLabel:
4000  case CE_TabBarTabShape:
4001  if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
4002  QStyleOptionTabV3 tabCopy(*tab);
4003  QRenderRule subRule = renderRule(w, opt, PseudoElement_TabBarTab);
4004  QRect r = positionRect(w, subRule, PseudoElement_TabBarTab, opt->rect, opt->direction);
4005  if (ce == CE_TabBarTabShape && subRule.hasDrawable()) {
4006  subRule.drawRule(p, r);
4007  return;
4008  }
4010  QFont oldFont = p->font();
4011  if (subRule.hasFont)
4012  p->setFont(subRule.font);
4013  if (subRule.hasBox() || !subRule.hasNativeBorder()) {
4014  tabCopy.rect = ce == CE_TabBarTabShape ? subRule.borderRect(r)
4015  : subRule.contentsRect(r);
4016  QWindowsStyle::drawControl(ce, &tabCopy, p, w);
4017  } else {
4018  baseStyle()->drawControl(ce, &tabCopy, p, w);
4019  }
4020  if (subRule.hasFont)
4021  p->setFont(oldFont);
4022 
4023  return;
4024  }
4025  break;
4026 #endif // QT_NO_TABBAR
4027 
4028  case CE_ColumnViewGrip:
4029  if (rule.hasDrawable()) {
4030  rule.drawRule(p, opt->rect);
4031  return;
4032  }
4033  break;
4034 
4035  case CE_DockWidgetTitle:
4036  if (const QStyleOptionDockWidgetV2 *dwOpt = qstyleoption_cast<const QStyleOptionDockWidgetV2 *>(opt)) {
4038  if (!subRule.hasDrawable() && !subRule.hasPosition())
4039  break;
4040  if (subRule.hasDrawable()) {
4041  subRule.drawRule(p, opt->rect);
4042  } else {
4043  QStyleOptionDockWidgetV2 dwCopy(*dwOpt);
4044  dwCopy.title = QString();
4045  baseStyle()->drawControl(ce, &dwCopy, p, w);
4046  }
4047 
4048  if (!dwOpt->title.isEmpty()) {
4049  QRect r = opt->rect;
4050  if (dwOpt->verticalTitleBar) {
4051  QSize s = r.size();
4052  s.transpose();
4053  r.setSize(s);
4054 
4055  p->save();
4056  p->translate(r.left(), r.top() + r.width());
4057  p->rotate(-90);
4058  p->translate(-r.left(), -r.top());
4059  }
4060 
4061  Qt::Alignment alignment = 0;
4062  if (subRule.hasPosition())
4063  alignment = subRule.position()->textAlignment;
4064  if (alignment == 0)
4065  alignment = Qt::AlignLeft;
4066  drawItemText(p, subRule.contentsRect(opt->rect),
4067  alignment | Qt::TextShowMnemonic, dwOpt->palette,
4068  dwOpt->state & State_Enabled, dwOpt->title,
4070 
4071  if (dwOpt->verticalTitleBar)
4072  p->restore();
4073  }
4074 
4075  return;
4076  }
4077  break;
4078  case CE_ShapedFrame:
4079  if (const QStyleOptionFrame *frm = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
4080  if (rule.hasNativeBorder()) {
4081  QStyleOptionFrameV3 frmOpt(*frm);
4082  rule.configurePalette(&frmOpt.palette, QPalette::Text, QPalette::Base);
4083  frmOpt.rect = rule.borderRect(frmOpt.rect);
4084  baseStyle()->drawControl(ce, &frmOpt, p, w);
4085  }
4086  // else, borders are already drawn in PE_Widget
4087  }
4088  return;
4089 
4090 
4091  default:
4092  break;
4093  }
4094 
4095  if (pe1 != PseudoElement_None) {
4096  QRenderRule subRule = renderRule(w, opt, pe1);
4097  if (subRule.bg != 0 || subRule.hasDrawable()) {
4098  //We test subRule.bg directly because hasBackground() would return false for background:none.
4099  //But we still don't want the default drawning in that case (example for QScrollBar::add-page) (task 198926)
4100  subRule.drawRule(p, opt->rect);
4101  } else if (fallback) {
4102  QWindowsStyle::drawControl(ce, opt, p, w);
4103  pe2 = PseudoElement_None;
4104  } else {
4105  baseStyle()->drawControl(ce, opt, p, w);
4106  }
4107  if (pe2 != PseudoElement_None) {
4108  QRenderRule subSubRule = renderRule(w, opt, pe2);
4109  QRect r = positionRect(w, subRule, subSubRule, pe2, opt->rect, opt->direction);
4110  subSubRule.drawRule(p, r);
4111  }
4112  return;
4113  }
4114 
4115  baseStyle()->drawControl(ce, opt, p, w);
4116 }
4117 
4118 void QStyleSheetStyle::drawItemPixmap(QPainter *p, const QRect &rect, int alignment, const
4119  QPixmap &pixmap) const
4120 {
4121  baseStyle()->drawItemPixmap(p, rect, alignment, pixmap);
4122 }
4123 
4124 void QStyleSheetStyle::drawItemText(QPainter *painter, const QRect& rect, int alignment, const QPalette &pal,
4125  bool enabled, const QString& text, QPalette::ColorRole textRole) const
4126 {
4127  baseStyle()->drawItemText(painter, rect, alignment, pal, enabled, text, textRole);
4128 }
4129 
4131  const QWidget *w) const
4132 {
4133  RECURSION_GUARD(baseStyle()->drawPrimitive(pe, opt, p, w); return)
4134 
4135  int pseudoElement = PseudoElement_None;
4136  QRenderRule rule = renderRule(w, opt);
4137  QRect rect = opt->rect;
4138 
4139  switch (pe) {
4140 
4141  case PE_FrameStatusBar: {
4142  QRenderRule subRule = renderRule(w->parentWidget(), opt, PseudoElement_Item);
4143  if (subRule.hasDrawable()) {
4144  subRule.drawRule(p, opt->rect);
4145  return;
4146  }
4147  break;
4148  }
4149 
4150  case PE_IndicatorArrowDown:
4151  pseudoElement = PseudoElement_DownArrow;
4152  break;
4153 
4154  case PE_IndicatorArrowUp:
4155  pseudoElement = PseudoElement_UpArrow;
4156  break;
4157 
4159  pseudoElement = PseudoElement_ExclusiveIndicator;
4160  break;
4161 
4163  pseudoElement = PseudoElement_ViewItemIndicator;
4164  break;
4165 
4166  case PE_IndicatorCheckBox:
4167  pseudoElement = PseudoElement_Indicator;
4168  break;
4169 
4171  if (const QStyleOptionHeader *hdr = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
4172  pseudoElement = hdr->sortIndicator == QStyleOptionHeader::SortUp
4175  }
4176  break;
4177 
4178  case PE_PanelButtonTool:
4179  case PE_PanelButtonCommand:
4180  if (qobject_cast<const QAbstractButton *>(w) && rule.hasBackground() && rule.hasNativeBorder()) {
4181  //the window style will draw the borders
4182  ParentStyle::drawPrimitive(pe, opt, p, w);
4183  if (!rule.background()->pixmap.isNull() || rule.hasImage()) {
4184  rule.drawRule(p, rule.boxRect(opt->rect, QRenderRule::Margin).adjusted(1,1,-1,-1));
4185  }
4186  return;
4187  }
4188  if (!rule.hasNativeBorder()) {
4189  rule.drawRule(p, rule.boxRect(opt->rect, QRenderRule::Margin));
4190  return;
4191  }
4192  break;
4193 
4196  if (!subRule.hasNativeBorder()) {
4197  rule.drawBorder(p, opt->rect);
4198  return;
4199  }
4200  break;
4201  }
4202 
4203  case PE_FrameDefaultButton:
4204  if (rule.hasNativeBorder()) {
4205  if (rule.baseStyleCanDraw())
4206  break;
4207  QWindowsStyle::drawPrimitive(pe, opt, p, w);
4208  }
4209  return;
4210 
4211  case PE_FrameWindow:
4212  case PE_FrameDockWidget:
4213  case PE_Frame:
4214  if (const QStyleOptionFrame *frm = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
4215  if (rule.hasNativeBorder()) {
4216  QStyleOptionFrameV2 frmOpt(*frm);
4217  rule.configurePalette(&frmOpt.palette, QPalette::Text, QPalette::Base);
4218  if (!qstyleoption_cast<const QStyleOptionFrameV3 *>(opt)) //if it comes from CE_ShapedFrame, the margins are already sustracted
4219  frmOpt.rect = rule.borderRect(frmOpt.rect);
4220  baseStyle()->drawPrimitive(pe, &frmOpt, p, w);
4221  } else {
4222  rule.drawBorder(p, rule.borderRect(opt->rect));
4223  }
4224  }
4225  return;
4226 
4227  case PE_PanelLineEdit:
4228  if (const QStyleOptionFrame *frm = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
4229 #ifndef QT_NO_SPINBOX
4230  if (w && qobject_cast<const QAbstractSpinBox *>(w->parentWidget())) {
4231  QRenderRule spinboxRule = renderRule(w->parentWidget(), opt);
4232  if (!spinboxRule.hasNativeBorder() || !spinboxRule.baseStyleCanDraw())
4233  return;
4234  rule = spinboxRule;
4235  }
4236 #endif
4237  if (rule.hasNativeBorder()) {
4238  QStyleOptionFrame frmOpt(*frm);
4239  rule.configurePalette(&frmOpt.palette, QPalette::Text, QPalette::Base);
4240  frmOpt.rect = rule.borderRect(frmOpt.rect);
4241  if (rule.baseStyleCanDraw()) {
4242  rule.drawBackgroundImage(p, opt->rect);
4243  baseStyle()->drawPrimitive(pe, &frmOpt, p, w);
4244  } else {
4245  rule.drawBackground(p, opt->rect);
4246  if (frmOpt.lineWidth > 0)
4247  baseStyle()->drawPrimitive(PE_FrameLineEdit, &frmOpt, p, w);
4248  }
4249  } else {
4250  rule.drawRule(p, opt->rect);
4251  }
4252  }
4253  return;
4254 
4255  case PE_Widget:
4256  if (w && !rule.hasDrawable()) {
4257  QWidget *container = containerWidget(w);
4258  if (styleSheetCaches->autoFillDisabledWidgets.contains(container)
4259  && (container == w || !renderRule(container, opt).hasBackground())) {
4260  //we do not have a background, but we disabled the autofillbackground anyway. so fill the background now.
4261  // (this may happen if we have rules like :focus)
4262  p->fillRect(opt->rect, opt->palette.brush(w->backgroundRole()));
4263  }
4264  break;
4265  }
4266 #ifndef QT_NO_SCROLLAREA
4267  if (const QAbstractScrollArea *sa = qobject_cast<const QAbstractScrollArea *>(w)) {
4268  const QAbstractScrollAreaPrivate *sap = sa->d_func();
4269  rule.drawBackground(p, opt->rect, sap->contentsOffset());
4270  if (rule.hasBorder()) {
4271  QRect brect = rule.borderRect(opt->rect);
4273  QRect r = brect.adjusted(0, 0, sa->verticalScrollBar()->isVisible() ? -sa->verticalScrollBar()->width() : 0,
4274  sa->horizontalScrollBar()->isVisible() ? -sa->horizontalScrollBar()->height() : 0);
4275  brect = QStyle::visualRect(opt->direction, brect, r);
4276  }
4277  rule.drawBorder(p, brect);
4278  }
4279  break;
4280  }
4281 #endif
4282  //fall tghought
4283  case PE_PanelMenu:
4284  case PE_PanelStatusBar:
4285  if(rule.hasDrawable()) {
4286  rule.drawRule(p, opt->rect);
4287  return;
4288  }
4289  break;
4290 
4291  case PE_FrameMenu:
4292  if (rule.hasDrawable()) {
4293  // Drawn by PE_PanelMenu
4294  return;
4295  }
4296  break;
4297 
4298  case PE_PanelMenuBar:
4299  if (rule.hasDrawable()) {
4300  // Drawn by PE_Widget
4301  return;
4302  }
4303  break;
4304 
4308  QRenderRule subRule = renderRule(w, opt, ps);
4309  if (subRule.hasDrawable()) {
4310  subRule.drawRule(p, opt->rect);
4311  return;
4312  }
4313  }
4314  break;
4315 
4317  pseudoElement = PseudoElement_MenuCheckMark;
4318  break;
4319 
4320  case PE_IndicatorArrowLeft:
4321  pseudoElement = PseudoElement_LeftArrow;
4322  break;
4323 
4325  pseudoElement = PseudoElement_RightArrow;
4326  break;
4327 
4329  if (const QStyleOptionViewItem *viewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
4330  bool reverse = (viewOpt->direction == Qt::RightToLeft);
4331  pseudoElement = reverse ? PseudoElement_LeftArrow : PseudoElement_RightArrow;
4332  } else {
4333  pseudoElement = PseudoElement_RightArrow;
4334  }
4335  break;
4336 
4337  case PE_IndicatorBranch:
4338  if (const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(opt)) {
4340  if (subRule.hasDrawable()) {
4341  if ((v2->state & QStyle::State_Selected) && v2->showDecorationSelected)
4342  p->fillRect(v2->rect, v2->palette.highlight());
4343  else if (v2->features & QStyleOptionViewItemV2::Alternate)
4344  p->fillRect(v2->rect, v2->palette.alternateBase());
4345  subRule.drawRule(p, opt->rect);
4346  } else {
4347  baseStyle()->drawPrimitive(pe, v2, p, w);
4348  }
4349  }
4350  return;
4351 
4352  case PE_PanelTipLabel:
4353  if (!rule.hasDrawable())
4354  break;
4355 
4356  if (const QStyleOptionFrame *frmOpt = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
4357  if (rule.hasNativeBorder()) {
4358  rule.drawBackground(p, opt->rect);
4359  QStyleOptionFrame optCopy(*frmOpt);
4360  optCopy.rect = rule.borderRect(opt->rect);
4361  optCopy.palette.setBrush(QPalette::Window, Qt::NoBrush); // oh dear
4362  baseStyle()->drawPrimitive(pe, &optCopy, p, w);
4363  } else {
4364  rule.drawRule(p, opt->rect);
4365  }
4366  }
4367  return;
4368 
4369  case PE_FrameGroupBox:
4370  if (rule.hasNativeBorder())
4371  break;
4372  rule.drawBorder(p, opt->rect);
4373  return;
4374 
4375 #ifndef QT_NO_TABWIDGET
4376  case PE_FrameTabWidget:
4377  if (const QStyleOptionTabWidgetFrame *frm = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
4379  if (subRule.hasNativeBorder()) {
4380  subRule.drawBackground(p, opt->rect);
4381  QStyleOptionTabWidgetFrameV2 frmCopy(*frm);
4383  baseStyle()->drawPrimitive(pe, &frmCopy, p, w);
4384  } else {
4385  subRule.drawRule(p, opt->rect);
4386  }
4387  return;
4388  }
4389  break;
4390 #endif // QT_NO_TABWIDGET
4391 
4393  pseudoElement = PseudoElement_ProgressBarChunk;
4394  break;
4395 
4396  case PE_IndicatorTabTear:
4397  pseudoElement = PseudoElement_TabBarTear;
4398  break;
4399 
4400  case PE_FrameFocusRect:
4401  if (!rule.hasNativeOutline()) {
4402  rule.drawOutline(p, opt->rect);
4403  return;
4404  }
4405  break;
4406 
4408  pseudoElement = PseudoElement_DockWidgetSeparator;
4409  break;
4410 
4411  case PE_PanelItemViewItem:
4412  pseudoElement = PseudoElement_ViewItem;
4413  break;
4414 
4416  pseudoElement = PseudoElement_ScrollAreaCorner;
4417  break;
4418 
4419  case PE_IndicatorSpinDown:
4420  case PE_IndicatorSpinMinus:
4421  pseudoElement = PseudoElement_SpinBoxDownArrow;
4422  break;
4423 
4424  case PE_IndicatorSpinUp:
4425  case PE_IndicatorSpinPlus:
4426  pseudoElement = PseudoElement_SpinBoxUpArrow;
4427  break;
4428 #ifndef QT_NO_TABBAR
4429  case PE_IndicatorTabClose:
4430  if (w)
4431  w = w->parentWidget(); //match on the QTabBar instead of the CloseButton
4432  pseudoElement = PseudoElement_TabBarTabCloseButton;
4433 #endif
4434 
4435  default:
4436  break;
4437  }
4438 
4439  if (pseudoElement != PseudoElement_None) {
4440  QRenderRule subRule = renderRule(w, opt, pseudoElement);
4441  if (subRule.hasDrawable()) {
4442  subRule.drawRule(p, rect);
4443  } else {
4444  baseStyle()->drawPrimitive(pe, opt, p, w);
4445  }
4446  } else {
4447  baseStyle()->drawPrimitive(pe, opt, p, w);
4448  }
4449 }
4450 
4452  const QStyleOption *option) const
4453 {
4454  return baseStyle()->generatedIconPixmap(iconMode, pixmap, option);
4455 }
4456 
4458  const QPoint &pt, const QWidget *w) const
4459 {
4460  RECURSION_GUARD(return baseStyle()->hitTestComplexControl(cc, opt, pt, w))
4461  switch (cc) {
4462  case CC_TitleBar:
4463  if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
4465  if (rule.hasDrawable() || rule.hasBox() || rule.hasBorder()) {
4467  QRect r;
4469  uint ctrl = SC_TitleBarSysMenu;
4470  while (ctrl <= SC_TitleBarLabel) {
4471  r = layout[QStyle::SubControl(ctrl)];
4472  if (r.isValid() && r.contains(pt)) {
4473  sc = QStyle::SubControl(ctrl);
4474  break;
4475  }
4476  ctrl <<= 1;
4477  }
4478  return sc;
4479  }
4480  }
4481  break;
4482 
4483  case CC_MdiControls:
4487  return QWindowsStyle::hitTestComplexControl(cc, opt, pt, w);
4488  break;
4489 
4490  case CC_ScrollBar: {
4491  QRenderRule rule = renderRule(w, opt);
4492  if (!rule.hasDrawable() && !rule.hasBox())
4493  break;
4494  }
4495  // intentionally falls through
4496  case CC_SpinBox:
4497  case CC_GroupBox:
4498  case CC_ComboBox:
4499  case CC_Slider:
4500  case CC_ToolButton:
4501  return QWindowsStyle::hitTestComplexControl(cc, opt, pt, w);
4502  default:
4503  break;
4504  }
4505 
4506  return baseStyle()->hitTestComplexControl(cc, opt, pt, w);
4507 }
4508 
4509 QRect QStyleSheetStyle::itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pixmap) const
4510 {
4511  return baseStyle()->itemPixmapRect(rect, alignment, pixmap);
4512 }
4513 
4514 QRect QStyleSheetStyle::itemTextRect(const QFontMetrics &metrics, const QRect& rect, int alignment,
4515  bool enabled, const QString& text) const
4516 {
4517  return baseStyle()->itemTextRect(metrics, rect, alignment, enabled, text);
4518 }
4519 
4521 {
4522  RECURSION_GUARD(return baseStyle()->pixelMetric(m, opt, w))
4523 
4524  QRenderRule rule = renderRule(w, opt);
4525  QRenderRule subRule;
4526 
4527  switch (m) {
4529 #ifndef QT_NO_TOOLBUTTON
4530  // QToolButton adds this directly to the width
4531  if (qobject_cast<const QToolButton *>(w) && (rule.hasBox() || !rule.hasNativeBorder()))
4532  return 0;
4533 #endif
4535  if (subRule.hasContentsSize())
4536  return subRule.size().width();
4537  break;
4538 
4541  case PM_ButtonMargin:
4543  if (rule.hasBox())
4544  return 0;
4545  break;
4546 
4547  case PM_DefaultFrameWidth:
4548  if (!rule.hasNativeBorder())
4549  return rule.border()->borders[LeftEdge];
4550  break;
4551 
4553  case PM_IndicatorWidth:
4555  case PM_IndicatorHeight:
4556  subRule = renderRule(w, opt, PseudoElement_Indicator);
4557  if (subRule.hasContentsSize()) {
4558  return (m == PM_ExclusiveIndicatorWidth) || (m == PM_IndicatorWidth)
4559  ? subRule.size().width() : subRule.size().height();
4560  }
4561  break;
4562 
4564  case PM_ToolTipLabelFrameWidth: // border + margin + padding (support only one width)
4565  if (!rule.hasDrawable())
4566  break;
4567 
4568  return (rule.border() ? rule.border()->borders[LeftEdge] : 0)
4569  + (rule.hasBox() ? rule.box()->margins[LeftEdge] + rule.box()->paddings[LeftEdge]: 0);
4570 
4571  case PM_ToolBarFrameWidth:
4572  if (rule.hasBorder() || rule.hasBox())
4573  return (rule.border() ? rule.border()->borders[LeftEdge] : 0)
4574  + (rule.hasBox() ? rule.box()->paddings[LeftEdge]: 0);
4575  break;
4576 
4577  case PM_MenuPanelWidth:
4578  case PM_MenuBarPanelWidth:
4579  if (rule.hasBorder() || rule.hasBox())
4580  return (rule.border() ? rule.border()->borders[LeftEdge] : 0)
4581  + (rule.hasBox() ? rule.box()->margins[LeftEdge]: 0);
4582  break;
4583 
4584 
4585  case PM_MenuHMargin:
4586  case PM_MenuBarHMargin:
4587  if (rule.hasBox())
4588  return rule.box()->paddings[LeftEdge];
4589  break;
4590 
4591  case PM_MenuVMargin:
4592  case PM_MenuBarVMargin:
4593  if (rule.hasBox())
4594  return rule.box()->paddings[TopEdge];
4595  break;
4596 
4598  case PM_ToolBarItemMargin:
4599  if (rule.hasBox())
4600  return rule.box()->margins[TopEdge];
4601  break;
4602 
4603  case PM_ToolBarItemSpacing:
4604  case PM_MenuBarItemSpacing:
4605  if (rule.hasBox() && rule.box()->spacing != -1)
4606  return rule.box()->spacing;
4607  break;
4608 
4609  case PM_MenuTearoffHeight:
4610  case PM_MenuScrollerHeight: {
4612  subRule = renderRule(w, opt, ps);
4613  if (subRule.hasContentsSize())
4614  return subRule.size().height();
4615  break;
4616  }
4617 
4619  break;
4620 
4621  case PM_SplitterWidth:
4623  case PM_ToolBarHandleExtent: {
4624  PseudoElement ps;
4626  else if (m == PM_SplitterWidth) ps = PseudoElement_SplitterHandle;
4628  subRule = renderRule(w, opt, ps);
4629  if (subRule.hasContentsSize()) {
4630  QSize sz = subRule.size();
4631  return (opt && opt->state & QStyle::State_Horizontal) ? sz.width() : sz.height();
4632  }
4633  break;
4634  }
4635 
4637  if (rule.hasBox() && rule.box()->spacing != -1)
4638  return rule.box()->spacing;
4639  break;
4641  if (qobject_cast<const QCheckBox *>(w)) {
4642  if (rule.hasBox() && rule.box()->spacing != -1)
4643  return rule.box()->spacing;
4644  }
4645  // assume group box
4646  subRule = renderRule(w, opt, PseudoElement_GroupBoxTitle);
4647  if (subRule.hasBox() && subRule.box()->spacing != -1)
4648  return subRule.box()->spacing;
4649  break;
4650 
4651 #ifndef QT_NO_SCROLLBAR
4652  case PM_ScrollBarExtent:
4653  if (rule.hasContentsSize()) {
4654  QSize sz = rule.size();
4655  if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt))
4656  return sb->orientation == Qt::Horizontal ? sz.height() : sz.width();
4657  return sz.width() == -1 ? sz.height() : sz.width();
4658  }
4659  break;
4660 
4661  case PM_ScrollBarSliderMin:
4663  subRule = renderRule(w, opt, PseudoElement_ScrollBarSlider);
4664  QSize msz = subRule.minimumSize();
4665  if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt))
4666  return sb->orientation == Qt::Horizontal ? msz.width() : msz.height();
4667  return msz.width() == -1 ? msz.height() : msz.width();
4668  }
4669  break;
4670 
4672  if(!rule.hasNativeBorder() || rule.hasBox())
4673  return 0;
4674  break;
4675 #endif // QT_NO_SCROLLBAR
4676 
4678  subRule = renderRule(w, opt, PseudoElement_ProgressBarChunk);
4679  if (subRule.hasContentsSize()) {
4680  QSize sz = subRule.size();
4681  return (opt->state & QStyle::State_Horizontal)
4682  ? sz.width() : sz.height();
4683  }
4684  break;
4685 
4686 #ifndef QT_NO_TABWIDGET
4687  case PM_TabBarTabHSpace:
4688  case PM_TabBarTabVSpace:
4689  subRule = renderRule(w, opt, PseudoElement_TabBarTab);
4690  if (subRule.hasBox() || subRule.hasBorder())
4691  return 0;
4692  break;
4693 
4695  subRule = renderRule(w, opt, PseudoElement_TabBarScroller);
4696  if (subRule.hasContentsSize()) {
4697  QSize sz = subRule.size();
4698  return sz.width() != -1 ? sz.width() : sz.height();
4699  }
4700  }
4701  break;
4702 
4705  subRule = renderRule(w, opt, PseudoElement_TabBarTab);
4706  if (subRule.hasBox())
4707  return 0;
4708  break;
4709 
4710  case PM_TabBarBaseOverlap: {
4711  const QWidget *tabWidget = qobject_cast<const QTabWidget *>(w) ? w : w->parentWidget();
4712  if (hasStyleRule(tabWidget, PseudoElement_TabWidgetPane)) {
4713  return 0;
4714  }
4715  break;
4716  }
4717 #endif // QT_NO_TABWIDGET
4718 
4719  case PM_SliderThickness: // horizontal slider's height (sizeHint)
4720  case PM_SliderLength: // minimum length of slider
4721  if (rule.hasContentsSize()) {
4722  bool horizontal = opt->state & QStyle::State_Horizontal;
4723  if (m == PM_SliderThickness) {
4724  QSize sz = rule.size();
4725  return horizontal ? sz.height() : sz.width();
4726  } else {
4727  QSize msz = rule.minimumContentsSize();
4728  return horizontal ? msz.width() : msz.height();
4729  }
4730  }
4731  break;
4732 
4735  if (!subRule.hasContentsSize())
4736  break;
4737  QSize size = subRule.size();
4738  return (opt->state & QStyle::State_Horizontal) ? size.height() : size.width();
4739  }
4740 
4741  case PM_ToolBarIconSize:
4742  case PM_ListViewIconSize:
4743  case PM_IconViewIconSize:
4744  case PM_TabBarIconSize:
4745  case PM_MessageBoxIconSize:
4746  case PM_ButtonIconSize:
4747  case PM_SmallIconSize:
4748  if (rule.hasStyleHint(QLatin1String("icon-size"))) {
4749  return rule.styleHint(QLatin1String("icon-size")).toSize().width();
4750  }
4751  break;
4752 
4753  case PM_DockWidgetTitleMargin: {
4755  if (!subRule.hasBox())
4756  break;
4757  return (subRule.border() ? subRule.border()->borders[TopEdge] : 0)
4758  + (subRule.hasBox() ? subRule.box()->margins[TopEdge] + subRule.box()->paddings[TopEdge]: 0);
4759  }
4760 
4763  if (!subRule.hasContentsSize())
4764  break;
4765  QSize sz = subRule.size();
4766  return qMax(sz.width(), sz.height());
4767  }
4768 
4769  case PM_TitleBarHeight: {
4770  QRenderRule subRule = renderRule(w, opt, PseudoElement_TitleBar);
4771  if (subRule.hasContentsSize())
4772  return subRule.size().height();
4773  else if (subRule.hasBox() || subRule.hasBorder()) {
4774  QFontMetrics fm = opt ? opt->fontMetrics : w->fontMetrics();
4775  return subRule.size(QSize(0, fm.height())).height();
4776  }
4777  break;
4778  }
4779 
4781  if (rule.hasBox() || rule.hasBorder()) {
4782  return (rule.border() ? rule.border()->borders[LeftEdge] : 0)
4783  + (rule.hasBox() ? rule.box()->paddings[LeftEdge]+rule.box()->margins[LeftEdge]: 0);
4784  }
4785  break;
4786 
4789  int width = subRule.size().width();
4790  if (width != -1)
4791  return width;
4792  break;
4793  }
4794  default:
4795  break;
4796  }
4797 
4798  return baseStyle()->pixelMetric(m, opt, w);
4799 }
4800 
4802  const QSize &csz, const QWidget *w) const
4803 {
4804  RECURSION_GUARD(return baseStyle()->sizeFromContents(ct, opt, csz, w))
4805 
4806  QRenderRule rule = renderRule(w, opt);
4807  QSize sz = rule.adjustSize(csz);
4808 
4809  switch (ct) {
4810  case CT_SpinBox: // ### hopelessly broken QAbstractSpinBox (part 1)
4811  if (rule.hasBox() || !rule.hasNativeBorder())
4812  return csz;
4813  return rule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w)
4814  : QWindowsStyle::sizeFromContents(ct, opt, sz, w);
4815  case CT_ToolButton:
4816  if (rule.hasBox() || !rule.hasNativeBorder() || !rule.baseStyleCanDraw())
4817  sz += QSize(3, 3); // ### broken QToolButton
4818  //fall thought
4819  case CT_ComboBox:
4820  case CT_PushButton:
4821  if (rule.hasBox() || !rule.hasNativeBorder()) {
4822  if(ct == CT_ComboBox) {
4823  //add some space for the drop down.
4825  QRect comboRect = positionRect(w, rule, subRule, PseudoElement_ComboBoxDropDown, opt->rect, opt->direction);
4826  //+2 because there is hardcoded margins in QCommonStyle::drawControl(CE_ComboBoxLabel)
4827  sz += QSize(comboRect.width() + 2, 0);
4828  }
4829  return rule.boxSize(sz);
4830  }
4831  sz = rule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w)
4832  : QWindowsStyle::sizeFromContents(ct, opt, sz, w);
4833  return rule.boxSize(sz, Margin);
4834 
4835  case CT_HeaderSection: {
4836  if (const QStyleOptionHeader *hdr = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
4838  if (subRule.hasGeometry() || subRule.hasBox() || !subRule.hasNativeBorder()) {
4839  sz = subRule.adjustSize(csz);
4840  if (!subRule.hasGeometry()) {
4841  QSize nativeContentsSize;
4842  bool nullIcon = hdr->icon.isNull();
4843  int iconSize = nullIcon ? 0 : pixelMetric(QStyle::PM_SmallIconSize, hdr, w);
4844  QSize txt = hdr->fontMetrics.size(0, hdr->text);
4845  nativeContentsSize.setHeight(qMax(iconSize, txt.height()));
4846  nativeContentsSize.setWidth(iconSize + txt.width());
4847  sz = sz.expandedTo(nativeContentsSize);
4848  }
4849  return subRule.size(sz);
4850  }
4851  return subRule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w)
4852  : QWindowsStyle::sizeFromContents(ct, opt, sz, w);
4853  }
4854  }
4855  break;
4856  case CT_GroupBox:
4857  case CT_LineEdit:
4858 #ifndef QT_NO_SPINBOX
4859  // ### hopelessly broken QAbstractSpinBox (part 2)
4860  if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(w ? w->parentWidget() : 0)) {
4861  QRenderRule rule = renderRule(spinBox, opt);
4862  if (rule.hasBox() || !rule.hasNativeBorder())
4863  return csz;
4864  return rule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w)
4865  : QWindowsStyle::sizeFromContents(ct, opt, sz, w);
4866  }
4867 #endif
4868  if (rule.hasBox() || !rule.hasNativeBorder()) {
4869  return rule.boxSize(sz);
4870  }
4871  break;
4872 
4873  case CT_CheckBox:
4874  case CT_RadioButton:
4875  if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
4876  if (rule.hasBox() || rule.hasBorder() || hasStyleRule(w, PseudoElement_Indicator)) {
4877  bool isRadio = (ct == CT_RadioButton);
4878  int iw = pixelMetric(isRadio ? PM_ExclusiveIndicatorWidth
4879  : PM_IndicatorWidth, btn, w);
4880  int ih = pixelMetric(isRadio ? PM_ExclusiveIndicatorHeight
4881  : PM_IndicatorHeight, btn, w);
4882 
4883  int spacing = pixelMetric(isRadio ? PM_RadioButtonLabelSpacing
4884  : PM_CheckBoxLabelSpacing, btn, w);
4885  sz.setWidth(sz.width() + iw + spacing);
4886  sz.setHeight(qMax(sz.height(), ih));
4887  return rule.boxSize(sz);
4888  }
4889  }
4890  break;
4891 
4892  case CT_Menu:
4893  case CT_MenuBar: // already has everything!
4894  case CT_ScrollBar:
4895  if (rule.hasBox() || rule.hasBorder())
4896  return sz;
4897  break;
4898 
4899  case CT_MenuItem:
4900  if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
4901  PseudoElement pe = (mi->menuItemType == QStyleOptionMenuItem::Separator)
4903  QRenderRule subRule = renderRule(w, opt, pe);
4904  if ((pe == PseudoElement_MenuSeparator) && subRule.hasContentsSize()) {
4905  return QSize(sz.width(), subRule.size().height());
4906  } else if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder())) {
4907  int width = csz.width();
4908  if (mi->text.contains(QLatin1Char('\t')))
4909  width += 12; //as in QCommonStyle
4910  return subRule.boxSize(subRule.adjustSize(QSize(width, csz.height())));
4911  }
4912  }
4913  break;
4914 
4915  case CT_Splitter:
4916  case CT_MenuBarItem: {
4918  QRenderRule subRule = renderRule(w, opt, pe);
4919  if (subRule.hasBox() || subRule.hasBorder())
4920  return subRule.boxSize(sz);
4921  break;
4922  }
4923 
4924  case CT_ProgressBar:
4925  case CT_SizeGrip:
4926  return (rule.hasContentsSize())
4927  ? rule.size(sz)
4928  : rule.boxSize(baseStyle()->sizeFromContents(ct, opt, sz, w));
4929  break;
4930 
4931  case CT_Slider:
4932  if (rule.hasBorder() || rule.hasBox() || rule.hasGeometry())
4933  return rule.boxSize(sz);
4934  break;
4935 
4936 #ifndef QT_NO_TABBAR
4937  case CT_TabBarTab: {
4938  QRenderRule subRule = renderRule(w, opt, PseudoElement_TabBarTab);
4939  if (subRule.hasBox() || !subRule.hasNativeBorder()) {
4940  int spaceForIcon = 0;
4941  bool vertical = false;
4942  if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
4943  if (!tab->icon.isNull())
4944  spaceForIcon = 6 /* icon offset */ + 4 /* spacing */ + 2 /* magic */; // ###: hardcoded to match with common style
4945  vertical = verticalTabs(tab->shape);
4946  }
4947  sz = csz + QSize(vertical ? 0 : spaceForIcon, vertical ? spaceForIcon : 0);
4948  return subRule.boxSize(subRule.adjustSize(sz));
4949  }
4950 #ifdef Q_WS_MAC
4951  if (baseStyle()->inherits("QMacStyle")) {
4952  //adjust the size after the call to the style because the mac style ignore the size arguments anyway.
4953  //this might cause the (max-){width,height} property to include the native style border while they should not.
4954  return subRule.adjustSize(baseStyle()->sizeFromContents(ct, opt, csz, w));
4955  }
4956 #endif
4957  sz = subRule.adjustSize(csz);
4958  break;
4959  }
4960 #endif // QT_NO_TABBAR
4961 
4962  case CT_MdiControls:
4963  if (const QStyleOptionComplex *ccOpt = qstyleoption_cast<const QStyleOptionComplex *>(opt)) {
4967  break;
4968 
4969  QList<QVariant> layout = rule.styleHint(QLatin1String("button-layout")).toList();
4970  if (layout.isEmpty())
4971  layout = subControlLayout(QLatin1String("mNX"));
4972 
4973  int width = 0, height = 0;
4974  for (int i = 0; i < layout.count(); i++) {
4975  int layoutButton = layout[i].toInt();
4976  if (layoutButton < PseudoElement_MdiCloseButton
4977  || layoutButton > PseudoElement_MdiNormalButton)
4978  continue;
4979  QStyle::SubControl sc = knownPseudoElements[layoutButton].subControl;
4980  if (!(ccOpt->subControls & sc))
4981  continue;
4982  QRenderRule subRule = renderRule(w, opt, layoutButton);
4983  QSize sz = subRule.size();
4984  width += sz.width();
4985  height = qMax(height, sz.height());
4986  }
4987 
4988  return QSize(width, height);
4989  }
4990  break;
4991 
4992 #ifndef QT_NO_ITEMVIEWS
4993  case CT_ItemViewItem: {
4994  QRenderRule subRule = renderRule(w, opt, PseudoElement_ViewItem);
4995  sz = baseStyle()->sizeFromContents(ct, opt, csz, w);
4996  sz = subRule.adjustSize(sz);
4997  if (subRule.hasBox() || subRule.hasBorder())
4998  sz = subRule.boxSize(sz);
4999  return sz;
5000  }
5001 #endif // QT_NO_ITEMVIEWS
5002 
5003  default:
5004  break;
5005  }
5006 
5007  return baseStyle()->sizeFromContents(ct, opt, sz, w);
5008 }
5009 
5014 {
5015  switch (sp) {
5016  case QStyle::SP_TitleBarMenuButton: return QLatin1String("titlebar-menu-icon");
5017  case QStyle::SP_TitleBarMinButton: return QLatin1String("titlebar-minimize-icon");
5018  case QStyle::SP_TitleBarMaxButton: return QLatin1String("titlebar-maximize-icon");
5019  case QStyle::SP_TitleBarCloseButton: return QLatin1String("titlebar-close-icon");
5020  case QStyle::SP_TitleBarNormalButton: return QLatin1String("titlebar-normal-icon");
5021  case QStyle::SP_TitleBarShadeButton: return QLatin1String("titlebar-shade-icon");
5022  case QStyle::SP_TitleBarUnshadeButton: return QLatin1String("titlebar-unshade-icon");
5023  case QStyle::SP_TitleBarContextHelpButton: return QLatin1String("titlebar-contexthelp-icon");
5024  case QStyle::SP_DockWidgetCloseButton: return QLatin1String("dockwidget-close-icon");
5025  case QStyle::SP_MessageBoxInformation: return QLatin1String("messagebox-information-icon");
5026  case QStyle::SP_MessageBoxWarning: return QLatin1String("messagebox-warning-icon");
5027  case QStyle::SP_MessageBoxCritical: return QLatin1String("messagebox-critical-icon");
5028  case QStyle::SP_MessageBoxQuestion: return QLatin1String("messagebox-question-icon");
5029  case QStyle::SP_DesktopIcon: return QLatin1String("desktop-icon");
5030  case QStyle::SP_TrashIcon: return QLatin1String("trash-icon");
5031  case QStyle::SP_ComputerIcon: return QLatin1String("computer-icon");
5032  case QStyle::SP_DriveFDIcon: return QLatin1String("floppy-icon");
5033  case QStyle::SP_DriveHDIcon: return QLatin1String("harddisk-icon");
5034  case QStyle::SP_DriveCDIcon: return QLatin1String("cd-icon");
5035  case QStyle::SP_DriveDVDIcon: return QLatin1String("dvd-icon");
5036  case QStyle::SP_DriveNetIcon: return QLatin1String("network-icon");
5037  case QStyle::SP_DirOpenIcon: return QLatin1String("directory-open-icon");
5038  case QStyle::SP_DirClosedIcon: return QLatin1String("directory-closed-icon");
5039  case QStyle::SP_DirLinkIcon: return QLatin1String("directory-link-icon");
5040  case QStyle::SP_FileIcon: return QLatin1String("file-icon");
5041  case QStyle::SP_FileLinkIcon: return QLatin1String("file-link-icon");
5042  case QStyle::SP_FileDialogStart: return QLatin1String("filedialog-start-icon");
5043  case QStyle::SP_FileDialogEnd: return QLatin1String("filedialog-end-icon");
5044  case QStyle::SP_FileDialogToParent: return QLatin1String("filedialog-parent-directory-icon");
5045  case QStyle::SP_FileDialogNewFolder: return QLatin1String("filedialog-new-directory-icon");
5046  case QStyle::SP_FileDialogDetailedView: return QLatin1String("filedialog-detailedview-icon");
5047  case QStyle::SP_FileDialogInfoView: return QLatin1String("filedialog-infoview-icon");
5048  case QStyle::SP_FileDialogContentsView: return QLatin1String("filedialog-contentsview-icon");
5049  case QStyle::SP_FileDialogListView: return QLatin1String("filedialog-listview-icon");
5050  case QStyle::SP_FileDialogBack: return QLatin1String("filedialog-backward-icon");
5051  case QStyle::SP_DirIcon: return QLatin1String("directory-icon");
5052  case QStyle::SP_DialogOkButton: return QLatin1String("dialog-ok-icon");
5053  case QStyle::SP_DialogCancelButton: return QLatin1String("dialog-cancel-icon");
5054  case QStyle::SP_DialogHelpButton: return QLatin1String("dialog-help-icon");
5055  case QStyle::SP_DialogOpenButton: return QLatin1String("dialog-open-icon");
5056  case QStyle::SP_DialogSaveButton: return QLatin1String("dialog-save-icon");
5057  case QStyle::SP_DialogCloseButton: return QLatin1String("dialog-close-icon");
5058  case QStyle::SP_DialogApplyButton: return QLatin1String("dialog-apply-icon");
5059  case QStyle::SP_DialogResetButton: return QLatin1String("dialog-reset-icon");
5060  case QStyle::SP_DialogDiscardButton: return QLatin1String("discard-icon");
5061  case QStyle::SP_DialogYesButton: return QLatin1String("dialog-yes-icon");
5062  case QStyle::SP_DialogNoButton: return QLatin1String("dialog-no-icon");
5063  case QStyle::SP_ArrowUp: return QLatin1String("uparrow-icon");
5064  case QStyle::SP_ArrowDown: return QLatin1String("downarrow-icon");
5065  case QStyle::SP_ArrowLeft: return QLatin1String("leftarrow-icon");
5066  case QStyle::SP_ArrowRight: return QLatin1String("rightarrow-icon");
5067  case QStyle::SP_ArrowBack: return QLatin1String("backward-icon");
5068  case QStyle::SP_ArrowForward: return QLatin1String("forward-icon");
5069  case QStyle::SP_DirHomeIcon: return QLatin1String("home-icon");
5070  default: return QLatin1String("");
5071  }
5072 }
5073 
5075  const QWidget *w) const
5076 {
5077  RECURSION_GUARD(return baseStyle()->standardIcon(standardIcon, opt, w))
5078  QString s = propertyNameForStandardPixmap(standardIcon);
5079  if (!s.isEmpty()) {
5080  QRenderRule rule = renderRule(w, opt);
5081  if (rule.hasStyleHint(s))
5082  return qvariant_cast<QIcon>(rule.styleHint(s));
5083  }
5084  return baseStyle()->standardIcon(standardIcon, opt, w);
5085 }
5086 
5088 {
5089  return baseStyle()->standardPalette();
5090 }
5091 
5093  const QWidget *w) const
5094 {
5095  RECURSION_GUARD(return baseStyle()->standardPixmap(standardPixmap, opt, w))
5096  QString s = propertyNameForStandardPixmap(standardPixmap);
5097  if (!s.isEmpty()) {
5098  QRenderRule rule = renderRule(w, opt);
5099  if (rule.hasStyleHint(s)) {
5100  QIcon icon = qvariant_cast<QIcon>(rule.styleHint(s));
5101  return icon.pixmap(16, 16); // ###: unhard-code this if someone complains
5102  }
5103  }
5104  return baseStyle()->standardPixmap(standardPixmap, opt, w);
5105 }
5106 
5108  Qt::Orientation orientation, const QStyleOption *option,
5109  const QWidget *widget) const
5110 {
5111  return baseStyle()->layoutSpacing(control1, control2, orientation, option, widget);
5112 }
5113 
5115  QSizePolicy::ControlType control2,
5116  Qt::Orientation orientation,
5117  const QStyleOption * option ,
5118  const QWidget * widget) const
5119 {
5120  return baseStyle()->layoutSpacing(control1, control2, orientation, option, widget);
5121 }
5122 
5124  QStyleHintReturn *shret) const
5125 {
5126  RECURSION_GUARD(return baseStyle()->styleHint(sh, opt, w, shret))
5127  // Prevent endless loop if somebody use isActiveWindow property as selector.
5128  // QWidget::isActiveWindow uses this styleHint to determine if the window is active or not
5129  if (sh == SH_Widget_ShareActivation)
5130  return baseStyle()->styleHint(sh, opt, w, shret);
5131 
5132  QRenderRule rule = renderRule(w, opt);
5133  QString s;
5134  switch (sh) {
5135  case SH_LineEdit_PasswordCharacter: s = QLatin1String("lineedit-password-character"); break;
5136  case SH_DitherDisabledText: s = QLatin1String("dither-disabled-text"); break;
5137  case SH_EtchDisabledText: s = QLatin1String("etch-disabled-text"); break;
5138  case SH_ItemView_ActivateItemOnSingleClick: s = QLatin1String("activate-on-singleclick"); break;
5139  case SH_ItemView_ShowDecorationSelected: s = QLatin1String("show-decoration-selected"); break;
5140  case SH_Table_GridLineColor: s = QLatin1String("gridline-color"); break;
5141  case SH_DialogButtonLayout: s = QLatin1String("button-layout"); break;
5142  case SH_ToolTipLabel_Opacity: s = QLatin1String("opacity"); break;
5143  case SH_ComboBox_Popup: s = QLatin1String("combobox-popup"); break;
5144  case SH_ComboBox_ListMouseTracking: s = QLatin1String("combobox-list-mousetracking"); break;
5145  case SH_MenuBar_AltKeyNavigation: s = QLatin1String("menubar-altkey-navigation"); break;
5146  case SH_Menu_Scrollable: s = QLatin1String("menu-scrollable"); break;
5147  case SH_DrawMenuBarSeparator: s = QLatin1String("menubar-separator"); break;
5148  case SH_MenuBar_MouseTracking: s = QLatin1String("mouse-tracking"); break;
5149  case SH_SpinBox_ClickAutoRepeatRate: s = QLatin1String("spinbox-click-autorepeat-rate"); break;
5150  case SH_SpinControls_DisableOnBounds: s = QLatin1String("spincontrol-disable-on-bounds"); break;
5151  case SH_MessageBox_TextInteractionFlags: s = QLatin1String("messagebox-text-interaction-flags"); break;
5152  case SH_ToolButton_PopupDelay: s = QLatin1String("toolbutton-popup-delay"); break;
5154  if (renderRule(w, opt, PseudoElement_ToolBoxTab).hasFont)
5155  return 0;
5156  break;
5158  if (rule.hasPalette() && rule.palette()->foreground.style() != Qt::NoBrush)
5159  return rule.palette()->foreground.color().rgba();
5160  break;
5161  case SH_ScrollView_FrameOnlyAroundContents: s = QLatin1String("scrollview-frame-around-contents"); break;
5162  case SH_ScrollBar_ContextMenu: s = QLatin1String("scrollbar-contextmenu"); break;
5163  case SH_ScrollBar_LeftClickAbsolutePosition: s = QLatin1String("scrollbar-leftclick-absolute-position"); break;
5164  case SH_ScrollBar_MiddleClickAbsolutePosition: s = QLatin1String("scrollbar-middleclick-absolute-position"); break;
5165  case SH_ScrollBar_RollBetweenButtons: s = QLatin1String("scrollbar-roll-between-buttons"); break;
5166  case SH_ScrollBar_ScrollWhenPointerLeavesControl: s = QLatin1String("scrollbar-scroll-when-pointer-leaves-control"); break;
5167  case SH_TabBar_Alignment:
5168 #ifndef QT_NO_TABWIDGET
5169  if (qobject_cast<const QTabWidget *>(w)) {
5170  rule = renderRule(w, opt, PseudoElement_TabWidgetTabBar);
5171  if (rule.hasPosition())
5172  return rule.position()->position;
5173  }
5174 #endif // QT_NO_TABWIDGET
5175  s = QLatin1String("alignment");
5176  break;
5177 #ifndef QT_NO_TABBAR
5180  if (rule.hasPosition()) {
5181  Qt::Alignment align = rule.position()->position;
5182  if (align & Qt::AlignLeft || align & Qt::AlignTop)
5183  return QTabBar::LeftSide;
5184  if (align & Qt::AlignRight || align & Qt::AlignBottom)
5185  return QTabBar::RightSide;
5186  }
5187  break;
5188 #endif
5189  case SH_TabBar_ElideMode: s = QLatin1String("tabbar-elide-mode"); break;
5190  case SH_TabBar_PreferNoArrows: s = QLatin1String("tabbar-prefer-no-arrows"); break;
5192 #ifndef QT_NO_COMBOBOX
5193  if (qobject_cast<const QComboBox *>(w)) {
5195  if (view) {
5196  view->ensurePolished();
5197  QRenderRule subRule = renderRule(view, PseudoElement_None);
5198  if (subRule.hasBox() || !subRule.hasNativeBorder())
5199  return QFrame::NoFrame;
5200  }
5201  }
5202 #endif // QT_NO_COMBOBOX
5203  break;
5204  case SH_DialogButtonBox_ButtonsHaveIcons: s = QLatin1String("dialogbuttonbox-buttons-have-icons"); break;
5205  case SH_Workspace_FillSpaceOnMaximize: s = QLatin1String("mdi-fill-space-on-maximize"); break;
5206  case SH_TitleBar_NoBorder:
5207  if (rule.hasBorder())
5208  return !rule.border()->borders[LeftEdge];
5209  break;
5210  case SH_TitleBar_AutoRaise: { // plain absurd
5211  QRenderRule subRule = renderRule(w, opt, PseudoElement_TitleBar);
5212  if (subRule.hasDrawable())
5213  return 1;
5214  break;
5215  }
5216  case SH_ItemView_ArrowKeysNavigateIntoChildren: s = QLatin1String("arrow-keys-navigate-into-children"); break;
5217  case SH_ItemView_PaintAlternatingRowColorsForEmptyArea: s = QLatin1String("paint-alternating-row-colors-for-empty-area"); break;
5218  default: break;
5219  }
5220  if (!s.isEmpty() && rule.hasStyleHint(s)) {
5221  return rule.styleHint(s).toInt();
5222  }
5223 
5224  return baseStyle()->styleHint(sh, opt, w, shret);
5225 }
5226 
5228  const QWidget *w) const
5229 {
5230  RECURSION_GUARD(return baseStyle()->subControlRect(cc, opt, sc, w))
5231 
5232  QRenderRule rule = renderRule(w, opt);
5233  switch (cc) {
5234  case CC_ComboBox:
5235  if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
5236  if (rule.hasBox() || !rule.hasNativeBorder()) {
5237  switch (sc) {
5238  case SC_ComboBoxFrame: return rule.borderRect(opt->rect);
5239  case SC_ComboBoxEditField:
5240  {
5242  QRect r = rule.contentsRect(opt->rect);
5243  QRect r2 = positionRect(w, rule, subRule, PseudoElement_ComboBoxDropDown,
5244  opt->rect, opt->direction);
5245  if (subRule.hasPosition() && subRule.position()->position & Qt::AlignLeft) {
5246  return visualRect(opt->direction, r, r.adjusted(r2.width(),0,0,0));
5247  } else {
5248  return visualRect(opt->direction, r, r.adjusted(0,0,-r2.width(),0));
5249  }
5250  }
5251  case SC_ComboBoxArrow: {
5253  return positionRect(w, rule, subRule, PseudoElement_ComboBoxDropDown, opt->rect, opt->direction);
5254  }
5256  default:
5257  return baseStyle()->subControlRect(cc, opt, sc, w);
5258  }
5259  }
5260 
5261  QStyleOptionComboBox comboBox(*cb);
5262  comboBox.rect = rule.borderRect(opt->rect);
5263  return rule.baseStyleCanDraw() ? baseStyle()->subControlRect(cc, &comboBox, sc, w)
5264  : QWindowsStyle::subControlRect(cc, &comboBox, sc, w);
5265  }
5266  break;
5267 
5268 #ifndef QT_NO_SPINBOX
5269  case CC_SpinBox:
5270  if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
5273  bool ruleMatch = rule.hasBox() || !rule.hasNativeBorder();
5274  bool upRuleMatch = upRule.hasGeometry() || upRule.hasPosition();
5275  bool downRuleMatch = downRule.hasGeometry() || upRule.hasPosition();
5276  if (ruleMatch || upRuleMatch || downRuleMatch) {
5277  switch (sc) {
5278  case SC_SpinBoxFrame:
5279  return rule.borderRect(opt->rect);
5280  case SC_SpinBoxEditField:
5281  {
5282  QRect r = rule.contentsRect(opt->rect);
5283  // Use the widest button on each side to determine edit field size.
5284  Qt::Alignment upAlign, downAlign;
5285 
5286  upAlign = upRule.hasPosition() ? upRule.position()->position
5287  : Qt::Alignment(Qt::AlignRight);
5288  upAlign = resolveAlignment(opt->direction, upAlign);
5289 
5290  downAlign = downRule.hasPosition() ? downRule.position()->position
5291  : Qt::Alignment(Qt::AlignRight);
5292  downAlign = resolveAlignment(opt->direction, downAlign);
5293 
5294  int upSize = subControlRect(CC_SpinBox, opt, SC_SpinBoxUp, w).width();
5295  int downSize = subControlRect(CC_SpinBox, opt, SC_SpinBoxDown, w).width();
5296  int widestL = qMax((upAlign & Qt::AlignLeft) ? upSize : 0,
5297  (downAlign & Qt::AlignLeft) ? downSize : 0);
5298  int widestR = qMax((upAlign & Qt::AlignRight) ? upSize : 0,
5299  (downAlign & Qt::AlignRight) ? downSize : 0);
5300  r.setRight(r.right() - widestR);
5301  r.setLeft(r.left() + widestL);
5302  return r;
5303  }
5304  case SC_SpinBoxDown:
5305  if (downRuleMatch)
5306  return positionRect(w, rule, downRule, PseudoElement_SpinBoxDownButton,
5307  opt->rect, opt->direction);
5308  break;
5309  case SC_SpinBoxUp:
5310  if (upRuleMatch)
5311  return positionRect(w, rule, upRule, PseudoElement_SpinBoxUpButton,
5312  opt->rect, opt->direction);
5313  break;
5314  default:
5315  break;
5316  }
5317 
5318  return baseStyle()->subControlRect(cc, opt, sc, w);
5319  }
5320 
5321  QStyleOptionSpinBox spinBox(*spin);
5322  spinBox.rect = rule.borderRect(opt->rect);
5323  return rule.baseStyleCanDraw() ? baseStyle()->subControlRect(cc, &spinBox, sc, w)
5324  : QWindowsStyle::subControlRect(cc, &spinBox, sc, w);
5325  }
5326  break;
5327 #endif // QT_NO_SPINBOX
5328 
5329  case CC_GroupBox:
5330  if (const QStyleOptionGroupBox *gb = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
5331  switch (sc) {
5332  case SC_GroupBoxFrame:
5333  case SC_GroupBoxContents: {
5334  if (rule.hasBox() || !rule.hasNativeBorder()) {
5335  return sc == SC_GroupBoxFrame ? rule.borderRect(opt->rect)
5336  : rule.contentsRect(opt->rect);
5337  }
5338  QStyleOptionGroupBox groupBox(*gb);
5339  groupBox.rect = rule.borderRect(opt->rect);
5340  return baseStyle()->subControlRect(cc, &groupBox, sc, w);
5341  }
5342  default:
5343  case SC_GroupBoxLabel:
5344  case SC_GroupBoxCheckBox: {
5346  QRenderRule labelRule = renderRule(w, opt, PseudoElement_GroupBoxTitle);
5347  if (!labelRule.hasPosition() && !labelRule.hasGeometry() && !labelRule.hasBox()
5348  && !labelRule.hasBorder() && !indRule.hasContentsSize()) {
5349  QStyleOptionGroupBox groupBox(*gb);
5350  groupBox.rect = rule.borderRect(opt->rect);
5351  return baseStyle()->subControlRect(cc, &groupBox, sc, w);
5352  }
5353  int tw = opt->fontMetrics.width(gb->text);
5354  int th = opt->fontMetrics.height();
5355  int spacing = pixelMetric(QStyle::PM_CheckBoxLabelSpacing, opt, w);
5356  int iw = pixelMetric(QStyle::PM_IndicatorWidth, opt, w);
5357  int ih = pixelMetric(QStyle::PM_IndicatorHeight, opt, w);
5358 
5359  if (gb->subControls & QStyle::SC_GroupBoxCheckBox) {
5360  tw = tw + iw + spacing;
5361  th = qMax(th, ih);
5362  }
5363  if (!labelRule.hasGeometry()) {
5364  labelRule.geo = new QStyleSheetGeometryData(tw, th, tw, th, -1, -1);
5365  } else {
5366  labelRule.geo->width = tw;
5367  labelRule.geo->height = th;
5368  }
5369  if (!labelRule.hasPosition()) {
5371  gb->textAlignment, PositionMode_Static);
5372  }
5373  QRect r = positionRect(w, rule, labelRule, PseudoElement_GroupBoxTitle,
5374  opt->rect, opt->direction);
5375  if (gb->subControls & SC_GroupBoxCheckBox) {
5376  r = labelRule.contentsRect(r);
5377  if (sc == SC_GroupBoxLabel) {
5378  r.setLeft(r.left() + iw + spacing);
5379  r.setTop(r.center().y() - th/2);
5380  } else {
5381  r = QRect(r.left(), r.center().y() - ih/2, iw, ih);
5382  }
5383  return r;
5384  } else {
5385  return labelRule.contentsRect(r);
5386  }
5387  }
5388  } // switch
5389  }
5390  break;
5391 
5392  case CC_ToolButton:
5393  if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
5394  if (rule.hasBox() || !rule.hasNativeBorder()) {
5395  switch (sc) {
5396  case SC_ToolButton: return rule.borderRect(opt->rect);
5397  case SC_ToolButtonMenu: {
5399  return positionRect(w, rule, subRule, PseudoElement_ToolButtonMenu, opt->rect, opt->direction);
5400  }
5401  default:
5402  break;
5403  }
5404  }
5405 
5406  QStyleOptionToolButton tool(*tb);
5407  tool.rect = rule.borderRect(opt->rect);
5408  return rule.baseStyleCanDraw() ? baseStyle()->subControlRect(cc, &tool, sc, w)
5409  : QWindowsStyle::subControlRect(cc, &tool, sc, w);
5410  }
5411  break;
5412 
5413 #ifndef QT_NO_SCROLLBAR
5414  case CC_ScrollBar:
5415  if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
5416  QStyleOptionSlider styleOptionSlider(*sb);
5417  styleOptionSlider.rect = rule.borderRect(opt->rect);
5418  if (rule.hasDrawable() || rule.hasBox()) {
5419  QRect grooveRect;
5420  if (!rule.hasBox()) {
5421  grooveRect = rule.baseStyleCanDraw() ? baseStyle()->subControlRect(cc, sb, SC_ScrollBarGroove, w)
5423  } else {
5424  grooveRect = rule.contentsRect(opt->rect);
5425  }
5426 
5428 
5429  switch (sc) {
5430  case SC_ScrollBarGroove:
5431  return grooveRect;
5432  case SC_ScrollBarAddPage:
5433  case SC_ScrollBarSubPage:
5434  case SC_ScrollBarSlider: {
5435  QRect contentRect = grooveRect;
5438  Origin origin = sliderRule.hasPosition() ? sliderRule.position()->origin : defaultOrigin(PseudoElement_ScrollBarSlider);
5439  contentRect = rule.originRect(opt->rect, origin);
5440  }
5441  int maxlen = (styleOptionSlider.orientation == Qt::Horizontal) ? contentRect.width() : contentRect.height();
5442  int sliderlen;
5443  if (sb->maximum != sb->minimum) {
5444  uint range = sb->maximum - sb->minimum;
5445  sliderlen = (qint64(sb->pageStep) * maxlen) / (range + sb->pageStep);
5446 
5447  int slidermin = pixelMetric(PM_ScrollBarSliderMin, sb, w);
5448  if (sliderlen < slidermin || range > INT_MAX / 2)
5449  sliderlen = slidermin;
5450  if (sliderlen > maxlen)
5451  sliderlen = maxlen;
5452  } else {
5453  sliderlen = maxlen;
5454  }
5455 
5456  int sliderstart = (styleOptionSlider.orientation == Qt::Horizontal ? contentRect.left() : contentRect.top())
5457  + sliderPositionFromValue(sb->minimum, sb->maximum, sb->sliderPosition,
5458  maxlen - sliderlen, sb->upsideDown);
5459 
5460  QRect sr = (sb->orientation == Qt::Horizontal)
5461  ? QRect(sliderstart, contentRect.top(), sliderlen, contentRect.height())
5462  : QRect(contentRect.left(), sliderstart, contentRect.width(), sliderlen);
5463  if (sc == SC_ScrollBarSlider) {
5464  return sr;
5465  } else if (sc == SC_ScrollBarSubPage) {
5466  return QRect(contentRect.topLeft(), sb->orientation == Qt::Horizontal ? sr.bottomLeft() : sr.topRight());
5467  } else { // SC_ScrollBarAddPage
5468  return QRect(sb->orientation == Qt::Horizontal ? sr.topRight() : sr.bottomLeft(), contentRect.bottomRight());
5469  }
5470  break;
5471  }
5476  default: break;
5477  }
5478  if (hasStyleRule(w,pe)) {
5479  QRenderRule subRule = renderRule(w, opt, pe);
5480  if (subRule.hasPosition() || subRule.hasGeometry() || subRule.hasBox()) {
5481  const QStyleSheetPositionData *pos = subRule.position();
5482  QRect originRect = grooveRect;
5483  if (rule.hasBox()) {
5484  Origin origin = (pos && pos->origin != Origin_Unknown) ? pos->origin : defaultOrigin(pe);
5485  originRect = rule.originRect(opt->rect, origin);
5486  }
5487  return positionRect(w, subRule, pe, originRect, styleOptionSlider.direction);
5488  }
5489  }
5490  }
5491  return rule.baseStyleCanDraw() ? baseStyle()->subControlRect(cc, &styleOptionSlider, sc, w)
5492  : QWindowsStyle::subControlRect(cc, &styleOptionSlider, sc, w);
5493  }
5494  break;
5495 #endif // QT_NO_SCROLLBAR
5496 
5497 #ifndef QT_NO_SLIDER
5498  case CC_Slider:
5499  if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
5501  if (!subRule.hasDrawable())
5502  break;
5503  subRule.img = 0;
5504  QRect gr = positionRect(w, rule, subRule, PseudoElement_SliderGroove, opt->rect, opt->direction);
5505  switch (sc) {
5506  case SC_SliderGroove:
5507  return gr;
5508  case SC_SliderHandle: {
5509  bool horizontal = slider->orientation & Qt::Horizontal;
5510  QRect cr = subRule.contentsRect(gr);
5512  int len = horizontal ? subRule2.size().width() : subRule2.size().height();
5513  subRule2.img = 0;
5514  subRule2.geo = 0;
5515  cr = positionRect(w, subRule2, PseudoElement_SliderHandle, cr, opt->direction);
5516  int thickness = horizontal ? cr.height() : cr.width();
5517  int sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum, slider->sliderPosition,
5518  (horizontal ? cr.width() : cr.height()) - len, slider->upsideDown);
5519  cr = horizontal ? QRect(cr.x() + sliderPos, cr.y(), len, thickness)
5520  : QRect(cr.x(), cr.y() + sliderPos, thickness, len);
5521  return subRule2.borderRect(cr);
5522  break; }
5523  case SC_SliderTickmarks:
5524  // TODO...
5525  default:
5526  break;
5527  }
5528  }
5529  break;
5530 #endif // QT_NO_SLIDER
5531 
5532  case CC_MdiControls:
5536  QList<QVariant> layout = rule.styleHint(QLatin1String("button-layout")).toList();
5537  if (layout.isEmpty())
5538  layout = subControlLayout(QLatin1String("mNX"));
5539 
5540  int x = 0, width = 0;
5541  QRenderRule subRule;
5542  for (int i = 0; i < layout.count(); i++) {
5543  int layoutButton = layout[i].toInt();
5544  if (layoutButton < PseudoElement_MdiCloseButton
5545  || layoutButton > PseudoElement_MdiNormalButton)
5546  continue;
5547  QStyle::SubControl control = knownPseudoElements[layoutButton].subControl;
5548  if (!(opt->subControls & control))
5549  continue;
5550  subRule = renderRule(w, opt, layoutButton);
5551  width = subRule.size().width();
5552  if (sc == control)
5553  break;
5554  x += width;
5555  }
5556 
5557  return subRule.borderRect(QRect(x, opt->rect.top(), width, opt->rect.height()));
5558  }
5559  break;
5560 
5561  case CC_TitleBar:
5562  if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
5563  QRenderRule subRule = renderRule(w, opt, PseudoElement_TitleBar);
5564  if (!subRule.hasDrawable() && !subRule.hasBox() && !subRule.hasBorder())
5565  break;
5566  QHash<QStyle::SubControl, QRect> layoutRects = titleBarLayout(w, tb);
5567  return layoutRects.value(sc);
5568  }
5569  break;
5570 
5571  default:
5572  break;
5573  }
5574 
5575  return baseStyle()->subControlRect(cc, opt, sc, w);
5576 }
5577 
5579 {
5580  RECURSION_GUARD(return baseStyle()->subElementRect(se, opt, w))
5581 
5582  QRenderRule rule = renderRule(w, opt);
5583 #ifndef QT_NO_TABBAR
5584  int pe = PseudoElement_None;
5585 #endif
5586 
5587  switch (se) {
5588  case SE_PushButtonContents:
5590  if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
5591  QStyleOptionButton btnOpt(*btn);
5592  if (rule.hasBox() || !rule.hasNativeBorder())
5593  return visualRect(opt->direction, opt->rect, rule.contentsRect(opt->rect));
5594  return rule.baseStyleCanDraw() ? baseStyle()->subElementRect(se, &btnOpt, w)
5595  : QWindowsStyle::subElementRect(se, &btnOpt, w);
5596  }
5597  break;
5598 
5599  case SE_LineEditContents:
5600  case SE_FrameContents:
5602  if (rule.hasBox() || !rule.hasNativeBorder()) {
5603  return visualRect(opt->direction, opt->rect, rule.contentsRect(opt->rect));
5604  }
5605  break;
5606 
5607  case SE_CheckBoxIndicator:
5609  if (rule.hasBox() || rule.hasBorder() || hasStyleRule(w, PseudoElement_Indicator)) {
5611  QRenderRule subRule = renderRule(w, opt, pe);
5612  return positionRect(w, rule, subRule, pe, opt->rect, opt->direction);
5613  }
5614  break;
5615 
5616  case SE_CheckBoxContents:
5618  if (rule.hasBox() || rule.hasBorder() || hasStyleRule(w, PseudoElement_Indicator)) {
5619  bool isRadio = se == SE_RadioButtonContents;
5621  opt, w);
5622  ir = visualRect(opt->direction, opt->rect, ir);
5623  int spacing = pixelMetric(isRadio ? PM_RadioButtonLabelSpacing : PM_CheckBoxLabelSpacing, 0, w);
5624  QRect cr = rule.contentsRect(opt->rect);
5625  ir.setRect(ir.left() + ir.width() + spacing, cr.y(),
5626  cr.width() - ir.width() - spacing, cr.height());
5627  return visualRect(opt->direction, opt->rect, ir);
5628  }
5629  break;
5630 
5631  case SE_ToolBoxTabContents:
5634  return visualRect(opt->direction, opt->rect, subRule.contentsRect(opt->rect));
5635  }
5636  break;
5637 
5639  case SE_RadioButtonClickRect: // focusrect | indicator
5640  if (rule.hasBox() || rule.hasBorder() || hasStyleRule(w, PseudoElement_Indicator)) {
5641  return opt->rect;
5642  }
5643  break;
5644 
5645  case SE_CheckBoxFocusRect:
5646  case SE_CheckBoxClickRect: // relies on indicator and contents
5647  return ParentStyle::subElementRect(se, opt, w);
5648 
5649 #ifndef QT_NO_ITEMVIEWS
5651  if (!qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) {
5652  return subElementRect(SE_CheckBoxIndicator, opt, w);
5653  }
5654  // intentionally falls through
5655  case SE_ItemViewItemText:
5658  if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) {
5659  QRenderRule subRule = renderRule(w, opt, PseudoElement_ViewItem);
5661  if (se == SE_ItemViewItemText || se == SE_ItemViewItemFocusRect)
5663  else if (se == SE_ItemViewItemDecoration && vopt->features & QStyleOptionViewItemV2::HasDecoration)
5667  else
5668  break;
5669  if (subRule.hasGeometry() || subRule.hasBox() || !subRule.hasNativeBorder() || hasStyleRule(w, pe)) {
5670  QRenderRule subRule2 = renderRule(w, opt, pe);
5671  QStyleOptionViewItemV4 optCopy(*vopt);
5672  optCopy.rect = subRule.contentsRect(vopt->rect);
5673  QRect rect = ParentStyle::subElementRect(se, &optCopy, w);
5674  return positionRect(w, subRule2, pe, rect, opt->direction);
5675  }
5676  }
5677  break;
5678 #endif // QT_NO_ITEMVIEWS
5679 
5680  case SE_HeaderArrow: {
5682  if (subRule.hasPosition() || subRule.hasGeometry())
5683  return positionRect(w, rule, subRule, PseudoElement_HeaderViewUpArrow, opt->rect, opt->direction);
5684  }
5685  break;
5686 
5687  case SE_HeaderLabel: {
5689  if (subRule.hasBox() || !subRule.hasNativeBorder())
5690  return subRule.contentsRect(opt->rect);
5691  }
5692  break;
5693 
5694  case SE_ProgressBarGroove:
5696  case SE_ProgressBarLabel:
5697  if (const QStyleOptionProgressBarV2 *pb = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
5698  if (rule.hasBox() || !rule.hasNativeBorder() || rule.hasPosition() || hasStyleRule(w, PseudoElement_ProgressBarChunk)) {
5699  if (se == SE_ProgressBarGroove)
5700  return rule.borderRect(pb->rect);
5701  else if (se == SE_ProgressBarContents)
5702  return rule.contentsRect(pb->rect);
5703 
5704  QSize sz = pb->fontMetrics.size(0, pb->text);
5705  return QStyle::alignedRect(Qt::LeftToRight, rule.hasPosition() ? rule.position()->textAlignment : pb->textAlignment,
5706  sz, pb->rect);
5707  }
5708  }
5709  break;
5710 
5711 #ifndef QT_NO_TABBAR
5714  // intentionally falls through
5716  if (pe == PseudoElement_None)
5718  // intentionally falls through
5719  case SE_TabWidgetTabBar:
5720  if (pe == PseudoElement_None)
5722  // intentionally falls through
5723  case SE_TabWidgetTabPane:
5725  if (pe == PseudoElement_None)
5727 
5728  if (hasStyleRule(w, pe)) {
5730  QRenderRule subRule = renderRule(w, opt, pe);
5731  r = positionRect(w, subRule, pe, r, opt->direction);
5732  if (pe == PseudoElement_TabWidgetTabBar) {
5733  Q_ASSERT(opt);
5734  r = opt->rect.intersected(r);
5735  }
5736  if (se == SE_TabWidgetTabContents)
5737  r = subRule.contentsRect(r);
5738  return r;
5739  }
5740  break;
5741 
5742  case SE_TabBarTearIndicator: {
5743  QRenderRule subRule = renderRule(w, opt, PseudoElement_TabBarTear);
5744  if (subRule.hasContentsSize()) {
5745  QRect r;
5746  if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
5747  switch (tab->shape) {
5748  case QTabBar::RoundedNorth:
5750  case QTabBar::RoundedSouth:
5752  r.setRect(tab->rect.left(), tab->rect.top(), subRule.size().width(), opt->rect.height());
5753  break;
5754  case QTabBar::RoundedWest:
5756  case QTabBar::RoundedEast:
5758  r.setRect(tab->rect.left(), tab->rect.top(), opt->rect.width(), subRule.size().height());
5759  break;
5760  default:
5761  break;
5762  }
5763  r = visualRect(opt->direction, opt->rect, r);
5764  }
5765  return r;
5766  }
5767  break;
5768  }
5769  case SE_TabBarTabText:
5771  case SE_TabBarTabRightButton: {
5772  QRenderRule subRule = renderRule(w, opt, PseudoElement_TabBarTab);
5773  if (subRule.hasBox() || !subRule.hasNativeBorder()) {
5774  return ParentStyle::subElementRect(se, opt, w);
5775  }
5776  break;
5777  }
5778 #endif // QT_NO_TABBAR
5779 
5781  case SE_DockWidgetFloatButton: {
5783  QRenderRule subRule2 = renderRule(w, opt, pe);
5784  if (!subRule2.hasPosition())
5785  break;
5787  return positionRect(w, subRule, subRule2, pe, opt->rect, opt->direction);
5788  }
5789 
5790 #ifndef QT_NO_TOOLBAR
5791  case SE_ToolBarHandle:
5793  return ParentStyle::subElementRect(se, opt, w);
5794  break;
5795 #endif //QT_NO_TOOLBAR
5796 
5797  default:
5798  break;
5799  }
5800 
5801  return baseStyle()->subElementRect(se, opt, w);
5802 }
5803 
5805 {
5806  return (baseStyle()->event(e) && e->isAccepted()) || ParentStyle::event(e);
5807 }
5808 
5810 {
5811  QWidget *container = containerWidget(w);
5812  QRenderRule rule = renderRule(container, PseudoElement_None,
5814  QFont font = rule.font.resolve(w->font());
5815 
5817  && isNaturalChild(w) && qobject_cast<QWidget *>(w->parent())) {
5818 
5819  font = font.resolve(static_cast<QWidget *>(w->parent())->font());
5820  }
5821 
5822  if (w->data->fnt == font)
5823  return;
5824 
5825 #ifdef QT3_SUPPORT
5826  QFont old = w->data->fnt;
5827 #endif
5828  w->data->fnt = font;
5829 #if defined(Q_WS_X11)
5830  // make sure the font set on this widget is associated with the correct screen
5831  //w->data->fnt.x11SetScreen(w->d_func()->xinfo.screen());
5832 #endif
5833 
5835  QApplication::sendEvent(w, &e);
5836 #ifdef QT3_SUPPORT
5837  w->fontChange(old);
5838 #endif
5839 }
5840 
5842 {
5843  w->setProperty("_q_styleSheetWidgetFont", font);
5844 }
5845 
5847 {
5848  w->setProperty("_q_styleSheetWidgetFont", QVariant(QVariant::Invalid));
5849 }
5850 
5851 // Polish palette that should be used for a particular widget, with particular states
5852 // (eg. :focus, :hover, ...)
5853 // this is called by widgets that paint themself in their paint event
5854 // Returns true if there is a new palette in pal.
5856 {
5857  if (!w || !opt || !pal)
5858  return false;
5859 
5860  RECURSION_GUARD(return false)
5861 
5862  w = containerWidget(w);
5863 
5865  if (!rule.hasPalette())
5866  return false;
5867 
5869  return true;
5870 }
5871 
5872 Qt::Alignment QStyleSheetStyle::resolveAlignment(Qt::LayoutDirection layDir, Qt::Alignment src)
5873 {
5874  if (layDir == Qt::LeftToRight || src & Qt::AlignAbsolute)
5875  return src;
5876 
5877  if (src & Qt::AlignLeft) {
5878  src &= ~Qt::AlignLeft;
5879  src |= Qt::AlignRight;
5880  } else if (src & Qt::AlignRight) {
5881  src &= ~Qt::AlignRight;
5882  src |= Qt::AlignLeft;
5883  }
5884  src |= Qt::AlignAbsolute;
5885  return src;
5886 }
5887 
5888 // Returns whether the given QWidget has a "natural" parent, meaning that
5889 // the parent contains this child as part of its normal operation.
5890 // An example is the QTabBar inside a QTabWidget.
5891 // This does not mean that any QTabBar which is a child of QTabWidget will
5892 // match, only the one that was created by the QTabWidget initialization
5893 // (and hence has the correct object name).
5895 {
5896  if (w->objectName().startsWith(QLatin1String("qt_")))
5897  return true;
5898 
5899  return false;
5900 }
5901 
5903 
5904 #include "moc_qstylesheetstyle_p.cpp"
5905 
5906 #endif // QT_NO_STYLE_STYLESHEET
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
T qobject_cast(QObject *object)
Definition: qobject.h:375
virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const =0
Returns a copy of the given pixmap, styled to conform to the specified iconMode and taking into accou...
const quint64 PseudoClass_Off
Definition: qcssparser_p.h:500
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QRect borderRect(const QRect &r) const
double d
Definition: qnumeric_p.h:62
QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget=0) const
Reimplemented Function
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
Definition: qstyle.cpp:2120
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
virtual void unpolish(QWidget *)
Uninitialize the given {widget}&#39;s appearance.
Definition: qstyle.cpp:409
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
const quint64 PseudoClass_Open
Definition: qcssparser_p.h:504
void polish(QApplication *)
Reimplemented Function
QColor colorValue(const QPalette &=QPalette()) const
void unpolish(QApplication *)
Reimplemented Function
QString attribute(NodePtr node, const QString &name) const
QPalette palette
the widget&#39;s palette
Definition: qwidget.h:180
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
const quint64 PseudoClass_Closed
Definition: qcssparser_p.h:503
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
const quint64 PseudoClass_Last
Definition: qcssparser_p.h:479
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
void setFont(const QFont &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4996
const quint64 PseudoClass_Enabled
Definition: qcssparser_p.h:462
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
The QStyleOptionToolBoxV2 class is used to describe the parameters necessary for drawing a frame in Q...
Definition: qstyleoption.h:649
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
QVariant styleHint(const QString &sh) const
const QStyleSheetBorderImageData * borderImage() const
StyleHint
This enum describes the available style hints.
Definition: qstyle.h:640
double qreal
Definition: qglobal.h:1193
bool isWritable() const
Returns true if this property is writable; otherwise returns false.
void drawBorder(QPainter *, const QRect &)
The QStyleHintReturn class provides style hints that return more than basic data types.
Definition: qstyleoption.h:907
void setClip(QPainter *p, const QRect &rect)
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
QString pseudoElement() const
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
QSharedDataPointer< QStyleSheetOutlineData > ou
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
EventRef event
QPointer< QWidget > widget
const quint64 PseudoClass_Any
Definition: qcssparser_p.h:508
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
void clear()
Removes all items from the hash.
Definition: qhash.h:574
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
static QList< QVariant > subControlLayout(const QString &layout)
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
bool hasGeometry() const
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:350
bool hasStyleRule(const QWidget *w, int part) const
const quint64 PseudoClass_Exclusive
Definition: qcssparser_p.h:489
NodePtr parentNode(NodePtr node) const
QHash< const QWidget *, QPalette > customPaletteWidgets
bool hasOutline() const
static const int numKnownStyleHints
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
TileRule
Definition: qnamespace.h:198
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
QRect rectValue() const
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
Definition: qstyleoption.h:251
QStyle * baseStyle() const
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
static bool unstylable(const QWidget *w)
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QIcon icon
the icon for the menu item
Definition: qstyleoption.h:451
static QLatin1String propertyNameForStandardPixmap(QStyle::StandardPixmap sp)
QStyleSheetOutlineData(int *b, QBrush *c, QCss::BorderStyle *s, QSize *r, int *o)
QSharedDataPointer< QStyleSheetGeometryData > geo
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...
NodePtr duplicateNode(NodePtr node) const
QStyleSheetBorderData(int *b, QBrush *c, QCss::BorderStyle *s, QSize *r)
virtual QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
Returns the area within the given rectangle in which to draw the specified pixmap according to the de...
Definition: qstyle.cpp:497
static Qt::Alignment resolveAlignment(Qt::LayoutDirection, Qt::Alignment)
const quint64 PseudoClass_Focus
Definition: qcssparser_p.h:465
static int refcount
Definition: proxyconf.cpp:398
void rotate(qreal a)
Rotates the coordinate system the given angle clockwise.
Definition: qpainter.cpp:3287
const quint64 PseudoClass_Hover
Definition: qcssparser_p.h:466
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
const quint64 PseudoClass_Vertical
Definition: qcssparser_p.h:473
ComplexControl
This enum describes the available complex controls.
Definition: qstyle.h:386
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
bool hasNativeOutline() const
static QPalette palette()
Returns the palette used to render tooltips.
Definition: qtooltip.cpp:557
QFont fnt
Definition: qwidget.h:133
bool remove(const T &value)
Definition: qset.h:89
QRect united(const QRect &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: qrect.h:491
static C reverse(const C &l)
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
bool hasGradientBackground() const
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void setPalette(QWidget *)
static bool verticalTabs(QTabBar::Shape shape)
const quint64 PseudoClass_Active
Definition: qcssparser_p.h:493
QFont font
the font currently set for the widget
Definition: qwidget.h:181
#define SLOT(a)
Definition: qobjectdefs.h:226
void polish(QWidget *widget)
Reimplemented Function
const quint64 PseudoClass_Middle
Definition: qcssparser_p.h:480
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
const QStyleSheetBackgroundData * background() const
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
static Qt::MouseButtons buttons
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
State
This enum describes the state for which a pixmap is intended to be used.
Definition: qicon.h:64
PixelMetric
This enum describes the various available pixel metrics.
Definition: qstyle.h:474
QStyleSheetBackgroundData(const QBrush &b, const QPixmap &p, QCss::Repeat r, Qt::Alignment a, QCss::Origin o, Attachment t, QCss::Origin c)
const quint64 PseudoClass_Minimized
Definition: qcssparser_p.h:497
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QSize sizeValue() const
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...
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
QHash< const QWidget *, QHash< int, bool > > hasStyleRuleCache
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int maxIconWidth
the maximum icon width for the icon in the menu item
Definition: qstyleoption.h:452
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
bool hasBackground() const
QPalette::ColorRole backgroundRole() const
Returns the background role of the widget.
Definition: qwidget.cpp:4677
void drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
QSize minimumSize() const
quint64 pseudoClass(quint64 *negated=0) const
QSharedDataPointer< QStyleSheetPositionData > p
void styleDestroyed(QObject *)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const
Reimplemented Function
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
QString text
the text of the title bar
Definition: qstyleoption.h:822
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.
Definition: qstyle.cpp:532
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QPalette palette()
Returns the application palette.
const QStyleSheetBoxData * box() const
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:481
QStringList nodeNames(NodePtr node) const
static QStyle * style()
Returns the application&#39;s style object.
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
#define QT_NO_MAINWINDOW
bool hasPosition() const
QHash< const void *, QCss::StyleSheet > styleSheetCache
void qNormalizeRadii(const QRect &br, const QSize *radii, QSize *tlr, QSize *trr, QSize *blr, QSize *brr)
Definition: qcssutil.cpp:316
void unpolish(QWidget *widget)
Reimplemented Function
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
PseudoElement
PositionMode
Definition: qcssparser_p.h:331
The QProgressBar widget provides a horizontal or vertical progress bar.
Definition: qprogressbar.h:58
#define QT_NO_MENUBAR
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QRect boxRect(const QRect &r, int flags=All) const
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QSize minimumContentsSize() const
bool extractGeometry(int *w, int *h, int *minw, int *minh, int *maxw, int *maxh)
Definition: qcssparser.cpp:447
QHash< const QWidget *, QRenderRules > renderRulesCache
The QStyleOptionToolBox class is used to describe the parameters needed for drawing a tool box...
Definition: qstyleoption.h:633
bool styleSheetPalette(const QWidget *w, const QStyleOption *opt, QPalette *pal)
void drawBorderImage(QPainter *, const QRect &)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void configurePalette(QPalette *, QPalette::ColorGroup, const QWidget *, bool)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
QSize contentsSize() const
StyleSheetOrigin origin
Definition: qcssparser_p.h:643
QStyle::SubControl subControl
const quint64 PseudoClass_Pressed
Definition: qcssparser_p.h:464
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
#define Q_D(Class)
Definition: qglobal.h:2482
QPainterPath borderClip(QRect rect)
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 QStyleOptionSizeGrip class is used to describe the parameter for drawing a size grip...
Definition: qstyleoption.h:853
static const uint base
Definition: qurl.cpp:268
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
void setMinimumHeight(int minh)
Definition: qwidget.cpp:4334
static QStyle::StandardPixmap subControlIcon(int pe)
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
const quint64 PseudoClass_ReadOnly
Definition: qcssparser_p.h:492
QString text
the text for the menu item
Definition: qstyleoption.h:450
bool autoFillBackground
whether the widget background is filled automatically
Definition: qwidget.h:218
static int sliderPositionFromValue(int min, int max, int val, int space, bool upsideDown=false)
Converts the given logicalValue to a pixel position.
Definition: qstyle.cpp:2176
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
The QStyleOptionToolButton class is used to describe the parameters for drawing a tool button...
Definition: qstyleoption.h:768
const char * className
Definition: qwizard.cpp:137
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void unsetClip(QPainter *)
StandardPixmap
This enum describes the available standard pixmaps.
Definition: qstyle.h:755
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QStyleSheetPositionData(int l, int t, int r, int b, Origin o, Qt::Alignment p, QCss::PositionMode m, Qt::Alignment a=0)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QStyle * style() const
Definition: qwidget.cpp:2742
QSharedDataPointer< QStyleSheetBorderData > bd
const quint64 PseudoClass_Checked
Definition: qcssparser_p.h:467
The QStyleOptionViewItemV2 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:562
ColorGroup
Definition: qpalette.h:92
const quint64 PseudoClass_Unchecked
Definition: qcssparser_p.h:468
QPainterPath clipPath
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=0, const QWidget *widget=0) const
Returns the spacing that should be used between control1 and control2 in a layout.
Definition: qstyle.cpp:2395
QRect contentsRect(const QRect &r) const
QIcon iconValue() const
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
QExplicitlySharedDataPointer< DeclarationData > d
Definition: qcssparser_p.h:430
QRect originRect(const QRect &rect, Origin origin) const
static void setClip(QPainter *painter, QGraphicsItem *item)
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w=0) const
Reimplemented Function
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
virtual ~QStyle()
Destroys the style object.
Definition: qstyle.cpp:362
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
Q_CORE_EXPORT void qDebug(const char *,...)
const QStyleSheetPaletteData * palette() const
QColor darker(int f=200) const
Returns a darker (or lighter) color, but does not change this object.
Definition: qcolor.h:301
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
static QStyleSheetStyleCaches * styleSheetCaches
void drawBackground(QPainter *, const QRect &, const QPoint &=QPoint(0, 0))
QSharedDataPointer< QStyleSheetBackgroundData > bg
unsigned char uchar
Definition: qglobal.h:994
void drawImage(QPainter *p, const QRect &rect)
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
The QStyleOptionProgressBarV2 class is used to describe the parameters necessary for drawing a progre...
Definition: qstyleoption.h:417
int width() const
Returns the width.
Definition: qsize.h:126
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
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
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
QCss::BorderStyle styles[4]
const quint64 PseudoClass_Horizontal
Definition: qcssparser_p.h:472
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
Returns an icon for the given standardIcon.
Definition: qstyle.cpp:2327
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QStyleSheetStyle(QStyle *baseStyle)
Shape
This enum type lists the built-in shapes supported by QTabBar.
Definition: qtabbar.h:81
virtual QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
Returns the area within the given rectangle in which to draw the provided text according to the speci...
Definition: qstyle.cpp:470
bool isAccepted() const
Definition: qcoreevent.h:307
bool event(QEvent *e)
This virtual function receives events to an object and should return true if the event e was recogniz...
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool isEmpty(const char *str)
void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment, using the provided painter.
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
const QStyleSheetPositionData * position() const
void setMaximumWidth(int maxw)
Definition: qwidget.cpp:4343
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
bool hasImage() const
void fillPath(const QPainterPath &path, const QBrush &brush)
Fills the given path using the given brush.
Definition: qpainter.cpp:3456
unsigned __int64 quint64
Definition: qglobal.h:943
const quint64 PseudoClass_Window
Definition: qcssparser_p.h:474
static QWidget * embeddedWidget(QWidget *w)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
virtual QPalette standardPalette() const
Returns the style&#39;s standard palette.
Definition: qstyle.cpp:2283
bool contains(const T &value) const
Definition: qset.h:91
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
QPalette::ColorRole foregroundRole() const
Returns the foreground role.
Definition: qwidget.cpp:4728
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const quint64 PseudoClass_Left
Definition: qcssparser_p.h:485
QVector< Selector > selectors
Definition: qcssparser_p.h:605
#define qApp
const quint64 PseudoClass_Sibling
Definition: qcssparser_p.h:476
void borderImageValue(QString *image, int *cuts, TileMode *h, TileMode *v) const
ContentsType
This enum describes the available contents types.
Definition: qstyle.h:602
void unsetPalette(QWidget *)
The QStyleOptionSpinBox class is used to describe the parameters necessary for drawing a spin box...
Definition: qstyleoption.h:729
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
const QFont & font() const
Returns the currently set font used for drawing text.
Definition: qpainter.cpp:4312
QStyleSheetStyleRecursionGuard(const QStyleSheetStyle *that)
bool checked
whether the menu item is checked or not
Definition: qstyleoption.h:447
void fixupBorder(int)
const char * name
void drawOutline(QPainter *, const QRect &)
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis)
Rotates the coordinate system counterclockwise by the given angle about the specified axis and return...
Definition: qtransform.cpp:615
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition: qicon.h:63
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool nodeNameEquals(NodePtr node, const QString &nodeName) const
static Origin defaultOrigin(int pe)
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
const char * layout
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
void drawBackgroundImage(QPainter *, const QRect &, QPoint=QPoint(0, 0))
LayoutDirection
Definition: qnamespace.h:1580
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
QWidgetData * data
Definition: qwidget.h:815
const quint64 PseudoClass_Movable
Definition: qcssparser_p.h:495
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
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...
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
The QStyleOptionFocusRect class is used to describe the parameters for drawing a focus rectangle with...
Definition: qstyleoption.h:103
QRect positionRect(const QWidget *, const QRenderRule &, const QRenderRule &, int, const QRect &, Qt::LayoutDirection) const
const quint64 PseudoClass_NonExclusive
Definition: qcssparser_p.h:490
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
Q_CORE_EXPORT void qWarning(const char *,...)
bool intValue(int *i, const char *unit=0) const
QSharedDataPointer< QStyleSheetImageData > img
QSize defaultSize(const QWidget *, QSize, const QRect &, int) const
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
QStringList nodeIds(NodePtr node) const
const_iterator insert(const T &value)
Definition: qset.h:179
static QVector< Declaration > declarations(const QVector< StyleRule > &styleRules, const QString &part, quint64 pseudoClass=PseudoClass_Unspecified)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void transpose()
Swaps the width and height values.
Definition: qsize.cpp:196
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
const quint64 PseudoClass_Right
Definition: qcssparser_p.h:486
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
const quint64 PseudoClass_Bottom
Definition: qcssparser_p.h:488
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:859
T findChild(const QString &aName=QString()) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object.
Definition: qobject.h:158
const quint64 PseudoClass_Selected
Definition: qcssparser_p.h:471
QBrush defaultBackground
QSharedDataPointer< QStyleSheetBoxData > b
QHash< const QWidget *, QHash< QString, QString > > m_attributeCache
void drawFrame(QPainter *, const QRect &)
The QStyleOptionTabWidgetFrame class is used to describe the parameters for drawing the frame around ...
Definition: qstyleoption.h:175
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
Definition: qdrawutil.cpp:303
The BorderImage element provides an image that can be used as a border.
const quint64 PseudoClass_Flat
Definition: qcssparser_p.h:484
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
static PositionMode defaultPositionMode(int pe)
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...
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QHash< QString, QVariant > styleHints
__int64 qint64
Definition: qglobal.h:942
QVector< Declaration > declarations
Definition: qcssparser_p.h:606
ButtonFeatures features
a bitwise OR of the features that describe this button
Definition: qstyleoption.h:289
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
const quint64 PseudoClass_Alternate
Definition: qcssparser_p.h:506
const quint64 PseudoClass_Frameless
Definition: qcssparser_p.h:491
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
The State element defines configurations of objects and properties.
void setGeometry(QWidget *)
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
static bool isNaturalChild(const QWidget *w)
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, const QPixmap &pixmap, const QRect &sourceRect, const QMargins &sourceMargins, const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints)
Draws the indicated sourceRect rectangle from the given pixmap into the given targetRect rectangle...
Definition: qdrawutil.cpp:1106
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275
const QStyleSheetGeometryData * geometry() const
#define ceil(x)
QSize toSize() const
Returns the variant as a QSize if the variant has type() Size ; otherwise returns an invalid QSize...
Definition: qvariant.cpp:2432
FrameFeatures features
a bitwise OR of the features that describe this frame.
Definition: qstyleoption.h:143
bool extractPosition(int *l, int *t, int *r, int *b, QCss::Origin *, Qt::Alignment *, QCss::PositionMode *, Qt::Alignment *)
Definition: qcssparser.cpp:468
int count() const
Definition: qstring.h:103
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
const quint64 PseudoClass_Editable
Definition: qcssparser_p.h:501
QString styleSheet
the widget&#39;s style sheet
Definition: qwidget.h:220
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
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static QWidget * parentWidget(const QWidget *w)
const QStyleSheetOutlineData * outline() const
int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=0, const QWidget *widget=0) const
void moveCenter(const QPoint &p)
Moves the rectangle, leaving the center point at the given position.
Definition: qrect.cpp:840
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
QPoint topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:294
QSharedDataPointer< QStyleSheetBorderImageData > bi
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
Definition: qpainter.cpp:7146
QStyleSheetPaletteData(const QBrush &fg, const QBrush &sfg, const QBrush &sbg, const QBrush &abg)
QStyleSheetImageData(const QIcon &i, Qt::Alignment a, const QSize &sz)
void freeNode(NodePtr) const
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
QVector< QCss::StyleRule > styleRules(const QWidget *w) const
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment, using the provided painter.
Definition: qstyle.cpp:570
bool extractOutline(int *borders, QBrush *colors, BorderStyle *Styles, QSize *radii, int *offsets)
Definition: qcssparser.cpp:618
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
QRect itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pixmap) const
Returns the area within the given rectangle in which to draw the specified pixmap according to the de...
The QAbstractItemView class provides the basic functionality for item view classes.
bool hasNativeBorder() const
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
bool hasContentsSize() const
QRect outlineRect(const QRect &r) const
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QHash< QStyle::SubControl, QRect > titleBarLayout(const QWidget *w, const QStyleOptionTitleBar *tb) const
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
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 compare(const QString &s) const
Definition: qstring.cpp:5037
const quint64 PseudoClass_OnlyOne
Definition: qcssparser_p.h:481
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QPoint bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:297
ToolButtonFeatures features
an OR combination of the tool button&#39;s features
Definition: qstyleoption.h:778
QBrush brushValue(const QPalette &=QPalette()) const
bool baseStyleCanDraw() const
const quint64 PseudoClass_EditFocus
Definition: qcssparser_p.h:505
PrimitiveElement
This enum describes the various primitive elements.
Definition: qstyle.h:145
QPalette standardPalette() const
Returns the style&#39;s standard palette.
static Qt::Alignment defaultPosition(int pe)
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
const quint64 PseudoClass_PreviousSelected
Definition: qcssparser_p.h:482
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
QSet< const QWidget * > autoFillDisabledWidgets
State
Definition: qaudio.h:59
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
static const QStyleSheetStyle * globalStyleSheetStyle
const quint64 PseudoClass_Unspecified
Definition: qcssparser_p.h:470
bool hasAlpha() const
Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false...
Definition: qpixmap.cpp:1938
QString uriValue() const
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
const quint64 PseudoClass_Children
Definition: qcssparser_p.h:475
unsigned short ushort
Definition: qglobal.h:995
Holds the rules used to draw a pixmap or image split into nine segments, similar to [CSS3 border-imag...
Definition: qdrawutil.h:136
int midLineWidth
the mid-line width for drawing the frame
Definition: qstyleoption.h:125
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w=0) const
Reimplemented Function
const quint64 PseudoClass_Maximized
Definition: qcssparser_p.h:498
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget=0) const
Reimplemented Function
QRect itemTextRect(const QFontMetrics &metrics, const QRect &rect, int alignment, bool enabled, const QString &text) const
Returns the area within the given rectangle in which to draw the provided text according to the speci...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
bool hasBorder() const
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...
#define WIDGET(x)
void setProperties(QWidget *)
int tabWidth
the tab width for the menu item
Definition: qstyleoption.h:453
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
bool hasBox() const
The QStyleOptionFrameV3 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:157
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool extractBox(int *margins, int *paddings, int *spacing=0)
Definition: qcssparser.cpp:492
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
QSize size(const QSize &sz) const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
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
bool extractImage(QIcon *icon, Qt::Alignment *a, QSize *size)
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
const QStyleSheetBorderData * border() const
bool hasDrawable() const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QStyleOptionGroupBox class describes the parameters for drawing a group box.
Definition: qstyleoption.h:834
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
bool initWidget(const QWidget *w) const
Make sure that the cache will be clean by connecting destroyed if needed.
#define RECURSION_GUARD(RETURN)
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
const quint64 PseudoClass_Indeterminate
Definition: qcssparser_p.h:469
bool isDesignable(const QObject *obj=0) const
Returns true if this property is designable for the given object; otherwise returns false...
static void qt_check_if_internal_widget(const QWidget **w, int *element)
void setMaximumHeight(int maxh)
Definition: qwidget.cpp:4352
QString objectName() const
const char * property
Definition: qwizard.cpp:138
bool hasAttributes(NodePtr) const
void qDrawBorder(QPainter *p, const QRect &rect, const QCss::BorderStyle *styles, const int *borders, const QBrush *colors, const QSize *radii)
Definition: qcssutil.cpp:348
static const PseudoElementInfo knownPseudoElements[NumPseudoElements]
The QStyleOptionTabV3 class is used to describe the parameters necessary for drawing a tabs in Qt 4...
Definition: qstyleoption.h:347
int height() const
Returns the height.
Definition: qsize.h:129
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setMinimumWidth(int minw)
Definition: qwidget.cpp:4325
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
Definition: qnamespace.h:54
The QAbstractSlider class provides an integer value within a range.
QFactoryLoader * l
bool hasStyleHint(const QString &sh) const
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w=0) const
Reimplemented Function
void saveWidgetFont(QWidget *w, const QFont &font) const
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
int styleHint(StyleHint sh, const QStyleOption *opt=0, const QWidget *w=0, QStyleHintReturn *shret=0) const
Reimplemented Function
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QSize adjustSize(const QSize &sz)
CheckType checkType
the type of checkmark of the menu item
Definition: qstyleoption.h:446
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget=0) const =0
Returns the sub control at the given position in the given complex control (with the style options sp...
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt=0, const QWidget *widget=0) const
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
quint16 index
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
QString title
the title of the dock window
Definition: qstyleoption.h:510
Qt::Orientation orientation
the slider&#39;s orientation (horizontal or vertical)
Definition: qstyleoption.h:707
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
static quint64 pseudoClass(QStyle::State state)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QStyleOptionTab class is used to describe the parameters for drawing a tab bar.
Definition: qstyleoption.h:304
virtual void polish(QWidget *)
Initializes the appearance of the given widget.
Definition: qstyle.cpp:390
bool hasPalette() const
const quint64 PseudoClass_First
Definition: qcssparser_p.h:478
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
Definition: qicon.cpp:693
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
QRenderRule renderRule(const QWidget *, int, quint64=0) const
QFont font
the font that is used for the text
Definition: qstyleoption.h:785
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
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
ControlElement
This enum represents a control element.
Definition: qstyle.h:217
The QStyleOptionSlider class is used to describe the parameters needed for drawing a slider...
Definition: qstyleoption.h:701
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
QRect paddingRect(const QRect &r) const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const
Reimplemented Function
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition: qwidget.h:937
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
const QBrush & buttonText() const
Returns the button text foreground brush of the current color group.
Definition: qpalette.h:138
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget=0) const
Reimplemented Function
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
The QTabWidget class provides a stack of tabbed widgets.
Definition: qtabwidget.h:60
Qt::WindowFlags titleBarFlags
the widget flags for the title bar
Definition: qstyleoption.h:825
void setClipPath(const QPainterPath &path, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation...
Definition: qpainter.cpp:3365
bool extractBackground(QBrush *, QString *, Repeat *, Qt::Alignment *, QCss::Origin *, QCss::Attachment *, QCss::Origin *)
Definition: qcssparser.cpp:990
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const quint64 PseudoClass_Top
Definition: qcssparser_p.h:487
The QStyleOptionComplex class is used to hold parameters that are common to all complex controls...
Definition: qstyleoption.h:687
bool extractBorder(int *borders, QBrush *colors, BorderStyle *Styles, QSize *radii)
Definition: qcssparser.cpp:559
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
const quint64 PseudoClass_Default
Definition: qcssparser_p.h:477
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:53
The QWindowsStyle class provides a Microsoft Windows-like look and feel.
Definition: qwindowsstyle.h:57
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
const quint64 PseudoClass_Closable
Definition: qcssparser_p.h:494
QHash< const QWidget *, QVector< QCss::StyleRule > > styleRulesCache
void drawRule(QPainter *, const QRect &)
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
QColor lighter(int f=150) const
Returns a lighter (or darker) color, but does not change this object.
Definition: qcolor.h:298
int height() const
Returns the height of the font.
QSize boxSize(const QSize &s, int flags=All) const
NodePtr previousSiblingNode(NodePtr) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
static quint64 extendedPseudoClass(const QWidget *w)
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
QStyleSheetBoxData(int *m, int *p, int s)
bool isNullNode(NodePtr node) const
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
static QWidget * containerWidget(const QWidget *w)
static const char * knownStyleHints[]
static void updateWidgets(const QList< const QWidget *> &widgets)
int titleBarState
the state of the title bar
Definition: qstyleoption.h:824
Orientation
Definition: qnamespace.h:174
QSize size() const
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define qPrintable(string)
Definition: qglobal.h:1750
#define QT_NO_COMBOBOX
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:55
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
virtual void fontChange(const QFont &)
Definition: qwidget.cpp:12003
const quint64 PseudoClass_Disabled
Definition: qcssparser_p.h:463
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
The QStyleOptionButton class is used to describe the parameters for drawing buttons.
Definition: qstyleoption.h:279
int layoutSpacingImplementation(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=0, const QWidget *widget=0) const
#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
void repolish(QWidget *widget)
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
QSharedDataPointer< QStyleSheetPaletteData > pal
QList< T > findChildren(const QString &aName=QString()) const
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
Definition: qobject.h:162
virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt=0, const QWidget *widget=0) const =0
The QStyleOptionTabWidgetFrameV2 class is used to describe the parameters for drawing the frame aroun...
Definition: qstyleoption.h:196
virtual QPoint contentsOffset() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
#define INT_MAX
void updateStyleSheetFont(QWidget *w) const
int nativeFrameWidth(const QWidget *)
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
The QMdiSubWindow class provides a subwindow class for QMdiArea.
Definition: qmdisubwindow.h:60
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
#define enabled
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option=0, const QWidget *w=0) const
Reimplemented Function
Qt::Alignment alignmentValue() const
void setPalette(const QPalette &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4858
const quint64 PseudoClass_Floatable
Definition: qcssparser_p.h:496
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
#define QT_NO_TABBAR
void widgetDestroyed(QObject *)
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
bool extractFont(QFont *font, int *fontSizeAdjustment)
#define text
Definition: qobjectdefs.h:80
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w=0) const
Reimplemented Function
const QBrush & text() const
Returns the text foreground brush of the current color group.
Definition: qpalette.h:129
SubElement
This enum represents a sub-area of a widget.
Definition: qstyle.h:289
void clearWidgetFont(QWidget *w) const
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
static QMenuBar * fallback
Definition: qmenu_mac.mm:1617
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment=Qt::AlignCenter, Mode mode=Normal, State state=Off) const
Uses the painter to paint the icon with specified alignment, required mode, and state into the rectan...
Definition: qicon.cpp:744
const quint64 PseudoClass_On
Definition: qcssparser_p.h:499
bool extractPalette(QBrush *fg, QBrush *sfg, QBrush *sbg, QBrush *abg)
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget=0) const
Reimplemented Function
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
QStyleSheetGeometryData(int w, int h, int minw, int minh, int maxw, int maxh)
QSize contentsSize(const QSize &sz) const
const quint64 PseudoClass_NextSelected
Definition: qcssparser_p.h:483
const quint64 PseudoClass_Item
Definition: qcssparser_p.h:502
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60