1// Copyright (C) 2014 BlackBerry Limited. All rights reserved.
2// Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
3// Copyright (C) 2016 The Qt Company Ltd.
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5
6#ifndef QPIXMAPSTYLE_H
7#define QPIXMAPSTYLE_H
8
9#include <QtWidgets/private/qtwidgetsglobal_p.h>
10#include <QtWidgets/QCommonStyle>
11#include <QtWidgets/QTileRules>
12
13//
14// W A R N I N G
15// -------------
16//
17// This file is not part of the Qt API. It exists purely as an
18// implementation detail. This header file may change from version to
19// version without notice, or even be removed.
20//
21// We mean it.
22//
23
24QT_BEGIN_NAMESPACE
25
26class QPixmapStylePrivate;
27
28class Q_WIDGETS_EXPORT QPixmapStyle : public QCommonStyle
29{
30 Q_OBJECT
31
32public:
33 enum ControlDescriptor {
34 BG_Background,
35 LE_Enabled, // QLineEdit
36 LE_Disabled,
37 LE_Focused,
38 PB_Enabled, // QPushButton
39 PB_Pressed,
40 PB_PressedDisabled,
41 PB_Checked,
42 PB_Disabled,
43 TE_Enabled, // QTextEdit
44 TE_Disabled,
45 TE_Focused,
46 PB_HBackground, // Horizontal QProgressBar
47 PB_HContent,
48 PB_HComplete,
49 PB_VBackground, // Vertical QProgressBar
50 PB_VContent,
51 PB_VComplete,
52 SG_HEnabled, // Horizontal QSlider groove
53 SG_HDisabled,
54 SG_HActiveEnabled,
55 SG_HActivePressed,
56 SG_HActiveDisabled,
57 SG_VEnabled, // Vertical QSlider groove
58 SG_VDisabled,
59 SG_VActiveEnabled,
60 SG_VActivePressed,
61 SG_VActiveDisabled,
62 DD_ButtonEnabled, // QComboBox (DropDown)
63 DD_ButtonDisabled,
64 DD_ButtonPressed,
65 DD_PopupDown,
66 DD_PopupUp,
67 DD_ItemSelected,
68 ID_Selected, // QStyledItemDelegate
69 SB_Horizontal, // QScrollBar
70 SB_Vertical
71 };
72
73 enum ControlPixmap {
74 CB_Enabled, // QCheckBox
75 CB_Checked,
76 CB_Pressed,
77 CB_PressedChecked,
78 CB_Disabled,
79 CB_DisabledChecked,
80 RB_Enabled, // QRadioButton
81 RB_Checked,
82 RB_Pressed,
83 RB_Disabled,
84 RB_DisabledChecked,
85 SH_HEnabled, // Horizontal QSlider handle
86 SH_HDisabled,
87 SH_HPressed,
88 SH_VEnabled, // Vertical QSlider handle
89 SH_VDisabled,
90 SH_VPressed,
91 DD_ArrowEnabled, // QComboBox (DropDown) arrow
92 DD_ArrowDisabled,
93 DD_ArrowPressed,
94 DD_ArrowOpen,
95 DD_ItemSeparator,
96 ID_Separator // QStyledItemDelegate separator
97 };
98
99public:
100 QPixmapStyle();
101 ~QPixmapStyle();
102
103 void polish(QApplication *application) override;
104 void polish(QPalette &palette) override;
105 void polish(QWidget *widget) override;
106 void unpolish(QApplication *application) override;
107 void unpolish(QWidget *widget) override;
108
109 void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
110 QPainter *painter, const QWidget *widget = nullptr) const override;
111 void drawControl(ControlElement element, const QStyleOption *option,
112 QPainter *painter, const QWidget *widget = nullptr) const override;
113 void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *option,
114 QPainter *painter, const QWidget *widget=nullptr) const override;
115
116 QSize sizeFromContents(ContentsType type, const QStyleOption *option,
117 const QSize &contentsSize, const QWidget *widget = nullptr) const override;
118 QRect subElementRect(SubElement element, const QStyleOption *option,
119 const QWidget *widget = nullptr) const override;
120 QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *option,
121 SubControl sc, const QWidget *widget = nullptr) const override;
122
123 int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
124 const QWidget *widget = nullptr) const override;
125 int styleHint(StyleHint hint, const QStyleOption *option,
126 const QWidget *widget, QStyleHintReturn *returnData) const override;
127 SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
128 const QPoint &pos, const QWidget *widget) const override;
129
130 bool eventFilter(QObject *watched, QEvent *event) override;
131
132 void addDescriptor(ControlDescriptor control, const QString &fileName,
133 QMargins margins = QMargins(),
134 QTileRules tileRules = QTileRules(Qt::RepeatTile, Qt::RepeatTile));
135 void copyDescriptor(ControlDescriptor source, ControlDescriptor dest);
136 void drawCachedPixmap(ControlDescriptor control, const QRect &rect, QPainter *p) const;
137
138 void addPixmap(ControlPixmap control, const QString &fileName,
139 QMargins margins = QMargins());
140 void copyPixmap(ControlPixmap source, ControlPixmap dest);
141
142protected:
143 void drawPushButton(const QStyleOption *option,
144 QPainter *painter, const QWidget *widget) const;
145 void drawLineEdit(const QStyleOption *option,
146 QPainter *painter, const QWidget *widget) const;
147 void drawTextEdit(const QStyleOption *option,
148 QPainter *painter, const QWidget *widget) const;
149 void drawCheckBox(const QStyleOption *option,
150 QPainter *painter, const QWidget *widget) const;
151 void drawRadioButton(const QStyleOption *option,
152 QPainter *painter, const QWidget *widget) const;
153 void drawPanelItemViewItem(const QStyleOption *option,
154 QPainter *painter, const QWidget *widget) const;
155 void drawProgressBarBackground(const QStyleOption *option,
156 QPainter *painter, const QWidget *widget) const;
157 void drawProgressBarLabel(const QStyleOption *option,
158 QPainter *painter, const QWidget *widget) const;
159 void drawProgressBarFill(const QStyleOption *option,
160 QPainter *painter, const QWidget *widget) const;
161 void drawSlider(const QStyleOptionComplex *option,
162 QPainter *painter, const QWidget *widget) const;
163 void drawComboBox(const QStyleOptionComplex *option,
164 QPainter *painter, const QWidget *widget) const;
165 void drawScrollBar(const QStyleOptionComplex *option,
166 QPainter *painter, const QWidget *widget) const;
167
168 QSize pushButtonSizeFromContents(const QStyleOption *option,
169 const QSize &contentsSize, const QWidget *widget) const;
170 QSize lineEditSizeFromContents(const QStyleOption *option,
171 const QSize &contentsSize, const QWidget *widget) const;
172 QSize progressBarSizeFromContents(const QStyleOption *option,
173 const QSize &contentsSize, const QWidget *widget) const;
174 QSize sliderSizeFromContents(const QStyleOption *option,
175 const QSize &contentsSize, const QWidget *widget) const;
176 QSize comboBoxSizeFromContents(const QStyleOption *option,
177 const QSize &contentsSize, const QWidget *widget) const;
178 QSize itemViewSizeFromContents(const QStyleOption *option,
179 const QSize &contentsSize, const QWidget *widget) const;
180
181 QRect comboBoxSubControlRect(const QStyleOptionComplex *option, QPixmapStyle::SubControl sc,
182 const QWidget *widget) const;
183 QRect scrollBarSubControlRect(const QStyleOptionComplex *option, QPixmapStyle::SubControl sc,
184 const QWidget *widget) const;
185
186protected:
187 QPixmapStyle(QPixmapStylePrivate &dd);
188
189private:
190 Q_DECLARE_PRIVATE(QPixmapStyle)
191};
192
193QT_END_NAMESPACE
194
195#endif // QPIXMAPSTYLE_H
196

source code of qtbase/src/widgets/styles/qpixmapstyle_p.h