Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/styles/qstylehelper.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||||||||||||||
34 | #include <qstyleoption.h> | - | ||||||||||||||||||||||||||||||||||||
35 | #include <qpainter.h> | - | ||||||||||||||||||||||||||||||||||||
36 | #include <qpixmapcache.h> | - | ||||||||||||||||||||||||||||||||||||
37 | #include <private/qmath_p.h> | - | ||||||||||||||||||||||||||||||||||||
38 | #include <private/qstyle_p.h> | - | ||||||||||||||||||||||||||||||||||||
39 | #include <qmath.h> | - | ||||||||||||||||||||||||||||||||||||
40 | #include <qscrollbar.h> | - | ||||||||||||||||||||||||||||||||||||
41 | #include <qabstractscrollarea.h> | - | ||||||||||||||||||||||||||||||||||||
42 | #include <qwindow.h> | - | ||||||||||||||||||||||||||||||||||||
43 | - | |||||||||||||||||||||||||||||||||||||
44 | #include "qstylehelper_p.h" | - | ||||||||||||||||||||||||||||||||||||
45 | #include <qstringbuilder.h> | - | ||||||||||||||||||||||||||||||||||||
46 | #include <qdatastream.h> | - | ||||||||||||||||||||||||||||||||||||
47 | #include <qcryptographichash.h> | - | ||||||||||||||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||||||||||||||
49 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||||||||||||||
51 | Q_GUI_EXPORT int qt_defaultDpiX(); | - | ||||||||||||||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||||||||||||||
53 | namespace QStyleHelper { | - | ||||||||||||||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||||||||||||||
55 | QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size) | - | ||||||||||||||||||||||||||||||||||||
56 | { | - | ||||||||||||||||||||||||||||||||||||
57 | const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option); | - | ||||||||||||||||||||||||||||||||||||
58 | QString tmp = key % HexString<uint>(option->state) | - | ||||||||||||||||||||||||||||||||||||
59 | % HexString<uint>(option->direction) | - | ||||||||||||||||||||||||||||||||||||
60 | % HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u) | - | ||||||||||||||||||||||||||||||||||||
61 | % HexString<uint>(size.width()) | - | ||||||||||||||||||||||||||||||||||||
62 | % HexString<uint>(size.height()); | - | ||||||||||||||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||||||||||||||
64 | #ifndef QT_NO_SPINBOX | - | ||||||||||||||||||||||||||||||||||||
65 | if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
| 0 | ||||||||||||||||||||||||||||||||||||
66 | tmp = tmp % HexString<uint>(spinBox->buttonSymbols) | - | ||||||||||||||||||||||||||||||||||||
67 | % HexString<uint>(spinBox->stepEnabled) | - | ||||||||||||||||||||||||||||||||||||
68 | % QLatin1Char(spinBox->frame ? '1' : '0'); ; | - | ||||||||||||||||||||||||||||||||||||
69 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
70 | #endif // QT_NO_SPINBOX | - | ||||||||||||||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||||||||||||||
72 | // QTBUG-56743, try to create a palette cache key reflecting the value, | - | ||||||||||||||||||||||||||||||||||||
73 | // as leaks may occur in conjunction with QStyleSheetStyle/QRenderRule modifying | - | ||||||||||||||||||||||||||||||||||||
74 | // palettes when using QPalette::cacheKey() | - | ||||||||||||||||||||||||||||||||||||
75 | if (option->palette != QGuiApplication::palette()) {
| 0 | ||||||||||||||||||||||||||||||||||||
76 | tmp.append(QLatin1Char('P')); | - | ||||||||||||||||||||||||||||||||||||
77 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||||||||
78 | QByteArray key; | - | ||||||||||||||||||||||||||||||||||||
79 | key.reserve(5120); // Observed 5040B for a serialized palette on 64bit | - | ||||||||||||||||||||||||||||||||||||
80 | { | - | ||||||||||||||||||||||||||||||||||||
81 | QDataStream str(&key, QIODevice::WriteOnly); | - | ||||||||||||||||||||||||||||||||||||
82 | str << option->palette; | - | ||||||||||||||||||||||||||||||||||||
83 | } | - | ||||||||||||||||||||||||||||||||||||
84 | const QByteArray sha1 = QCryptographicHash::hash(key, QCryptographicHash::Sha1).toHex(); | - | ||||||||||||||||||||||||||||||||||||
85 | tmp.append(QString::fromLatin1(sha1)); | - | ||||||||||||||||||||||||||||||||||||
86 | #else // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||||||||
87 | tmp.append(QString::number(option->palette.cacheKey(), 16)); | - | ||||||||||||||||||||||||||||||||||||
88 | #endif // !QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||||||||
89 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
90 | return tmp; never executed: return tmp; | 0 | ||||||||||||||||||||||||||||||||||||
91 | } | - | ||||||||||||||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||||||||||||||
93 | qreal dpiScaled(qreal value) | - | ||||||||||||||||||||||||||||||||||||
94 | { | - | ||||||||||||||||||||||||||||||||||||
95 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||||||||||||||
96 | // On mac the DPI is always 72 so we should not scale it | - | ||||||||||||||||||||||||||||||||||||
97 | return value; | - | ||||||||||||||||||||||||||||||||||||
98 | #else | - | ||||||||||||||||||||||||||||||||||||
99 | static const qreal scale = qreal(qt_defaultDpiX()) / 96.0; | - | ||||||||||||||||||||||||||||||||||||
100 | return value * scale; never executed: return value * scale; | 0 | ||||||||||||||||||||||||||||||||||||
101 | #endif | - | ||||||||||||||||||||||||||||||||||||
102 | } | - | ||||||||||||||||||||||||||||||||||||
103 | - | |||||||||||||||||||||||||||||||||||||
104 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
105 | bool isInstanceOf(QObject *obj, QAccessible::Role role) | - | ||||||||||||||||||||||||||||||||||||
106 | { | - | ||||||||||||||||||||||||||||||||||||
107 | bool match = false; | - | ||||||||||||||||||||||||||||||||||||
108 | QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(obj); | - | ||||||||||||||||||||||||||||||||||||
109 | match = iface && iface->role() == role;
| 0 | ||||||||||||||||||||||||||||||||||||
110 | return match; never executed: return match; | 0 | ||||||||||||||||||||||||||||||||||||
111 | } | - | ||||||||||||||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||||||||||||||
113 | // Searches for an ancestor of a particular accessible role | - | ||||||||||||||||||||||||||||||||||||
114 | bool hasAncestor(QObject *obj, QAccessible::Role role) | - | ||||||||||||||||||||||||||||||||||||
115 | { | - | ||||||||||||||||||||||||||||||||||||
116 | bool found = false; | - | ||||||||||||||||||||||||||||||||||||
117 | QObject *parent = obj ? obj->parent() : 0;
| 0 | ||||||||||||||||||||||||||||||||||||
118 | while (parent && !found) {
| 0 | ||||||||||||||||||||||||||||||||||||
119 | if (isInstanceOf(parent, role))
| 0 | ||||||||||||||||||||||||||||||||||||
120 | found = true; never executed: found = true; | 0 | ||||||||||||||||||||||||||||||||||||
121 | parent = parent->parent(); | - | ||||||||||||||||||||||||||||||||||||
122 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
123 | return found; never executed: return found; | 0 | ||||||||||||||||||||||||||||||||||||
124 | } | - | ||||||||||||||||||||||||||||||||||||
125 | #endif // QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||||||||||||||
128 | #ifndef QT_NO_DIAL | - | ||||||||||||||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||||||||||||||
130 | int calcBigLineSize(int radius) | - | ||||||||||||||||||||||||||||||||||||
131 | { | - | ||||||||||||||||||||||||||||||||||||
132 | int bigLineSize = radius / 6; | - | ||||||||||||||||||||||||||||||||||||
133 | if (bigLineSize < 4)
| 0 | ||||||||||||||||||||||||||||||||||||
134 | bigLineSize = 4; never executed: bigLineSize = 4; | 0 | ||||||||||||||||||||||||||||||||||||
135 | if (bigLineSize > radius / 2)
| 0 | ||||||||||||||||||||||||||||||||||||
136 | bigLineSize = radius / 2; never executed: bigLineSize = radius / 2; | 0 | ||||||||||||||||||||||||||||||||||||
137 | return bigLineSize; never executed: return bigLineSize; | 0 | ||||||||||||||||||||||||||||||||||||
138 | } | - | ||||||||||||||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||||||||||||||
140 | static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset) | - | ||||||||||||||||||||||||||||||||||||
141 | { | - | ||||||||||||||||||||||||||||||||||||
142 | const int width = dial->rect.width(); | - | ||||||||||||||||||||||||||||||||||||
143 | const int height = dial->rect.height(); | - | ||||||||||||||||||||||||||||||||||||
144 | const int r = qMin(width, height) / 2; | - | ||||||||||||||||||||||||||||||||||||
145 | const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
| 0 | ||||||||||||||||||||||||||||||||||||
146 | qreal a = 0; | - | ||||||||||||||||||||||||||||||||||||
147 | if (dial->maximum == dial->minimum)
| 0 | ||||||||||||||||||||||||||||||||||||
148 | a = Q_PI / 2; never executed: a = Q_PI / 2; | 0 | ||||||||||||||||||||||||||||||||||||
149 | else if (dial->dialWrapping)
| 0 | ||||||||||||||||||||||||||||||||||||
150 | a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI never executed: a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI / (dial->maximum - dial->minimum); | 0 | ||||||||||||||||||||||||||||||||||||
151 | / (dial->maximum - dial->minimum); never executed: a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI / (dial->maximum - dial->minimum); | 0 | ||||||||||||||||||||||||||||||||||||
152 | else | - | ||||||||||||||||||||||||||||||||||||
153 | a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI never executed: a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI / (dial->maximum - dial->minimum)) / 6; | 0 | ||||||||||||||||||||||||||||||||||||
154 | / (dial->maximum - dial->minimum)) / 6; never executed: a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI / (dial->maximum - dial->minimum)) / 6; | 0 | ||||||||||||||||||||||||||||||||||||
155 | qreal xc = width / 2.0; | - | ||||||||||||||||||||||||||||||||||||
156 | qreal yc = height / 2.0; | - | ||||||||||||||||||||||||||||||||||||
157 | qreal len = r - QStyleHelper::calcBigLineSize(r) - 3; | - | ||||||||||||||||||||||||||||||||||||
158 | qreal back = offset * len; | - | ||||||||||||||||||||||||||||||||||||
159 | QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a))); | - | ||||||||||||||||||||||||||||||||||||
160 | return pos; never executed: return pos; | 0 | ||||||||||||||||||||||||||||||||||||
161 | } | - | ||||||||||||||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||||||||||||||
163 | qreal angle(const QPointF &p1, const QPointF &p2) | - | ||||||||||||||||||||||||||||||||||||
164 | { | - | ||||||||||||||||||||||||||||||||||||
165 | static const qreal rad_factor = 180 / Q_PI; | - | ||||||||||||||||||||||||||||||||||||
166 | qreal _angle = 0; | - | ||||||||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||||||||
168 | if (p1.x() == p2.x()) {
| 0 | ||||||||||||||||||||||||||||||||||||
169 | if (p1.y() < p2.y())
| 0 | ||||||||||||||||||||||||||||||||||||
170 | _angle = 270; never executed: _angle = 270; | 0 | ||||||||||||||||||||||||||||||||||||
171 | else | - | ||||||||||||||||||||||||||||||||||||
172 | _angle = 90; never executed: _angle = 90; | 0 | ||||||||||||||||||||||||||||||||||||
173 | } else { | - | ||||||||||||||||||||||||||||||||||||
174 | qreal x1, x2, y1, y2; | - | ||||||||||||||||||||||||||||||||||||
175 | - | |||||||||||||||||||||||||||||||||||||
176 | if (p1.x() <= p2.x()) {
| 0 | ||||||||||||||||||||||||||||||||||||
177 | x1 = p1.x(); y1 = p1.y(); | - | ||||||||||||||||||||||||||||||||||||
178 | x2 = p2.x(); y2 = p2.y(); | - | ||||||||||||||||||||||||||||||||||||
179 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
180 | x2 = p1.x(); y2 = p1.y(); | - | ||||||||||||||||||||||||||||||||||||
181 | x1 = p2.x(); y1 = p2.y(); | - | ||||||||||||||||||||||||||||||||||||
182 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||||||||||||||
184 | qreal m = -(y2 - y1) / (x2 - x1); | - | ||||||||||||||||||||||||||||||||||||
185 | _angle = qAtan(m) * rad_factor; | - | ||||||||||||||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||||||||||||||
187 | if (p1.x() < p2.x())
| 0 | ||||||||||||||||||||||||||||||||||||
188 | _angle = 180 - _angle; never executed: _angle = 180 - _angle; | 0 | ||||||||||||||||||||||||||||||||||||
189 | else | - | ||||||||||||||||||||||||||||||||||||
190 | _angle = -_angle; never executed: _angle = -_angle; | 0 | ||||||||||||||||||||||||||||||||||||
191 | } | - | ||||||||||||||||||||||||||||||||||||
192 | return _angle; never executed: return _angle; | 0 | ||||||||||||||||||||||||||||||||||||
193 | } | - | ||||||||||||||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||||||||||||||
195 | QPolygonF calcLines(const QStyleOptionSlider *dial) | - | ||||||||||||||||||||||||||||||||||||
196 | { | - | ||||||||||||||||||||||||||||||||||||
197 | QPolygonF poly; | - | ||||||||||||||||||||||||||||||||||||
198 | int width = dial->rect.width(); | - | ||||||||||||||||||||||||||||||||||||
199 | int height = dial->rect.height(); | - | ||||||||||||||||||||||||||||||||||||
200 | qreal r = qMin(width, height) / 2; | - | ||||||||||||||||||||||||||||||||||||
201 | int bigLineSize = calcBigLineSize(int(r)); | - | ||||||||||||||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||||||||||||||
203 | qreal xc = width / 2 + 0.5; | - | ||||||||||||||||||||||||||||||||||||
204 | qreal yc = height / 2 + 0.5; | - | ||||||||||||||||||||||||||||||||||||
205 | const int ns = dial->tickInterval; | - | ||||||||||||||||||||||||||||||||||||
206 | if (!ns) // Invalid values may be set by Qt Designer.
| 0 | ||||||||||||||||||||||||||||||||||||
207 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||
208 | int notches = (dial->maximum + ns - 1 - dial->minimum) / ns; | - | ||||||||||||||||||||||||||||||||||||
209 | if (notches <= 0)
| 0 | ||||||||||||||||||||||||||||||||||||
210 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||
211 | if (dial->maximum < dial->minimum || dial->maximum - dial->minimum > 1000) {
| 0 | ||||||||||||||||||||||||||||||||||||
212 | int maximum = dial->minimum + 1000; | - | ||||||||||||||||||||||||||||||||||||
213 | notches = (maximum + ns - 1 - dial->minimum) / ns; | - | ||||||||||||||||||||||||||||||||||||
214 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
215 | - | |||||||||||||||||||||||||||||||||||||
216 | poly.resize(2 + 2 * notches); | - | ||||||||||||||||||||||||||||||||||||
217 | int smallLineSize = bigLineSize / 2; | - | ||||||||||||||||||||||||||||||||||||
218 | for (int i = 0; i <= notches; ++i) {
| 0 | ||||||||||||||||||||||||||||||||||||
219 | qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
| 0 | ||||||||||||||||||||||||||||||||||||
220 | : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6; | - | ||||||||||||||||||||||||||||||||||||
221 | qreal s = qSin(angle); | - | ||||||||||||||||||||||||||||||||||||
222 | qreal c = qCos(angle); | - | ||||||||||||||||||||||||||||||||||||
223 | if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)) {
| 0 | ||||||||||||||||||||||||||||||||||||
224 | poly[2 * i] = QPointF(xc + (r - bigLineSize) * c, | - | ||||||||||||||||||||||||||||||||||||
225 | yc - (r - bigLineSize) * s); | - | ||||||||||||||||||||||||||||||||||||
226 | poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s); | - | ||||||||||||||||||||||||||||||||||||
227 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
228 | poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c, | - | ||||||||||||||||||||||||||||||||||||
229 | yc - (r - 1 - smallLineSize) * s); | - | ||||||||||||||||||||||||||||||||||||
230 | poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s); | - | ||||||||||||||||||||||||||||||||||||
231 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
232 | } | - | ||||||||||||||||||||||||||||||||||||
233 | return poly; never executed: return poly; | 0 | ||||||||||||||||||||||||||||||||||||
234 | } | - | ||||||||||||||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||||||||||||||
236 | // This will draw a nice and shiny QDial for us. We don't want | - | ||||||||||||||||||||||||||||||||||||
237 | // all the shinyness in QWindowsStyle, hence we place it here | - | ||||||||||||||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||||||||||||||
239 | void drawDial(const QStyleOptionSlider *option, QPainter *painter) | - | ||||||||||||||||||||||||||||||||||||
240 | { | - | ||||||||||||||||||||||||||||||||||||
241 | QPalette pal = option->palette; | - | ||||||||||||||||||||||||||||||||||||
242 | QColor buttonColor = pal.button().color(); | - | ||||||||||||||||||||||||||||||||||||
243 | const int width = option->rect.width(); | - | ||||||||||||||||||||||||||||||||||||
244 | const int height = option->rect.height(); | - | ||||||||||||||||||||||||||||||||||||
245 | const bool enabled = option->state & QStyle::State_Enabled; | - | ||||||||||||||||||||||||||||||||||||
246 | qreal r = qMin(width, height) / 2; | - | ||||||||||||||||||||||||||||||||||||
247 | r -= r/50; | - | ||||||||||||||||||||||||||||||||||||
248 | const qreal penSize = r/20.0; | - | ||||||||||||||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||||||||||||||
250 | painter->save(); | - | ||||||||||||||||||||||||||||||||||||
251 | painter->setRenderHint(QPainter::Antialiasing); | - | ||||||||||||||||||||||||||||||||||||
252 | - | |||||||||||||||||||||||||||||||||||||
253 | // Draw notches | - | ||||||||||||||||||||||||||||||||||||
254 | if (option->subControls & QStyle::SC_DialTickmarks) {
| 0 | ||||||||||||||||||||||||||||||||||||
255 | painter->setPen(option->palette.dark().color().darker(120)); | - | ||||||||||||||||||||||||||||||||||||
256 | painter->drawLines(QStyleHelper::calcLines(option)); | - | ||||||||||||||||||||||||||||||||||||
257 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||||||||||||||
259 | // Cache dial background | - | ||||||||||||||||||||||||||||||||||||
260 | BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial")); never executed: end of block never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
261 | p->setRenderHint(QPainter::Antialiasing); | - | ||||||||||||||||||||||||||||||||||||
262 | - | |||||||||||||||||||||||||||||||||||||
263 | const qreal d_ = r / 6; | - | ||||||||||||||||||||||||||||||||||||
264 | const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; | - | ||||||||||||||||||||||||||||||||||||
265 | const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; | - | ||||||||||||||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||||||||||||||
267 | QRectF br = QRectF(dx + 0.5, dy + 0.5, | - | ||||||||||||||||||||||||||||||||||||
268 | int(r * 2 - 2 * d_ - 2), | - | ||||||||||||||||||||||||||||||||||||
269 | int(r * 2 - 2 * d_ - 2)); | - | ||||||||||||||||||||||||||||||||||||
270 | buttonColor.setHsv(buttonColor .hue(), | - | ||||||||||||||||||||||||||||||||||||
271 | qMin(140, buttonColor .saturation()), | - | ||||||||||||||||||||||||||||||||||||
272 | qMax(180, buttonColor.value())); | - | ||||||||||||||||||||||||||||||||||||
273 | QColor shadowColor(0, 0, 0, 20); | - | ||||||||||||||||||||||||||||||||||||
274 | - | |||||||||||||||||||||||||||||||||||||
275 | if (enabled) {
| 0 | ||||||||||||||||||||||||||||||||||||
276 | // Drop shadow | - | ||||||||||||||||||||||||||||||||||||
277 | qreal shadowSize = qMax(1.0, penSize/2.0); | - | ||||||||||||||||||||||||||||||||||||
278 | QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, | - | ||||||||||||||||||||||||||||||||||||
279 | 2*shadowSize, 2*shadowSize); | - | ||||||||||||||||||||||||||||||||||||
280 | QRadialGradient shadowGradient(shadowRect.center().x(), | - | ||||||||||||||||||||||||||||||||||||
281 | shadowRect.center().y(), shadowRect.width()/2.0, | - | ||||||||||||||||||||||||||||||||||||
282 | shadowRect.center().x(), shadowRect.center().y()); | - | ||||||||||||||||||||||||||||||||||||
283 | shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); | - | ||||||||||||||||||||||||||||||||||||
284 | shadowGradient.setColorAt(qreal(1.0), Qt::transparent); | - | ||||||||||||||||||||||||||||||||||||
285 | p->setBrush(shadowGradient); | - | ||||||||||||||||||||||||||||||||||||
286 | p->setPen(Qt::NoPen); | - | ||||||||||||||||||||||||||||||||||||
287 | p->translate(shadowSize, shadowSize); | - | ||||||||||||||||||||||||||||||||||||
288 | p->drawEllipse(shadowRect); | - | ||||||||||||||||||||||||||||||||||||
289 | p->translate(-shadowSize, -shadowSize); | - | ||||||||||||||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||||||||||||||
291 | // Main gradient | - | ||||||||||||||||||||||||||||||||||||
292 | QRadialGradient gradient(br.center().x() - br.width()/3, dy, | - | ||||||||||||||||||||||||||||||||||||
293 | br.width()*1.3, br.center().x(), | - | ||||||||||||||||||||||||||||||||||||
294 | br.center().y() - br.height()/2); | - | ||||||||||||||||||||||||||||||||||||
295 | gradient.setColorAt(0, buttonColor.lighter(110)); | - | ||||||||||||||||||||||||||||||||||||
296 | gradient.setColorAt(qreal(0.5), buttonColor); | - | ||||||||||||||||||||||||||||||||||||
297 | gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); | - | ||||||||||||||||||||||||||||||||||||
298 | gradient.setColorAt(1, buttonColor.darker(115)); | - | ||||||||||||||||||||||||||||||||||||
299 | p->setBrush(gradient); | - | ||||||||||||||||||||||||||||||||||||
300 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
301 | p->setBrush(Qt::NoBrush); | - | ||||||||||||||||||||||||||||||||||||
302 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
303 | - | |||||||||||||||||||||||||||||||||||||
304 | p->setPen(QPen(buttonColor.darker(280))); | - | ||||||||||||||||||||||||||||||||||||
305 | p->drawEllipse(br); | - | ||||||||||||||||||||||||||||||||||||
306 | p->setBrush(Qt::NoBrush); | - | ||||||||||||||||||||||||||||||||||||
307 | p->setPen(buttonColor.lighter(110)); | - | ||||||||||||||||||||||||||||||||||||
308 | p->drawEllipse(br.adjusted(1, 1, -1, -1)); | - | ||||||||||||||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||||||||||||||
310 | if (option->state & QStyle::State_HasFocus) {
| 0 | ||||||||||||||||||||||||||||||||||||
311 | QColor highlight = pal.highlight().color(); | - | ||||||||||||||||||||||||||||||||||||
312 | highlight.setHsv(highlight.hue(), | - | ||||||||||||||||||||||||||||||||||||
313 | qMin(160, highlight.saturation()), | - | ||||||||||||||||||||||||||||||||||||
314 | qMax(230, highlight.value())); | - | ||||||||||||||||||||||||||||||||||||
315 | highlight.setAlpha(127); | - | ||||||||||||||||||||||||||||||||||||
316 | p->setPen(QPen(highlight, 2.0)); | - | ||||||||||||||||||||||||||||||||||||
317 | p->setBrush(Qt::NoBrush); | - | ||||||||||||||||||||||||||||||||||||
318 | p->drawEllipse(br.adjusted(-1, -1, 1, 1)); | - | ||||||||||||||||||||||||||||||||||||
319 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
320 | - | |||||||||||||||||||||||||||||||||||||
321 | END_STYLE_PIXMAPCACHE never executed: end of block never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
322 | - | |||||||||||||||||||||||||||||||||||||
323 | QPointF dp = calcRadialPos(option, qreal(0.70)); | - | ||||||||||||||||||||||||||||||||||||
324 | buttonColor = buttonColor.lighter(104); | - | ||||||||||||||||||||||||||||||||||||
325 | buttonColor.setAlphaF(qreal(0.8)); | - | ||||||||||||||||||||||||||||||||||||
326 | const qreal ds = r/qreal(7.0); | - | ||||||||||||||||||||||||||||||||||||
327 | QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds); | - | ||||||||||||||||||||||||||||||||||||
328 | QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2, | - | ||||||||||||||||||||||||||||||||||||
329 | dialRect.center().y() + dialRect.width(), | - | ||||||||||||||||||||||||||||||||||||
330 | dialRect.width()*2, | - | ||||||||||||||||||||||||||||||||||||
331 | dialRect.center().x(), dialRect.center().y()); | - | ||||||||||||||||||||||||||||||||||||
332 | dialGradient.setColorAt(1, buttonColor.darker(140)); | - | ||||||||||||||||||||||||||||||||||||
333 | dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120)); | - | ||||||||||||||||||||||||||||||||||||
334 | dialGradient.setColorAt(0, buttonColor.darker(110)); | - | ||||||||||||||||||||||||||||||||||||
335 | if (penSize > 3.0) {
| 0 | ||||||||||||||||||||||||||||||||||||
336 | painter->setPen(QPen(QColor(0, 0, 0, 25), penSize)); | - | ||||||||||||||||||||||||||||||||||||
337 | painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96))); | - | ||||||||||||||||||||||||||||||||||||
338 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
339 | - | |||||||||||||||||||||||||||||||||||||
340 | painter->setBrush(dialGradient); | - | ||||||||||||||||||||||||||||||||||||
341 | painter->setPen(QColor(255, 255, 255, 150)); | - | ||||||||||||||||||||||||||||||||||||
342 | painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1)); | - | ||||||||||||||||||||||||||||||||||||
343 | painter->setPen(QColor(0, 0, 0, 80)); | - | ||||||||||||||||||||||||||||||||||||
344 | painter->drawEllipse(dialRect); | - | ||||||||||||||||||||||||||||||||||||
345 | painter->restore(); | - | ||||||||||||||||||||||||||||||||||||
346 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
347 | #endif //QT_NO_DIAL | - | ||||||||||||||||||||||||||||||||||||
348 | - | |||||||||||||||||||||||||||||||||||||
349 | void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect, | - | ||||||||||||||||||||||||||||||||||||
350 | int left, int top, int right, | - | ||||||||||||||||||||||||||||||||||||
351 | int bottom) | - | ||||||||||||||||||||||||||||||||||||
352 | { | - | ||||||||||||||||||||||||||||||||||||
353 | QSize size = pixmap.size(); | - | ||||||||||||||||||||||||||||||||||||
354 | //painter->setRenderHint(QPainter::SmoothPixmapTransform); | - | ||||||||||||||||||||||||||||||||||||
355 | - | |||||||||||||||||||||||||||||||||||||
356 | //top | - | ||||||||||||||||||||||||||||||||||||
357 | if (top > 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
358 | painter->drawPixmap(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), pixmap, | - | ||||||||||||||||||||||||||||||||||||
359 | QRect(left, 0, size.width() -right - left, top)); | - | ||||||||||||||||||||||||||||||||||||
360 | - | |||||||||||||||||||||||||||||||||||||
361 | //top-left | - | ||||||||||||||||||||||||||||||||||||
362 | if(left > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
363 | painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap, never executed: painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap, QRect(0, 0, left, top)); | 0 | ||||||||||||||||||||||||||||||||||||
364 | QRect(0, 0, left, top)); never executed: painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap, QRect(0, 0, left, top)); | 0 | ||||||||||||||||||||||||||||||||||||
365 | - | |||||||||||||||||||||||||||||||||||||
366 | //top-right | - | ||||||||||||||||||||||||||||||||||||
367 | if (right > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
368 | painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap, never executed: painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap, QRect(size.width() - right, 0, right, top)); | 0 | ||||||||||||||||||||||||||||||||||||
369 | QRect(size.width() - right, 0, right, top)); never executed: painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap, QRect(size.width() - right, 0, right, top)); | 0 | ||||||||||||||||||||||||||||||||||||
370 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
371 | - | |||||||||||||||||||||||||||||||||||||
372 | //left | - | ||||||||||||||||||||||||||||||||||||
373 | if (left > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
374 | painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap, never executed: painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap, QRect(0, top, left, size.height() - bottom - top)); | 0 | ||||||||||||||||||||||||||||||||||||
375 | QRect(0, top, left, size.height() - bottom - top)); never executed: painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap, QRect(0, top, left, size.height() - bottom - top)); | 0 | ||||||||||||||||||||||||||||||||||||
376 | - | |||||||||||||||||||||||||||||||||||||
377 | //center | - | ||||||||||||||||||||||||||||||||||||
378 | painter->drawPixmap(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left, | - | ||||||||||||||||||||||||||||||||||||
379 | rect.height() - bottom - top), pixmap, | - | ||||||||||||||||||||||||||||||||||||
380 | QRect(left, top, size.width() -right -left, | - | ||||||||||||||||||||||||||||||||||||
381 | size.height() - bottom - top)); | - | ||||||||||||||||||||||||||||||||||||
382 | //right | - | ||||||||||||||||||||||||||||||||||||
383 | if (right > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
384 | painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap, never executed: painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap, QRect(size.width() - right, top, right, size.height() - bottom - top)); | 0 | ||||||||||||||||||||||||||||||||||||
385 | QRect(size.width() - right, top, right, size.height() - bottom - top)); never executed: painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap, QRect(size.width() - right, top, right, size.height() - bottom - top)); | 0 | ||||||||||||||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||||||||||||||
387 | //bottom | - | ||||||||||||||||||||||||||||||||||||
388 | if (bottom > 0) {
| 0 | ||||||||||||||||||||||||||||||||||||
389 | painter->drawPixmap(QRect(rect.left() +left, rect.top() + rect.height() - bottom, | - | ||||||||||||||||||||||||||||||||||||
390 | rect.width() - right - left, bottom), pixmap, | - | ||||||||||||||||||||||||||||||||||||
391 | QRect(left, size.height() - bottom, | - | ||||||||||||||||||||||||||||||||||||
392 | size.width() - right - left, bottom)); | - | ||||||||||||||||||||||||||||||||||||
393 | //bottom-left | - | ||||||||||||||||||||||||||||||||||||
394 | if (left > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
395 | painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap, never executed: painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap, QRect(0, size.height() - bottom, left, bottom)); | 0 | ||||||||||||||||||||||||||||||||||||
396 | QRect(0, size.height() - bottom, left, bottom)); never executed: painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap, QRect(0, size.height() - bottom, left, bottom)); | 0 | ||||||||||||||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||||||||||||||
398 | //bottom-right | - | ||||||||||||||||||||||||||||||||||||
399 | if (right > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
400 | painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap, never executed: painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap, QRect(size.width() - right, size.height() - bottom, right, bottom)); | 0 | ||||||||||||||||||||||||||||||||||||
401 | QRect(size.width() - right, size.height() - bottom, right, bottom)); never executed: painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap, QRect(size.width() - right, size.height() - bottom, right, bottom)); | 0 | ||||||||||||||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||||||||||||||
403 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
404 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
405 | - | |||||||||||||||||||||||||||||||||||||
406 | QColor backgroundColor(const QPalette &pal, const QWidget* widget) | - | ||||||||||||||||||||||||||||||||||||
407 | { | - | ||||||||||||||||||||||||||||||||||||
408 | if (qobject_cast<const QScrollBar *>(widget) && widget->parent() &&
| 0 | ||||||||||||||||||||||||||||||||||||
409 | qobject_cast<const QAbstractScrollArea *>(widget->parent()->parent()))
| 0 | ||||||||||||||||||||||||||||||||||||
410 | return widget->parentWidget()->parentWidget()->palette().color(QPalette::Base); never executed: return widget->parentWidget()->parentWidget()->palette().color(QPalette::Base); | 0 | ||||||||||||||||||||||||||||||||||||
411 | return pal.color(QPalette::Base); never executed: return pal.color(QPalette::Base); | 0 | ||||||||||||||||||||||||||||||||||||
412 | } | - | ||||||||||||||||||||||||||||||||||||
413 | - | |||||||||||||||||||||||||||||||||||||
414 | QWindow *styleObjectWindow(QObject *so) | - | ||||||||||||||||||||||||||||||||||||
415 | { | - | ||||||||||||||||||||||||||||||||||||
416 | if (so)
| 0 | ||||||||||||||||||||||||||||||||||||
417 | return so->property("_q_styleObjectWindow").value<QWindow *>(); never executed: return so->property("_q_styleObjectWindow").value<QWindow *>(); | 0 | ||||||||||||||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||||||||||||||
419 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||
420 | } | - | ||||||||||||||||||||||||||||||||||||
421 | - | |||||||||||||||||||||||||||||||||||||
422 | } | - | ||||||||||||||||||||||||||||||||||||
423 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |