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