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