1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Quick Controls 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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QQUICKSTYLEITEM_P_H |
41 | #define QQUICKSTYLEITEM_P_H |
42 | |
43 | #include <QtGui/qimage.h> |
44 | #include <QtQuick/qquickitem.h> |
45 | #include <QtQuick/qquickimageprovider.h> |
46 | #include "qquickpadding_p.h" |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | class QWidget; |
51 | class QStyleOption; |
52 | |
53 | class QQuickTableRowImageProvider1 : public QQuickImageProvider |
54 | { |
55 | public: |
56 | QQuickTableRowImageProvider1() |
57 | : QQuickImageProvider(QQuickImageProvider::Pixmap) {} |
58 | QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override; |
59 | }; |
60 | |
61 | class QQuickStyleItem1: public QQuickItem |
62 | { |
63 | Q_OBJECT |
64 | |
65 | Q_PROPERTY(QQuickPadding1* border READ border CONSTANT) |
66 | |
67 | Q_PROPERTY( bool sunken READ sunken WRITE setSunken NOTIFY sunkenChanged) |
68 | Q_PROPERTY( bool raised READ raised WRITE setRaised NOTIFY raisedChanged) |
69 | Q_PROPERTY( bool active READ active WRITE setActive NOTIFY activeChanged) |
70 | Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectedChanged) |
71 | Q_PROPERTY( bool hasFocus READ hasFocus WRITE sethasFocus NOTIFY hasFocusChanged) |
72 | Q_PROPERTY( bool on READ on WRITE setOn NOTIFY onChanged) |
73 | Q_PROPERTY( bool hover READ hover WRITE setHover NOTIFY hoverChanged) |
74 | Q_PROPERTY( bool horizontal READ horizontal WRITE setHorizontal NOTIFY horizontalChanged) |
75 | Q_PROPERTY( bool isTransient READ isTransient WRITE setTransient NOTIFY transientChanged) |
76 | |
77 | Q_PROPERTY( QString elementType READ elementType WRITE setElementType NOTIFY elementTypeChanged) |
78 | Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged) |
79 | Q_PROPERTY( QString activeControl READ activeControl WRITE setActiveControl NOTIFY activeControlChanged) |
80 | Q_PROPERTY( QString style READ style NOTIFY styleChanged) |
81 | Q_PROPERTY( QVariantMap hints READ hints WRITE setHints NOTIFY hintChanged RESET resetHints) |
82 | Q_PROPERTY( QVariantMap properties READ properties WRITE setProperties NOTIFY propertiesChanged) |
83 | Q_PROPERTY( QFont font READ font NOTIFY fontChanged) |
84 | |
85 | // For range controls |
86 | Q_PROPERTY( int minimum READ minimum WRITE setMinimum NOTIFY minimumChanged) |
87 | Q_PROPERTY( int maximum READ maximum WRITE setMaximum NOTIFY maximumChanged) |
88 | Q_PROPERTY( int value READ value WRITE setValue NOTIFY valueChanged) |
89 | Q_PROPERTY( int step READ step WRITE setStep NOTIFY stepChanged) |
90 | Q_PROPERTY( int paintMargins READ paintMargins WRITE setPaintMargins NOTIFY paintMarginsChanged) |
91 | |
92 | Q_PROPERTY( int contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged) |
93 | Q_PROPERTY( int contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged) |
94 | |
95 | Q_PROPERTY( int textureWidth READ textureWidth WRITE setTextureWidth NOTIFY textureWidthChanged) |
96 | Q_PROPERTY( int textureHeight READ textureHeight WRITE setTextureHeight NOTIFY textureHeightChanged) |
97 | |
98 | QQuickPadding1* border() { return &m_border; } |
99 | |
100 | public: |
101 | QQuickStyleItem1(QQuickItem *parent = 0); |
102 | ~QQuickStyleItem1(); |
103 | |
104 | enum Type { |
105 | Undefined, |
106 | Button, |
107 | RadioButton, |
108 | CheckBox, |
109 | ComboBox, |
110 | ComboBoxItem, |
111 | Dial, |
112 | ToolBar, |
113 | ToolButton, |
114 | Tab, |
115 | TabFrame, |
116 | Frame, |
117 | FocusFrame, |
118 | FocusRect, |
119 | SpinBox, |
120 | Slider, |
121 | ScrollBar, |
122 | ProgressBar, |
123 | Edit, |
124 | GroupBox, |
125 | , |
126 | Item, |
127 | ItemRow, |
128 | ItemBranchIndicator, |
129 | Splitter, |
130 | , |
131 | , |
132 | Widget, |
133 | StatusBar, |
134 | ScrollAreaCorner, |
135 | MacHelpButton, |
136 | , |
137 | |
138 | }; |
139 | |
140 | void paint(QPainter *); |
141 | |
142 | bool sunken() const { return m_sunken; } |
143 | bool raised() const { return m_raised; } |
144 | bool active() const { return m_active; } |
145 | bool selected() const { return m_selected; } |
146 | bool hasFocus() const { return m_focus; } |
147 | bool on() const { return m_on; } |
148 | bool hover() const { return m_hover; } |
149 | bool horizontal() const { return m_horizontal; } |
150 | bool isTransient() const { return m_transient; } |
151 | |
152 | int minimum() const { return m_minimum; } |
153 | int maximum() const { return m_maximum; } |
154 | int step() const { return m_step; } |
155 | int value() const { return m_value; } |
156 | int paintMargins() const { return m_paintMargins; } |
157 | |
158 | QString elementType() const { return m_type; } |
159 | QString text() const { return m_text; } |
160 | QString activeControl() const { return m_activeControl; } |
161 | QVariantMap hints() const { return m_hints; } |
162 | QVariantMap properties() const { return m_properties; } |
163 | QFont font() const { return m_font;} |
164 | QString style() const; |
165 | |
166 | void setSunken(bool sunken) { if (m_sunken != sunken) {m_sunken = sunken; emit sunkenChanged();}} |
167 | void setRaised(bool raised) { if (m_raised!= raised) {m_raised = raised; emit raisedChanged();}} |
168 | void setActive(bool active) { if (m_active!= active) {m_active = active; emit activeChanged();}} |
169 | void setSelected(bool selected) { if (m_selected!= selected) {m_selected = selected; emit selectedChanged();}} |
170 | void sethasFocus(bool focus) { if (m_focus != focus) {m_focus = focus; emit hasFocusChanged();}} |
171 | void setOn(bool on) { if (m_on != on) {m_on = on ; emit onChanged();}} |
172 | void setHover(bool hover) { if (m_hover != hover) {m_hover = hover ; emit hoverChanged();}} |
173 | void setHorizontal(bool horizontal) { if (m_horizontal != horizontal) {m_horizontal = horizontal; emit horizontalChanged();}} |
174 | void setTransient(bool transient) { if (m_transient != transient) {m_transient = transient; emit transientChanged();}} |
175 | void setMinimum(int minimum) { if (m_minimum!= minimum) {m_minimum = minimum; emit minimumChanged();}} |
176 | void setMaximum(int maximum) { if (m_maximum != maximum) {m_maximum = maximum; emit maximumChanged();}} |
177 | void setValue(int value) { if (m_value!= value) {m_value = value; emit valueChanged();}} |
178 | void setStep(int step) { if (m_step != step) { m_step = step; emit stepChanged(); }} |
179 | void setPaintMargins(int value) { if (m_paintMargins!= value) {m_paintMargins = value; emit paintMarginsChanged(); } } |
180 | void setElementType(const QString &str); |
181 | void setText(const QString &str) { if (m_text != str) {m_text = str; emit textChanged();}} |
182 | void setActiveControl(const QString &str) { if (m_activeControl != str) {m_activeControl = str; emit activeControlChanged();}} |
183 | void setHints(const QVariantMap &str); |
184 | void setProperties(const QVariantMap &props) { if (m_properties != props) { m_properties = props; emit propertiesChanged(); } } |
185 | void resetHints(); |
186 | |
187 | int contentWidth() const { return m_contentWidth; } |
188 | void setContentWidth(int arg); |
189 | |
190 | int contentHeight() const { return m_contentHeight; } |
191 | void setContentHeight(int arg); |
192 | |
193 | virtual void initStyleOption (); |
194 | void resolvePalette(); |
195 | |
196 | Q_INVOKABLE qreal textWidth(const QString &); |
197 | Q_INVOKABLE qreal textHeight(const QString &); |
198 | |
199 | int textureWidth() const { return m_textureWidth; } |
200 | void setTextureWidth(int w); |
201 | |
202 | int textureHeight() const { return m_textureHeight; } |
203 | void setTextureHeight(int h); |
204 | |
205 | public Q_SLOTS: |
206 | int pixelMetric(const QString&); |
207 | QVariant styleHint(const QString&); |
208 | void updateSizeHint(); |
209 | void updateRect(); |
210 | void updateBaselineOffset(); |
211 | void updateItem(){polish();} |
212 | QString hitTest(int x, int y); |
213 | QRectF subControlRect(const QString &subcontrolString); |
214 | QString elidedText(const QString &text, int elideMode, int width); |
215 | bool hasThemeIcon(const QString &) const; |
216 | |
217 | Q_SIGNALS: |
218 | void elementTypeChanged(); |
219 | void textChanged(); |
220 | void sunkenChanged(); |
221 | void raisedChanged(); |
222 | void activeChanged(); |
223 | void selectedChanged(); |
224 | void hasFocusChanged(); |
225 | void onChanged(); |
226 | void hoverChanged(); |
227 | void horizontalChanged(); |
228 | void transientChanged(); |
229 | void minimumChanged(); |
230 | void maximumChanged(); |
231 | void stepChanged(); |
232 | void valueChanged(); |
233 | void activeControlChanged(); |
234 | void infoChanged(); |
235 | void styleChanged(); |
236 | void paintMarginsChanged(); |
237 | void hintChanged(); |
238 | void propertiesChanged(); |
239 | void fontChanged(); |
240 | |
241 | void contentWidthChanged(int arg); |
242 | void contentHeightChanged(int arg); |
243 | |
244 | void textureWidthChanged(int w); |
245 | void textureHeightChanged(int h); |
246 | |
247 | protected: |
248 | bool event(QEvent *) |
249 | override; |
250 | QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; |
251 | void updatePolish() override; |
252 | |
253 | private: |
254 | QSize sizeFromContents(int width, int height); |
255 | qreal baselineOffset(); |
256 | |
257 | protected: |
258 | QWidget *m_dummywidget; |
259 | QStyleOption *m_styleoption; |
260 | Type m_itemType; |
261 | |
262 | QString m_type; |
263 | QString m_text; |
264 | QString m_activeControl; |
265 | QVariantMap m_hints; |
266 | QVariantMap m_properties; |
267 | QFont m_font; |
268 | |
269 | bool m_sunken; |
270 | bool m_raised; |
271 | bool m_active; |
272 | bool m_selected; |
273 | bool m_focus; |
274 | bool m_hover; |
275 | bool m_on; |
276 | bool m_horizontal; |
277 | bool m_transient; |
278 | bool m_sharedWidget; |
279 | |
280 | int m_minimum; |
281 | int m_maximum; |
282 | int m_value; |
283 | int m_step; |
284 | int m_paintMargins; |
285 | |
286 | int m_contentWidth; |
287 | int m_contentHeight; |
288 | |
289 | int m_textureWidth; |
290 | int m_textureHeight; |
291 | |
292 | QImage m_image; |
293 | QQuickPadding1 m_border; |
294 | }; |
295 | |
296 | QT_END_NAMESPACE |
297 | |
298 | #endif // QQUICKSTYLEITEM_P_H |
299 | |