Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qstylesheetstyle_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QSTYLESHEETSTYLE_P_H
6#define QSTYLESHEETSTYLE_P_H
7
8#include <QtWidgets/private/qtwidgetsglobal_p.h>
9#include "private/qwindowsstyle_p.h"
10
11#ifndef QT_NO_STYLE_STYLESHEET
12
13#include "QtWidgets/qapplication.h"
14#include "QtWidgets/qstyleoption.h"
15#include "QtCore/qhash.h"
16#include "QtCore/qlist.h"
17#include "QtCore/qset.h"
18#include "QtGui/qbrush.h"
19#include "QtGui/qevent.h"
20#include "private/qcssparser_p.h"
21
22QT_BEGIN_NAMESPACE
23
24//
25// W A R N I N G
26// -------------
27//
28// This file is not part of the Qt API. It exists purely as an
29// implementation detail. This header file may change from version to
30// version without notice, or even be removed.
31//
32// We mean it.
33//
34
35class QRenderRule;
36class QAbstractScrollArea;
37class QStyleSheetStylePrivate;
38class QStyleOptionTitleBar;
39
40class Q_AUTOTEST_EXPORT QStyleSheetStyle : public QWindowsStyle
41{
42 typedef QWindowsStyle ParentStyle;
43
44 Q_OBJECT
45public:
46 QStyleSheetStyle(QStyle *baseStyle);
47 ~QStyleSheetStyle();
48
49 void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p,
50 const QWidget *w = nullptr) const override;
51 void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p,
52 const QWidget *w = nullptr) const override;
53 void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const override;
54 void drawItemText(QPainter *painter, const QRect& rect, int alignment, const QPalette &pal,
55 bool enabled, const QString& text, QPalette::ColorRole textRole = QPalette::NoRole) const override;
56 void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
57 const QWidget *w = nullptr) const override;
58 QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
59 const QStyleOption *option) const override;
60 SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
61 const QPoint &pt, const QWidget *w = nullptr) const override;
62 QRect itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pixmap) const override;
63 QRect itemTextRect(const QFontMetrics &metrics, const QRect &rect, int alignment, bool enabled,
64 const QString &text) const override;
65 int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override;
66 void polish(QWidget *widget) override;
67 void polish(QApplication *app) override;
68 void polish(QPalette &pal) override;
69 QSize sizeFromContents(ContentsType ct, const QStyleOption *opt,
70 const QSize &contentsSize, const QWidget *widget = nullptr) const override;
71 QPalette standardPalette() const override;
72 QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *opt = nullptr,
73 const QWidget *widget = nullptr) const override;
74 QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option = nullptr,
75 const QWidget *w = nullptr ) const override;
76 int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2,
77 Qt::Orientation orientation, const QStyleOption *option = nullptr,
78 const QWidget *widget = nullptr) const override;
79 int styleHint(StyleHint sh, const QStyleOption *opt = nullptr, const QWidget *w = nullptr,
80 QStyleHintReturn *shret = nullptr) const override;
81 QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr) const override;
82 QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc,
83 const QWidget *w = nullptr) const override;
84
85 // These functions are called from QApplication/QWidget. Be careful.
86 QStyle *baseStyle() const;
87 void repolish(QWidget *widget);
88 void repolish(QApplication *app);
89
90 void unpolish(QWidget *widget) override;
91 void unpolish(QApplication *app) override;
92
93 QStyle *base;
94 void ref() { ++refcount; }
95 void deref() { Q_ASSERT(refcount > 0); if (!--refcount) delete this; }
96
97 void updateStyleSheetFont(QWidget* w) const;
98 void saveWidgetFont(QWidget* w, const QFont& font) const;
99 void clearWidgetFont(QWidget* w) const;
100
101 bool styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal);
102
103protected:
104 bool event(QEvent *e) override;
105
106private:
107 int refcount;
108
109 friend class QRenderRule;
110 int nativeFrameWidth(const QWidget *);
111 QRenderRule renderRule(const QObject *, int, quint64 = 0) const;
112 QRenderRule renderRule(const QObject *, const QStyleOption *, int = 0) const;
113 QSize defaultSize(const QWidget *, QSize, const QRect&, int) const;
114 QRect positionRect(const QWidget *, const QRenderRule&, const QRenderRule&, int,
115 const QRect&, Qt::LayoutDirection) const;
116 QRect positionRect(const QWidget *w, const QRenderRule &rule2, int pe,
117 const QRect &originRect, Qt::LayoutDirection dir) const;
118
119 mutable QCss::Parser parser;
120
121 void setPalette(QWidget *);
122 void unsetPalette(QWidget *);
123 void setProperties(QWidget *);
124 void setGeometry(QWidget *);
125 void unsetStyleSheetFont(QWidget *) const;
126 QList<QCss::StyleRule> styleRules(const QObject *obj) const;
127 bool hasStyleRule(const QObject *obj, int part) const;
128
129 QHash<QStyle::SubControl, QRect> titleBarLayout(const QWidget *w, const QStyleOptionTitleBar *tb) const;
130
131 QCss::StyleSheet getDefaultStyleSheet() const;
132
133 static Qt::Alignment resolveAlignment(Qt::LayoutDirection, Qt::Alignment);
134 static bool isNaturalChild(const QObject *obj);
135 static QPixmap loadPixmap(const QString &fileName, const QObject *context);
136 bool initObject(const QObject *obj) const;
137 void renderMenuItemIcon(const QStyleOptionMenuItem *mi, QPainter *p, const QWidget *w,
138 const QRect &rect, QRenderRule &subRule) const;
139public:
140 static int numinstances;
141
142private:
143 Q_DISABLE_COPY_MOVE(QStyleSheetStyle)
144 Q_DECLARE_PRIVATE(QStyleSheetStyle)
145};
146
148{
150public Q_SLOTS:
152 void styleDestroyed(QObject *);
153public:
155 QHash<const QObject *, QHash<int, bool> > hasStyleRuleCache;
158 QHash<const void *, QCss::StyleSheet> styleSheetCache; // parsed style sheets
160 // widgets with whose palettes and fonts we have tampered:
161 template <typename T>
162 struct Tampered {
164 decltype(std::declval<T>().resolveMask()) resolveMask;
165
166 // only call this function on an rvalue *this (it mangles oldWidgetValue)
167 T reverted(T current)
168#ifdef Q_COMPILER_REF_QUALIFIERS
169 &&
170#endif
171 {
172 oldWidgetValue.setResolveMask(oldWidgetValue.resolveMask() & resolveMask);
173 current.setResolveMask(current.resolveMask() & ~resolveMask);
174 current.resolve(oldWidgetValue);
175 current.setResolveMask(current.resolveMask() | oldWidgetValue.resolveMask());
176 return current;
177 }
178 };
181};
182template <typename T>
185
186
187// Returns a QStyleSheet from the given style.
188inline QStyleSheetStyle* qt_styleSheet(QStyle *style)
189{
190 return qobject_cast<QStyleSheetStyle *>(style);
191}
192
193QT_END_NAMESPACE
194#endif // QT_NO_STYLE_STYLESHEET
195#endif // QSTYLESHEETSTYLE_P_H
QHash< const void *, QCss::StyleSheet > styleSheetCache
void styleDestroyed(QObject *)
QHash< const QObject *, QRenderRules > renderRulesCache
QSet< const QWidget * > autoFillDisabledWidgets
QHash< int, QHash< quint64, QRenderRule > > QRenderRules
QStyleSheetStyle * qt_styleSheet(QStyle *style)
decltype(std::declval< T >().resolveMask()) resolveMask