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

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

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