~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/widgets/qtoolbox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the widgets module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qtoolbox.h"
 
30
 
 
31
#ifndef QT_NO_TOOLBOX
 
32
 
 
33
#include <qapplication.h>
 
34
#include <qeventloop.h>
 
35
#include <qlayout.h>
 
36
#include <qlist.h>
 
37
#include <qpainter.h>
 
38
#include <qscrollarea.h>
 
39
#include <qstyle.h>
 
40
#include <qstyleoption.h>
 
41
#include <qtooltip.h>
 
42
#include <qabstractbutton.h>
 
43
 
 
44
#include "qframe_p.h"
 
45
 
 
46
class QToolBoxButton : public QAbstractButton
 
47
{
 
48
    Q_OBJECT
 
49
public:
 
50
    QToolBoxButton(QWidget *parent)
 
51
        : QAbstractButton(parent), selected(false)
 
52
    {
 
53
        setBackgroundRole(QPalette::Background);
 
54
        setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
 
55
        setFocusPolicy(Qt::NoFocus);
 
56
    }
 
57
 
 
58
    inline void setSelected(bool b) { selected = b; update(); }
 
59
 
 
60
    QSize sizeHint() const;
 
61
    QSize minimumSizeHint() const;
 
62
 
 
63
protected:
 
64
    void paintEvent(QPaintEvent *);
 
65
 
 
66
private:
 
67
    bool selected;
 
68
};
 
69
 
 
70
#include "qtoolbox.moc"
 
71
 
 
72
 
 
73
class QToolBoxPrivate : public QFramePrivate
 
74
{
 
75
    Q_DECLARE_PUBLIC(QToolBox)
 
76
public:
 
77
    struct Page
 
78
    {
 
79
        QToolBoxButton *button;
 
80
        QScrollArea *sv;
 
81
        QWidget *widget;
 
82
 
 
83
        inline void setText(const QString &text) { button->setText(text); }
 
84
        inline void setIcon(const QIcon &is) { button->setIcon(is); }
 
85
        inline void setToolTip(const QString &tip) { button->setToolTip(tip); }
 
86
        inline QString text() const { return button->text(); }
 
87
        inline QIcon icon() const { return button->icon(); }
 
88
        inline QString toolTip() const { return button->toolTip(); }
 
89
 
 
90
        inline bool operator==(const Page& other) const
 
91
        {
 
92
            return widget == other.widget;
 
93
        }
 
94
    };
 
95
    typedef QList<Page> PageList;
 
96
 
 
97
    inline QToolBoxPrivate()
 
98
        : currentPage(0)
 
99
    {
 
100
    }
 
101
    void buttonClicked();
 
102
    void widgetDestroyed(QObject*);
 
103
 
 
104
    Page *page(QWidget *widget) const;
 
105
    const Page *page(int index) const;
 
106
    Page *page(int index);
 
107
 
 
108
    void updateTabs();
 
109
    void relayout();
 
110
 
 
111
    PageList pageList;
 
112
    QVBoxLayout *layout;
 
113
    Page *currentPage;
 
114
};
 
115
 
 
116
QToolBoxPrivate::Page *QToolBoxPrivate::page(QWidget *widget) const
 
117
{
 
118
    if (!widget)
 
119
        return 0;
 
120
 
 
121
    for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
 
122
        if ((*i).widget == widget)
 
123
            return (Page*) &(*i);
 
124
    return 0;
 
125
}
 
126
 
 
127
QToolBoxPrivate::Page *QToolBoxPrivate::page(int index)
 
128
{
 
129
    if (index >= 0 && index < pageList.size())
 
130
        return &pageList[index];
 
131
    return 0;
 
132
}
 
133
 
 
134
const QToolBoxPrivate::Page *QToolBoxPrivate::page(int index) const
 
135
{
 
136
    if (index >= 0 && index < pageList.size())
 
137
        return &pageList.at(index);
 
138
    return 0;
 
139
}
 
140
 
 
141
void QToolBoxPrivate::updateTabs()
 
142
{
 
143
    QToolBoxButton *lastButton = currentPage ? currentPage->button : 0;
 
144
    bool after = false;
 
145
    for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) {
 
146
        QToolBoxButton *tB = (*i).button;
 
147
        QWidget *tW = (*i).widget;
 
148
        if (after) {
 
149
            QPalette p = tB->palette();
 
150
            p.setColor(tB->backgroundRole(), tW->palette().color(tW->backgroundRole()));
 
151
            tB->setPalette(p);
 
152
            tB->update();
 
153
        } else if (tB->backgroundRole() != QPalette::Background) {
 
154
            tB->setBackgroundRole(QPalette::Background);
 
155
            tB->update();
 
156
        }
 
157
        after = (*i).button == lastButton;
 
158
    }
 
159
}
 
160
 
 
161
QSize QToolBoxButton::sizeHint() const
 
162
{
 
163
    QSize iconSize(8, 8);
 
164
    if (!icon().isNull()) {
 
165
        int icone = style()->pixelMetric(QStyle::PM_SmallIconSize);
 
166
        iconSize += QSize(icone + 2, icone);
 
167
    }
 
168
    QSize textSize = fontMetrics().size(Qt::TextShowMnemonic, text()) + QSize(0, 8);
 
169
 
 
170
    QSize total(iconSize.width() + textSize.width(), qMax(iconSize.height(), textSize.height()));
 
171
    return total.expandedTo(QApplication::globalStrut());
 
172
}
 
173
 
 
174
QSize QToolBoxButton::minimumSizeHint() const
 
175
{
 
176
    if (icon().isNull())
 
177
        return QSize();
 
178
    int icone = style()->pixelMetric(QStyle::PM_SmallIconSize);
 
179
    return QSize(icone + 8, icone + 8);
 
180
}
 
181
 
 
182
void QToolBoxButton::paintEvent(QPaintEvent *)
 
183
{
 
184
    QPainter paint(this);
 
185
    QString text = QAbstractButton::text();
 
186
    QPainter *p = &paint;
 
187
    const QPalette &pal = palette();
 
188
    QStyleOptionToolBox opt;
 
189
    opt.init(this);
 
190
    if (selected)
 
191
        opt.state |= QStyle::State_Selected;
 
192
    if (isDown())
 
193
        opt.state |= QStyle::State_Sunken;
 
194
    opt.text = text;
 
195
    opt.icon = icon();
 
196
    style()->drawControl(QStyle::CE_ToolBoxTab, &opt, p, parentWidget());
 
197
 
 
198
    QPixmap pm = icon().pixmap(style()->pixelMetric(QStyle::PM_SmallIconSize), isEnabled() ? QIcon::Normal : QIcon::Disabled);
 
199
 
 
200
    QRect cr = style()->subElementRect(QStyle::SE_ToolBoxTabContents, &opt, this);
 
201
    QRect tr, ir;
 
202
    int ih = 0;
 
203
    if (pm.isNull()) {
 
204
        tr = cr;
 
205
        tr.adjust(4, 0, -8, 0);
 
206
    } else {
 
207
        int iw = pm.width() + 4;
 
208
        ih = pm.height();
 
209
        ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih);
 
210
        tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height());
 
211
    }
 
212
 
 
213
    if (selected && style()->styleHint(QStyle::SH_ToolBox_SelectedPageTitleBold, &opt, this)) {
 
214
        QFont f(p->font());
 
215
        f.setBold(true);
 
216
        p->setFont(f);
 
217
    }
 
218
 
 
219
    QString txt;
 
220
    if (p->fontMetrics().width(text) < tr.width()) {
 
221
        txt = text;
 
222
    } else {
 
223
        txt = text.left(1);
 
224
        int ew = p->fontMetrics().width("...");
 
225
        int i = 1;
 
226
        while (p->fontMetrics().width(txt) + ew +
 
227
                p->fontMetrics().width(text[i])  < tr.width())
 
228
            txt += text[i++];
 
229
        txt += "...";
 
230
    }
 
231
 
 
232
    if (ih)
 
233
        p->drawPixmap(ir.left(), (height() - ih) / 2, pm);
 
234
 
 
235
    int alignment = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic;
 
236
    if (!style()->styleHint(QStyle::SH_UnderlineShortcut, 0, this))
 
237
        alignment |= Qt::TextHideMnemonic;
 
238
    style()->drawItemText(p, tr, alignment, pal, isEnabled(), txt, foregroundRole());
 
239
 
 
240
    if (!txt.isEmpty() && hasFocus()) {
 
241
        QStyleOptionFocusRect opt;
 
242
        opt.rect = tr;
 
243
        opt.palette = pal;
 
244
        opt.state = QStyle::State_None;
 
245
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, this);
 
246
    }
 
247
}
 
248
 
 
249
/*!
 
250
    \class QToolBox
 
251
 
 
252
    \brief The QToolBox class provides a column of tabbed widget items.
 
253
 
 
254
    \mainclass
 
255
    \ingroup advanced
 
256
 
 
257
    A toolbox is a widget that displays a column of tabs one above the
 
258
    other, with the current item displayed below the current tab.
 
259
    Every tab has an index position within the column of tabs. A tab's
 
260
    item is a QWidget.
 
261
 
 
262
    Each item has an itemText(), an optional itemIcon(), an optional
 
263
    itemToolTip(), and a widget(). The item's attributes can be
 
264
    changed with setItemText(), setItemIcon(), and
 
265
    setItemToolTip(). Each item can be enabled or disabled
 
266
    individually with setItemEnabled().
 
267
 
 
268
    Items are added using addItem(), or inserted at particular
 
269
    positions using insertItem(). The total number of items is given
 
270
    by count(). Items can be deleted with delete, or removed from the
 
271
    toolbox with removeItem(). Combining removeItem() and insertItem()
 
272
    allows you to move items to different positions.
 
273
 
 
274
    The index of the current item widget is returned by currentIndex(),
 
275
    and set with setCurrentIndex(). The index of a particular item can
 
276
    be found using indexOf(), and the item at a given index is returned
 
277
    by item().
 
278
 
 
279
    The currentChanged() signal is emitted when the current item is
 
280
    changed.
 
281
 
 
282
    \sa QTabWidget
 
283
*/
 
284
 
 
285
/*!
 
286
    \fn void QToolBox::currentChanged(int index)
 
287
 
 
288
    This signal is emitted when the current item is changed. The new
 
289
    current item's index is passed in \a index, or -1 if there is no
 
290
    current item.
 
291
*/
 
292
 
 
293
#ifdef QT3_SUPPORT
 
294
/*!
 
295
    Constructs a toolbox called \a name with parent \a parent and flags \a f.
 
296
*/
 
297
QToolBox::QToolBox(QWidget *parent, const char *name, Qt::WFlags f)
 
298
    :  QFrame(*new QToolBoxPrivate, parent, f)
 
299
{
 
300
    Q_D(QToolBox);
 
301
    setObjectName(name);
 
302
    d->layout = new QVBoxLayout(this);
 
303
    d->layout->setMargin(0);
 
304
    setBackgroundRole(QPalette::Button);
 
305
}
 
306
#endif
 
307
 
 
308
/*!
 
309
    Constructs a new toolbox with the given \a parent and the flags, \a f.
 
310
*/
 
311
QToolBox::QToolBox(QWidget *parent, Qt::WFlags f)
 
312
    :  QFrame(*new QToolBoxPrivate, parent, f)
 
313
{
 
314
    Q_D(QToolBox);
 
315
    d->layout = new QVBoxLayout(this);
 
316
    d->layout->setMargin(0);
 
317
    setBackgroundRole(QPalette::Button);
 
318
}
 
319
 
 
320
/*!
 
321
    Destroys the toolbox.
 
322
*/
 
323
 
 
324
QToolBox::~QToolBox()
 
325
{
 
326
}
 
327
 
 
328
/*!
 
329
    \fn int QToolBox::addItem(QWidget *w, const QString &text)
 
330
    \overload
 
331
 
 
332
    Adds the widget \a w in a new tab at bottom of the toolbox. The
 
333
    new tab's text is set to \a text. Returns the new tab's index.
 
334
*/
 
335
 
 
336
/*!
 
337
    \fn int QToolBox::addItem(QWidget *widget, const QIcon &iconSet,const QString &text)
 
338
    Adds the \a widget in a new tab at bottom of the toolbox. The
 
339
    new tab's text is set to \a text, and the \a iconSet is
 
340
    displayed to the left of the \a text.  Returns the new tab's index.
 
341
*/
 
342
 
 
343
/*!
 
344
    \fn int QToolBox::insertItem(int index, QWidget *widget, const QString &text)
 
345
    \overload
 
346
 
 
347
    Inserts the \a widget at position \a index, or at the bottom
 
348
    of the toolbox if \a index is out of range. The new item's text is
 
349
    set to \a text. Returns the new item's index.
 
350
*/
 
351
 
 
352
/*!
 
353
    Inserts the \a widget at position \a index, or at the bottom
 
354
    of the toolbox if \a index is out of range. The new item's text
 
355
    is set to \a text, and the \a icon is displayed to the left of
 
356
    the \a text. Returns the new item's index.
 
357
*/
 
358
 
 
359
int QToolBox::insertItem(int index, QWidget *widget, const QIcon &icon, const QString &text)
 
360
{
 
361
    if (!widget)
 
362
        return -1;
 
363
 
 
364
    Q_D(QToolBox);
 
365
    connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed(QObject*)));
 
366
 
 
367
    QToolBoxPrivate::Page c;
 
368
    c.widget = widget;
 
369
    c.button = new QToolBoxButton(this);
 
370
    connect(c.button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
 
371
 
 
372
    c.sv = new QScrollArea(this);
 
373
    c.sv->setWidget(widget);
 
374
    c.sv->setWidgetResizable(true);
 
375
    c.sv->hide();
 
376
    c.sv->setFrameStyle(QFrame::NoFrame);
 
377
 
 
378
    c.setText(text);
 
379
    c.setIcon(icon);
 
380
 
 
381
    if (index < 0 || index >= (int)d->pageList.count()) {
 
382
        index = d->pageList.count();
 
383
        d->pageList.append(c);
 
384
        d->layout->addWidget(c.button);
 
385
        d->layout->addWidget(c.sv);
 
386
        if (index == 0)
 
387
            setCurrentIndex(index);
 
388
    } else {
 
389
        d->pageList.insert(index, c);
 
390
        d->relayout();
 
391
        if (d->currentPage) {
 
392
            QWidget *current = d->currentPage->widget;
 
393
            int oldindex = indexOf(current);
 
394
            if (index <= oldindex) {
 
395
                d->currentPage = 0; // trigger change
 
396
                setCurrentIndex(oldindex);
 
397
            }
 
398
        }
 
399
    }
 
400
 
 
401
    c.button->show();
 
402
 
 
403
    d->updateTabs();
 
404
    itemInserted(index);
 
405
    return index;
 
406
}
 
407
 
 
408
void QToolBoxPrivate::buttonClicked()
 
409
{
 
410
    Q_Q(QToolBox);
 
411
    QToolBoxButton *tb = ::qobject_cast<QToolBoxButton*>(q->sender());
 
412
    QWidget* item = 0;
 
413
    for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
 
414
        if ((*i).button == tb) {
 
415
            item = (*i).widget;
 
416
            break;
 
417
        }
 
418
 
 
419
    q->setCurrentIndex(q->indexOf(item));
 
420
}
 
421
 
 
422
/*!
 
423
    \property QToolBox::count
 
424
    \brief The number of items contained in the toolbox.
 
425
*/
 
426
 
 
427
int QToolBox::count() const
 
428
{
 
429
    Q_D(const QToolBox);
 
430
    return d->pageList.count();
 
431
}
 
432
 
 
433
void QToolBox::setCurrentIndex(int index)
 
434
{
 
435
    Q_D(QToolBox);
 
436
    QToolBoxPrivate::Page *c = d->page(index);
 
437
    if (!c || d->currentPage == c)
 
438
        return;
 
439
 
 
440
    c->button->setSelected(true);
 
441
    if (d->currentPage) {
 
442
        d->currentPage->sv->hide();
 
443
        d->currentPage->button->setSelected(false);
 
444
    }
 
445
    d->currentPage = c;
 
446
    d->currentPage->sv->show();
 
447
    d->updateTabs();
 
448
    emit currentChanged(index);
 
449
}
 
450
 
 
451
void QToolBoxPrivate::relayout()
 
452
{
 
453
    Q_Q(QToolBox);
 
454
    delete layout;
 
455
    layout = new QVBoxLayout(q);
 
456
    for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) {
 
457
        layout->addWidget((*i).button);
 
458
        layout->addWidget((*i).sv);
 
459
    }
 
460
}
 
461
 
 
462
void QToolBoxPrivate::widgetDestroyed(QObject *object)
 
463
{
 
464
    Q_Q(QToolBox);
 
465
    // no verification - vtbl corrupted already
 
466
    QWidget *p = (QWidget*)object;
 
467
 
 
468
    QToolBoxPrivate::Page *c = page(p);
 
469
    if (!p || !c)
 
470
        return;
 
471
 
 
472
    layout->removeWidget(c->sv);
 
473
    layout->removeWidget(c->button);
 
474
    c->sv->deleteLater(); // page might still be a child of sv
 
475
    delete c->button;
 
476
 
 
477
    bool removeCurrent = c == currentPage;
 
478
    pageList.removeAll(*c);
 
479
 
 
480
    if (!pageList.count()) {
 
481
        currentPage = 0;
 
482
        emit q->currentChanged(-1);
 
483
    } else if (removeCurrent) {
 
484
        currentPage = 0;
 
485
        q->setCurrentIndex(0);
 
486
    }
 
487
}
 
488
 
 
489
/*!
 
490
    Removes the item at position \a index from the toolbox. Note that
 
491
    the widget is \e not deleted.
 
492
*/
 
493
 
 
494
void QToolBox::removeItem(int index)
 
495
{
 
496
    Q_D(QToolBox);
 
497
    if (QWidget *w = widget(index)) {
 
498
        disconnect(w, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed(QObject*)));
 
499
        w->setParent(this);
 
500
        // destroy internal data
 
501
        d->widgetDestroyed(w);
 
502
        itemRemoved(index);
 
503
    }
 
504
}
 
505
 
 
506
 
 
507
/*!
 
508
    \property QToolBox::currentIndex
 
509
    \brief The index of the current item, or -1 if the toolbox is empty.
 
510
 
 
511
    \sa indexOf(), widget()
 
512
*/
 
513
 
 
514
 
 
515
int QToolBox::currentIndex() const
 
516
{
 
517
    Q_D(const QToolBox);
 
518
    return d->currentPage ? indexOf(d->currentPage->widget) : -1;
 
519
}
 
520
 
 
521
/*!
 
522
    Returns a pointer to the current widget, or 0 if there is no such item.
 
523
 
 
524
    \sa currentIndex(), setCurrentWidget()
 
525
*/
 
526
 
 
527
QWidget * QToolBox::currentWidget() const
 
528
{
 
529
    Q_D(const QToolBox);
 
530
    return d->currentPage ? d->currentPage->widget : 0;
 
531
}
 
532
 
 
533
/*!
 
534
  Makes\a widget the current widget. The \a widget must be an item in this tool box.
 
535
 
 
536
  \sa addItem(), setCurrentIndex(), currentWidget()
 
537
 */
 
538
void QToolBox::setCurrentWidget(QWidget *widget)
 
539
{
 
540
    Q_ASSERT_X(indexOf(widget) >= 0, "QToolBox::setCurrentWidget", "widget not contained in tool box");
 
541
    setCurrentIndex(indexOf(widget));
 
542
}
 
543
 
 
544
/*!
 
545
    Returns the widget at position \a index, or 0 if there is no such
 
546
    item.
 
547
*/
 
548
 
 
549
QWidget *QToolBox::widget(int index) const
 
550
{
 
551
    Q_D(const QToolBox);
 
552
    if (index < 0 || index >= (int) d->pageList.size())
 
553
        return 0;
 
554
    return d->pageList.at(index).widget;
 
555
}
 
556
 
 
557
/*!
 
558
    Returns the index of \a widget, or -1 if the item does not
 
559
    exist.
 
560
*/
 
561
 
 
562
int QToolBox::indexOf(QWidget *widget) const
 
563
{
 
564
    Q_D(const QToolBox);
 
565
    QToolBoxPrivate::Page *c = d->page(widget);
 
566
    return c ? d->pageList.indexOf(*c) : -1;
 
567
}
 
568
 
 
569
/*!
 
570
    If \a enabled is true then the item at position \a index is enabled; otherwise
 
571
    the item at position \a index is disabled.
 
572
*/
 
573
 
 
574
void QToolBox::setItemEnabled(int index, bool enabled)
 
575
{
 
576
    Q_D(QToolBox);
 
577
    QToolBoxPrivate::Page *c = d->page(index);
 
578
    if (!c)
 
579
        return;
 
580
 
 
581
    c->button->setEnabled(enabled);
 
582
    if (!enabled && c == d->currentPage) {
 
583
        int curIndexUp = index;
 
584
        int curIndexDown = curIndexUp;
 
585
        const int count = d->pageList.count();
 
586
        while (curIndexUp > 0 || curIndexDown < count-1) {
 
587
            if (curIndexDown < count-1) {
 
588
                if (d->page(++curIndexDown)->button->isEnabled()) {
 
589
                    index = curIndexDown;
 
590
                    break;
 
591
                }
 
592
            }
 
593
            if (curIndexUp > 0) {
 
594
                if (d->page(--curIndexUp)->button->isEnabled()) {
 
595
                    index = curIndexUp;
 
596
                    break;
 
597
                }
 
598
            }
 
599
        }
 
600
        setCurrentIndex(index);
 
601
    }
 
602
}
 
603
 
 
604
 
 
605
/*!
 
606
    Sets the text of the item at position \a index to \a text.
 
607
*/
 
608
 
 
609
void QToolBox::setItemText(int index, const QString &text)
 
610
{
 
611
    Q_D(QToolBox);
 
612
    QToolBoxPrivate::Page *c = d->page(index);
 
613
    if (c)
 
614
        c->setText(text);
 
615
}
 
616
 
 
617
/*!
 
618
    Sets the icon of the item at position \a index to \a icon.
 
619
*/
 
620
 
 
621
void QToolBox::setItemIcon(int index, const QIcon &icon)
 
622
{
 
623
    Q_D(QToolBox);
 
624
    QToolBoxPrivate::Page *c = d->page(index);
 
625
    if (c)
 
626
        c->setIcon(icon);
 
627
}
 
628
 
 
629
/*!
 
630
    Sets the tooltip of the item at position \a index to \a toolTip.
 
631
*/
 
632
 
 
633
void QToolBox::setItemToolTip(int index, const QString &toolTip)
 
634
{
 
635
    Q_D(QToolBox);
 
636
    QToolBoxPrivate::Page *c = d->page(index);
 
637
    if (c)
 
638
        c->setToolTip(toolTip);
 
639
}
 
640
 
 
641
/*!
 
642
    Returns true if the item at position \a index is enabled; otherwise returns false.
 
643
*/
 
644
 
 
645
bool QToolBox::isItemEnabled(int index) const
 
646
{
 
647
    Q_D(const QToolBox);
 
648
    const QToolBoxPrivate::Page *c = d->page(index);
 
649
    return c && c->button->isEnabled();
 
650
}
 
651
 
 
652
/*!
 
653
    Returns the text of the item at position \a index, or an empty string if
 
654
    \a index is out of range.
 
655
*/
 
656
 
 
657
QString QToolBox::itemText(int index) const
 
658
{
 
659
    Q_D(const QToolBox);
 
660
    const QToolBoxPrivate::Page *c = d->page(index);
 
661
    return (c ? c->text() : QString());
 
662
}
 
663
 
 
664
/*!
 
665
    Returns the icon of the item at position \a index, or a null
 
666
    icon if \a index is out of range.
 
667
*/
 
668
 
 
669
QIcon QToolBox::itemIcon(int index) const
 
670
{
 
671
    Q_D(const QToolBox);
 
672
    const QToolBoxPrivate::Page *c = d->page(index);
 
673
    return (c ? c->icon() : QIcon());
 
674
}
 
675
 
 
676
/*!
 
677
    Returns the tooltip of the item at position \a index, or an
 
678
    empty string if \a index is out of range.
 
679
*/
 
680
 
 
681
QString QToolBox::itemToolTip(int index) const
 
682
{
 
683
    Q_D(const QToolBox);
 
684
    const QToolBoxPrivate::Page *c = d->page(index);
 
685
    return (c ? c->toolTip() : QString());
 
686
}
 
687
 
 
688
/*! \reimp */
 
689
void QToolBox::showEvent(QShowEvent *e)
 
690
{
 
691
    QWidget::showEvent(e);
 
692
}
 
693
 
 
694
/*! \reimp */
 
695
void QToolBox::changeEvent(QEvent *ev)
 
696
{
 
697
    Q_D(QToolBox);
 
698
    if(ev->type() == QEvent::StyleChange)
 
699
        d->updateTabs();
 
700
    QFrame::changeEvent(ev);
 
701
}
 
702
 
 
703
/*!
 
704
  This virtual handler is called after a new item was added or
 
705
  inserted at position \a index.
 
706
 
 
707
  \sa itemRemoved()
 
708
 */
 
709
void QToolBox::itemInserted(int index)
 
710
{
 
711
    Q_UNUSED(index)
 
712
}
 
713
 
 
714
/*!
 
715
  This virtual handler is called after an item was removed from
 
716
  position \a index.
 
717
 
 
718
  \sa itemInserted()
 
719
 */
 
720
void QToolBox::itemRemoved(int index)
 
721
{
 
722
    Q_UNUSED(index)
 
723
}
 
724
 
 
725
/*!
 
726
    \fn void QToolBox::setItemLabel(int index, const QString &text)
 
727
 
 
728
    Use setItemText() instead.
 
729
*/
 
730
 
 
731
/*!
 
732
    \fn QString QToolBox::itemLabel(int index) const
 
733
 
 
734
    Use itemText() instead.
 
735
*/
 
736
 
 
737
/*!
 
738
    \fn QWidget *QToolBox::currentItem() const
 
739
 
 
740
    Use widget(currentIndex()) instead.
 
741
*/
 
742
 
 
743
/*!
 
744
    \fn void QToolBox::setCurrentItem(QWidget *widget)
 
745
 
 
746
    Use setCurrentIndex(indexOf(widget)) instead.
 
747
*/
 
748
 
 
749
/*!
 
750
    \fn void QToolBox::setItemIconSet(int index, const QIcon &icon)
 
751
 
 
752
    Use setItemIcon() instead.
 
753
*/
 
754
 
 
755
/*!
 
756
    \fn QIcon QToolBox::itemIconSet(int index) const
 
757
 
 
758
    Use itemIcon() instead.
 
759
*/
 
760
 
 
761
/*!
 
762
    \fn int QToolBox::removeItem(QWidget *widget)
 
763
 
 
764
    Use toolbox->removeItem(toolbox->indexOf(widget)) instead.
 
765
*/
 
766
 
 
767
/*!
 
768
    \fn QWidget *QToolBox::item(int index) const
 
769
 
 
770
    Use widget() instead.
 
771
*/
 
772
 
 
773
 
 
774
#include "moc_qtoolbox.cpp"
 
775
 
 
776
#endif //QT_NO_TOOLBOX