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