OpenCoverage

qtoolbox.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qtoolbox.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qtoolbox.h"-
41-
42#ifndef QT_NO_TOOLBOX-
43-
44#include <qapplication.h>-
45#include <qeventloop.h>-
46#include <qlayout.h>-
47#include <qlist.h>-
48#include <qpainter.h>-
49#include <qscrollarea.h>-
50#include <qstyle.h>-
51#include <qstyleoption.h>-
52#include <qtooltip.h>-
53#include <qabstractbutton.h>-
54-
55#include "qframe_p.h"-
56-
57QT_BEGIN_NAMESPACE-
58-
59class QToolBoxButton : public QAbstractButton-
60{-
61 Q_OBJECT-
62public:-
63 QToolBoxButton(QWidget *parent)-
64 : QAbstractButton(parent), selected(false), indexInPage(-1)-
65 {-
66 setBackgroundRole(QPalette::Window);-
67 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);-
68 setFocusPolicy(Qt::NoFocus);-
69 }
never executed: end of block
0
70-
71 inline void setSelected(bool b) { selected = b; update(); }
never executed: end of block
0
72 inline void setIndex(int newIndex) { indexInPage = newIndex; }
never executed: end of block
0
73-
74 QSize sizeHint() const Q_DECL_OVERRIDE;-
75 QSize minimumSizeHint() const Q_DECL_OVERRIDE;-
76-
77protected:-
78 void initStyleOption(QStyleOptionToolBox *opt) const;-
79 void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;-
80-
81private:-
82 bool selected;-
83 int indexInPage;-
84};-
85-
86-
87class QToolBoxPrivate : public QFramePrivate-
88{-
89 Q_DECLARE_PUBLIC(QToolBox)-
90public:-
91 struct Page-
92 {-
93 QToolBoxButton *button;-
94 QScrollArea *sv;-
95 QWidget *widget;-
96-
97 inline void setText(const QString &text) { button->setText(text); }
never executed: end of block
0
98 inline void setIcon(const QIcon &is) { button->setIcon(is); }
never executed: end of block
0
99#ifndef QT_NO_TOOLTIP-
100 inline void setToolTip(const QString &tip) { button->setToolTip(tip); }
never executed: end of block
0
101 inline QString toolTip() const { return button->toolTip(); }
never executed: return button->toolTip();
0
102#endif-
103 inline QString text() const { return button->text(); }
never executed: return button->text();
0
104 inline QIcon icon() const { return button->icon(); }
never executed: return button->icon();
0
105-
106 inline bool operator==(const Page& other) const-
107 {-
108 return widget == other.widget;
never executed: return widget == other.widget;
0
109 }-
110 };-
111 typedef QList<Page> PageList;-
112-
113 inline QToolBoxPrivate()-
114 : currentPage(0)-
115 {-
116 }
never executed: end of block
0
117 void _q_buttonClicked();-
118 void _q_widgetDestroyed(QObject*);-
119-
120 const Page *page(QWidget *widget) const;-
121 const Page *page(int index) const;-
122 Page *page(int index);-
123-
124 void updateTabs();-
125 void relayout();-
126-
127 PageList pageList;-
128 QVBoxLayout *layout;-
129 Page *currentPage;-
130};-
131-
132const QToolBoxPrivate::Page *QToolBoxPrivate::page(QWidget *widget) const-
133{-
134 if (!widget)
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
135 return 0;
never executed: return 0;
0
136-
137 for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
i != pageList.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
138 if ((*i).widget == widget)
(*i).widget == widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
139 return (const Page*) &(*i);
never executed: return (const Page*) &(*i);
0
140 return 0;
never executed: return 0;
0
141}-
142-
143QToolBoxPrivate::Page *QToolBoxPrivate::page(int index)-
144{-
145 if (index >= 0 && index < pageList.size())
index >= 0Description
TRUEnever evaluated
FALSEnever evaluated
index < pageList.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
146 return &pageList[index];
never executed: return &pageList[index];
0
147 return 0;
never executed: return 0;
0
148}-
149-
150const QToolBoxPrivate::Page *QToolBoxPrivate::page(int index) const-
151{-
152 if (index >= 0 && index < pageList.size())
index >= 0Description
TRUEnever evaluated
FALSEnever evaluated
index < pageList.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
153 return &pageList.at(index);
never executed: return &pageList.at(index);
0
154 return 0;
never executed: return 0;
0
155}-
156-
157void QToolBoxPrivate::updateTabs()-
158{-
159 QToolBoxButton *lastButton = currentPage ? currentPage->button : 0;
currentPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
160 bool after = false;-
161 int index = 0;-
162 for (index = 0; index < pageList.count(); ++index) {
index < pageList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
163 const Page &page = pageList.at(index);-
164 QToolBoxButton *tB = page.button;-
165 // update indexes, since the updates are delayed, the indexes will be correct-
166 // when we actually paint.-
167 tB->setIndex(index);-
168 QWidget *tW = page.widget;-
169 if (after) {
afterDescription
TRUEnever evaluated
FALSEnever evaluated
0
170 QPalette p = tB->palette();-
171 p.setColor(tB->backgroundRole(), tW->palette().color(tW->backgroundRole()));-
172 tB->setPalette(p);-
173 tB->update();-
174 } else if (tB->backgroundRole() != QPalette::Window) {
never executed: end of block
tB->background...alette::WindowDescription
TRUEnever evaluated
FALSEnever evaluated
0
175 tB->setBackgroundRole(QPalette::Window);-
176 tB->update();-
177 }
never executed: end of block
0
178 after = tB == lastButton;-
179 }
never executed: end of block
0
180}
never executed: end of block
0
181-
182QSize QToolBoxButton::sizeHint() const-
183{-
184 QSize iconSize(8, 8);-
185 if (!icon().isNull()) {
!icon().isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
186 int icone = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, parentWidget() /* QToolBox */);-
187 iconSize += QSize(icone + 2, icone);-
188 }
never executed: end of block
0
189 QSize textSize = fontMetrics().size(Qt::TextShowMnemonic, text()) + QSize(0, 8);-
190-
191 QSize total(iconSize.width() + textSize.width(), qMax(iconSize.height(), textSize.height()));-
192 return total.expandedTo(QApplication::globalStrut());
never executed: return total.expandedTo(QApplication::globalStrut());
0
193}-
194-
195QSize QToolBoxButton::minimumSizeHint() const-
196{-
197 if (icon().isNull())
icon().isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
198 return QSize();
never executed: return QSize();
0
199 int icone = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, parentWidget() /* QToolBox */);-
200 return QSize(icone + 8, icone + 8);
never executed: return QSize(icone + 8, icone + 8);
0
201}-
202-
203void QToolBoxButton::initStyleOption(QStyleOptionToolBox *option) const-
204{-
205 if (!option)
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
0
206 return;
never executed: return;
0
207 option->initFrom(this);-
208 if (selected)
selectedDescription
TRUEnever evaluated
FALSEnever evaluated
0
209 option->state |= QStyle::State_Selected;
never executed: option->state |= QStyle::State_Selected;
0
210 if (isDown())
isDown()Description
TRUEnever evaluated
FALSEnever evaluated
0
211 option->state |= QStyle::State_Sunken;
never executed: option->state |= QStyle::State_Sunken;
0
212 option->text = text();-
213 option->icon = icon();-
214-
215 QToolBox *toolBox = static_cast<QToolBox *>(parentWidget()); // I know I'm in a tool box.-
216 const int widgetCount = toolBox->count();-
217 const int currIndex = toolBox->currentIndex();-
218 if (widgetCount == 1) {
widgetCount == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
219 option->position = QStyleOptionToolBox::OnlyOneTab;-
220 } else if (indexInPage == 0) {
never executed: end of block
indexInPage == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
221 option->position = QStyleOptionToolBox::Beginning;-
222 } else if (indexInPage == widgetCount - 1) {
never executed: end of block
indexInPage == widgetCount - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
223 option->position = QStyleOptionToolBox::End;-
224 } else {
never executed: end of block
0
225 option->position = QStyleOptionToolBox::Middle;-
226 }
never executed: end of block
0
227 if (currIndex == indexInPage - 1) {
currIndex == indexInPage - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
228 option->selectedPosition = QStyleOptionToolBox::PreviousIsSelected;-
229 } else if (currIndex == indexInPage + 1) {
never executed: end of block
currIndex == indexInPage + 1Description
TRUEnever evaluated
FALSEnever evaluated
0
230 option->selectedPosition = QStyleOptionToolBox::NextIsSelected;-
231 } else {
never executed: end of block
0
232 option->selectedPosition = QStyleOptionToolBox::NotAdjacent;-
233 }
never executed: end of block
0
234}-
235-
236void QToolBoxButton::paintEvent(QPaintEvent *)-
237{-
238 QPainter paint(this);-
239 QPainter *p = &paint;-
240 QStyleOptionToolBox opt;-
241 initStyleOption(&opt);-
242 style()->drawControl(QStyle::CE_ToolBoxTab, &opt, p, parentWidget());-
243}
never executed: end of block
0
244-
245/*!-
246 \class QToolBox-
247-
248 \brief The QToolBox class provides a column of tabbed widget items.-
249-
250-
251 \ingroup basicwidgets-
252 \inmodule QtWidgets-
253-
254 A toolbox is a widget that displays a column of tabs one above the-
255 other, with the current item displayed below the current tab.-
256 Every tab has an index position within the column of tabs. A tab's-
257 item is a QWidget.-
258-
259 Each item has an itemText(), an optional itemIcon(), an optional-
260 itemToolTip(), and a widget(). The item's attributes can be-
261 changed with setItemText(), setItemIcon(), and-
262 setItemToolTip(). Each item can be enabled or disabled-
263 individually with setItemEnabled().-
264-
265 Items are added using addItem(), or inserted at particular-
266 positions using insertItem(). The total number of items is given-
267 by count(). Items can be deleted with delete, or removed from the-
268 toolbox with removeItem(). Combining removeItem() and insertItem()-
269 allows you to move items to different positions.-
270-
271 The index of the current item widget is returned by currentIndex(),-
272 and set with setCurrentIndex(). The index of a particular item can-
273 be found using indexOf(), and the item at a given index is returned-
274 by item().-
275-
276 The currentChanged() signal is emitted when the current item is-
277 changed.-
278-
279 \sa QTabWidget-
280*/-
281-
282/*!-
283 \fn void QToolBox::currentChanged(int index)-
284-
285 This signal is emitted when the current item is changed. The new-
286 current item's index is passed in \a index, or -1 if there is no-
287 current item.-
288*/-
289-
290-
291/*!-
292 Constructs a new toolbox with the given \a parent and the flags, \a f.-
293*/-
294QToolBox::QToolBox(QWidget *parent, Qt::WindowFlags f)-
295 : QFrame(*new QToolBoxPrivate, parent, f)-
296{-
297 Q_D(QToolBox);-
298 d->layout = new QVBoxLayout(this);-
299 d->layout->setMargin(0);-
300 setBackgroundRole(QPalette::Button);-
301}
never executed: end of block
0
302-
303/*!-
304 Destroys the toolbox.-
305*/-
306-
307QToolBox::~QToolBox()-
308{-
309}-
310-
311/*!-
312 \fn int QToolBox::addItem(QWidget *w, const QString &text)-
313 \overload-
314-
315 Adds the widget \a w in a new tab at bottom of the toolbox. The-
316 new tab's text is set to \a text. Returns the new tab's index.-
317*/-
318-
319/*!-
320 \fn int QToolBox::addItem(QWidget *widget, const QIcon &iconSet,const QString &text)-
321 Adds the \a widget in a new tab at bottom of the toolbox. The-
322 new tab's text is set to \a text, and the \a iconSet is-
323 displayed to the left of the \a text. Returns the new tab's index.-
324*/-
325-
326/*!-
327 \fn int QToolBox::insertItem(int index, QWidget *widget, const QString &text)-
328 \overload-
329-
330 Inserts the \a widget at position \a index, or at the bottom-
331 of the toolbox if \a index is out of range. The new item's text is-
332 set to \a text. Returns the new item's index.-
333*/-
334-
335/*!-
336 Inserts the \a widget at position \a index, or at the bottom-
337 of the toolbox if \a index is out of range. The new item's text-
338 is set to \a text, and the \a icon is displayed to the left of-
339 the \a text. Returns the new item's index.-
340*/-
341-
342int QToolBox::insertItem(int index, QWidget *widget, const QIcon &icon, const QString &text)-
343{-
344 if (!widget)
!widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
345 return -1;
never executed: return -1;
0
346-
347 Q_D(QToolBox);-
348 connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(_q_widgetDestroyed(QObject*)));-
349-
350 QToolBoxPrivate::Page c;-
351 c.widget = widget;-
352 c.button = new QToolBoxButton(this);-
353 c.button->setObjectName(QLatin1String("qt_toolbox_toolboxbutton"));-
354 connect(c.button, SIGNAL(clicked()), this, SLOT(_q_buttonClicked()));-
355-
356 c.sv = new QScrollArea(this);-
357 c.sv->setWidget(widget);-
358 c.sv->setWidgetResizable(true);-
359 c.sv->hide();-
360 c.sv->setFrameStyle(QFrame::NoFrame);-
361-
362 c.setText(text);-
363 c.setIcon(icon);-
364-
365 if (index < 0 || index >= (int)d->pageList.count()) {
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index >= (int)...geList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
366 index = d->pageList.count();-
367 d->pageList.append(c);-
368 d->layout->addWidget(c.button);-
369 d->layout->addWidget(c.sv);-
370 if (index == 0)
index == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
371 setCurrentIndex(index);
never executed: setCurrentIndex(index);
0
372 } else {
never executed: end of block
0
373 d->pageList.insert(index, c);-
374 d->relayout();-
375 if (d->currentPage) {
d->currentPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
376 QWidget *current = d->currentPage->widget;-
377 int oldindex = indexOf(current);-
378 if (index <= oldindex) {
index <= oldindexDescription
TRUEnever evaluated
FALSEnever evaluated
0
379 d->currentPage = 0; // trigger change-
380 setCurrentIndex(oldindex);-
381 }
never executed: end of block
0
382 }
never executed: end of block
0
383 }
never executed: end of block
0
384-
385 c.button->show();-
386-
387 d->updateTabs();-
388 itemInserted(index);-
389 return index;
never executed: return index;
0
390}-
391-
392void QToolBoxPrivate::_q_buttonClicked()-
393{-
394 Q_Q(QToolBox);-
395 QToolBoxButton *tb = qobject_cast<QToolBoxButton*>(q->sender());-
396 QWidget* item = 0;-
397 for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
i != pageList.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
398 if ((*i).button == tb) {
(*i).button == tbDescription
TRUEnever evaluated
FALSEnever evaluated
0
399 item = (*i).widget;-
400 break;
never executed: break;
0
401 }-
402-
403 q->setCurrentIndex(q->indexOf(item));-
404}
never executed: end of block
0
405-
406/*!-
407 \property QToolBox::count-
408 \brief The number of items contained in the toolbox.-
409-
410 By default, this property has a value of 0.-
411*/-
412-
413int QToolBox::count() const-
414{-
415 Q_D(const QToolBox);-
416 return d->pageList.count();
never executed: return d->pageList.count();
0
417}-
418-
419void QToolBox::setCurrentIndex(int index)-
420{-
421 Q_D(QToolBox);-
422 QToolBoxPrivate::Page *c = d->page(index);-
423 if (!c || d->currentPage == c)
!cDescription
TRUEnever evaluated
FALSEnever evaluated
d->currentPage == cDescription
TRUEnever evaluated
FALSEnever evaluated
0
424 return;
never executed: return;
0
425-
426 c->button->setSelected(true);-
427 if (d->currentPage) {
d->currentPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
428 d->currentPage->sv->hide();-
429 d->currentPage->button->setSelected(false);-
430 }
never executed: end of block
0
431 d->currentPage = c;-
432 d->currentPage->sv->show();-
433 d->updateTabs();-
434 emit currentChanged(index);-
435}
never executed: end of block
0
436-
437void QToolBoxPrivate::relayout()-
438{-
439 Q_Q(QToolBox);-
440 delete layout;-
441 layout = new QVBoxLayout(q);-
442 layout->setMargin(0);-
443 for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) {
i != pageList.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
444 layout->addWidget((*i).button);-
445 layout->addWidget((*i).sv);-
446 }
never executed: end of block
0
447}
never executed: end of block
0
448-
449void QToolBoxPrivate::_q_widgetDestroyed(QObject *object)-
450{-
451 Q_Q(QToolBox);-
452 // no verification - vtbl corrupted already-
453 QWidget *p = (QWidget*)object;-
454-
455 const QToolBoxPrivate::Page *c = page(p);-
456 if (!p || !c)
!pDescription
TRUEnever evaluated
FALSEnever evaluated
!cDescription
TRUEnever evaluated
FALSEnever evaluated
0
457 return;
never executed: return;
0
458-
459 layout->removeWidget(c->sv);-
460 layout->removeWidget(c->button);-
461 c->sv->deleteLater(); // page might still be a child of sv-
462 delete c->button;-
463-
464 bool removeCurrent = c == currentPage;-
465 pageList.removeAll(*c);-
466-
467 if (!pageList.count()) {
!pageList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
468 currentPage = 0;-
469 emit q->currentChanged(-1);-
470 } else if (removeCurrent) {
never executed: end of block
removeCurrentDescription
TRUEnever evaluated
FALSEnever evaluated
0
471 currentPage = 0;-
472 q->setCurrentIndex(0);-
473 }
never executed: end of block
0
474}
never executed: end of block
0
475-
476/*!-
477 Removes the item at position \a index from the toolbox. Note that-
478 the widget is \e not deleted.-
479*/-
480-
481void QToolBox::removeItem(int index)-
482{-
483 Q_D(QToolBox);-
484 if (QWidget *w = widget(index)) {
QWidget *w = widget(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
485 disconnect(w, SIGNAL(destroyed(QObject*)), this, SLOT(_q_widgetDestroyed(QObject*)));-
486 w->setParent(this);-
487 // destroy internal data-
488 d->_q_widgetDestroyed(w);-
489 itemRemoved(index);-
490 }
never executed: end of block
0
491}
never executed: end of block
0
492-
493-
494/*!-
495 \property QToolBox::currentIndex-
496 \brief the index of the current item-
497-
498 By default, for an empty toolbox, this property has a value of -1.-
499-
500 \sa indexOf(), widget()-
501*/-
502-
503-
504int QToolBox::currentIndex() const-
505{-
506 Q_D(const QToolBox);-
507 return d->currentPage ? indexOf(d->currentPage->widget) : -1;
never executed: return d->currentPage ? indexOf(d->currentPage->widget) : -1;
0
508}-
509-
510/*!-
511 Returns a pointer to the current widget, or 0 if there is no such item.-
512-
513 \sa currentIndex(), setCurrentWidget()-
514*/-
515-
516QWidget * QToolBox::currentWidget() const-
517{-
518 Q_D(const QToolBox);-
519 return d->currentPage ? d->currentPage->widget : 0;
never executed: return d->currentPage ? d->currentPage->widget : 0;
0
520}-
521-
522/*!-
523 Makes\a widget the current widget. The \a widget must be an item in this tool box.-
524-
525 \sa addItem(), setCurrentIndex(), currentWidget()-
526 */-
527void QToolBox::setCurrentWidget(QWidget *widget)-
528{-
529 int i = indexOf(widget);-
530 if (Q_UNLIKELY(i < 0))
__builtin_expe...i < 0), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
531 qWarning("QToolBox::setCurrentWidget: widget not contained in tool box");
never executed: QMessageLogger(__FILE__, 531, __PRETTY_FUNCTION__).warning("QToolBox::setCurrentWidget: widget not contained in tool box");
0
532 else-
533 setCurrentIndex(i);
never executed: setCurrentIndex(i);
0
534}-
535-
536/*!-
537 Returns the widget at position \a index, or 0 if there is no such-
538 item.-
539*/-
540-
541QWidget *QToolBox::widget(int index) const-
542{-
543 Q_D(const QToolBox);-
544 if (index < 0 || index >= (int) d->pageList.size())
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index >= (int)...ageList.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
545 return 0;
never executed: return 0;
0
546 return d->pageList.at(index).widget;
never executed: return d->pageList.at(index).widget;
0
547}-
548-
549/*!-
550 Returns the index of \a widget, or -1 if the item does not-
551 exist.-
552*/-
553-
554int QToolBox::indexOf(QWidget *widget) const-
555{-
556 Q_D(const QToolBox);-
557 const QToolBoxPrivate::Page *c = (widget ? d->page(widget) : 0);
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
558 return c ? d->pageList.indexOf(*c) : -1;
never executed: return c ? d->pageList.indexOf(*c) : -1;
0
559}-
560-
561/*!-
562 If \a enabled is true then the item at position \a index is enabled; otherwise-
563 the item at position \a index is disabled.-
564*/-
565-
566void QToolBox::setItemEnabled(int index, bool enabled)-
567{-
568 Q_D(QToolBox);-
569 QToolBoxPrivate::Page *c = d->page(index);-
570 if (!c)
!cDescription
TRUEnever evaluated
FALSEnever evaluated
0
571 return;
never executed: return;
0
572-
573 c->button->setEnabled(enabled);-
574 if (!enabled && c == d->currentPage) {
!enabledDescription
TRUEnever evaluated
FALSEnever evaluated
c == d->currentPageDescription
TRUEnever evaluated
FALSEnever evaluated
0
575 int curIndexUp = index;-
576 int curIndexDown = curIndexUp;-
577 const int count = d->pageList.count();-
578 while (curIndexUp > 0 || curIndexDown < count-1) {
curIndexUp > 0Description
TRUEnever evaluated
FALSEnever evaluated
curIndexDown < count-1Description
TRUEnever evaluated
FALSEnever evaluated
0
579 if (curIndexDown < count-1) {
curIndexDown < count-1Description
TRUEnever evaluated
FALSEnever evaluated
0
580 if (d->page(++curIndexDown)->button->isEnabled()) {
d->page(++curI...n->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
581 index = curIndexDown;-
582 break;
never executed: break;
0
583 }-
584 }
never executed: end of block
0
585 if (curIndexUp > 0) {
curIndexUp > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
586 if (d->page(--curIndexUp)->button->isEnabled()) {
d->page(--curI...n->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
587 index = curIndexUp;-
588 break;
never executed: break;
0
589 }-
590 }
never executed: end of block
0
591 }
never executed: end of block
0
592 setCurrentIndex(index);-
593 }
never executed: end of block
0
594}
never executed: end of block
0
595-
596-
597/*!-
598 Sets the text of the item at position \a index to \a text.-
599-
600 If the provided text contains an ampersand character ('&'), a-
601 mnemonic is automatically created for it. The character that-
602 follows the '&' will be used as the shortcut key. Any previous-
603 mnemonic will be overwritten, or cleared if no mnemonic is defined-
604 by the text. See the \l {QShortcut#mnemonic}{QShortcut}-
605 documentation for details (to display an actual ampersand, use-
606 '&&').-
607*/-
608-
609void QToolBox::setItemText(int index, const QString &text)-
610{-
611 Q_D(QToolBox);-
612 QToolBoxPrivate::Page *c = d->page(index);-
613 if (c)
cDescription
TRUEnever evaluated
FALSEnever evaluated
0
614 c->setText(text);
never executed: c->setText(text);
0
615}
never executed: end of block
0
616-
617/*!-
618 Sets the icon of the item at position \a index to \a icon.-
619*/-
620-
621void QToolBox::setItemIcon(int index, const QIcon &icon)-
622{-
623 Q_D(QToolBox);-
624 QToolBoxPrivate::Page *c = d->page(index);-
625 if (c)
cDescription
TRUEnever evaluated
FALSEnever evaluated
0
626 c->setIcon(icon);
never executed: c->setIcon(icon);
0
627}
never executed: end of block
0
628-
629#ifndef QT_NO_TOOLTIP-
630/*!-
631 Sets the tooltip of the item at position \a index to \a toolTip.-
632*/-
633-
634void QToolBox::setItemToolTip(int index, const QString &toolTip)-
635{-
636 Q_D(QToolBox);-
637 QToolBoxPrivate::Page *c = d->page(index);-
638 if (c)
cDescription
TRUEnever evaluated
FALSEnever evaluated
0
639 c->setToolTip(toolTip);
never executed: c->setToolTip(toolTip);
0
640}
never executed: end of block
0
641#endif // QT_NO_TOOLTIP-
642-
643/*!-
644 Returns \c true if the item at position \a index is enabled; otherwise returns \c false.-
645*/-
646-
647bool QToolBox::isItemEnabled(int index) const-
648{-
649 Q_D(const QToolBox);-
650 const QToolBoxPrivate::Page *c = d->page(index);-
651 return c && c->button->isEnabled();
never executed: return c && c->button->isEnabled();
0
652}-
653-
654/*!-
655 Returns the text of the item at position \a index, or an empty string if-
656 \a index is out of range.-
657*/-
658-
659QString QToolBox::itemText(int index) const-
660{-
661 Q_D(const QToolBox);-
662 const QToolBoxPrivate::Page *c = d->page(index);-
663 return (c ? c->text() : QString());
never executed: return (c ? c->text() : QString());
0
664}-
665-
666/*!-
667 Returns the icon of the item at position \a index, or a null-
668 icon if \a index is out of range.-
669*/-
670-
671QIcon QToolBox::itemIcon(int index) const-
672{-
673 Q_D(const QToolBox);-
674 const QToolBoxPrivate::Page *c = d->page(index);-
675 return (c ? c->icon() : QIcon());
never executed: return (c ? c->icon() : QIcon());
0
676}-
677-
678#ifndef QT_NO_TOOLTIP-
679/*!-
680 Returns the tooltip of the item at position \a index, or an-
681 empty string if \a index is out of range.-
682*/-
683-
684QString QToolBox::itemToolTip(int index) const-
685{-
686 Q_D(const QToolBox);-
687 const QToolBoxPrivate::Page *c = d->page(index);-
688 return (c ? c->toolTip() : QString());
never executed: return (c ? c->toolTip() : QString());
0
689}-
690#endif // QT_NO_TOOLTIP-
691-
692/*! \reimp */-
693void QToolBox::showEvent(QShowEvent *e)-
694{-
695 QWidget::showEvent(e);-
696}
never executed: end of block
0
697-
698/*! \reimp */-
699void QToolBox::changeEvent(QEvent *ev)-
700{-
701 Q_D(QToolBox);-
702 if(ev->type() == QEvent::StyleChange)
ev->type() == ...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
703 d->updateTabs();
never executed: d->updateTabs();
0
704 QFrame::changeEvent(ev);-
705}
never executed: end of block
0
706-
707/*!-
708 This virtual handler is called after a new item was added or-
709 inserted at position \a index.-
710-
711 \sa itemRemoved()-
712 */-
713void QToolBox::itemInserted(int index)-
714{-
715 Q_UNUSED(index)-
716}
never executed: end of block
0
717-
718/*!-
719 This virtual handler is called after an item was removed from-
720 position \a index.-
721-
722 \sa itemInserted()-
723 */-
724void QToolBox::itemRemoved(int index)-
725{-
726 Q_UNUSED(index)-
727}
never executed: end of block
0
728-
729/*! \reimp */-
730bool QToolBox::event(QEvent *e)-
731{-
732 return QFrame::event(e);
never executed: return QFrame::event(e);
0
733}-
734-
735QT_END_NAMESPACE-
736-
737#include "moc_qtoolbox.cpp"-
738#include "qtoolbox.moc"-
739-
740#endif //QT_NO_TOOLBOX-
Source codeSwitch to Preprocessed file

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