1/***************************************************************************
2**
3** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
4** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
5** Copyright (C) 2016 The Qt Company Ltd.
6** Contact: https://www.qt.io/licensing/
7**
8** This file is part of the QtWidgets module of the Qt Toolkit.
9**
10** $QT_BEGIN_LICENSE:LGPL$
11** Commercial License Usage
12** Licensees holding valid commercial Qt licenses may use this file in
13** accordance with the commercial license agreement provided with the
14** Software or, alternatively, in accordance with the terms contained in
15** a written agreement between you and The Qt Company. For licensing terms
16** and conditions see https://www.qt.io/terms-conditions. For further
17** information use the contact form at https://www.qt.io/contact-us.
18**
19** GNU Lesser General Public License Usage
20** Alternatively, this file may be used under the terms of the GNU Lesser
21** General Public License version 3 as published by the Free Software
22** Foundation and appearing in the file LICENSE.LGPL3 included in the
23** packaging of this file. Please review the following information to
24** ensure the GNU Lesser General Public License version 3 requirements
25** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
26**
27** GNU General Public License Usage
28** Alternatively, this file may be used under the terms of the GNU
29** General Public License version 2.0 or (at your option) the GNU General
30** Public license version 3 or any later version approved by the KDE Free
31** Qt Foundation. The licenses are as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
33** included in the packaging of this file. Please review the following
34** information to ensure the GNU General Public License requirements will
35** be met: https://www.gnu.org/licenses/gpl-2.0.html and
36** https://www.gnu.org/licenses/gpl-3.0.html.
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QPIXMAPSTYLE_H
43#define QPIXMAPSTYLE_H
44
45#include <QtWidgets/private/qtwidgetsglobal_p.h>
46#include <QtWidgets/QCommonStyle>
47#include <QtWidgets/QTileRules>
48
49//
50// W A R N I N G
51// -------------
52//
53// This file is not part of the Qt API. It exists purely as an
54// implementation detail. This header file may change from version to
55// version without notice, or even be removed.
56//
57// We mean it.
58//
59
60QT_BEGIN_NAMESPACE
61
62class QPixmapStylePrivate;
63
64class Q_WIDGETS_EXPORT QPixmapStyle : public QCommonStyle
65{
66 Q_OBJECT
67
68public:
69 enum ControlDescriptor {
70 BG_Background,
71 LE_Enabled, // QLineEdit
72 LE_Disabled,
73 LE_Focused,
74 PB_Enabled, // QPushButton
75 PB_Pressed,
76 PB_PressedDisabled,
77 PB_Checked,
78 PB_Disabled,
79 TE_Enabled, // QTextEdit
80 TE_Disabled,
81 TE_Focused,
82 PB_HBackground, // Horizontal QProgressBar
83 PB_HContent,
84 PB_HComplete,
85 PB_VBackground, // Vertical QProgressBar
86 PB_VContent,
87 PB_VComplete,
88 SG_HEnabled, // Horizontal QSlider groove
89 SG_HDisabled,
90 SG_HActiveEnabled,
91 SG_HActivePressed,
92 SG_HActiveDisabled,
93 SG_VEnabled, // Vertical QSlider groove
94 SG_VDisabled,
95 SG_VActiveEnabled,
96 SG_VActivePressed,
97 SG_VActiveDisabled,
98 DD_ButtonEnabled, // QComboBox (DropDown)
99 DD_ButtonDisabled,
100 DD_ButtonPressed,
101 DD_PopupDown,
102 DD_PopupUp,
103 DD_ItemSelected,
104 ID_Selected, // QStyledItemDelegate
105 SB_Horizontal, // QScrollBar
106 SB_Vertical
107 };
108
109 enum ControlPixmap {
110 CB_Enabled, // QCheckBox
111 CB_Checked,
112 CB_Pressed,
113 CB_PressedChecked,
114 CB_Disabled,
115 CB_DisabledChecked,
116 RB_Enabled, // QRadioButton
117 RB_Checked,
118 RB_Pressed,
119 RB_Disabled,
120 RB_DisabledChecked,
121 SH_HEnabled, // Horizontal QSlider handle
122 SH_HDisabled,
123 SH_HPressed,
124 SH_VEnabled, // Vertical QSlider handle
125 SH_VDisabled,
126 SH_VPressed,
127 DD_ArrowEnabled, // QComboBox (DropDown) arrow
128 DD_ArrowDisabled,
129 DD_ArrowPressed,
130 DD_ArrowOpen,
131 DD_ItemSeparator,
132 ID_Separator // QStyledItemDelegate separator
133 };
134
135public:
136 QPixmapStyle();
137 ~QPixmapStyle();
138
139 void polish(QApplication *application) override;
140 void polish(QPalette &palette) override;
141 void polish(QWidget *widget) override;
142 void unpolish(QApplication *application) override;
143 void unpolish(QWidget *widget) override;
144
145 void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
146 QPainter *painter, const QWidget *widget = nullptr) const override;
147 void drawControl(ControlElement element, const QStyleOption *option,
148 QPainter *painter, const QWidget *widget = nullptr) const override;
149 void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *option,
150 QPainter *painter, const QWidget *widget=nullptr) const override;
151
152 QSize sizeFromContents(ContentsType type, const QStyleOption *option,
153 const QSize &contentsSize, const QWidget *widget = nullptr) const override;
154 QRect subElementRect(SubElement element, const QStyleOption *option,
155 const QWidget *widget = nullptr) const override;
156 QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *option,
157 SubControl sc, const QWidget *widget = nullptr) const override;
158
159 int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
160 const QWidget *widget = nullptr) const override;
161 int styleHint(StyleHint hint, const QStyleOption *option,
162 const QWidget *widget, QStyleHintReturn *returnData) const override;
163 SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
164 const QPoint &pos, const QWidget *widget) const override;
165
166 bool eventFilter(QObject *watched, QEvent *event) override;
167
168 void addDescriptor(ControlDescriptor control, const QString &fileName,
169 QMargins margins = QMargins(),
170 QTileRules tileRules = QTileRules(Qt::RepeatTile, Qt::RepeatTile));
171 void copyDescriptor(ControlDescriptor source, ControlDescriptor dest);
172 void drawCachedPixmap(ControlDescriptor control, const QRect &rect, QPainter *p) const;
173
174 void addPixmap(ControlPixmap control, const QString &fileName,
175 QMargins margins = QMargins());
176 void copyPixmap(ControlPixmap source, ControlPixmap dest);
177
178protected:
179 void drawPushButton(const QStyleOption *option,
180 QPainter *painter, const QWidget *widget) const;
181 void drawLineEdit(const QStyleOption *option,
182 QPainter *painter, const QWidget *widget) const;
183 void drawTextEdit(const QStyleOption *option,
184 QPainter *painter, const QWidget *widget) const;
185 void drawCheckBox(const QStyleOption *option,
186 QPainter *painter, const QWidget *widget) const;
187 void drawRadioButton(const QStyleOption *option,
188 QPainter *painter, const QWidget *widget) const;
189 void drawPanelItemViewItem(const QStyleOption *option,
190 QPainter *painter, const QWidget *widget) const;
191 void drawProgressBarBackground(const QStyleOption *option,
192 QPainter *painter, const QWidget *widget) const;
193 void drawProgressBarLabel(const QStyleOption *option,
194 QPainter *painter, const QWidget *widget) const;
195 void drawProgressBarFill(const QStyleOption *option,
196 QPainter *painter, const QWidget *widget) const;
197 void drawSlider(const QStyleOptionComplex *option,
198 QPainter *painter, const QWidget *widget) const;
199 void drawComboBox(const QStyleOptionComplex *option,
200 QPainter *painter, const QWidget *widget) const;
201 void drawScrollBar(const QStyleOptionComplex *option,
202 QPainter *painter, const QWidget *widget) const;
203
204 QSize pushButtonSizeFromContents(const QStyleOption *option,
205 const QSize &contentsSize, const QWidget *widget) const;
206 QSize lineEditSizeFromContents(const QStyleOption *option,
207 const QSize &contentsSize, const QWidget *widget) const;
208 QSize progressBarSizeFromContents(const QStyleOption *option,
209 const QSize &contentsSize, const QWidget *widget) const;
210 QSize sliderSizeFromContents(const QStyleOption *option,
211 const QSize &contentsSize, const QWidget *widget) const;
212 QSize comboBoxSizeFromContents(const QStyleOption *option,
213 const QSize &contentsSize, const QWidget *widget) const;
214 QSize itemViewSizeFromContents(const QStyleOption *option,
215 const QSize &contentsSize, const QWidget *widget) const;
216
217 QRect comboBoxSubControlRect(const QStyleOptionComplex *option, QPixmapStyle::SubControl sc,
218 const QWidget *widget) const;
219 QRect scrollBarSubControlRect(const QStyleOptionComplex *option, QPixmapStyle::SubControl sc,
220 const QWidget *widget) const;
221
222protected:
223 QPixmapStyle(QPixmapStylePrivate &dd);
224
225private:
226 Q_DECLARE_PRIVATE(QPixmapStyle)
227};
228
229QT_END_NAMESPACE
230
231#endif // QPIXMAPSTYLE_H
232