1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QSTYLESHEETSTYLE_P_H |
43 | #define QSTYLESHEETSTYLE_P_H |
44 | |
45 | #include "QtGui/qwindowsstyle.h" |
46 | |
47 | #ifndef QT_NO_STYLE_STYLESHEET |
48 | |
49 | #include "QtGui/qstyleoption.h" |
50 | #include "QtCore/qhash.h" |
51 | #include "QtGui/qevent.h" |
52 | #include "QtCore/qvector.h" |
53 | #include "QtGui/qapplication.h" |
54 | #include "private/qcssparser_p.h" |
55 | #include "QtGui/qbrush.h" |
56 | |
57 | QT_BEGIN_NAMESPACE |
58 | |
59 | // |
60 | // W A R N I N G |
61 | // ------------- |
62 | // |
63 | // This file is not part of the Qt API. It exists purely as an |
64 | // implementation detail. This header file may change from version to |
65 | // version without notice, or even be removed. |
66 | // |
67 | // We mean it. |
68 | // |
69 | |
70 | class QRenderRule; |
71 | class QAbstractScrollArea; |
72 | class QStyleSheetStylePrivate; |
73 | class QStyleOptionTitleBar; |
74 | |
75 | class Q_AUTOTEST_EXPORT QStyleSheetStyle : public QWindowsStyle |
76 | { |
77 | typedef QWindowsStyle ParentStyle; |
78 | |
79 | Q_OBJECT |
80 | public: |
81 | QStyleSheetStyle(QStyle *baseStyle); |
82 | ~QStyleSheetStyle(); |
83 | |
84 | void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, |
85 | const QWidget *w = 0) const; |
86 | void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, |
87 | const QWidget *w = 0) const; |
88 | void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const; |
89 | void drawItemText(QPainter *painter, const QRect& rect, int alignment, const QPalette &pal, |
90 | bool enabled, const QString& text, QPalette::ColorRole textRole = QPalette::NoRole) const; |
91 | void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, |
92 | const QWidget *w = 0) const; |
93 | QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, |
94 | const QStyleOption *option) const; |
95 | SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, |
96 | const QPoint &pt, const QWidget *w = 0) const; |
97 | QRect itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pixmap) const; |
98 | QRect itemTextRect(const QFontMetrics &metrics, const QRect &rect, int alignment, bool enabled, |
99 | const QString &text) const; |
100 | int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const; |
101 | void polish(QWidget *widget); |
102 | void polish(QApplication *app); |
103 | void polish(QPalette &pal); |
104 | QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, |
105 | const QSize &contentsSize, const QWidget *widget = 0) const; |
106 | QPalette standardPalette() const; |
107 | QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option = 0, |
108 | const QWidget *w = 0 ) const; |
109 | int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, |
110 | Qt::Orientation orientation, const QStyleOption *option = 0, |
111 | const QWidget *widget = 0) const; |
112 | int styleHint(StyleHint sh, const QStyleOption *opt = 0, const QWidget *w = 0, |
113 | QStyleHintReturn *shret = 0) const; |
114 | QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget = 0) const; |
115 | QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, |
116 | const QWidget *w = 0) const; |
117 | |
118 | // These functions are called from QApplication/QWidget. Be careful. |
119 | QStyle *baseStyle() const; |
120 | void repolish(QWidget *widget); |
121 | void repolish(QApplication *app); |
122 | |
123 | void unpolish(QWidget *widget); |
124 | void unpolish(QApplication *app); |
125 | |
126 | QStyle *base; |
127 | void ref() { ++refcount; } |
128 | void deref() { Q_ASSERT(refcount > 0); if (!--refcount) delete this; } |
129 | |
130 | void updateStyleSheetFont(QWidget* w) const; |
131 | void saveWidgetFont(QWidget* w, const QFont& font) const; |
132 | void clearWidgetFont(QWidget* w) const; |
133 | |
134 | bool styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal); |
135 | |
136 | protected Q_SLOTS: |
137 | QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt = 0, |
138 | const QWidget *widget = 0) const; |
139 | int layoutSpacingImplementation(QSizePolicy::ControlType control1, |
140 | QSizePolicy::ControlType control2, |
141 | Qt::Orientation orientation, |
142 | const QStyleOption *option = 0, |
143 | const QWidget *widget = 0) const; |
144 | |
145 | protected: |
146 | bool event(QEvent *e); |
147 | |
148 | private: |
149 | int refcount; |
150 | |
151 | friend class QRenderRule; |
152 | int nativeFrameWidth(const QWidget *); |
153 | QRenderRule renderRule(const QWidget *, int, quint64 = 0) const; |
154 | QRenderRule renderRule(const QWidget *, const QStyleOption *, int = 0) const; |
155 | QSize defaultSize(const QWidget *, QSize, const QRect&, int) const; |
156 | QRect positionRect(const QWidget *, const QRenderRule&, const QRenderRule&, int, |
157 | const QRect&, Qt::LayoutDirection) const; |
158 | QRect positionRect(const QWidget *w, const QRenderRule &rule2, int pe, |
159 | const QRect &originRect, Qt::LayoutDirection dir) const; |
160 | |
161 | mutable QCss::Parser parser; |
162 | |
163 | void setPalette(QWidget *); |
164 | void unsetPalette(QWidget *); |
165 | void setProperties(QWidget *); |
166 | void setGeometry(QWidget *); |
167 | QVector<QCss::StyleRule> styleRules(const QWidget *w) const; |
168 | bool hasStyleRule(const QWidget *w, int part) const; |
169 | |
170 | QHash<QStyle::SubControl, QRect> titleBarLayout(const QWidget *w, const QStyleOptionTitleBar *tb) const; |
171 | |
172 | QCss::StyleSheet getDefaultStyleSheet() const; |
173 | |
174 | static Qt::Alignment resolveAlignment(Qt::LayoutDirection, Qt::Alignment); |
175 | static bool isNaturalChild(const QWidget *w); |
176 | bool initWidget(const QWidget *w) const; |
177 | public: |
178 | static int numinstances; |
179 | |
180 | private: |
181 | Q_DISABLE_COPY(QStyleSheetStyle) |
182 | Q_DECLARE_PRIVATE(QStyleSheetStyle) |
183 | }; |
184 | |
185 | class QStyleSheetStyleCaches : public QObject |
186 | { |
187 | Q_OBJECT |
188 | public Q_SLOTS: |
189 | void widgetDestroyed(QObject *); |
190 | void styleDestroyed(QObject *); |
191 | public: |
192 | QHash<const QWidget *, QVector<QCss::StyleRule> > styleRulesCache; |
193 | QHash<const QWidget *, QHash<int, bool> > hasStyleRuleCache; |
194 | typedef QHash<int, QHash<quint64, QRenderRule> > QRenderRules; |
195 | QHash<const QWidget *, QRenderRules> renderRulesCache; |
196 | QHash<const QWidget *, QPalette> customPaletteWidgets; // widgets whose palette we tampered |
197 | QHash<const void *, QCss::StyleSheet> styleSheetCache; // parsed style sheets |
198 | QSet<const QWidget *> autoFillDisabledWidgets; |
199 | }; |
200 | |
201 | |
202 | QT_END_NAMESPACE |
203 | #endif // QT_NO_STYLE_STYLESHEET |
204 | #endif // QSTYLESHEETSTYLE_P_H |
205 | |