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

Generated by Squish Coco Non-Commercial