5#ifndef QSTYLESHEETSTYLE_P_H
6#define QSTYLESHEETSTYLE_P_H
8#include <QtWidgets/private/qtwidgetsglobal_p.h>
10#if QT_CONFIG(style_windows)
11#include "private/qwindowsstyle_p.h"
13#if QT_CONFIG(style_stylesheet)
15#include "QtWidgets/qapplication.h"
16#include "QtWidgets/qstyleoption.h"
17#include "QtCore/qhash.h"
18#include "QtCore/qlist.h"
19#include "QtCore/qset.h"
20#include "QtGui/qbrush.h"
21#include "QtGui/qevent.h"
22#include "private/qcssparser_p.h"
38class QAbstractScrollArea;
39class QStyleSheetStylePrivate;
40class QStyleOptionTitleBar;
42class Q_AUTOTEST_EXPORT QStyleSheetStyle :
public QWindowsStyle
44 typedef QWindowsStyle ParentStyle;
48 QStyleSheetStyle(QStyle *baseStyle);
51 void drawComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt, QPainter *p,
52 const QWidget *w =
nullptr)
const override;
53 void drawControl(ControlElement element,
const QStyleOption *opt, QPainter *p,
54 const QWidget *w =
nullptr)
const override;
55 void drawItemPixmap(QPainter *painter,
const QRect &rect,
int alignment,
const QPixmap &pixmap)
const override;
56 void drawItemText(QPainter *painter,
const QRect& rect,
int alignment,
const QPalette &pal,
57 bool enabled,
const QString& text, QPalette::ColorRole textRole = QPalette::NoRole)
const override;
58 void drawPrimitive(PrimitiveElement pe,
const QStyleOption *opt, QPainter *p,
59 const QWidget *w =
nullptr)
const override;
60 QPixmap generatedIconPixmap(QIcon::Mode iconMode,
const QPixmap &pixmap,
61 const QStyleOption *option)
const override;
62 SubControl hitTestComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt,
63 const QPoint &pt,
const QWidget *w =
nullptr)
const override;
64 QRect itemPixmapRect(
const QRect &rect,
int alignment,
const QPixmap &pixmap)
const override;
65 QRect itemTextRect(
const QFontMetrics &metrics,
const QRect &rect,
int alignment,
bool enabled,
66 const QString &text)
const override;
67 int pixelMetric(PixelMetric metric,
const QStyleOption *option =
nullptr,
const QWidget *widget =
nullptr)
const override;
68 void polish(QWidget *widget) override;
69 void polish(QApplication *app) override;
70 void polish(QPalette &pal) override;
71 QSize sizeFromContents(ContentsType ct,
const QStyleOption *opt,
72 const QSize &contentsSize,
const QWidget *widget =
nullptr)
const override;
73 QPalette standardPalette()
const override;
74 QIcon standardIcon(StandardPixmap standardIcon,
const QStyleOption *opt =
nullptr,
75 const QWidget *widget =
nullptr)
const override;
76 QPixmap standardPixmap(StandardPixmap standardPixmap,
const QStyleOption *option =
nullptr,
77 const QWidget *w =
nullptr )
const override;
78 int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2,
79 Qt::Orientation orientation,
const QStyleOption *option =
nullptr,
80 const QWidget *widget =
nullptr)
const override;
81 int styleHint(StyleHint sh,
const QStyleOption *opt =
nullptr,
const QWidget *w =
nullptr,
82 QStyleHintReturn *shret =
nullptr)
const override;
83 QRect subElementRect(SubElement r,
const QStyleOption *opt,
const QWidget *widget =
nullptr)
const override;
84 QRect subControlRect(ComplexControl cc,
const QStyleOptionComplex *opt, SubControl sc,
85 const QWidget *w =
nullptr)
const override;
88 QStyle *baseStyle()
const;
89 void repolish(QWidget *widget);
90 void repolish(QApplication *app);
92 void unpolish(QWidget *widget) override;
93 void unpolish(QApplication *app) override;
96 void ref() { ++refcount; }
97 void deref() { Q_ASSERT(refcount > 0);
if (!--refcount)
delete this; }
99 void updateStyleSheetFont(QWidget* w)
const;
100 void saveWidgetFont(QWidget* w,
const QFont& font)
const;
101 void clearWidgetFont(QWidget* w)
const;
103 bool styleSheetPalette(
const QWidget* w,
const QStyleOption* opt, QPalette* pal);
106 bool event(QEvent *e) override;
111 friend class QRenderRule;
112 int nativeFrameWidth(
const QWidget *);
113 QRenderRule renderRule(
const QWidget *,
int, quint64 = 0)
const;
114 QRenderRule renderRule(
const QWidget *,
const QStyleOption *,
int = 0)
const;
115 QSize defaultSize(
const QWidget *, QSize,
const QRect&,
int)
const;
116 QRect positionRect(
const QWidget *,
const QRenderRule&,
const QRenderRule&,
int,
117 const QRect&, Qt::LayoutDirection)
const;
118 QRect positionRect(
const QWidget *w,
const QRenderRule &rule2,
int pe,
119 const QRect &originRect, Qt::LayoutDirection dir)
const;
121 mutable QCss::Parser parser;
123 void setPalette(QWidget *);
124 void unsetPalette(QWidget *);
125 void setProperties(QWidget *);
126 void setGeometry(QWidget *);
127 void unsetStyleSheetFont(QWidget *)
const;
128 QList<QCss::StyleRule> styleRules(
const QWidget *w)
const;
129 bool hasStyleRule(
const QWidget *w,
int part)
const;
131 QHash<QStyle::SubControl, QRect> titleBarLayout(
const QWidget *w,
const QStyleOptionTitleBar *tb)
const;
133 QCss::StyleSheet getDefaultStyleSheet()
const;
135 static Qt::Alignment resolveAlignment(Qt::LayoutDirection, Qt::Alignment);
136 static bool isNaturalChild(
const QObject *obj);
137 static QPixmap loadPixmap(
const QString &fileName,
const QObject *context);
138 bool initWidget(
const QWidget *w)
const;
139 void renderMenuItemIcon(
const QStyleOptionMenuItem *mi, QPainter *p,
const QWidget *w,
140 const QRect &rect, QRenderRule &subRule)
const;
142 static int numinstances;
145 Q_DISABLE_COPY_MOVE(QStyleSheetStyle)
146 Q_DECLARE_PRIVATE(QStyleSheetStyle)
149class QStyleSheetStyleCaches :
public QObject
153 void objectDestroyed(QObject *);
154 void styleDestroyed(QObject *);
156 QHash<
const QObject *, QList<QCss::StyleRule>> styleRulesCache;
157 QHash<
const QObject *, QHash<
int,
bool> > hasStyleRuleCache;
158 typedef QHash<
int, QHash<quint64, QRenderRule> > QRenderRules;
159 QHash<
const QObject *, QRenderRules> renderRulesCache;
160 QHash<
const void *, QCss::StyleSheet> styleSheetCache;
161 QSet<
const QWidget *> autoFillDisabledWidgets;
163 template <
typename T>
166 decltype(std::declval<T>().resolveMask()) resolveMask;
169 T reverted(T current)
170#ifdef Q_COMPILER_REF_QUALIFIERS
174 oldWidgetValue.setResolveMask(oldWidgetValue.resolveMask() & resolveMask);
175 current.setResolveMask(current.resolveMask() & ~resolveMask);
176 current.resolve(oldWidgetValue);
177 current.setResolveMask(current.resolveMask() | oldWidgetValue.resolveMask());
181 QHash<
const QWidget *, Tampered<QPalette>> customPaletteWidgets;
182 QHash<
const QWidget *, Tampered<QFont>> customFontWidgets;
185class QTypeInfo<QStyleSheetStyleCaches::Tampered<T>>
186 :
public QTypeInfoMerger<QStyleSheetStyleCaches::Tampered<T>, T> {};
190inline QStyleSheetStyle* qt_styleSheet(QStyle *style)
192 return qobject_cast<QStyleSheetStyle *>(style);