qstatusbar.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qstatusbar.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10class QStatusBarPrivate : public QWidgetPrivate-
11{-
12 inline QStatusBar* q_func() { return static_cast<QStatusBar *>(q_ptr); } inline const QStatusBar* q_func() const { return static_cast<const QStatusBar *>(q_ptr); } friend class QStatusBar;-
13public:-
14 QStatusBarPrivate() {}-
15-
16 struct SBItem {-
17 SBItem(QWidget* widget, int stretch, bool permanent)-
18 : s(stretch), w(widget), p(permanent) {}
never executed: end of block
0
19 int s;-
20 QWidget * w;-
21 bool p;-
22 };-
23-
24 QList<SBItem *> items;-
25 QString tempItem;-
26-
27 QBoxLayout * box;-
28 QTimer * timer;-
29-
30-
31 QSizeGrip * resizer;-
32 bool showSizeGrip;-
33-
34-
35 int savedStrut;-
36-
37-
38-
39-
40-
41 int indexToLastNonPermanentWidget() const-
42 {-
43 int i = items.size() - 1;-
44 for (; i >= 0
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
; --i) {
0
45 SBItem *item = items.at(i);-
46 if (!(item
itemDescription
TRUEnever evaluated
FALSEnever evaluated
&& item->p
item->pDescription
TRUEnever evaluated
FALSEnever evaluated
))
0
47 break;
never executed: break;
0
48 }
never executed: end of block
0
49 return
never executed: return i;
i;
never executed: return i;
0
50 }-
51-
52-
53 void tryToShowSizeGrip()-
54 {-
55 if (!showSizeGrip
!showSizeGripDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
56 return;
never executed: return;
0
57 showSizeGrip = false;-
58 if (!resizer
!resizerDescription
TRUEnever evaluated
FALSEnever evaluated
|| resizer->isVisible()
resizer->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
59 return;
never executed: return;
0
60 resizer->setAttribute(Qt::WA_WState_ExplicitShowHide, false);-
61 QMetaObject::invokeMethod(resizer, "_q_showIfNotHidden", Qt::DirectConnection);-
62 resizer->setAttribute(Qt::WA_WState_ExplicitShowHide, false);-
63 }
never executed: end of block
0
64-
65-
66 QRect messageRect() const;-
67};-
68-
69-
70QRect QStatusBarPrivate::messageRect() const-
71{-
72 const QStatusBar * const q = q_func();-
73 bool rtl = q->layoutDirection() == Qt::RightToLeft;-
74-
75 int left = 6;-
76 int right = q->width() - 12;-
77-
78-
79 if (resizer
resizerDescription
TRUEnever evaluated
FALSEnever evaluated
&& resizer->isVisible()
resizer->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
80 if (rtl
rtlDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
81 left = resizer->x() + resizer->width();
never executed: left = resizer->x() + resizer->width();
0
82 else-
83 right = resizer->x();
never executed: right = resizer->x();
0
84 }-
85-
86-
87 for (int i=0; i<items.size()
i<items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
88 QStatusBarPrivate::SBItem* item = items.at(i);-
89 if (!item
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
90 break;
never executed: break;
0
91 if (item->p
item->pDescription
TRUEnever evaluated
FALSEnever evaluated
&& item->w->isVisible()
item->w->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
92 if (item->p
item->pDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
93 if (rtl
rtlDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
94 left = qMax(left, item->w->x() + item->w->width() + 2);
never executed: left = qMax(left, item->w->x() + item->w->width() + 2);
0
95 else-
96 right = qMin(right, item->w->x() - 2);
never executed: right = qMin(right, item->w->x() - 2);
0
97 }-
98 break;
never executed: break;
0
99 }-
100 }
never executed: end of block
0
101 return
never executed: return QRect(left, 0, right-left, q->height());
QRect(left, 0, right-left, q->height());
never executed: return QRect(left, 0, right-left, q->height());
0
102}-
103QStatusBar::QStatusBar(QWidget * parent)-
104 : QWidget(*new QStatusBarPrivate, parent, 0)-
105{-
106 QStatusBarPrivate * const d = d_func();-
107 d->box = 0;-
108 d->timer = 0;-
109-
110-
111 d->resizer = 0;-
112 setSizeGripEnabled(true);-
113-
114-
115-
116}
never executed: end of block
0
117-
118-
119-
120-
121-
122QStatusBar::~QStatusBar()-
123{-
124 QStatusBarPrivate * const d = d_func();-
125 while (!d->items.isEmpty()
!d->items.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
126 delete d->items.takeFirst();
never executed: delete d->items.takeFirst();
0
127}
never executed: end of block
0
128void QStatusBar::addWidget(QWidget * widget, int stretch)-
129{-
130 if (!widget
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
131 return;
never executed: return;
0
132 insertWidget(d_func()->indexToLastNonPermanentWidget() + 1, widget, stretch);-
133}
never executed: end of block
0
134int QStatusBar::insertWidget(int index, QWidget *widget, int stretch)-
135{-
136 if (!widget
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
137 return
never executed: return -1;
-1;
never executed: return -1;
0
138-
139 QStatusBarPrivate * const d = d_func();-
140 QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, false);-
141-
142 int idx = d->indexToLastNonPermanentWidget();-
143 if (__builtin_expect(!!(index < 0 || index > d->items.size() || (idx >= 0 && index > idx + 1)), false)
__builtin_expe... + 1)), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
144 QMessageLogger(__FILE__, 306, __PRETTY_FUNCTION__).warning("QStatusBar::insertWidget: Index out of range (%d), appending widget", index);-
145 index = idx + 1;-
146 }
never executed: end of block
0
147 d->items.insert(index, item);-
148-
149 if (!d->tempItem.isEmpty()
!d->tempItem.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
150 widget->hide();
never executed: widget->hide();
0
151-
152 reformat();-
153 if (!widget->isHidden()
!widget->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
|| !widget->testAttribute(Qt::WA_WState_ExplicitShowHide)
!widget->testA...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
154 widget->show();
never executed: widget->show();
0
155-
156 return
never executed: return index;
index;
never executed: return index;
0
157}-
158void QStatusBar::addPermanentWidget(QWidget * widget, int stretch)-
159{-
160 if (!widget
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
161 return;
never executed: return;
0
162 insertPermanentWidget(d_func()->items.size(), widget, stretch);-
163}
never executed: end of block
0
164int QStatusBar::insertPermanentWidget(int index, QWidget *widget, int stretch)-
165{-
166 if (!widget
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
167 return
never executed: return -1;
-1;
never executed: return -1;
0
168-
169 QStatusBarPrivate * const d = d_func();-
170 QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, true);-
171-
172 int idx = d->indexToLastNonPermanentWidget();-
173 if (__builtin_expect(!!(index < 0 || index > d->items.size() || (idx >= 0 && index <= idx)), false)
__builtin_expe... idx)), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
174 QMessageLogger(__FILE__, 371, __PRETTY_FUNCTION__).warning("QStatusBar::insertPermanentWidget: Index out of range (%d), appending widget", index);-
175 index = d->items.size();-
176 }
never executed: end of block
0
177 d->items.insert(index, item);-
178-
179 reformat();-
180 if (!widget->isHidden()
!widget->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
|| !widget->testAttribute(Qt::WA_WState_ExplicitShowHide)
!widget->testA...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
181 widget->show();
never executed: widget->show();
0
182-
183 return
never executed: return index;
index;
never executed: return index;
0
184}-
185void QStatusBar::removeWidget(QWidget *widget)-
186{-
187 if (!widget
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
188 return;
never executed: return;
0
189-
190 QStatusBarPrivate * const d = d_func();-
191 bool found = false;-
192 QStatusBarPrivate::SBItem* item;-
193 for (int i=0; i<d->items.size()
i<d->items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
194 item = d->items.at(i);-
195 if (!item
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
196 break;
never executed: break;
0
197 if (item->w == widget
item->w == widgetDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
198 d->items.removeAt(i);-
199 item->w->hide();-
200 delete item;-
201 found = true;-
202 break;
never executed: break;
0
203 }-
204 }
never executed: end of block
0
205-
206 if (found
foundDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
207 reformat();
never executed: reformat();
0
208-
209 else-
210 QMessageLogger(__FILE__, 418, __PRETTY_FUNCTION__).debug("QStatusBar::removeWidget(): Widget not found.");
never executed: QMessageLogger(__FILE__, 418, __PRETTY_FUNCTION__).debug("QStatusBar::removeWidget(): Widget not found.");
0
211-
212}-
213bool QStatusBar::isSizeGripEnabled() const-
214{-
215-
216-
217-
218 const QStatusBarPrivate * const d = d_func();-
219 return
never executed: return !!d->resizer;
!!d->resizer;
never executed: return !!d->resizer;
0
220-
221}-
222-
223void QStatusBar::setSizeGripEnabled(bool enabled)-
224{-
225-
226-
227-
228 QStatusBarPrivate * const d = d_func();-
229 if (!enabled != !d->resizer
!enabled != !d->resizerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
230 if (enabled
enabledDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
231 d->resizer = new QSizeGrip(this);-
232 d->resizer->hide();-
233 d->resizer->installEventFilter(this);-
234 d->showSizeGrip = true;-
235 }
never executed: end of block
else {
0
236 delete d->resizer;-
237 d->resizer = 0;-
238 d->showSizeGrip = false;-
239 }
never executed: end of block
0
240 reformat();-
241 if (d->resizer
d->resizerDescription
TRUEnever evaluated
FALSEnever evaluated
&& isVisible()
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
242 d->tryToShowSizeGrip();
never executed: d->tryToShowSizeGrip();
0
243 }
never executed: end of block
0
244-
245}
never executed: end of block
0
246void QStatusBar::reformat()-
247{-
248 QStatusBarPrivate * const d = d_func();-
249 if (d->box
d->boxDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
250 delete d->box;
never executed: delete d->box;
0
251-
252 QBoxLayout *vbox;-
253-
254 if (d->resizer
d->resizerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
255 d->box = new QHBoxLayout(this);-
256 d->box->setMargin(0);-
257 vbox = new QVBoxLayout;-
258 d->box->addLayout(vbox);-
259 }
never executed: end of block
else
0
260-
261 {-
262 vbox = d->box = new QVBoxLayout(this);-
263 d->box->setMargin(0);-
264 }
never executed: end of block
0
265 vbox->addSpacing(3);-
266 QBoxLayout* l = new QHBoxLayout;-
267 vbox->addLayout(l);-
268 l->addSpacing(2);-
269 l->setSpacing(6);-
270-
271 int maxH = fontMetrics().height();-
272-
273 int i;-
274 QStatusBarPrivate::SBItem* item;-
275 for (i=0,item=0; i<d->items.size()
i<d->items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
276 item = d->items.at(i);-
277 if (!item
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
|| item->p
item->pDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
278 break;
never executed: break;
0
279 l->addWidget(item->w, item->s);-
280 int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight());-
281 maxH = qMax(maxH, itemH);-
282 }
never executed: end of block
0
283-
284 l->addStretch(0);-
285-
286 for (item=0; i<d->items.size()
i<d->items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
287 item = d->items.at(i);-
288 if (!item
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
289 break;
never executed: break;
0
290 l->addWidget(item->w, item->s);-
291 int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight());-
292 maxH = qMax(maxH, itemH);-
293 }
never executed: end of block
0
294-
295 if (d->resizer
d->resizerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
296 maxH = qMax(maxH, d->resizer->sizeHint().height());-
297 d->box->addSpacing(1);-
298 d->box->addWidget(d->resizer, 0, Qt::AlignBottom);-
299 }
never executed: end of block
0
300-
301 l->addStrut(maxH);-
302 d->savedStrut = maxH;-
303 vbox->addSpacing(2);-
304 d->box->activate();-
305 update();-
306}
never executed: end of block
0
307void QStatusBar::showMessage(const QString &message, int timeout)-
308{-
309 QStatusBarPrivate * const d = d_func();-
310-
311 if (timeout > 0
timeout > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
312 if (!d->timer
!d->timerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
313 d->timer = new QTimer(this);-
314 connect(d->timer, qFlagLocation("2""timeout()" "\0" __FILE__ ":" "555"), this, qFlagLocation("1""clearMessage()" "\0" __FILE__ ":" "555"));-
315 }
never executed: end of block
0
316 d->timer->start(timeout);-
317 }
never executed: end of block
else if (d->timer
d->timerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
318 delete d->timer;-
319 d->timer = 0;-
320 }
never executed: end of block
0
321 if (d->tempItem == message
d->tempItem == messageDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
322 return;
never executed: return;
0
323 d->tempItem = message;-
324-
325 hideOrShow();-
326}
never executed: end of block
0
327-
328-
329-
330-
331-
332-
333-
334void QStatusBar::clearMessage()-
335{-
336 QStatusBarPrivate * const d = d_func();-
337 if (d->tempItem.isEmpty()
d->tempItem.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
338 return;
never executed: return;
0
339 if (d->timer
d->timerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
340 qDeleteInEventHandler(d->timer);-
341 d->timer = 0;-
342 }
never executed: end of block
0
343 d->tempItem.clear();-
344 hideOrShow();-
345}
never executed: end of block
0
346-
347-
348-
349-
350-
351-
352-
353QString QStatusBar::currentMessage() const-
354{-
355 const QStatusBarPrivate * const d = d_func();-
356 return
never executed: return d->tempItem;
d->tempItem;
never executed: return d->tempItem;
0
357}-
358void QStatusBar::hideOrShow()-
359{-
360 QStatusBarPrivate * const d = d_func();-
361 bool haveMessage = !d->tempItem.isEmpty();-
362-
363 QStatusBarPrivate::SBItem* item = 0;-
364 for (int i=0; i<d->items.size()
i<d->items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
365 item = d->items.at(i);-
366 if (!item
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
|| item->p
item->pDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
367 break;
never executed: break;
0
368 if (haveMessage
haveMessageDescription
TRUEnever evaluated
FALSEnever evaluated
&& item->w->isVisible()
item->w->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
369 item->w->hide();-
370 item->w->setAttribute(Qt::WA_WState_ExplicitShowHide, false);-
371 }
never executed: end of block
else if (!haveMessage
!haveMessageDescription
TRUEnever evaluated
FALSEnever evaluated
&& !item->w->testAttribute(Qt::WA_WState_ExplicitShowHide)
!item->w->test...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
372 item->w->show();-
373 }
never executed: end of block
0
374 }
never executed: end of block
0
375-
376 messageChanged(d->tempItem);-
377-
378-
379 if (QAccessible::isActive()
QAccessible::isActive()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
380 QAccessibleEvent event(this, QAccessible::NameChanged);-
381 QAccessible::updateAccessibility(&event);-
382 }
never executed: end of block
0
383-
384-
385 repaint(d->messageRect());-
386}
never executed: end of block
0
387-
388-
389-
390-
391void QStatusBar::showEvent(QShowEvent *)-
392{-
393-
394 QStatusBarPrivate * const d = d_func();-
395 if (d->resizer
d->resizerDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->showSizeGrip
d->showSizeGripDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
396 d->tryToShowSizeGrip();
never executed: d->tryToShowSizeGrip();
0
397-
398}
never executed: end of block
0
399void QStatusBar::paintEvent(QPaintEvent *event)-
400{-
401 QStatusBarPrivate * const d = d_func();-
402 bool haveMessage = !d->tempItem.isEmpty();-
403-
404 QPainter p(this);-
405 QStyleOption opt;-
406 opt.initFrom(this);-
407 style()->drawPrimitive(QStyle::PE_PanelStatusBar, &opt, &p, this);-
408-
409 for (int i=0; i<d->items.size()
i<d->items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
410 QStatusBarPrivate::SBItem* item = d->items.at(i);-
411 if (item
itemDescription
TRUEnever evaluated
FALSEnever evaluated
&& item->w->isVisible()
item->w->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
&& (!haveMessage
!haveMessageDescription
TRUEnever evaluated
FALSEnever evaluated
|| item->p
item->pDescription
TRUEnever evaluated
FALSEnever evaluated
)) {
0
412 QRect ir = item->w->geometry().adjusted(-2, -1, 2, 1);-
413 if (event->rect().intersects(ir)
event->rect().intersects(ir)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
414 QStyleOption opt(0);-
415 opt.rect = ir;-
416 opt.palette = palette();-
417 opt.state = QStyle::State_None;-
418 style()->drawPrimitive(QStyle::PE_FrameStatusBarItem, &opt, &p, item->w);-
419 }
never executed: end of block
0
420 }
never executed: end of block
0
421 }
never executed: end of block
0
422 if (haveMessage
haveMessageDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
423 p.setPen(palette().foreground().color());-
424 p.drawText(d->messageRect(), Qt::AlignLeading | Qt::AlignVCenter | Qt::TextSingleLine, d->tempItem);-
425 }
never executed: end of block
0
426}
never executed: end of block
0
427-
428-
429-
430-
431void QStatusBar::resizeEvent(QResizeEvent * e)-
432{-
433 QWidget::resizeEvent(e);-
434}
never executed: end of block
0
435-
436-
437-
438-
439-
440bool QStatusBar::event(QEvent *e)-
441{-
442 QStatusBarPrivate * const d = d_func();-
443-
444 if (e->type() == QEvent::LayoutRequest
e->type() == Q...:LayoutRequestDescription
TRUEnever evaluated
FALSEnever evaluated
0
445 ) {-
446-
447 int maxH = fontMetrics().height();-
448-
449 QStatusBarPrivate::SBItem* item = 0;-
450 for (int i=0; i<d->items.size()
i<d->items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
451 item = d->items.at(i);-
452 if (!item
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
453 break;
never executed: break;
0
454 int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight());-
455 maxH = qMax(maxH, itemH);-
456 }
never executed: end of block
0
457-
458-
459 if (d->resizer
d->resizerDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
460 maxH = qMax(maxH, d->resizer->sizeHint().height());
never executed: maxH = qMax(maxH, d->resizer->sizeHint().height());
0
461-
462-
463 if (maxH != d->savedStrut
maxH != d->savedStrutDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
464 reformat();
never executed: reformat();
0
465 else-
466 update();
never executed: update();
0
467 }-
468 if (e->type() == QEvent::ChildRemoved
e->type() == Q...::ChildRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
469 QStatusBarPrivate::SBItem* item = 0;-
470 for (int i=0; i<d->items.size()
i<d->items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
471 item = d->items.at(i);-
472 if (!item
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
473 break;
never executed: break;
0
474 if (item->w == ((QChildEvent*)e)->child()
item->w == ((Q...t*)e)->child()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
475 d->items.removeAt(i);-
476 delete item;-
477 }
never executed: end of block
0
478 }
never executed: end of block
0
479 }
never executed: end of block
0
480-
481-
482-
483-
484 return
never executed: return QWidget::event(e);
QWidget::event(e);
never executed: return QWidget::event(e);
0
485}-
486-
487-
488-
Switch to Source codePreprocessed file

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