source: trunk/src/qt3support/dialogs/q3tabdialog.cpp@ 497

Last change on this file since 497 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 26.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt3Support module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "q3tabdialog.h"
43
44#include "qtabbar.h"
45#include "qtabwidget.h"
46#include "qpushbutton.h"
47#include "qpainter.h"
48#include "qpixmap.h"
49#include "qapplication.h"
50#include "q3widgetstack.h"
51#include "qlayout.h"
52
53QT_BEGIN_NAMESPACE
54
55using namespace Qt;
56
57/*!
58 \class Q3TabDialog
59 \compat
60 \brief The Q3TabDialog class provides a stack of tabbed widgets.
61
62 A tabbed dialog is one in which several "tab pages" are available.
63 By clicking on a tab page's tab or by pressing the indicated
64 Alt+\e{letter} key combination, the user can select which tab page
65 they want to use.
66
67 Q3TabDialog provides a tab bar consisting of single row of tabs at
68 the top; each tab has an associated widget which is that tab's
69 tab page. In addition, Q3TabDialog provides an OK button and the
70 following optional buttons: Apply, Cancel, Defaults and Help.
71
72 The normal way to use Q3TabDialog is to do the following in the
73 constructor:
74 \list 1
75 \i Create a Q3TabDialog.
76 \i Create a QWidget for each of the pages in the tab dialog, insert
77 children into it, set up geometry management for it, and use
78 addTab() (or insertTab()) to set up a tab and keyboard accelerator
79 for it.
80 \i Set up the buttons for the tab dialog using setOkButton(),
81 setApplyButton(), setDefaultsButton(), setCancelButton() and
82 setHelpButton().
83 \i Connect to the signals and slots.
84 \endlist
85
86 If you don't call addTab() the page you have created will not be
87 visible. Don't confuse the object name you supply to the
88 QWidget constructor and the tab label you supply to addTab();
89 addTab() takes user-visible name that appears on the widget's tab
90 and may identify an accelerator, whereas the widget name is used
91 primarily for debugging.
92
93 Almost all applications have to connect the applyButtonPressed()
94 signal to something. applyButtonPressed() is emitted when either OK
95 or Apply is clicked, and your slot must copy the dialog's state into
96 the application.
97
98 There are also several other signals which may be useful:
99 \list
100 \i cancelButtonPressed() is emitted when the user clicks Cancel.
101 \i defaultButtonPressed() is emitted when the user clicks Defaults;
102 the slot it is connected to should reset the state of the dialog to
103 the application defaults.
104 \i helpButtonPressed() is emitted when the user clicks Help.
105 \i aboutToShow() is emitted at the start of show(); if there is any
106 chance that the state of the application may change between the
107 creation of the tab dialog and the time show() is called, you must
108 connect this signal to a slot that resets the state of the dialog.
109 \i currentChanged() is emitted when the user selects a page.
110 \endlist
111
112 Each tab is either enabled or disabled at any given time (see
113 setTabEnabled()). If a tab is enabled the tab text is drawn in
114 black and the user can select that tab. If it is disabled the tab
115 is drawn in a different way and the user cannot select that tab.
116 Note that even if a tab is disabled, the page can still be visible;
117 for example, if all of the tabs happen to be disabled.
118
119 You can change a tab's label and iconset using changeTab(). A tab
120 page can be removed with removePage() and shown with showPage(). The
121 current page is given by currentPage().
122
123 Q3TabDialog does not support tabs on the sides or bottom, nor can
124 you set or retrieve the visible page. If you need more functionality
125 than Q3TabDialog provides, consider creating a QDialog and using a
126 QTabBar with QTabWidgets.
127
128 Most of the functionality in Q3TabDialog is provided by a QTabWidget.
129*/
130
131/*!
132 \fn void Q3TabDialog::selected(const QString &name)
133
134 This signal is emitted whenever a tab is selected (raised),
135 including during the first show(). \a name is the name of the
136 selected tab.
137
138 \sa raise()
139*/
140
141/*! \fn void Q3TabDialog::currentChanged(QWidget *widget)
142
143 This signal is emitted whenever the current page changes. \a widget
144 is the new current page.
145
146 \sa currentPage(), showPage(), tabLabel()
147*/
148
149class Q3TabDialogPrivate
150{
151public:
152 Q3TabDialogPrivate();
153
154 QTabWidget* tw;
155
156 QPushButton * ok;
157 QPushButton * cb;
158 QPushButton * db;
159 QPushButton * hb;
160 QPushButton * ab;
161
162 QBoxLayout * tll;
163};
164
165Q3TabDialogPrivate::Q3TabDialogPrivate()
166 : tw(0),
167 ok(0), cb(0), db(0), hb(0), ab(0),
168 tll(0)
169{ }
170
171/*!
172 Constructs a Q3TabDialog with only an OK button.
173 The \a parent, \a name, \a modal and widget flag, \a f, arguments
174 are passed on to the QDialog constructor.
175*/
176
177Q3TabDialog::Q3TabDialog(QWidget *parent, const char *name, bool modal, Qt::WindowFlags f)
178 : QDialog(parent, name, modal, f)
179{
180 d = new Q3TabDialogPrivate;
181 Q_CHECK_PTR(d);
182
183 d->tw = new QTabWidget(this, "tab widget");
184 connect (d->tw, SIGNAL (selected(QString)), this, SIGNAL(selected(QString)));
185 connect (d->tw, SIGNAL (currentChanged(QWidget*)), this, SIGNAL(currentChanged(QWidget*)));
186
187 d->ok = new QPushButton(this, "ok");
188 Q_CHECK_PTR(d->ok);
189 d->ok->setText(tr("OK"));
190 d->ok->setDefault(true);
191 connect(d->ok, SIGNAL(clicked()),
192 this, SIGNAL(applyButtonPressed()));
193 connect(d->ok, SIGNAL(clicked()),
194 this, SLOT(accept()));
195}
196
197
198/*!
199 Destroys the tab dialog.
200*/
201
202Q3TabDialog::~Q3TabDialog()
203{
204 delete d;
205}
206
207
208/*!
209 Sets the font for the tabs to \a font.
210
211 If the widget is visible, the display is updated with the new font
212 immediately. There may be some geometry changes, depending on the
213 size of the old and new fonts.
214*/
215
216void Q3TabDialog::setFont(const QFont & font)
217{
218 QDialog::setFont(font);
219 setSizes();
220}
221
222
223/*!
224 \fn void Q3TabDialog::applyButtonPressed();
225
226 This signal is emitted when either the Apply or OK button is clicked.
227
228 It should be connected to a slot (or several slots) that change the
229 application's state according to the state of the dialog.
230
231 \sa cancelButtonPressed() defaultButtonPressed() setApplyButton()
232*/
233
234
235/*!
236 Returns true if the tab dialog has a Defaults button; otherwise
237 returns false.
238
239 \sa setDefaultButton() defaultButtonPressed() hasApplyButton()
240 hasCancelButton()
241*/
242
243bool Q3TabDialog::hasDefaultButton() const
244{
245 return d->db != 0;
246}
247
248
249/*!
250 Returns true if the tab dialog has a Help button; otherwise returns
251 false.
252
253 \sa setHelpButton() helpButtonPressed() hasApplyButton()
254 hasCancelButton()
255*/
256
257bool Q3TabDialog::hasHelpButton() const
258{
259 return d->hb != 0;
260}
261
262
263/*!
264 \fn void Q3TabDialog::cancelButtonPressed();
265
266 This signal is emitted when the Cancel button is clicked. It is
267 automatically connected to QDialog::reject(), which will hide the
268 dialog.
269
270 The Cancel button should not change the application's state at all,
271 so you should generally not need to connect it to any slot.
272
273 \sa applyButtonPressed() defaultButtonPressed() setCancelButton()
274*/
275
276
277/*!
278 Returns true if the tab dialog has a Cancel button; otherwise
279 returns false.
280
281 \sa setCancelButton() cancelButtonPressed() hasApplyButton()
282 hasDefaultButton()
283*/
284
285bool Q3TabDialog::hasCancelButton() const
286{
287 return d->cb != 0;
288}
289
290
291/*!
292 \fn void Q3TabDialog::defaultButtonPressed();
293
294 This signal is emitted when the Defaults button is pressed. It
295 should reset the dialog (but not the application) to the "factory
296 defaults".
297
298 The application's state should not be changed until the user clicks
299 Apply or OK.
300
301 \sa applyButtonPressed() cancelButtonPressed() setDefaultButton()
302*/
303
304
305/*!
306 \fn void Q3TabDialog::helpButtonPressed();
307
308 This signal is emitted when the Help button is pressed. It
309 could be used to present information about how to use the dialog.
310
311 \sa applyButtonPressed() cancelButtonPressed() setHelpButton()
312*/
313
314
315/*!
316 Returns true if the tab dialog has an Apply button; otherwise
317 returns false.
318
319 \sa setApplyButton() applyButtonPressed() hasCancelButton()
320 hasDefaultButton()
321*/
322
323bool Q3TabDialog::hasApplyButton() const
324{
325 return d->ab != 0;
326}
327
328
329/*!
330 Returns true if the tab dialog has an OK button; otherwise returns
331 false.
332
333 \sa setOkButton() hasApplyButton() hasCancelButton()
334 hasDefaultButton()
335*/
336
337bool Q3TabDialog::hasOkButton() const
338{
339 return d->ok != 0;
340}
341
342
343/*!
344 \fn void Q3TabDialog::aboutToShow()
345
346 This signal is emitted by show() when it is time to set the state of
347 the dialog's contents. The dialog should reflect the current state
348 of the application when it appears; if there is any possibility that
349 the state of the application may change between the time you call
350 Q3TabDialog() and show(), you should set the
351 dialog's state in a slot and connect this signal to it.
352
353 This applies mainly to Q3TabDialog objects that are kept around
354 hidden, rather than being created, shown, and deleted afterwards.
355
356 \sa applyButtonPressed(), QWidget::show(), cancelButtonPressed()
357*/
358
359
360/*!
361 \internal
362
363 Implemented to delay show()'ing of every page.
364*/
365void Q3TabDialog::show()
366{
367 // Reimplemented in order to delay show()'ing of every page
368 // except the initially visible one, and in order to emit the
369 // aboutToShow() signal.
370 if (window() == this)
371 d->tw->setFocus();
372 emit aboutToShow();
373 setSizes();
374 setUpLayout();
375 QDialog::show();
376}
377
378
379
380/*!
381 Adds another tab and page to the tab view.
382
383 The new page is \a child; the tab's label is \a label.
384 Note the difference between the widget name (which you supply to
385 widget constructors and to setTabEnabled(), for example) and the tab
386 label. The name is internal to the program and invariant, whereas
387 the label is shown on-screen and may vary according to language and
388 other factors.
389
390 If the tab's \a label contains an ampersand, the letter following
391 the ampersand is used as an accelerator for the tab, e.g. if the
392 label is "Bro&wse" then Alt+W becomes an accelerator which will
393 move the focus to this tab.
394
395 If you call addTab() after show() the screen will flicker and the
396 user may be confused.
397
398 \sa insertTab()
399*/
400
401void Q3TabDialog::addTab(QWidget * child, const QString &label)
402{
403 d->tw->addTab(child, label);
404}
405
406
407
408/*! \overload
409
410 This version of the function shows the \a iconset as well as the \a
411 label on the tab of \a child.
412*/
413void Q3TabDialog::addTab(QWidget *child, const QIcon& iconset, const QString &label)
414{
415 d->tw->addTab(child, iconset, label);
416}
417
418
419/*!
420 Inserts another tab and page to the tab view.
421
422 The new page is \a child; the tab's label is \a label.
423 Note the difference between the widget name (which you supply to
424 widget constructors and to setTabEnabled(), for example) and the tab
425 label. The name is internal to the program and invariant, whereas
426 the label is shown on-screen and may vary according to language and
427 other factors.
428
429 If the tab's \a label contains an ampersand, the letter following
430 the ampersand is used as an accelerator for the tab, e.g. if the
431 label is "Bro&wse" then Alt+W becomes an accelerator which will
432 move the focus to this tab.
433
434 If \a index is not specified, the tab is simply added. Otherwise
435 it is inserted at the specified position.
436
437 If you call insertTab() after show(), the screen will flicker and the
438 user may be confused.
439
440 \sa addTab()
441*/
442
443void Q3TabDialog::insertTab(QWidget * child, const QString &label, int index)
444{
445 d->tw->insertTab(child, label, index);
446}
447
448
449/*! \overload
450
451 This version of the function shows the \a iconset as well as the \a
452 label on the tab of \a child.
453 */
454void Q3TabDialog::insertTab(QWidget *child, const QIcon& iconset, const QString &label, int index)
455{
456 d->tw->insertTab(child, iconset, label, index);
457}
458
459/*!
460 Replaces the QTabBar heading the dialog by the given tab bar, \a tb.
461 Note that this must be called \e before any tabs have been added,
462 or the behavior is undefined.
463 \sa tabBar()
464*/
465void Q3TabDialog::setTabBar(QTabBar* tb)
466{
467 if (tb == 0){
468 qWarning("Q3TabDialog::setTabBar() called with null QTabBar pointer");
469 return;
470 }
471
472 d->tw->setTabBar(tb);
473 setUpLayout();
474}
475
476/*!
477 Returns the currently set QTabBar.
478 \sa setTabBar()
479*/
480QTabBar* Q3TabDialog::tabBar() const
481{
482 return d->tw->tabBar();
483}
484
485/*! Ensures that widget \a w is shown. This is mainly useful for accelerators.
486
487 \warning If used carelessly, this function can easily surprise or
488 confuse the user.
489
490 \sa QTabBar::setCurrentTab()
491*/
492
493void Q3TabDialog::showPage(QWidget * w)
494{
495 d->tw->showPage(w);
496}
497
498
499/*! \obsolete
500 Returns true if the page with object name \a name is enabled and
501 false if it is disabled.
502
503 If \a name is 0 or not the name of any of the pages, isTabEnabled()
504 returns false.
505
506 \sa setTabEnabled(), QWidget::isEnabled()
507*/
508
509bool Q3TabDialog::isTabEnabled(const char* name) const
510{
511 if (!name)
512 return false;
513 QObjectList l = this->queryList("QWidget", name, false, true);
514 if (!l.isEmpty()) {
515 for (int i = 0; i < l.size(); ++i) {
516 QObject *o = l.at(i);
517 if (!o->isWidgetType())
518 continue;
519 QWidget *w = static_cast<QWidget *>(o);
520 return d->tw->isTabEnabled(w);
521 }
522 }
523 return false;
524}
525
526
527/*!\obsolete
528
529 Finds the page with object name \a name, enables/disables it
530 according to the value of \a enable and redraws the page's tab
531 appropriately.
532
533 Q3TabDialog uses QWidget::setEnabled() internally, rather than keeping a
534 separate flag.
535
536 Note that even a disabled tab/page may be visible. If the page is
537 already visible Q3TabDialog will not hide it; if all the pages
538 are disabled Q3TabDialog will show one of them.
539
540 The object name is used (rather than the tab label) because the tab
541 text may not be invariant in multi-language applications.
542
543 \sa isTabEnabled(), QWidget::setEnabled()
544*/
545
546void Q3TabDialog::setTabEnabled(const char* name, bool enable)
547{
548 if (!name)
549 return;
550 QObjectList l = this->queryList("QWidget", name, false, true);
551 if (!l.isEmpty()) {
552 for (int i = 0; i < l.size(); ++i) {
553 QObject *o = l.at(i);
554 if(o->isWidgetType())
555 d->tw->setTabEnabled(static_cast<QWidget*>(o), enable);
556 }
557 }
558}
559
560
561/* ### SHOULD THIS BE HERE?
562 Adds an Apply button to the dialog. The button's text is set to \e
563 text (and defaults to "Apply").
564
565 The Apply button should apply the current settings in the dialog box
566 to the application, while keeping the dialog visible.
567
568 When Apply is clicked, the applyButtonPressed() signal is emitted.
569
570 If \a text is an empty string, no button is shown.
571
572 \sa setCancelButton() setDefaultButton() applyButtonPressed()
573*/
574
575
576/*!
577 Returns true if the page \a w is enabled; otherwise returns false.
578
579 \sa setTabEnabled(), QWidget::isEnabled()
580*/
581
582bool Q3TabDialog::isTabEnabled(QWidget* w) const
583{
584 return d->tw->isTabEnabled(w);
585}
586
587/*!
588 If \a enable is true the page \a w is enabled; otherwise \a w is
589 disabled. The page's tab is redrawn appropriately.
590
591 QTabWidget uses QWidget::setEnabled() internally, rather than keeping a
592 separate flag.
593
594 Note that even a disabled tab and tab page may be visible. If the
595 page is already visible QTabWidget will not hide it; if all the
596 pages are disabled QTabWidget will show one of them.
597
598 \sa isTabEnabled(), QWidget::setEnabled()
599*/
600
601void Q3TabDialog::setTabEnabled(QWidget* w, bool enable)
602{
603 d->tw->setTabEnabled(w, enable);
604}
605
606
607/*!
608 Adds an Apply button to the dialog. The button's text is set to \a
609 text.
610
611 The Apply button should apply the current settings in the dialog box
612 to the application while keeping the dialog visible.
613
614 When Apply is clicked, the applyButtonPressed() signal is emitted.
615
616 If \a text is an empty string, no button is shown.
617
618 \sa setCancelButton() setDefaultButton() applyButtonPressed()
619*/
620void Q3TabDialog::setApplyButton(const QString &text)
621{
622 if (text.isEmpty() && d->ab) {
623 delete d->ab;
624 d->ab = 0;
625 setSizes();
626 } else {
627 if (!d->ab) {
628 d->ab = new QPushButton(this, "apply settings");
629 connect(d->ab, SIGNAL(clicked()),
630 this, SIGNAL(applyButtonPressed()));
631 setUpLayout();
632 }
633 d->ab->setText(text);
634 setSizes();
635 //d->ab->show();
636 }
637}
638
639/*!
640 \overload
641
642 Adds an Apply button to the dialog. The button's text is set to
643 a localizable "Apply".
644 */
645void Q3TabDialog::setApplyButton()
646{
647 setApplyButton(tr("Apply"));
648}
649
650
651/*!
652 Adds a Help button to the dialog. The button's text is set to \a
653 text.
654
655 When Help is clicked, the helpButtonPressed() signal is emitted.
656
657 If \a text is an empty string, no button is shown.
658
659 \sa setApplyButton() setCancelButton() helpButtonPressed()
660*/
661
662void Q3TabDialog::setHelpButton(const QString &text)
663{
664 if (text.isEmpty()) {
665 delete d->hb;
666 d->hb = 0;
667 setSizes();
668 } else {
669 if (!d->hb) {
670 d->hb = new QPushButton(this, "give help");
671 connect(d->hb, SIGNAL(clicked()),
672 this, SIGNAL(helpButtonPressed()));
673 setUpLayout();
674 }
675 d->hb->setText(text);
676 setSizes();
677 //d->hb->show();
678 }
679}
680
681
682/*!
683 \overload
684
685 Adds a Help button to the dialog. The button's text is set to
686 a localizable "Help".
687 */
688void Q3TabDialog::setHelpButton()
689{
690 setHelpButton(tr("Help"));
691}
692
693/*!
694 Adds a Defaults button to the dialog. The button's text is set to \a
695 text.
696
697 The Defaults button should set the dialog (but not the application)
698 back to the application defaults.
699
700 When Defaults is clicked, the defaultButtonPressed() signal is emitted.
701
702 If \a text is an empty string, no button is shown.
703
704 \sa setApplyButton() setCancelButton() defaultButtonPressed()
705*/
706
707void Q3TabDialog::setDefaultButton(const QString &text)
708{
709 if (text.isEmpty()) {
710 delete d->db;
711 d->db = 0;
712 setSizes();
713 } else {
714 if (!d->db) {
715 d->db = new QPushButton(this, "back to default");
716 connect(d->db, SIGNAL(clicked()),
717 this, SIGNAL(defaultButtonPressed()));
718 setUpLayout();
719 }
720 d->db->setText(text);
721 setSizes();
722 //d->db->show();
723 }
724}
725
726
727/*!
728 \overload
729
730 Adds a Defaults button to the dialog. The button's text is set to
731 a localizable "Defaults".
732 */
733void Q3TabDialog::setDefaultButton()
734{
735 setDefaultButton(tr("Defaults"));
736}
737
738/*!
739 Adds a Cancel button to the dialog. The button's text is set to \a
740 text.
741
742 The cancel button should always return the application to the state
743 it was in before the tab view popped up, or if the user has clicked
744 Apply, back to the state immediately after the last Apply.
745
746 When Cancel is clicked, the cancelButtonPressed() signal is emitted.
747 The dialog is closed at the same time.
748
749 If \a text is an empty string, no button is shown.
750
751 \sa setApplyButton() setDefaultButton() cancelButtonPressed()
752*/
753
754void Q3TabDialog::setCancelButton(const QString &text)
755{
756 if (text.isEmpty()) {
757 delete d->cb;
758 d->cb = 0;
759 setSizes();
760 } else {
761 if (!d->cb) {
762 d->cb = new QPushButton(this, "cancel dialog");
763 connect(d->cb, SIGNAL(clicked()),
764 this, SIGNAL(cancelButtonPressed()));
765 connect(d->cb, SIGNAL(clicked()),
766 this, SLOT(reject()));
767 setUpLayout();
768 }
769 d->cb->setText(text);
770 setSizes();
771 //d->cb->show();
772 }
773}
774
775
776/*!
777 \overload
778
779 Adds a Cancel button to the dialog. The button's text is set to
780 a localizable "Cancel".
781 */
782
783void Q3TabDialog::setCancelButton()
784{
785 setCancelButton(tr("Cancel"));
786}
787
788/*! Sets up the layout manager for the tab dialog.
789
790 \sa setSizes() setApplyButton() setCancelButton() setDefaultButton()
791*/
792
793void Q3TabDialog::setUpLayout()
794{
795 // the next four are probably the same, really?
796 const int topMargin = 6;
797 const int leftMargin = 6;
798 const int rightMargin = 6;
799 const int bottomMargin = 6;
800 const int betweenButtonsMargin = 7;
801 const int aboveButtonsMargin = 8;
802
803 delete d->tll;
804 d->tll = new QBoxLayout(this, QBoxLayout::Down);
805
806 // top margin
807 d->tll->addSpacing(topMargin);
808
809 QBoxLayout * tmp = new QHBoxLayout();
810 d->tll->addLayout(tmp, 1);
811 tmp->addSpacing(leftMargin);
812 tmp->addWidget(d->tw, 1);
813 tmp->addSpacing(rightMargin + 2);
814
815 d->tll->addSpacing(aboveButtonsMargin + 2);
816 QBoxLayout * buttonRow = new QBoxLayout(QBoxLayout::RightToLeft);
817 d->tll->addLayout(buttonRow, 0);
818 d->tll->addSpacing(bottomMargin);
819
820 buttonRow->addSpacing(rightMargin);
821 if (d->cb) {
822 buttonRow->addWidget(d->cb, 0);
823 buttonRow->addSpacing(betweenButtonsMargin);
824 d->cb->raise();
825 }
826
827 if (d->ab) {
828 buttonRow->addWidget(d->ab, 0);
829 buttonRow->addSpacing(betweenButtonsMargin);
830 d->ab->raise();
831 }
832
833 if (d->db) {
834 buttonRow->addWidget(d->db, 0);
835 buttonRow->addSpacing(betweenButtonsMargin);
836 d->db->raise();
837 }
838
839 if (d->hb) {
840 buttonRow->addWidget(d->hb, 0);
841 buttonRow->addSpacing(betweenButtonsMargin);
842 d->hb->raise();
843 }
844
845 if (d->ok) {
846 buttonRow->addWidget(d->ok, 0);
847 buttonRow->addSpacing(betweenButtonsMargin);
848 d->ok->raise();
849 }
850
851 // add one custom widget here
852 buttonRow->addStretch(1);
853 // add another custom widget here
854
855 d->tll->activate();
856}
857
858
859/*! Sets up the minimum and maximum sizes for each child widget.
860
861 \sa setUpLayout() setFont()
862*/
863
864void Q3TabDialog::setSizes()
865{
866 // compute largest button size
867 QSize s(0, 0);
868 int bw = s.width();
869 int bh = s.height();
870
871 if (d->ok) {
872 s = d->ok->sizeHint();
873 if (s.width() > bw)
874 bw = s.width();
875 if (s.height() > bh)
876 bh = s.height();
877 }
878
879 if (d->ab) {
880 s = d->ab->sizeHint();
881 if (s.width() > bw)
882 bw = s.width();
883 if (s.height() > bh)
884 bh = s.height();
885 }
886
887 if (d->db) {
888 s = d->db->sizeHint();
889 if (s.width() > bw)
890 bw = s.width();
891 if (s.height() > bh)
892 bh = s.height();
893 }
894
895 if (d->hb) {
896 s = d->hb->sizeHint();
897 if (s.width() > bw)
898 bw = s.width();
899 if (s.height() > bh)
900 bh = s.height();
901 }
902
903 if (d->cb) {
904 s = d->cb->sizeHint();
905 if (s.width() > bw)
906 bw = s.width();
907 if (s.height() > bh)
908 bh = s.height();
909 }
910
911 // and set all the buttons to that size
912 if (d->ok)
913 d->ok->setFixedSize(bw, bh);
914 if (d->ab)
915 d->ab->setFixedSize(bw, bh);
916 if (d->db)
917 d->db->setFixedSize(bw, bh);
918 if (d->hb)
919 d->hb->setFixedSize(bw, bh);
920 if (d->cb)
921 d->cb->setFixedSize(bw, bh);
922
923 // fiddle the tab chain so the buttons are in their natural order
924 QWidget * w = d->ok;
925
926 if (d->hb) {
927 if (w)
928 setTabOrder(w, d->hb);
929 w = d->hb;
930 }
931 if (d->db) {
932 if (w)
933 setTabOrder(w, d->db);
934 w = d->db;
935 }
936 if (d->ab) {
937 if (w)
938 setTabOrder(w, d->ab);
939 w = d->ab;
940 }
941 if (d->cb) {
942 if (w)
943 setTabOrder(w, d->cb);
944 w = d->cb;
945 }
946 setTabOrder(w, d->tw);
947}
948
949/*!\reimp
950*/
951void Q3TabDialog::resizeEvent(QResizeEvent * e)
952{
953 QDialog::resizeEvent(e);
954}
955
956
957/*!\reimp
958*/
959void Q3TabDialog::paintEvent(QPaintEvent *)
960{
961}
962
963
964/*!
965 Adds an OK button to the dialog and sets the button's text to \a text.
966
967 When the OK button is clicked, the applyButtonPressed() signal is emitted,
968 and the current settings in the dialog box should be applied to
969 the application. The dialog then closes.
970
971 If \a text is an empty string, no button is shown.
972
973 \sa setCancelButton() setDefaultButton() applyButtonPressed()
974*/
975
976void Q3TabDialog::setOkButton(const QString &text)
977{
978 if (text.isEmpty()) {
979 delete d->ok;
980 d->ok = 0;
981 setSizes();
982 } else {
983 if (!d->ok) {
984 d->ok = new QPushButton(this, "ok");
985 connect(d->ok, SIGNAL(clicked()),
986 this, SIGNAL(applyButtonPressed()));
987 setUpLayout();
988 }
989 d->ok->setText(text);
990 setSizes();
991 //d->ok->show();
992 }
993}
994/*!
995 \overload
996
997 Adds an OK button to the dialog. The button's text is set to
998 a localizable "OK".
999 */
1000
1001void Q3TabDialog::setOkButton()
1002{
1003 setOkButton(tr("OK"));
1004}
1005
1006
1007/*
1008 \overload
1009 Old version of setOkButton(), provided for backward compatibility.
1010*/
1011void Q3TabDialog::setOKButton(const QString &text)
1012{
1013 // Ugly workaround for original "OK" default argument
1014 QString newText(text);
1015 if (text.isNull())
1016 newText = QString::fromLatin1("OK");
1017 setOkButton(newText);
1018}
1019
1020
1021/*! Returns the text in the tab for page \a w.
1022*/
1023
1024QString Q3TabDialog::tabLabel(QWidget * w)
1025{
1026 return d->tw->tabLabel(w);
1027}
1028
1029
1030/*! \reimp
1031*/
1032void Q3TabDialog::styleChange(QStyle& s)
1033{
1034 QDialog::styleChange(s);
1035 setSizes();
1036}
1037
1038
1039/*! Returns a pointer to the page currently being displayed by the
1040tab dialog. The tab dialog does its best to make sure that this value
1041is never 0 (but if you try hard enough, it can be).
1042*/
1043
1044QWidget * Q3TabDialog::currentPage() const
1045{
1046 return d->tw->currentPage();
1047}
1048
1049/*!
1050 \overload
1051 Defines a new \a label for the tab of page \a w
1052 */
1053void Q3TabDialog::changeTab(QWidget *w, const QString &label)
1054{
1055 d->tw->changeTab(w, label);
1056}
1057
1058/*!
1059 Changes tab page \a w's iconset to \a iconset and label to \a label.
1060
1061 */
1062void Q3TabDialog::changeTab(QWidget *w, const QIcon& iconset, const QString &label)
1063{
1064 d->tw->changeTab(w, iconset, label);
1065}
1066
1067/*! Removes page \a w from this stack of widgets. Does not
1068 delete \a w.
1069 \sa showPage(), QTabWidget::removePage()
1070*/
1071void Q3TabDialog::removePage(QWidget * w)
1072{
1073 d->tw->removePage(w);
1074}
1075
1076QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.