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