qprogressbar.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qprogressbar.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7class QProgressBarPrivate : public QWidgetPrivate-
8{-
9 inline QProgressBar* q_func() { return static_cast<QProgressBar *>(q_ptr); } inline const QProgressBar* q_func() const { return static_cast<const QProgressBar *>(q_ptr); } friend class QProgressBar;-
10-
11public:-
12 QProgressBarPrivate();-
13-
14 void init();-
15 void initDefaultFormat();-
16 inline void resetLayoutItemMargins();-
17-
18 int minimum;-
19 int maximum;-
20 int value;-
21 Qt::Alignment alignment;-
22 uint textVisible : 1;-
23 uint defaultFormat: 1;-
24 int lastPaintedValue;-
25 Qt::Orientation orientation;-
26 bool invertedAppearance;-
27 QProgressBar::Direction textDirection;-
28 QString format;-
29 inline int bound(int val) const { return
never executed: return qMax(minimum-1, qMin(maximum, val));
qMax(minimum-1, qMin(maximum, val));
never executed: return qMax(minimum-1, qMin(maximum, val));
}
0
30 bool repaintRequired() const;-
31};-
32-
33QProgressBarPrivate::QProgressBarPrivate()-
34 : minimum(0), maximum(100), value(-1), alignment(Qt::AlignLeft), textVisible(true),-
35 defaultFormat(true), lastPaintedValue(-1), orientation(Qt::Horizontal), invertedAppearance(false),-
36 textDirection(QProgressBar::TopToBottom)-
37{-
38 initDefaultFormat();-
39}
never executed: end of block
0
40-
41void QProgressBarPrivate::initDefaultFormat()-
42{-
43 if (defaultFormat
defaultFormatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
44 format = QLatin1String("%p") + locale.percent();
never executed: format = QLatin1String("%p") + locale.percent();
0
45}
never executed: end of block
0
46-
47void QProgressBarPrivate::init()-
48{-
49 QProgressBar * const q = q_func();-
50 QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed);-
51 if (orientation == Qt::Vertical
orientation == Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
52 sp.transpose();
never executed: sp.transpose();
0
53 q->setSizePolicy(sp);-
54 q->setAttribute(Qt::WA_WState_OwnSizePolicy, false);-
55 resetLayoutItemMargins();-
56}
never executed: end of block
0
57-
58void QProgressBarPrivate::resetLayoutItemMargins()-
59{-
60 QProgressBar * const q = q_func();-
61 QStyleOptionProgressBar option;-
62 q->initStyleOption(&option);-
63 setLayoutItemMargins(QStyle::SE_ProgressBarLayoutItem, &option);-
64}
never executed: end of block
0
65void QProgressBar::initStyleOption(QStyleOptionProgressBar *option) const-
66{-
67 if (!option
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
68 return;
never executed: return;
0
69 const QProgressBarPrivate * const d = d_func();-
70 option->initFrom(this);-
71-
72 if (d->orientation == Qt::Horizontal
d->orientation...Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
73 option->state |= QStyle::State_Horizontal;
never executed: option->state |= QStyle::State_Horizontal;
0
74 option->minimum = d->minimum;-
75 option->maximum = d->maximum;-
76 option->progress = d->value;-
77 option->textAlignment = d->alignment;-
78 option->textVisible = d->textVisible;-
79 option->text = text();-
80 option->orientation = d->orientation;-
81 option->invertedAppearance = d->invertedAppearance;-
82 option->bottomToTop = d->textDirection == QProgressBar::BottomToTop;-
83}
never executed: end of block
0
84-
85bool QProgressBarPrivate::repaintRequired() const-
86{-
87 const QProgressBar * const q = q_func();-
88 if (value == lastPaintedValue
value == lastPaintedValueDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
89 return
never executed: return false;
false;
never executed: return false;
0
90-
91 int valueDifference = qAbs(value - lastPaintedValue);-
92-
93-
94 if (value == minimum
value == minimumDescription
TRUEnever evaluated
FALSEnever evaluated
|| value == maximum
value == maximumDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
95 return
never executed: return true;
true;
never executed: return true;
0
96 if (textVisible
textVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
97 if ((
(format.contai...String("%v")))Description
TRUEnever evaluated
FALSEnever evaluated
format.contains(QLatin1String("%v")))
(format.contai...String("%v")))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
98 return
never executed: return true;
true;
never executed: return true;
0
99 if ((format.contains(QLatin1String("%p"))
format.contain...1String("%p"))Description
TRUEnever evaluated
FALSEnever evaluated
0
100 && valueDifference >= qAbs((maximum - minimum) / 100)
valueDifferenc...inimum) / 100)Description
TRUEnever evaluated
FALSEnever evaluated
))
0
101 return
never executed: return true;
true;
never executed: return true;
0
102 }
never executed: end of block
0
103-
104-
105 QStyleOptionProgressBar opt;-
106 q->initStyleOption(&opt);-
107 int cw = q->style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, q);-
108 QRect groove = q->style()->subElementRect(QStyle::SE_ProgressBarGroove, &opt, q);-
109-
110-
111-
112 int grooveBlock = (
(q->orientatio...t::Horizontal)Description
TRUEnever evaluated
FALSEnever evaluated
q->orientation() == Qt::Horizontal)
(q->orientatio...t::Horizontal)Description
TRUEnever evaluated
FALSEnever evaluated
? groove.width() : groove.height();
0
113 return
never executed: return (valueDifference * grooveBlock > cw * (maximum - minimum));
(valueDifference * grooveBlock > cw * (maximum - minimum));
never executed: return (valueDifference * grooveBlock > cw * (maximum - minimum));
0
114}-
115QProgressBar::QProgressBar(QWidget *parent)-
116 : QWidget(*(new QProgressBarPrivate), parent, 0)-
117{-
118 d_func()->init();-
119}
never executed: end of block
0
120-
121-
122-
123-
124QProgressBar::~QProgressBar()-
125{-
126}-
127-
128-
129-
130-
131-
132-
133void QProgressBar::reset()-
134{-
135 QProgressBarPrivate * const d = d_func();-
136 d->value = d->minimum - 1;-
137 if (d->minimum == (-2147483647 - 1)
d->minimum == ...147483647 - 1)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
138 d->value = (-2147483647 - 1);
never executed: d->value = (-2147483647 - 1);
0
139 repaint();-
140}
never executed: end of block
0
141void QProgressBar::setMinimum(int minimum)-
142{-
143 setRange(minimum, qMax(d_func()->maximum, minimum));-
144}
never executed: end of block
0
145-
146int QProgressBar::minimum() const-
147{-
148 return
never executed: return d_func()->minimum;
d_func()->minimum;
never executed: return d_func()->minimum;
0
149}-
150void QProgressBar::setMaximum(int maximum)-
151{-
152 setRange(qMin(d_func()->minimum, maximum), maximum);-
153}
never executed: end of block
0
154-
155int QProgressBar::maximum() const-
156{-
157 return
never executed: return d_func()->maximum;
d_func()->maximum;
never executed: return d_func()->maximum;
0
158}-
159void QProgressBar::setValue(int value)-
160{-
161 QProgressBarPrivate * const d = d_func();-
162 if (d->value == value
d->value == valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
163 || ((value > d->maximum
value > d->maximumDescription
TRUEnever evaluated
FALSEnever evaluated
|| value < d->minimum
value < d->minimumDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
164 && (d->maximum != 0
d->maximum != 0Description
TRUEnever evaluated
FALSEnever evaluated
|| d->minimum != 0
d->minimum != 0Description
TRUEnever evaluated
FALSEnever evaluated
)))
0
165 return;
never executed: return;
0
166 d->value = value;-
167 valueChanged(value);-
168-
169 if (isVisible()
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
170 QAccessibleValueChangeEvent event(this, value);-
171 QAccessible::updateAccessibility(&event);-
172 }
never executed: end of block
0
173-
174 if (d->repaintRequired()
d->repaintRequired()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
175 repaint();
never executed: repaint();
0
176}
never executed: end of block
0
177-
178int QProgressBar::value() const-
179{-
180 return
never executed: return d_func()->value;
d_func()->value;
never executed: return d_func()->value;
0
181}-
182void QProgressBar::setRange(int minimum, int maximum)-
183{-
184 QProgressBarPrivate * const d = d_func();-
185 if (minimum != d->minimum
minimum != d->minimumDescription
TRUEnever evaluated
FALSEnever evaluated
|| maximum != d->maximum
maximum != d->maximumDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
186 d->minimum = minimum;-
187 d->maximum = qMax(minimum, maximum);-
188-
189 if (d->value < (d->minimum - 1)
d->value < (d->minimum - 1)Description
TRUEnever evaluated
FALSEnever evaluated
|| d->value > d->maximum
d->value > d->maximumDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
190 reset();
never executed: reset();
0
191 else-
192 update();
never executed: update();
0
193 }-
194}
never executed: end of block
0
195void QProgressBar::setTextVisible(bool visible)-
196{-
197 QProgressBarPrivate * const d = d_func();-
198 if (d->textVisible != visible
d->textVisible != visibleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
199 d->textVisible = visible;-
200 repaint();-
201 }
never executed: end of block
0
202}
never executed: end of block
0
203-
204bool QProgressBar::isTextVisible() const-
205{-
206 return
never executed: return d_func()->textVisible;
d_func()->textVisible;
never executed: return d_func()->textVisible;
0
207}-
208-
209-
210-
211-
212-
213void QProgressBar::setAlignment(Qt::Alignment alignment)-
214{-
215 if (d_func()->alignment != alignment
d_func()->alig...t != alignmentDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
216 d_func()->alignment = alignment;-
217 repaint();-
218 }
never executed: end of block
0
219}
never executed: end of block
0
220-
221Qt::Alignment QProgressBar::alignment() const-
222{-
223 return
never executed: return d_func()->alignment;
d_func()->alignment;
never executed: return d_func()->alignment;
0
224}-
225-
226-
227-
228-
229void QProgressBar::paintEvent(QPaintEvent *)-
230{-
231 QStylePainter paint(this);-
232 QStyleOptionProgressBar opt;-
233 initStyleOption(&opt);-
234 paint.drawControl(QStyle::CE_ProgressBar, opt);-
235 d_func()->lastPaintedValue = d_func()->value;-
236}
never executed: end of block
0
237-
238-
239-
240-
241QSize QProgressBar::sizeHint() const-
242{-
243 ensurePolished();-
244 QFontMetrics fm = fontMetrics();-
245 QStyleOptionProgressBar opt;-
246 initStyleOption(&opt);-
247 int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this);-
248 QSize size = QSize(qMax(9, cw) * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8);-
249 if (opt.orientation == Qt::Vertical
opt.orientatio...= Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
250 size = size.transposed();
never executed: size = size.transposed();
0
251 return
never executed: return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this);
style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this);
never executed: return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this);
0
252}-
253-
254-
255-
256-
257QSize QProgressBar::minimumSizeHint() const-
258{-
259 QSize size;-
260 if (orientation() == Qt::Horizontal
orientation() ...Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
261 size = QSize(sizeHint().width(), fontMetrics().height() + 2);
never executed: size = QSize(sizeHint().width(), fontMetrics().height() + 2);
0
262 else-
263 size = QSize(fontMetrics().height() + 2, sizeHint().height());
never executed: size = QSize(fontMetrics().height() + 2, sizeHint().height());
0
264 return
never executed: return size;
size;
never executed: return size;
0
265}-
266QString QProgressBar::text() const-
267{-
268 const QProgressBarPrivate * const d = d_func();-
269 if ((d->maximum == 0
d->maximum == 0Description
TRUEnever evaluated
FALSEnever evaluated
&& d->minimum == 0
d->minimum == 0Description
TRUEnever evaluated
FALSEnever evaluated
) || d->value < d->minimum
d->value < d->minimumDescription
TRUEnever evaluated
FALSEnever evaluated
0
270 || (d->value == (-2147483647 - 1)
d->value == (-2147483647 - 1)Description
TRUEnever evaluated
FALSEnever evaluated
&& d->minimum == (-2147483647 - 1)
d->minimum == ...147483647 - 1)Description
TRUEnever evaluated
FALSEnever evaluated
))
0
271 return
never executed: return QString();
QString();
never executed: return QString();
0
272-
273 qint64 totalSteps = qint64(d->maximum) - d->minimum;-
274-
275 QString result = d->format;-
276 QLocale locale = d->locale;-
277 locale.setNumberOptions(locale.numberOptions() | QLocale::OmitGroupSeparator);-
278 result.replace(QLatin1String("%m"), locale.toString(totalSteps));-
279 result.replace(QLatin1String("%v"), locale.toString(d->value));-
280-
281-
282-
283-
284 if (totalSteps == 0
totalSteps == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
285 result.replace(QLatin1String("%p"), locale.toString(int(100)));-
286 return
never executed: return result;
result;
never executed: return result;
0
287 }-
288-
289 int progress = (qreal(d->value) - d->minimum) * 100.0 / totalSteps;-
290 result.replace(QLatin1String("%p"), locale.toString(progress));-
291 return
never executed: return result;
result;
never executed: return result;
0
292}-
293void QProgressBar::setOrientation(Qt::Orientation orientation)-
294{-
295 QProgressBarPrivate * const d = d_func();-
296 if (d->orientation == orientation
d->orientation == orientationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
297 return;
never executed: return;
0
298 d->orientation = orientation;-
299 if (!testAttribute(Qt::WA_WState_OwnSizePolicy)
!testAttribute...OwnSizePolicy)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
300 QSizePolicy sp = sizePolicy();-
301 sp.transpose();-
302 setSizePolicy(sp);-
303 setAttribute(Qt::WA_WState_OwnSizePolicy, false);-
304 }
never executed: end of block
0
305 d->resetLayoutItemMargins();-
306 update();-
307 updateGeometry();-
308}
never executed: end of block
0
309-
310Qt::Orientation QProgressBar::orientation() const-
311{-
312 const QProgressBarPrivate * const d = d_func();-
313 return
never executed: return d->orientation;
d->orientation;
never executed: return d->orientation;
0
314}-
315void QProgressBar::setInvertedAppearance(bool invert)-
316{-
317 QProgressBarPrivate * const d = d_func();-
318 d->invertedAppearance = invert;-
319 update();-
320}
never executed: end of block
0
321-
322bool QProgressBar::invertedAppearance() const-
323{-
324 const QProgressBarPrivate * const d = d_func();-
325 return
never executed: return d->invertedAppearance;
d->invertedAppearance;
never executed: return d->invertedAppearance;
0
326}-
327void QProgressBar::setTextDirection(QProgressBar::Direction textDirection)-
328{-
329 QProgressBarPrivate * const d = d_func();-
330 d->textDirection = textDirection;-
331 update();-
332}
never executed: end of block
0
333-
334QProgressBar::Direction QProgressBar::textDirection() const-
335{-
336 const QProgressBarPrivate * const d = d_func();-
337 return
never executed: return d->textDirection;
d->textDirection;
never executed: return d->textDirection;
0
338}-
339-
340-
341bool QProgressBar::event(QEvent *e)-
342{-
343 QProgressBarPrivate * const d = d_func();-
344 switch (e->type()) {-
345 case
never executed: case QEvent::StyleChange:
QEvent::StyleChange:
never executed: case QEvent::StyleChange:
0
346-
347-
348-
349 d->resetLayoutItemMargins();-
350 break;
never executed: break;
0
351 case
never executed: case QEvent::LocaleChange:
QEvent::LocaleChange:
never executed: case QEvent::LocaleChange:
0
352 d->initDefaultFormat();-
353 break;
never executed: break;
0
354 default
never executed: default:
:
never executed: default:
0
355 break;
never executed: break;
0
356 }-
357 return
never executed: return QWidget::event(e);
QWidget::event(e);
never executed: return QWidget::event(e);
0
358}-
359void QProgressBar::setFormat(const QString &format)-
360{-
361 QProgressBarPrivate * const d = d_func();-
362 if (d->format == format
d->format == formatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
363 return;
never executed: return;
0
364 d->format = format;-
365 d->defaultFormat = false;-
366 update();-
367}
never executed: end of block
0
368-
369void QProgressBar::resetFormat()-
370{-
371 QProgressBarPrivate * const d = d_func();-
372 d->defaultFormat = true;-
373 d->initDefaultFormat();-
374 update();-
375}
never executed: end of block
0
376-
377QString QProgressBar::format() const-
378{-
379 const QProgressBarPrivate * const d = d_func();-
380 return
never executed: return d->format;
d->format;
never executed: return d->format;
0
381}-
382-
383-
384-
Switch to Source codePreprocessed file

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