Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QSTYLESHEETSTYLE_P_H
5#define QSTYLESHEETSTYLE_P_H
6
7#include <QtWidgets/private/qtwidgetsglobal_p.h>
8#include "private/qwindowsstyle_p.h"
9
10#ifndef QT_NO_STYLE_STYLESHEET
11
12#include "QtWidgets/qapplication.h"
13#include "QtWidgets/qstyleoption.h"
14#include "QtCore/qhash.h"
15#include "QtCore/qlist.h"
16#include "QtCore/qset.h"
17#include "QtGui/qbrush.h"
18#include "QtGui/qevent.h"
19#include "private/qcssparser_p.h"
20
22
23//
24// W A R N I N G
25// -------------
26//
27// This file is not part of the Qt API. It exists purely as an
28// implementation detail. This header file may change from version to
29// version without notice, or even be removed.
30//
31// We mean it.
32//
33
34class QRenderRule;
35class QAbstractScrollArea;
36class QStyleSheetStylePrivate;
38
39class Q_AUTOTEST_EXPORT QStyleSheetStyle : public QWindowsStyle
40{
41 typedef QWindowsStyle ParentStyle;
42
44public:
47
48 void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p,
49 const QWidget *w = nullptr) const override;
50 void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p,
51 const QWidget *w = nullptr) const override;
52 void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const override;
53 void drawItemText(QPainter *painter, const QRect& rect, int alignment, const QPalette &pal,
54 bool enabled, const QString& text, QPalette::ColorRole textRole = QPalette::NoRole) const override;
55 void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
56 const QWidget *w = nullptr) const override;
58 const QStyleOption *option) const override;
59 SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
60 const QPoint &pt, const QWidget *w = nullptr) const override;
61 QRect itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pixmap) const override;
63 const QString &text) const override;
64 int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override;
65 void polish(QWidget *widget) override;
66 void polish(QApplication *app) override;
67 void polish(QPalette &pal) override;
68 QSize sizeFromContents(ContentsType ct, const QStyleOption *opt,
69 const QSize &contentsSize, const QWidget *widget = nullptr) const override;
70 QPalette standardPalette() const override;
71 QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *opt = nullptr,
72 const QWidget *widget = nullptr) const override;
73 QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option = nullptr,
74 const QWidget *w = nullptr ) const override;
76 Qt::Orientation orientation, const QStyleOption *option = nullptr,
77 const QWidget *widget = nullptr) const override;
78 int styleHint(StyleHint sh, const QStyleOption *opt = nullptr, const QWidget *w = nullptr,
79 QStyleHintReturn *shret = nullptr) const override;
80 QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr) const override;
81 QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc,
82 const QWidget *w = nullptr) const override;
83
84 // These functions are called from QApplication/QWidget. Be careful.
85 QStyle *baseStyle() const;
88
89 void unpolish(QWidget *widget) override;
90 void unpolish(QApplication *app) override;
91
93 void ref() { ++refcount; }
94 void deref() { Q_ASSERT(refcount > 0); if (!--refcount) delete this; }
95
97 void saveWidgetFont(QWidget* w, const QFont& font) const;
99
101
102protected:
103 bool event(QEvent *e) override;
104
105private:
106 int refcount;
107
108 friend class QRenderRule;
109 int nativeFrameWidth(const QWidget *);
110 QRenderRule renderRule(const QObject *, int, quint64 = 0) const;
111 QRenderRule renderRule(const QObject *, const QStyleOption *, int = 0) const;
112 QSize defaultSize(const QWidget *, QSize, const QRect&, int) const;
113 QRect positionRect(const QWidget *, const QRenderRule&, const QRenderRule&, int,
114 const QRect&, Qt::LayoutDirection) const;
115 QRect positionRect(const QWidget *w, const QRenderRule &rule2, int pe,
116 const QRect &originRect, Qt::LayoutDirection dir) const;
117
118 mutable QCss::Parser parser;
119
120 void setPalette(QWidget *);
121 void unsetPalette(QWidget *);
122 void setProperties(QWidget *);
123 void setGeometry(QWidget *);
124 void unsetStyleSheetFont(QWidget *) const;
125 QList<QCss::StyleRule> styleRules(const QObject *obj) const;
126 bool hasStyleRule(const QObject *obj, int part) const;
127
128 QHash<QStyle::SubControl, QRect> titleBarLayout(const QWidget *w, const QStyleOptionTitleBar *tb) const;
129
130 QCss::StyleSheet getDefaultStyleSheet() const;
131
132 static Qt::Alignment resolveAlignment(Qt::LayoutDirection, Qt::Alignment);
133 static bool isNaturalChild(const QObject *obj);
134 static QPixmap loadPixmap(const QString &fileName, const QObject *context);
135 bool initObject(const QObject *obj) const;
136 void renderMenuItemIcon(const QStyleOptionMenuItem *mi, QPainter *p, const QWidget *w,
137 const QRect &rect, QRenderRule &subRule) const;
138public:
139 static int numinstances;
140
141private:
142 Q_DISABLE_COPY_MOVE(QStyleSheetStyle)
143 Q_DECLARE_PRIVATE(QStyleSheetStyle)
144};
145
147{
149public Q_SLOTS:
152public:
153 QHash<const QObject *, QList<QCss::StyleRule>> styleRulesCache;
154 QHash<const QObject *, QHash<int, bool> > hasStyleRuleCache;
155 typedef QHash<int, QHash<quint64, QRenderRule> > QRenderRules;
156 QHash<const QObject *, QRenderRules> renderRulesCache;
157 QHash<const void *, QCss::StyleSheet> styleSheetCache; // parsed style sheets
158 QSet<const QWidget *> autoFillDisabledWidgets;
159 // widgets with whose palettes and fonts we have tampered:
160 template <typename T>
161 struct Tampered {
163 decltype(std::declval<T>().resolveMask()) resolveMask;
164
165 // only call this function on an rvalue *this (it mangles oldWidgetValue)
166 T reverted(T current)
167#ifdef Q_COMPILER_REF_QUALIFIERS
168 &&
169#endif
170 {
171 oldWidgetValue.setResolveMask(oldWidgetValue.resolveMask() & resolveMask);
172 current.setResolveMask(current.resolveMask() & ~resolveMask);
173 current.resolve(oldWidgetValue);
174 current.setResolveMask(current.resolveMask() | oldWidgetValue.resolveMask());
175 return current;
176 }
177 };
178 QHash<const QWidget *, Tampered<QPalette>> customPaletteWidgets;
179 QHash<const QWidget *, Tampered<QFont>> customFontWidgets;
180};
181template <typename T>
183 : public QTypeInfoMerger<QStyleSheetStyleCaches::Tampered<T>, T> {};
184
185
186// Returns a QStyleSheet from the given style.
188{
189 return qobject_cast<QStyleSheetStyle *>(style);
190}
191
193#endif // QT_NO_STYLE_STYLESHEET
194#endif // QSTYLESHEETSTYLE_P_H
The QApplication class manages the GUI application's control flow and main settings.
\inmodule QtCore
Definition qcoreevent.h:45
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:22
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition qicon.h:22
\inmodule QtCore
Definition qobject.h:103
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\variable QStyleOptionGraphicsItem::exposedRect
\variable QStyleOptionMenuItem::menuItemType
\variable QStyleOptionProgressBar::minimum
\variable QStyleOptionToolBox::selectedPosition
The QStyleOption class stores the parameters used by QStyle functions.
QHash< const QObject *, QList< QCss::StyleRule > > styleRulesCache
QHash< const QWidget *, Tampered< QFont > > customFontWidgets
QHash< const QWidget *, Tampered< QPalette > > customPaletteWidgets
QHash< const void *, QCss::StyleSheet > styleSheetCache
void styleDestroyed(QObject *)
QHash< const QObject *, QRenderRules > renderRulesCache
QHash< const QObject *, QHash< int, bool > > hasStyleRuleCache
QSet< const QWidget * > autoFillDisabledWidgets
QHash< int, QHash< quint64, QRenderRule > > QRenderRules
void objectDestroyed(QObject *)
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const override
bool styleSheetPalette(const QWidget *w, const QStyleOption *opt, QPalette *pal)
void drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const override
void updateStyleSheetFont(QWidget *w) const
void polish(QApplication *app) override
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr) const override
QStyleSheetStyle(QStyle *baseStyle)
QRect itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pixmap) const override
void unpolish(QWidget *widget) override
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option=nullptr, const QWidget *w=nullptr) const override
int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const override
int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
void unpolish(QApplication *app) override
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w=nullptr) const override
void polish(QWidget *widget) override
void repolish(QWidget *widget)
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget=nullptr) const override
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w=nullptr) const override
QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget=nullptr) const override
void saveWidgetFont(QWidget *w, const QFont &font) const
int styleHint(StyleHint sh, const QStyleOption *opt=nullptr, const QWidget *w=nullptr, QStyleHintReturn *shret=nullptr) const override
bool event(QEvent *e) override
void clearWidgetFont(QWidget *w) const
QPalette standardPalette() const override
void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const override
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w=nullptr) const override
QRect itemTextRect(const QFontMetrics &metrics, const QRect &rect, int alignment, bool enabled, const QString &text) const override
QStyle * baseStyle() const
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const override
void polish(QPalette &pal) override
void repolish(QApplication *app)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
\inmodule QtCore
Definition qtypeinfo.h:100
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
QString text
rect
[4]
uint alignment
QStyleOptionButton opt
Combined button and popup list for selecting options.
LayoutDirection
Orientation
Definition qnamespace.h:98
static void * context
GLfloat GLfloat GLfloat w
[0]
GLboolean r
[2]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
GLhandleARB obj
[2]
GLfloat GLfloat p
[1]
GLuint GLenum option
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static void setProperties(QQuick3DObject &obj, const QSSGSceneDesc::Node &node, const QString &workingDir={})
QStyleSheetStyle * qt_styleSheet(QStyle *style)
#define Q_AUTOTEST_EXPORT
#define Q_OBJECT
#define Q_SLOTS
unsigned long long quint64
Definition qtypes.h:61
QString dir
[11]
QApplication app(argc, argv)
[0]
widget render & pixmap
QPainter painter(this)
[7]
decltype(std::declval< T >().resolveMask()) resolveMask