styles/qstylesheetstyle.cpp

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

Generated by Squish Coco Non-Commercial