styles/qstylehelper.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5__attribute__((visibility("default"))) int qt_defaultDpiX(); -
6 -
7namespace QStyleHelper { -
8 -
9QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size) -
10{ -
11 const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option); -
12 QString tmp = key % HexString<uint>(option->state) -
13 % HexString<uint>(option->direction) -
14 % HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u) -
15 % HexString<quint64>(option->palette.cacheKey()) -
16 % HexString<uint>(size.width()) -
17 % HexString<uint>(size.height()); -
18 -
19 -
20 if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
evaluated: const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1436
3-1436
21 tmp = tmp % HexString<uint>(spinBox->buttonSymbols) -
22 % HexString<uint>(spinBox->stepEnabled) -
23 % QLatin1Char(spinBox->frame ? '1' : '0'); ; -
24 }
executed: }
Execution Count:3
3
25 -
26 return tmp;
executed: return tmp;
Execution Count:1439
1439
27} -
28 -
29qreal dpiScaled(qreal value) -
30{ -
31 -
32 -
33 -
34 -
35 static const qreal scale = qreal(qt_defaultDpiX()) / 96.0; -
36 return value * scale;
executed: return value * scale;
Execution Count:215013
215013
37 -
38} -
39 -
40bool isInstanceOf(QObject *obj, QAccessible::Role role) -
41{ -
42 bool match = false; -
43 -
44 QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(obj); -
45 match = iface && iface->role() == role;
never evaluated: iface
never evaluated: iface->role() == role
0
46 delete iface; -
47 -
48 -
49 -
50 -
51 return match;
never executed: return match;
0
52} -
53 -
54 -
55bool hasAncestor(QObject *obj, QAccessible::Role role) -
56{ -
57 bool found = false; -
58 -
59 QObject *parent = obj ? obj->parent() : 0;
never evaluated: obj
0
60 while (parent && !found) {
never evaluated: parent
never evaluated: !found
0
61 if (isInstanceOf(parent, role))
never evaluated: isInstanceOf(parent, role)
0
62 found = true;
never executed: found = true;
0
63 parent = parent->parent(); -
64 }
never executed: }
0
65 -
66 -
67 -
68 -
69 return found;
never executed: return found;
0
70} -
71 -
72 -
73 -
74 -
75int calcBigLineSize(int radius) -
76{ -
77 int bigLineSize = radius / 6; -
78 if (bigLineSize < 4)
partially evaluated: bigLineSize < 4
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
79 bigLineSize = 4;
never executed: bigLineSize = 4;
0
80 if (bigLineSize > radius / 2)
partially evaluated: bigLineSize > radius / 2
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
81 bigLineSize = radius / 2;
never executed: bigLineSize = radius / 2;
0
82 return bigLineSize;
executed: return bigLineSize;
Execution Count:10
10
83} -
84 -
85static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset) -
86{ -
87 const int width = dial->rect.width(); -
88 const int height = dial->rect.height(); -
89 const int r = qMin(width, height) / 2; -
90 const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
partially evaluated: dial->upsideDown
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
91 qreal a = 0; -
92 if (dial->maximum == dial->minimum)
partially evaluated: dial->maximum == dial->minimum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
93 a = Q_PI / 2;
never executed: a = Q_PI / 2;
0
94 else if (dial->dialWrapping)
partially evaluated: dial->dialWrapping
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
95 a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI 0
96 / (dial->maximum - dial->minimum);
never executed: a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI / (dial->maximum - dial->minimum);
0
97 else -
98 a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI 3
99 / (dial->maximum - dial->minimum)) / 6;
executed: a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI / (dial->maximum - dial->minimum)) / 6;
Execution Count:3
3
100 qreal xc = width / 2.0; -
101 qreal yc = height / 2.0; -
102 qreal len = r - QStyleHelper::calcBigLineSize(r) - 3; -
103 qreal back = offset * len; -
104 QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a))); -
105 return pos;
executed: return pos;
Execution Count:3
3
106} -
107 -
108qreal angle(const QPointF &p1, const QPointF &p2) -
109{ -
110 static const qreal rad_factor = 180 / Q_PI; -
111 qreal _angle = 0; -
112 -
113 if (p1.x() == p2.x()) {
partially evaluated: p1.x() == p2.x()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
114 if (p1.y() < p2.y())
never evaluated: p1.y() < p2.y()
0
115 _angle = 270;
never executed: _angle = 270;
0
116 else -
117 _angle = 90;
never executed: _angle = 90;
0
118 } else { -
119 qreal x1, x2, y1, y2; -
120 -
121 if (p1.x() <= p2.x()) {
partially evaluated: p1.x() <= p2.x()
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
122 x1 = p1.x(); y1 = p1.y(); -
123 x2 = p2.x(); y2 = p2.y(); -
124 } else {
executed: }
Execution Count:3
3
125 x2 = p1.x(); y2 = p1.y(); -
126 x1 = p2.x(); y1 = p2.y(); -
127 }
never executed: }
0
128 -
129 qreal m = -(y2 - y1) / (x2 - x1); -
130 _angle = qAtan(m) * rad_factor; -
131 -
132 if (p1.x() < p2.x())
partially evaluated: p1.x() < p2.x()
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
133 _angle = 180 - _angle;
executed: _angle = 180 - _angle;
Execution Count:3
3
134 else -
135 _angle = -_angle;
never executed: _angle = -_angle;
0
136 } -
137 return _angle;
executed: return _angle;
Execution Count:3
3
138} -
139 -
140QPolygonF calcLines(const QStyleOptionSlider *dial) -
141{ -
142 QPolygonF poly; -
143 int width = dial->rect.width(); -
144 int height = dial->rect.height(); -
145 qreal r = qMin(width, height) / 2; -
146 int bigLineSize = calcBigLineSize(int(r)); -
147 -
148 qreal xc = width / 2 + 0.5; -
149 qreal yc = height / 2 + 0.5; -
150 const int ns = dial->tickInterval; -
151 if (!ns)
partially evaluated: !ns
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
152 return poly;
never executed: return poly;
0
153 int notches = (dial->maximum + ns - 1 - dial->minimum) / ns; -
154 if (notches <= 0)
partially evaluated: notches <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
155 return poly;
never executed: return poly;
0
156 if (dial->maximum < dial->minimum || dial->maximum - dial->minimum > 1000) {
partially evaluated: dial->maximum < dial->minimum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
partially evaluated: dial->maximum - dial->minimum > 1000
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
157 int maximum = dial->minimum + 1000; -
158 notches = (maximum + ns - 1 - dial->minimum) / ns; -
159 }
never executed: }
0
160 -
161 poly.resize(2 + 2 * notches); -
162 int smallLineSize = bigLineSize / 2; -
163 for (int i = 0; i <= notches; ++i) {
evaluated: i <= notches
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:4
4-20
164 qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
partially evaluated: dial->dialWrapping
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:20
0-20
165 : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6; -
166 qreal s = qSin(angle); -
167 qreal c = qCos(angle); -
168 if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)) {
evaluated: i == 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:16
partially evaluated: (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)
TRUEFALSE
yes
Evaluation Count:16
no
Evaluation Count:0
partially evaluated: dial->pageStep
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
0-16
169 poly[2 * i] = QPointF(xc + (r - bigLineSize) * c, -
170 yc - (r - bigLineSize) * s); -
171 poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s); -
172 } else {
executed: }
Execution Count:20
20
173 poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c, -
174 yc - (r - 1 - smallLineSize) * s); -
175 poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s); -
176 }
never executed: }
0
177 } -
178 return poly;
executed: return poly;
Execution Count:4
4
179} -
180 -
181 -
182 -
183 -
184void drawDial(const QStyleOptionSlider *option, QPainter *painter) -
185{ -
186 QPalette pal = option->palette; -
187 QColor buttonColor = pal.button().color(); -
188 const int width = option->rect.width(); -
189 const int height = option->rect.height(); -
190 const bool enabled = option->state & QStyle::State_Enabled; -
191 qreal r = qMin(width, height) / 2; -
192 r -= r/50; -
193 const qreal penSize = r/20.0; -
194 -
195 painter->save(); -
196 painter->setRenderHint(QPainter::Antialiasing); -
197 -
198 -
199 if (option->subControls & QStyle::SC_DialTickmarks) {
partially evaluated: option->subControls & QStyle::SC_DialTickmarks
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
200 painter->setPen(option->palette.dark().color().darker(120)); -
201 painter->drawLines(QStyleHelper::calcLines(option)); -
202 }
executed: }
Execution Count:1
1
203 -
204 -
205 QRect rect = option->rect; QPixmap internalPixmapCache; QImage imageCache; QPainter *p = painter; QString unique = QStyleHelper::uniqueName((QString::fromLatin1("qdial")), option, option->rect.size()); int txType = painter->deviceTransform().type() | painter->worldTransform().type(); bool doPixmapCache = (txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale); if (doPixmapCache && QPixmapCache::find(unique, internalPixmapCache)) { painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); } else { if (doPixmapCache) { rect.setRect(0, 0, option->rect.width(), option->rect.height()); imageCache = styleCacheImage(option->rect.size()); imageCache.fill(0); p = new QPainter(&imageCache); };
never executed: }
executed: }
Execution Count:1
partially evaluated: doPixmapCache
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
partially evaluated: (txType <= QTransform::TxTranslate)
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
never evaluated: (painter->deviceTransform().type() == QTransform::TxScale)
partially evaluated: doPixmapCache
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
partially evaluated: QPixmapCache::find(unique, internalPixmapCache)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
206 p->setRenderHint(QPainter::Antialiasing); -
207 -
208 const qreal d_ = r / 6; -
209 const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; -
210 const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; -
211 -
212 QRectF br = QRectF(dx + 0.5, dy + 0.5, -
213 int(r * 2 - 2 * d_ - 2), -
214 int(r * 2 - 2 * d_ - 2)); -
215 buttonColor.setHsv(buttonColor .hue(), -
216 qMin(140, buttonColor .saturation()), -
217 qMax(180, buttonColor.value())); -
218 QColor shadowColor(0, 0, 0, 20); -
219 -
220 if (enabled) {
partially evaluated: enabled
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
221 -
222 qreal shadowSize = qMax(1.0, penSize/2.0); -
223 QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, -
224 2*shadowSize, 2*shadowSize); -
225 QRadialGradient shadowGradient(shadowRect.center().x(), -
226 shadowRect.center().y(), shadowRect.width()/2.0, -
227 shadowRect.center().x(), shadowRect.center().y()); -
228 shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); -
229 shadowGradient.setColorAt(qreal(1.0), Qt::transparent); -
230 p->setBrush(shadowGradient); -
231 p->setPen(Qt::NoPen); -
232 p->translate(shadowSize, shadowSize); -
233 p->drawEllipse(shadowRect); -
234 p->translate(-shadowSize, -shadowSize); -
235 -
236 -
237 QRadialGradient gradient(br.center().x() - br.width()/3, dy, -
238 br.width()*1.3, br.center().x(), -
239 br.center().y() - br.height()/2); -
240 gradient.setColorAt(0, buttonColor.lighter(110)); -
241 gradient.setColorAt(qreal(0.5), buttonColor); -
242 gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); -
243 gradient.setColorAt(1, buttonColor.darker(115)); -
244 p->setBrush(gradient); -
245 } else {
executed: }
Execution Count:1
1
246 p->setBrush(Qt::NoBrush); -
247 }
never executed: }
0
248 -
249 p->setPen(QPen(buttonColor.darker(280))); -
250 p->drawEllipse(br); -
251 p->setBrush(Qt::NoBrush); -
252 p->setPen(buttonColor.lighter(110)); -
253 p->drawEllipse(br.adjusted(1, 1, -1, -1)); -
254 -
255 if (option->state & QStyle::State_HasFocus) {
partially evaluated: option->state & QStyle::State_HasFocus
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
256 QColor highlight = pal.highlight().color(); -
257 highlight.setHsv(highlight.hue(), -
258 qMin(160, highlight.saturation()), -
259 qMax(230, highlight.value())); -
260 highlight.setAlpha(127); -
261 p->setPen(QPen(highlight, 2.0)); -
262 p->setBrush(Qt::NoBrush); -
263 p->drawEllipse(br.adjusted(-1, -1, 1, 1)); -
264 }
never executed: }
0
265 -
266 if (doPixmapCache) { p->end(); delete p; internalPixmapCache = QPixmap::fromImage(imageCache); painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); QPixmapCache::insert(unique, internalPixmapCache); } }
executed: }
Execution Count:1
executed: }
Execution Count:1
partially evaluated: doPixmapCache
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
267 -
268 QPointF dp = calcRadialPos(option, qreal(0.70)); -
269 buttonColor = buttonColor.lighter(104); -
270 buttonColor.setAlphaF(qreal(0.8)); -
271 const qreal ds = r/qreal(7.0); -
272 QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds); -
273 QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2, -
274 dialRect.center().y() + dialRect.width(), -
275 dialRect.width()*2, -
276 dialRect.center().x(), dialRect.center().y()); -
277 dialGradient.setColorAt(1, buttonColor.darker(140)); -
278 dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120)); -
279 dialGradient.setColorAt(0, buttonColor.darker(110)); -
280 if (penSize > 3.0) {
partially evaluated: penSize > 3.0
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
281 painter->setPen(QPen(QColor(0, 0, 0, 25), penSize)); -
282 painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96))); -
283 }
executed: }
Execution Count:1
1
284 -
285 painter->setBrush(dialGradient); -
286 painter->setPen(QColor(255, 255, 255, 150)); -
287 painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1)); -
288 painter->setPen(QColor(0, 0, 0, 80)); -
289 painter->drawEllipse(dialRect); -
290 painter->restore(); -
291}
executed: }
Execution Count:1
1
292 -
293 -
294void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect, -
295 int left, int top, int right, -
296 int bottom) -
297{ -
298 QSize size = pixmap.size(); -
299 -
300 -
301 -
302 if (top > 0) {
never evaluated: top > 0
0
303 painter->drawPixmap(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), pixmap, -
304 QRect(left, 0, size.width() -right - left, top)); -
305 -
306 -
307 if(left > 0)
never evaluated: left > 0
0
308 painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap, 0
309 QRect(0, 0, left, top));
never executed: painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap, QRect(0, 0, left, top));
0
310 -
311 -
312 if (right > 0)
never evaluated: right > 0
0
313 painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap, 0
314 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
315 }
never executed: }
0
316 -
317 -
318 if (left > 0)
never evaluated: left > 0
0
319 painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap, 0
320 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
321 -
322 -
323 painter->drawPixmap(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left, -
324 rect.height() - bottom - top), pixmap, -
325 QRect(left, top, size.width() -right -left, -
326 size.height() - bottom - top)); -
327 -
328 if (right > 0)
never evaluated: right > 0
0
329 painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap, 0
330 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
331 -
332 -
333 if (bottom > 0) {
never evaluated: bottom > 0
0
334 painter->drawPixmap(QRect(rect.left() +left, rect.top() + rect.height() - bottom, -
335 rect.width() - right - left, bottom), pixmap, -
336 QRect(left, size.height() - bottom, -
337 size.width() - right - left, bottom)); -
338 -
339 if (left > 0)
never evaluated: left > 0
0
340 painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap, 0
341 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
342 -
343 -
344 if (right > 0)
never evaluated: right > 0
0
345 painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap, 0
346 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
347 -
348 }
never executed: }
0
349}
never executed: }
0
350} -
351 -
352 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial