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 "QtCore/private/qflatmap_p.h"
21#include "QtGui/qbrush.h"
22#include "QtGui/qevent.h"
23#include "private/qcssparser_p.h"
39class QAbstractScrollArea;
40class QStyleSheetStylePrivate;
41class QStyleOptionTitleBar;
43class Q_AUTOTEST_EXPORT QStyleSheetStyle :
public QWindowsStyle
45 typedef QWindowsStyle ParentStyle;
49 QStyleSheetStyle(QStyle *baseStyle);
52 void drawComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt, QPainter *p,
53 const QWidget *w =
nullptr)
const override;
54 void drawControl(ControlElement element,
const QStyleOption *opt, QPainter *p,
55 const QWidget *w =
nullptr)
const override;
56 void drawItemPixmap(QPainter *painter,
const QRect &rect,
int alignment,
const QPixmap &pixmap)
const override;
57 void drawItemText(QPainter *painter,
const QRect& rect,
int alignment,
const QPalette &pal,
58 bool enabled,
const QString& text, QPalette::ColorRole textRole = QPalette::NoRole)
const override;
59 void drawPrimitive(PrimitiveElement pe,
const QStyleOption *opt, QPainter *p,
60 const QWidget *w =
nullptr)
const override;
61 QPixmap generatedIconPixmap(QIcon::Mode iconMode,
const QPixmap &pixmap,
62 const QStyleOption *option)
const override;
63 SubControl hitTestComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt,
64 const QPoint &pt,
const QWidget *w =
nullptr)
const override;
65 QRect itemPixmapRect(
const QRect &rect,
int alignment,
const QPixmap &pixmap)
const override;
66 QRect itemTextRect(
const QFontMetrics &metrics,
const QRect &rect,
int alignment,
bool enabled,
67 const QString &text)
const override;
68 int pixelMetric(PixelMetric metric,
const QStyleOption *option =
nullptr,
const QWidget *widget =
nullptr)
const override;
69 void polish(QWidget *widget) override;
70 void polish(QApplication *app) override;
71 void polish(QPalette &pal) override;
72 QSize sizeFromContents(ContentsType ct,
const QStyleOption *opt,
73 const QSize &contentsSize,
const QWidget *widget =
nullptr)
const override;
74 QPalette standardPalette()
const override;
75 QIcon standardIcon(StandardPixmap standardIcon,
const QStyleOption *opt =
nullptr,
76 const QWidget *widget =
nullptr)
const override;
77 QPixmap standardPixmap(StandardPixmap standardPixmap,
const QStyleOption *option =
nullptr,
78 const QWidget *w =
nullptr )
const override;
79 int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2,
80 Qt::Orientation orientation,
const QStyleOption *option =
nullptr,
81 const QWidget *widget =
nullptr)
const override;
82 int styleHint(StyleHint sh,
const QStyleOption *opt =
nullptr,
const QWidget *w =
nullptr,
83 QStyleHintReturn *shret =
nullptr)
const override;
84 QRect subElementRect(SubElement r,
const QStyleOption *opt,
const QWidget *widget =
nullptr)
const override;
85 QRect subControlRect(ComplexControl cc,
const QStyleOptionComplex *opt, SubControl sc,
86 const QWidget *w =
nullptr)
const override;
89 QStyle *baseStyle()
const;
90 void repolish(QWidget *widget);
91 void repolish(QApplication *app);
93 void unpolish(QWidget *widget) override;
94 void unpolish(QApplication *app) override;
97 void ref() { ++refcount; }
98 void deref() { Q_ASSERT(refcount > 0);
if (!--refcount)
delete this; }
100 void updateStyleSheetFont(QWidget* w)
const;
101 void saveWidgetFont(QWidget* w,
const QFont& font)
const;
102 void clearWidgetFont(QWidget* w)
const;
104 bool styleSheetPalette(
const QWidget* w,
const QStyleOption* opt, QPalette* pal);
107 bool event(QEvent *e) override;
112 friend class QRenderRule;
113 int nativeFrameWidth(
const QWidget *)
const;
114 QRenderRule renderRule(
const QWidget *,
int, quint64 = 0)
const;
115 QRenderRule renderRule(
const QWidget *,
const QStyleOption *,
int = 0)
const;
116 QSize defaultSize(
const QWidget *, QSize,
const QRect&,
int)
const;
117 QRect positionRect(
const QWidget *,
const QRenderRule&,
const QRenderRule&,
int,
118 const QRect&, Qt::LayoutDirection)
const;
119 QRect positionRect(
const QWidget *w,
const QRenderRule &rule2,
int pe,
120 const QRect &originRect, Qt::LayoutDirection dir)
const;
122 mutable QCss::Parser parser;
124 void setPalette(QWidget *);
125 void unsetPalette(QWidget *);
126 void setProperties(QWidget *);
127 void setGeometry(QWidget *);
128 void unsetStyleSheetFont(QWidget *)
const;
129 QList<QCss::StyleRule> styleRules(
const QWidget *w)
const;
130 bool hasStyleRule(
const QWidget *w,
int part)
const;
132 QHash<QStyle::SubControl, QRect> titleBarLayout(
const QWidget *w,
const QStyleOptionTitleBar *tb)
const;
134 QCss::StyleSheet getDefaultStyleSheet()
const;
136 static Qt::Alignment resolveAlignment(Qt::LayoutDirection, Qt::Alignment);
137 static bool isNaturalChild(
const QObject *obj);
138 static QPixmap loadPixmap(
const QString &fileName,
const QObject *context);
139 bool initWidget(
const QWidget *w)
const;
140 void renderMenuItemIcon(
const QStyleOptionMenuItem *mi, QPainter *p,
const QWidget *w,
141 const QRect &rect, QRenderRule &subRule)
const;
143 static int numinstances;
146 Q_DISABLE_COPY_MOVE(QStyleSheetStyle)
147 Q_DECLARE_PRIVATE(QStyleSheetStyle)
150class QStyleSheetStyleCaches :
public QObject
154 void objectDestroyed(QObject *);
155 void styleDestroyed(QObject *);
157 QHash<
const QObject *, QList<QCss::StyleRule>> styleRulesCache;
158 QHash<
const QObject *, QVarLengthFlatMap<
int,
bool, 4>> hasStyleRuleCache;
159 typedef QVarLengthFlatMap<
int, QHash<quint64, QRenderRule>, 4> QRenderRules;
160 QHash<
const QObject *, QRenderRules> renderRulesCache;
161 QHash<
const void *, QCss::StyleSheet> styleSheetCache;
162 QSet<
const QWidget *> autoFillDisabledWidgets;
164 template <
typename T>
167 decltype(std::declval<T>().resolveMask()) resolveMask;
170 T reverted(T current)
171#ifdef Q_COMPILER_REF_QUALIFIERS
175 oldWidgetValue.setResolveMask(oldWidgetValue.resolveMask() & resolveMask);
176 current.setResolveMask(current.resolveMask() & ~resolveMask);
177 current.resolve(oldWidgetValue);
178 current.setResolveMask(current.resolveMask() | oldWidgetValue.resolveMask());
182 QHash<
const QWidget *, Tampered<QPalette>> customPaletteWidgets;
183 QHash<
const QWidget *, Tampered<QFont>> customFontWidgets;
186class QTypeInfo<QStyleSheetStyleCaches::Tampered<T>>
187 :
public QTypeInfoMerger<QStyleSheetStyleCaches::Tampered<T>, T> {};
191inline QStyleSheetStyle* qt_styleSheet(QStyle *style)
193 return qobject_cast<QStyleSheetStyle *>(style);