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