qdial.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qdial.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9class QDialPrivate : public QAbstractSliderPrivate-
10{-
11 inline QDial* q_func() { return static_cast<QDial *>(q_ptr); } inline const QDial* q_func() const { return static_cast<const QDial *>(q_ptr); } friend class QDial;-
12public:-
13 QDialPrivate()-
14 {-
15 wrapping = false;-
16 tracking = true;-
17 doNotEmit = false;-
18 target = qreal(3.7);-
19 }
never executed: end of block
0
20-
21 qreal target;-
22 uint showNotches : 1;-
23 uint wrapping : 1;-
24 uint doNotEmit : 1;-
25-
26 int valueFromPoint(const QPoint &) const;-
27 double angle(const QPoint &, const QPoint &) const;-
28 void init();-
29 virtual int bound(int val) const override;-
30};-
31-
32void QDialPrivate::init()-
33{-
34 QDial * const q = q_func();-
35 showNotches = false;-
36 q->setFocusPolicy(Qt::WheelFocus);-
37}
never executed: end of block
0
38-
39int QDialPrivate::bound(int val) const-
40{-
41 if (wrapping
wrappingDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
42 if ((
(val >= minimum)Description
TRUEnever evaluated
FALSEnever evaluated
val >= minimum)
(val >= minimum)Description
TRUEnever evaluated
FALSEnever evaluated
&& (
(val <= maximum)Description
TRUEnever evaluated
FALSEnever evaluated
val <= maximum)
(val <= maximum)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
43 return
never executed: return val;
val;
never executed: return val;
0
44 val = minimum + ((val - minimum) % (maximum - minimum));-
45 if (val < minimum
val < minimumDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
46 val += maximum - minimum;
never executed: val += maximum - minimum;
0
47 return
never executed: return val;
val;
never executed: return val;
0
48 } else {-
49 return
never executed: return QAbstractSliderPrivate::bound(val);
QAbstractSliderPrivate::bound(val);
never executed: return QAbstractSliderPrivate::bound(val);
0
50 }-
51}-
52void QDial::initStyleOption(QStyleOptionSlider *option) const-
53{-
54 if (!option
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
55 return;
never executed: return;
0
56-
57 const QDialPrivate * const d = d_func();-
58 option->initFrom(this);-
59 option->minimum = d->minimum;-
60 option->maximum = d->maximum;-
61 option->sliderPosition = d->position;-
62 option->sliderValue = d->value;-
63 option->singleStep = d->singleStep;-
64 option->pageStep = d->pageStep;-
65 option->upsideDown = !d->invertedAppearance;-
66 option->notchTarget = d->target;-
67 option->dialWrapping = d->wrapping;-
68 option->subControls = QStyle::SC_All;-
69 option->activeSubControls = QStyle::SC_None;-
70 if (!d->showNotches
!d->showNotchesDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
71 option->subControls &= ~QStyle::SC_DialTickmarks;-
72 option->tickPosition = QSlider::TicksAbove;-
73 }
never executed: end of block
else {
0
74 option->tickPosition = QSlider::NoTicks;-
75 }
never executed: end of block
0
76 option->tickInterval = notchSize();-
77}
never executed: end of block
0
78-
79int QDialPrivate::valueFromPoint(const QPoint &p) const-
80{-
81 const QDial * const q = q_func();-
82 double yy = q->height()/2.0 - p.y();-
83 double xx = p.x() - q->width()/2.0;-
84 double a = (xx
xxDescription
TRUEnever evaluated
FALSEnever evaluated
|| yy
yyDescription
TRUEnever evaluated
FALSEnever evaluated
) ? std::atan2(yy, xx) : 0;
0
85-
86 if (a < Q_PI / -2
a < Q_PI / -2Description
TRUEnever evaluated
FALSEnever evaluated
)
0
87 a = a + Q_PI * 2;
never executed: a = a + Q_PI * 2;
0
88-
89 int dist = 0;-
90 int minv = minimum, maxv = maximum;-
91-
92 if (minimum < 0
minimum < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
93 dist = -minimum;-
94 minv = 0;-
95 maxv = maximum + dist;-
96 }
never executed: end of block
0
97-
98 int r = maxv - minv;-
99 int v;-
100 if (wrapping
wrappingDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
101 v = (int)(0.5 + minv + r * (Q_PI * 3 / 2 - a) / (2 * Q_PI));
never executed: v = (int)(0.5 + minv + r * (Q_PI * 3 / 2 - a) / (2 * Q_PI));
0
102 else-
103 v = (int)(0.5 + minv + r* (Q_PI * 4 / 3 - a) / (Q_PI * 10 / 6));
never executed: v = (int)(0.5 + minv + r* (Q_PI * 4 / 3 - a) / (Q_PI * 10 / 6));
0
104-
105 if (dist > 0
dist > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
106 v -= dist;
never executed: v -= dist;
0
107-
108 return
never executed: return !invertedAppearance ? bound(v) : maximum - bound(v);
!invertedAppearance ? bound(v) : maximum - bound(v);
never executed: return !invertedAppearance ? bound(v) : maximum - bound(v);
0
109}-
110QDial::QDial(QWidget *parent)-
111 : QAbstractSlider(*new QDialPrivate, parent)-
112{-
113 QDialPrivate * const d = d_func();-
114 d->init();-
115}
never executed: end of block
0
116-
117-
118-
119-
120QDial::~QDial()-
121{-
122}-
123-
124-
125void QDial::resizeEvent(QResizeEvent *e)-
126{-
127 QWidget::resizeEvent(e);-
128}
never executed: end of block
0
129-
130-
131-
132-
133-
134void QDial::paintEvent(QPaintEvent *)-
135{-
136 QStylePainter p(this);-
137 QStyleOptionSlider option;-
138 initStyleOption(&option);-
139 p.drawComplexControl(QStyle::CC_Dial, option);-
140}
never executed: end of block
0
141-
142-
143-
144-
145-
146void QDial::mousePressEvent(QMouseEvent *e)-
147{-
148 QDialPrivate * const d = d_func();-
149 if (d->maximum == d->minimum
d->maximum == d->minimumDescription
TRUEnever evaluated
FALSEnever evaluated
||
0
150 (
(e->button() !...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
e->button() != Qt::LeftButton)
(e->button() !...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
||
0
151 (
(e->buttons() ^ e->button())Description
TRUEnever evaluated
FALSEnever evaluated
e->buttons() ^ e->button())
(e->buttons() ^ e->button())Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
152 e->ignore();-
153 return;
never executed: return;
0
154 }-
155 e->accept();-
156 setSliderPosition(d->valueFromPoint(e->pos()));-
157-
158-
159-
160-
161 setSliderDown(true);-
162}
never executed: end of block
0
163-
164-
165-
166-
167-
168-
169void QDial::mouseReleaseEvent(QMouseEvent * e)-
170{-
171 QDialPrivate * const d = d_func();-
172 if (e->buttons() & (~e->button())
e->buttons() & (~e->button())Description
TRUEnever evaluated
FALSEnever evaluated
||
0
173 (
(e->button() !...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
e->button() != Qt::LeftButton)
(e->button() !...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
174 e->ignore();-
175 return;
never executed: return;
0
176 }-
177 e->accept();-
178 setValue(d->valueFromPoint(e->pos()));-
179 setSliderDown(false);-
180}
never executed: end of block
0
181-
182-
183-
184-
185-
186-
187void QDial::mouseMoveEvent(QMouseEvent * e)-
188{-
189 QDialPrivate * const d = d_func();-
190 if (!(e->buttons() & Qt::LeftButton)
!(e->buttons()...t::LeftButton)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
191 e->ignore();-
192 return;
never executed: return;
0
193 }-
194 e->accept();-
195 d->doNotEmit = true;-
196 setSliderPosition(d->valueFromPoint(e->pos()));-
197 d->doNotEmit = false;-
198}
never executed: end of block
0
199-
200-
201-
202-
203-
204-
205void QDial::sliderChange(SliderChange change)-
206{-
207 QAbstractSlider::sliderChange(change);-
208}
never executed: end of block
0
209-
210void QDial::setWrapping(bool enable)-
211{-
212 QDialPrivate * const d = d_func();-
213 if (d->wrapping == enable
d->wrapping == enableDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
214 return;
never executed: return;
0
215 d->wrapping = enable;-
216 update();-
217}
never executed: end of block
0
218bool QDial::wrapping() const-
219{-
220 const QDialPrivate * const d = d_func();-
221 return
never executed: return d->wrapping;
d->wrapping;
never executed: return d->wrapping;
0
222}-
223int QDial::notchSize() const-
224{-
225 const QDialPrivate * const d = d_func();-
226-
227 int r = qMin(width(), height())/2;-
228-
229 int l = (int)(r * (d->wrapping ? 6 : 5) * Q_PI / 6);-
230-
231 if (d->maximum > d->minimum + d->pageStep
d->maximum > d... + d->pageStepDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
232 l = (int)(0.5 + l * d->pageStep / (d->maximum - d->minimum));
never executed: l = (int)(0.5 + l * d->pageStep / (d->maximum - d->minimum));
0
233-
234 l = l * d->singleStep / (d->pageStep
d->pageStepDescription
TRUEnever evaluated
FALSEnever evaluated
? d->pageStep : 1);
0
235 if (l < 1
l < 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
236 l = 1;
never executed: l = 1;
0
237-
238 l = (int)(0.5 + d->target / l);-
239-
240 if (!l
!lDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
241 l = 1;
never executed: l = 1;
0
242 return
never executed: return d->singleStep * l;
d->singleStep * l;
never executed: return d->singleStep * l;
0
243}-
244-
245void QDial::setNotchTarget(double target)-
246{-
247 QDialPrivate * const d = d_func();-
248 d->target = target;-
249 update();-
250}
never executed: end of block
0
251qreal QDial::notchTarget() const-
252{-
253 const QDialPrivate * const d = d_func();-
254 return
never executed: return d->target;
d->target;
never executed: return d->target;
0
255}-
256-
257-
258void QDial::setNotchesVisible(bool visible)-
259{-
260 QDialPrivate * const d = d_func();-
261 d->showNotches = visible;-
262 update();-
263}
never executed: end of block
0
264bool QDial::notchesVisible() const-
265{-
266 const QDialPrivate * const d = d_func();-
267 return
never executed: return d->showNotches;
d->showNotches;
never executed: return d->showNotches;
0
268}-
269-
270-
271-
272-
273-
274QSize QDial::minimumSizeHint() const-
275{-
276 return
never executed: return QSize(50, 50);
QSize(50, 50);
never executed: return QSize(50, 50);
0
277}-
278-
279-
280-
281-
282-
283QSize QDial::sizeHint() const-
284{-
285 return
never executed: return QSize(100, 100).expandedTo(QApplication::globalStrut());
QSize(100, 100).expandedTo(QApplication::globalStrut());
never executed: return QSize(100, 100).expandedTo(QApplication::globalStrut());
0
286}-
287-
288-
289-
290-
291bool QDial::event(QEvent *e)-
292{-
293 return
never executed: return QAbstractSlider::event(e);
QAbstractSlider::event(e);
never executed: return QAbstractSlider::event(e);
0
294}-
295-
296-
297-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9