00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "kdialog.h"
00024 #include "kdialog_p.h"
00025 #include "kdialogqueue_p.h"
00026
00027 #include <config.h>
00028
00029 #include <QApplication>
00030 #include <QDesktopWidget>
00031 #include <QDialogButtonBox>
00032 #include <QHBoxLayout>
00033 #include <QHideEvent>
00034 #include <QPointer>
00035 #include <QTimer>
00036 #include <QVBoxLayout>
00037 #include <QWhatsThis>
00038
00039 #include <klocale.h>
00040 #include <kpushbutton.h>
00041 #include <kseparator.h>
00042 #include <kstandardguiitem.h>
00043 #include <ktoolinvocation.h>
00044 #include <kurllabel.h>
00045 #include <kwhatsthismanager_p.h>
00046
00047 #ifdef Q_WS_X11
00048 #include <qx11info_x11.h>
00049 #include <netwm.h>
00050 #endif
00051
00052 int KDialogPrivate::mMarginSize = 9;
00053 int KDialogPrivate::mSpacingSize = 6;
00054
00055 void KDialogPrivate::setupLayout()
00056 {
00057 Q_Q(KDialog);
00058 if (!dirty) {
00059 QMetaObject::invokeMethod( q, "queuedLayoutUpdate", Qt::QueuedConnection );
00060 dirty = true;
00061 }
00062 }
00063
00064 void KDialogPrivate::queuedLayoutUpdate()
00065 {
00066 if (!dirty)
00067 return;
00068
00069 dirty = false;
00070
00071 Q_Q(KDialog);
00072
00073 delete mTopLayout;
00074
00075 if ( mButtonOrientation == Qt::Horizontal )
00076 mTopLayout = new QVBoxLayout(q);
00077 else
00078 mTopLayout = new QHBoxLayout(q);
00079
00080 mTopLayout->setMargin( KDialog::marginHint() );
00081 mTopLayout->setSpacing( KDialog::spacingHint() );
00082
00083 if ( mUrlHelp )
00084 mTopLayout->addWidget( mUrlHelp, 0, Qt::AlignRight );
00085
00086 if ( mMainWidget )
00087 mTopLayout->addWidget( mMainWidget, 10 );
00088
00089 if ( mDetailsWidget )
00090 mTopLayout->addWidget( mDetailsWidget );
00091
00092 if ( mActionSeparator )
00093 mTopLayout->addWidget( mActionSeparator );
00094
00095 if ( mButtonBox ) {
00096 mButtonBox->setOrientation( mButtonOrientation );
00097 mTopLayout->addWidget( mButtonBox );
00098 }
00099 }
00100
00101 void KDialogPrivate::setButtonFocus(QPushButton *button, bool isDefault, bool isFocus)
00102 {
00103 button->setDefault( isDefault );
00104 if ( isFocus )
00105 button->setFocus();
00106 }
00107
00108 void KDialogPrivate::appendButton(KDialog::ButtonCode key, const KGuiItem &item)
00109 {
00110 QDialogButtonBox::ButtonRole role = QDialogButtonBox::InvalidRole;
00111 switch ( key ) {
00112 case KDialog::Help:
00113 case KDialog::Details:
00114 role = QDialogButtonBox::HelpRole;
00115 break;
00116 case KDialog::Default:
00117 case KDialog::Reset:
00118 role = QDialogButtonBox::ResetRole;
00119 break;
00120 case KDialog::Ok:
00121 role = QDialogButtonBox::AcceptRole;
00122 break;
00123 case KDialog::Apply:
00124 role = QDialogButtonBox::ApplyRole;
00125 break;
00126 case KDialog::Try:
00127 case KDialog::Yes:
00128 role = QDialogButtonBox::YesRole;
00129 break;
00130 case KDialog::Close:
00131 case KDialog::Cancel:
00132 role = QDialogButtonBox::RejectRole;
00133 break;
00134 case KDialog::No:
00135 role = QDialogButtonBox::NoRole;
00136 break;
00137 case KDialog::User1:
00138 case KDialog::User2:
00139 case KDialog::User3:
00140 role = QDialogButtonBox::ActionRole;
00141 break;
00142 case KDialog::NoDefault:
00143 default:
00144 role = QDialogButtonBox::InvalidRole;
00145 break;
00146 }
00147
00148 if ( role == QDialogButtonBox::InvalidRole )
00149 return;
00150
00151 KPushButton *button = new KPushButton( item );
00152 mButtonBox->addButton( button, role );
00153
00154 mButtonList.insert( key, button );
00155 mButtonSignalMapper.setMapping( button, key );
00156
00157 QObject::connect(button, SIGNAL(clicked()),
00158 &mButtonSignalMapper, SLOT( map() ) );
00159 }
00160
00161 void KDialogPrivate::init(KDialog *q)
00162 {
00163 q_ptr = q;
00164 KWhatsThisManager::init();
00165
00166 dirty = false;
00167
00168 q->setButtons(KDialog::Ok | KDialog::Cancel);
00169 q->setDefaultButton(KDialog::Ok);
00170
00171 q->connect(q, SIGNAL(layoutHintChanged()), q, SLOT(updateGeometry()));
00172 q->connect(&mButtonSignalMapper, SIGNAL(mapped(int)), q, SLOT(slotButtonClicked(int)));
00173
00174 q->setPlainCaption(KGlobal::caption());
00175 }
00176
00177 KDialog::KDialog( QWidget *parent, Qt::WFlags flags )
00178 : QDialog(parent, flags), d_ptr(new KDialogPrivate)
00179 {
00180 d_ptr->init(this);
00181 }
00182
00183 KDialog::KDialog(KDialogPrivate &dd, QWidget *parent, Qt::WFlags flags)
00184 : QDialog(parent, flags), d_ptr(&dd)
00185 {
00186 d_ptr->init(this);
00187 }
00188
00189 KDialog::~KDialog()
00190 {
00191 delete d_ptr;
00192 }
00193
00194 void KDialog::setButtons( ButtonCodes buttonMask )
00195 {
00196 Q_D(KDialog);
00197 if ( d->mButtonBox ) {
00198 d->mButtonList.clear();
00199
00200 delete d->mButtonBox;
00201 d->mButtonBox = 0;
00202 }
00203
00204 if ( buttonMask & Cancel )
00205 buttonMask &= ~Close;
00206
00207 if ( buttonMask & Apply )
00208 buttonMask &= ~Try;
00209
00210 if ( buttonMask & Details )
00211 buttonMask &= ~Default;
00212
00213 if ( buttonMask == None ) {
00214 d->setupLayout();
00215 return;
00216 }
00217
00218 d->mEscapeButton = (buttonMask & Cancel) ? Cancel : Close;
00219 d->mButtonBox = new QDialogButtonBox( this );
00220
00221 if ( buttonMask & Help )
00222 d->appendButton( Help, KStandardGuiItem::help() );
00223 if ( buttonMask & Default )
00224 d->appendButton( Default, KStandardGuiItem::defaults() );
00225 if ( buttonMask & Reset )
00226 d->appendButton( Reset, KStandardGuiItem::reset() );
00227 if ( buttonMask & User3 )
00228 d->appendButton( User3, KGuiItem() );
00229 if ( buttonMask & User2 )
00230 d->appendButton( User2, KGuiItem() );
00231 if ( buttonMask & User1 )
00232 d->appendButton( User1, KGuiItem() );
00233 if ( buttonMask & Ok )
00234 d->appendButton( Ok, KStandardGuiItem::ok() );
00235 if ( buttonMask & Apply )
00236 d->appendButton( Apply, KStandardGuiItem::apply() );
00237 if ( buttonMask & Try )
00238 d->appendButton( Try, KGuiItem(i18n( "&Try" )) );
00239 if ( buttonMask & Cancel )
00240 d->appendButton( Cancel, KStandardGuiItem::cancel() );
00241 if ( buttonMask & Close )
00242 d->appendButton( Close, KStandardGuiItem::close() );
00243 if ( buttonMask & Yes )
00244 d->appendButton( Yes, KStandardGuiItem::yes() );
00245 if ( buttonMask & No )
00246 d->appendButton( No, KStandardGuiItem::no() );
00247 if ( buttonMask & Details ) {
00248 d->appendButton( Details, KGuiItem(QString()) );
00249 setDetailsWidgetVisible( false );
00250 }
00251
00252 d->setupLayout();
00253 }
00254
00255
00256 void KDialog::setButtonsOrientation( Qt::Orientation orientation )
00257 {
00258 Q_D(KDialog);
00259 if ( d->mButtonOrientation != orientation ) {
00260 d->mButtonOrientation = orientation;
00261
00262 if ( d->mActionSeparator )
00263 d->mActionSeparator->setOrientation( d->mButtonOrientation );
00264
00265 if ( d->mButtonOrientation == Qt::Vertical )
00266 enableLinkedHelp( false );
00267 }
00268 }
00269
00270 void KDialog::setEscapeButton( ButtonCode id )
00271 {
00272 d_func()->mEscapeButton = id;
00273 }
00274
00275 void KDialog::setDefaultButton( ButtonCode newDefaultButton )
00276 {
00277 Q_D(KDialog);
00278 bool makeDefault = true;
00279 if (newDefaultButton == NoDefault) {
00280
00281
00282 newDefaultButton = defaultButton();
00283 makeDefault = false;
00284 }
00285
00286 KPushButton *b = button(newDefaultButton);
00287 if (b) {
00288 d->setButtonFocus(b, makeDefault, false);
00289 }
00290 }
00291
00292 KDialog::ButtonCode KDialog::defaultButton() const
00293 {
00294 Q_D(const KDialog);
00295 QHashIterator<int, KPushButton*> it( d->mButtonList );
00296 while ( it.hasNext() ) {
00297 it.next();
00298 if ( it.value()->isDefault() )
00299 return (ButtonCode)it.key();
00300 }
00301
00302 return NoDefault;
00303 }
00304
00305 void KDialog::setMainWidget( QWidget *widget )
00306 {
00307 Q_D(KDialog);
00308 if ( d->mMainWidget == widget )
00309 return;
00310 d->mMainWidget = widget;
00311 QLayout* layout = d->mMainWidget->layout();
00312 if (layout) {
00313
00314 layout->setMargin(0);
00315 }
00316 d->setupLayout();
00317 }
00318
00319 QWidget *KDialog::mainWidget()
00320 {
00321 Q_D(KDialog);
00322 if (!d->mMainWidget)
00323 setMainWidget( new QWidget(this) );
00324 return d->mMainWidget;
00325 }
00326
00327 QSize KDialog::sizeHint() const
00328 {
00329 Q_D(const KDialog);
00330
00331 if (!d->mMinSize.isEmpty())
00332 return d->mMinSize.expandedTo( minimumSizeHint() ) + d->mIncSize;
00333 else {
00334 if (d->dirty)
00335 const_cast<KDialogPrivate*>(d)->queuedLayoutUpdate();
00336 return QDialog::sizeHint() + d->mIncSize;
00337 }
00338 }
00339
00340 QSize KDialog::minimumSizeHint() const
00341 {
00342 Q_D(const KDialog);
00343
00344 if (d->dirty)
00345 const_cast<KDialogPrivate*>(d)->queuedLayoutUpdate();
00346 return QDialog::minimumSizeHint() + d->mIncSize;
00347 }
00348
00349
00350
00351
00352 void KDialog::keyPressEvent( QKeyEvent *event )
00353 {
00354 Q_D(KDialog);
00355 if ( event->modifiers() == 0 ) {
00356 if ( event->key() == Qt::Key_F1 ) {
00357 KPushButton *button = this->button( Help );
00358
00359 if ( button ) {
00360 button->animateClick();
00361 event->accept();
00362 return;
00363 }
00364 }
00365
00366 if ( event->key() == Qt::Key_Escape ) {
00367 KPushButton *button = this->button( d->mEscapeButton );
00368
00369 if ( button ) {
00370 button->animateClick();
00371 event->accept();
00372 return;
00373 }
00374
00375 }
00376 } else if ( event->key() == Qt::Key_F1 && event->modifiers() == Qt::ShiftModifier ) {
00377 QWhatsThis::enterWhatsThisMode();
00378 event->accept();
00379 return;
00380 } else if ( event->modifiers() == Qt::ControlModifier &&
00381 ( event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter ) ) {
00382
00383 KPushButton *button = this->button( Ok );
00384
00385 if ( button ) {
00386 button->animateClick();
00387 event->accept();
00388 return;
00389 }
00390 }
00391
00392 QDialog::keyPressEvent( event );
00393 }
00394
00395 int KDialog::marginHint()
00396 {
00397 return KDialogPrivate::mMarginSize;
00398 }
00399
00400 int KDialog::spacingHint()
00401 {
00402 return KDialogPrivate::mSpacingSize;
00403 }
00404
00405 QString KDialog::makeStandardCaption( const QString &userCaption,
00406 QWidget* window,
00407 CaptionFlags flags )
00408 {
00409 Q_UNUSED(window);
00410 QString caption = KGlobal::caption();
00411 QString captionString = userCaption.isEmpty() ? caption : userCaption;
00412
00413
00414 if (flags & ModifiedCaption)
00415 captionString += QString::fromUtf8(" [") + i18n("modified") + QString::fromUtf8("]");
00416
00417 if ( !userCaption.isEmpty() ) {
00418
00419
00420 if ( flags & AppNameCaption &&
00421 !caption.isEmpty() &&
00422 !userCaption.endsWith(caption) ) {
00423
00424
00425 captionString += QString::fromUtf8(" - ") + caption;
00426 }
00427 }
00428
00429 return captionString;
00430 }
00431
00432 void KDialog::setCaption( const QString &_caption )
00433 {
00434 QString caption = makeStandardCaption( _caption, this );
00435 setPlainCaption( caption );
00436 }
00437
00438 void KDialog::setCaption( const QString &caption, bool modified )
00439 {
00440 CaptionFlags flags = HIGCompliantCaption;
00441
00442 if ( modified )
00443 {
00444 flags |= ModifiedCaption;
00445 }
00446
00447 setPlainCaption( makeStandardCaption(caption, this, flags) );
00448 }
00449
00450
00451 void KDialog::setPlainCaption( const QString &caption )
00452 {
00453 QDialog::setWindowTitle( caption );
00454
00455 #ifdef Q_WS_X11
00456 NETWinInfo info( QX11Info::display(), winId(), QX11Info::appRootWindow(), 0 );
00457 info.setName( caption.toUtf8().constData() );
00458 #endif
00459 }
00460
00461 void KDialog::resizeLayout( QWidget *widget, int margin, int spacing )
00462 {
00463 if ( widget->layout() )
00464 resizeLayout( widget->layout(), margin, spacing );
00465
00466 if ( widget->children().count() > 0 ) {
00467 QList<QObject*> list = widget->children();
00468 foreach ( QObject *object, list ) {
00469 if ( object->isWidgetType() )
00470 resizeLayout( (QWidget*)object, margin, spacing );
00471 }
00472 }
00473 }
00474
00475 void KDialog::resizeLayout( QLayout *layout, int margin, int spacing )
00476 {
00477 QLayoutItem *child;
00478 int pos = 0;
00479
00480 while ( (child = layout->itemAt( pos ) ) ) {
00481 if ( child->layout() )
00482 resizeLayout( child->layout(), margin, spacing );
00483
00484 ++pos;
00485 }
00486
00487 if ( layout->layout() ) {
00488 layout->layout()->setMargin( margin );
00489 layout->layout()->setSpacing( spacing );
00490 }
00491 }
00492
00493 static QRect screenRect( QWidget *widget, int screen )
00494 {
00495 QDesktopWidget *desktop = QApplication::desktop();
00496 KConfig gc( "kdeglobals", KConfig::NoGlobals );
00497 KConfigGroup cg(&gc, "Windows" );
00498 if ( desktop->isVirtualDesktop() &&
00499 cg.readEntry( "XineramaEnabled", true ) &&
00500 cg.readEntry( "XineramaPlacementEnabled", true ) ) {
00501
00502 if ( screen < 0 || screen >= desktop->numScreens() ) {
00503 if ( screen == -1 )
00504 screen = desktop->primaryScreen();
00505 else if ( screen == -3 )
00506 screen = desktop->screenNumber( QCursor::pos() );
00507 else
00508 screen = desktop->screenNumber( widget );
00509 }
00510
00511 return desktop->availableGeometry( screen );
00512 } else
00513 return desktop->geometry();
00514 }
00515
00516 void KDialog::centerOnScreen( QWidget *widget, int screen )
00517 {
00518 if ( !widget )
00519 return;
00520
00521 #ifdef Q_WS_X11
00522 if( !( widget->windowFlags() & Qt::X11BypassWindowManagerHint ) && widget->windowType() != Qt::Popup
00523 && NETRootInfo( QX11Info::display(), NET::Supported ).isSupported( NET::WM2FullPlacement )) {
00524 return;
00525 }
00526 #endif
00527
00528 QRect rect = screenRect( widget, screen );
00529
00530 widget->move( rect.center().x() - widget->width() / 2,
00531 rect.center().y() - widget->height() / 2 );
00532 }
00533
00534 bool KDialog::avoidArea( QWidget *widget, const QRect& area, int screen )
00535 {
00536 if ( !widget )
00537 return false;
00538
00539 QRect fg = widget->frameGeometry();
00540 if ( !fg.intersects( area ) )
00541 return true;
00542
00543 QRect scr = screenRect( widget, screen );
00544 QRect avoid( area );
00545 avoid.translate( -5, -5 );
00546 avoid.setRight( avoid.right() + 10 );
00547 avoid.setBottom( avoid.bottom() + 10 );
00548
00549 if ( qMax( fg.top(), avoid.top() ) <= qMin( fg.bottom(), avoid.bottom() ) ) {
00550
00551 int spaceAbove = qMax( 0, avoid.top() - scr.top() );
00552 int spaceBelow = qMax( 0, scr.bottom() - avoid.bottom() );
00553 if ( spaceAbove > spaceBelow )
00554 if ( fg.height() <= spaceAbove )
00555 fg.setY( avoid.top() - fg.height() );
00556 else
00557 return false;
00558 else
00559 if ( fg.height() <= spaceBelow )
00560 fg.setY( avoid.bottom() );
00561 else
00562 return false;
00563 }
00564
00565 if ( qMax( fg.left(), avoid.left() ) <= qMin( fg.right(), avoid.right() ) ) {
00566
00567 int spaceLeft = qMax( 0, avoid.left() - scr.left() );
00568 int spaceRight = qMax( 0, scr.right() - avoid.right() );
00569 if ( spaceLeft > spaceRight )
00570 if ( fg.width() <= spaceLeft )
00571 fg.setX( avoid.left() - fg.width() );
00572 else
00573 return false;
00574 else
00575 if ( fg.width() <= spaceRight )
00576 fg.setX( avoid.right() );
00577 else
00578 return false;
00579 }
00580
00581 widget->move( fg.x(), fg.y() );
00582
00583 return true;
00584 }
00585
00586 void KDialog::showButtonSeparator( bool state )
00587 {
00588 Q_D(KDialog);
00589 if ( ( d->mActionSeparator != 0 ) == state )
00590 return;
00591 if ( state ) {
00592 if ( d->mActionSeparator )
00593 return;
00594
00595 d->mActionSeparator = new KSeparator( this );
00596 d->mActionSeparator->setOrientation( d->mButtonOrientation );
00597 } else {
00598 delete d->mActionSeparator;
00599 d->mActionSeparator = 0;
00600 }
00601
00602 d->setupLayout();
00603 }
00604
00605 void KDialog::setInitialSize( const QSize &size )
00606 {
00607 d_func()->mMinSize = size;
00608 adjustSize();
00609 }
00610
00611 void KDialog::incrementInitialSize( const QSize &size )
00612 {
00613 d_func()->mIncSize = size;
00614 adjustSize();
00615 }
00616
00617 KPushButton *KDialog::button( ButtonCode id ) const
00618 {
00619 Q_D(const KDialog);
00620 return d->mButtonList.value( id, 0 );
00621 }
00622
00623 void KDialog::enableButton( ButtonCode id, bool state )
00624 {
00625 KPushButton *button = this->button( id );
00626 if ( button )
00627 button->setEnabled( state );
00628 }
00629
00630 bool KDialog::isButtonEnabled( ButtonCode id ) const
00631 {
00632 KPushButton *button = this->button( id );
00633 if ( button )
00634 return button->isEnabled();
00635
00636 return false;
00637 }
00638
00639 void KDialog::enableButtonOk( bool state )
00640 {
00641 enableButton( Ok, state );
00642 }
00643
00644 void KDialog::enableButtonApply( bool state )
00645 {
00646 enableButton( Apply, state );
00647 }
00648
00649 void KDialog::enableButtonCancel( bool state )
00650 {
00651 enableButton( Cancel, state );
00652 }
00653
00654 void KDialog::showButton( ButtonCode id, bool state )
00655 {
00656 KPushButton *button = this->button( id );
00657 if ( button )
00658 state ? button->show() : button->hide();
00659 }
00660
00661 void KDialog::setButtonGuiItem( ButtonCode id, const KGuiItem &item )
00662 {
00663 KPushButton *button = this->button( id );
00664 if ( !button )
00665 return;
00666
00667 button->setGuiItem( item );
00668 }
00669
00670 void KDialog::setButtonMenu( ButtonCode id, QMenu *menu, ButtonPopupMode popupmode)
00671 {
00672 KPushButton *button = this->button( id );
00673 if ( button ) {
00674 if (popupmode==InstantPopup)
00675 button->setMenu( menu );
00676 else
00677 button->setDelayedMenu(menu);
00678 }
00679 }
00680
00681 void KDialog::setButtonText( ButtonCode id, const QString &text )
00682 {
00683 Q_D(KDialog);
00684 if ( !d->mSettingDetails && (id == Details) ) {
00685 d->mDetailsButtonText = text;
00686 setDetailsWidgetVisible( d->mDetailsVisible );
00687 return;
00688 }
00689
00690 KPushButton *button = this->button( id );
00691 if ( button )
00692 button->setText( text );
00693 }
00694
00695 QString KDialog::buttonText( ButtonCode id ) const
00696 {
00697 KPushButton *button = this->button( id );
00698 if ( button )
00699 return button->text();
00700 else
00701 return QString();
00702 }
00703
00704 void KDialog::setButtonIcon( ButtonCode id, const KIcon &icon )
00705 {
00706 KPushButton *button = this->button( id );
00707 if ( button )
00708 button->setIcon( icon );
00709 }
00710
00711 KIcon KDialog::buttonIcon( ButtonCode id ) const
00712 {
00713 KPushButton *button = this->button( id );
00714 if ( button )
00715 return KIcon(button->icon());
00716 else
00717 return KIcon();
00718 }
00719
00720 void KDialog::setButtonToolTip( ButtonCode id, const QString &text )
00721 {
00722 KPushButton *button = this->button( id );
00723 if ( button ) {
00724 if ( text.isEmpty() )
00725 button->setToolTip( QString() );
00726 else
00727 button->setToolTip( text );
00728 }
00729 }
00730
00731 QString KDialog::buttonToolTip( ButtonCode id ) const
00732 {
00733 KPushButton *button = this->button( id );
00734 if ( button )
00735 return button->toolTip();
00736 else
00737 return QString();
00738 }
00739
00740 void KDialog::setButtonWhatsThis( ButtonCode id, const QString &text )
00741 {
00742 KPushButton *button = this->button( id );
00743 if ( button ) {
00744 if ( text.isEmpty() )
00745 button->setWhatsThis( QString() );
00746 else
00747 button->setWhatsThis( text );
00748 }
00749 }
00750
00751 QString KDialog::buttonWhatsThis( ButtonCode id ) const
00752 {
00753 KPushButton *button = this->button( id );
00754 if ( button )
00755 return button->whatsThis();
00756 else
00757 return QString();
00758 }
00759
00760 void KDialog::setButtonFocus( ButtonCode id )
00761 {
00762 KPushButton *button = this->button( id );
00763 if ( button )
00764 d_func()->setButtonFocus(button, false, true);
00765 }
00766
00767 void KDialog::setDetailsWidget( QWidget *detailsWidget )
00768 {
00769 Q_D(KDialog);
00770 if ( d->mDetailsWidget == detailsWidget )
00771 return;
00772 delete d->mDetailsWidget;
00773 d->mDetailsWidget = detailsWidget;
00774
00775 if ( d->mDetailsWidget->parentWidget() != this )
00776 d->mDetailsWidget->setParent( this );
00777
00778 d->mDetailsWidget->hide();
00779 d->setupLayout();
00780
00781 if ( !d->mSettingDetails )
00782 setDetailsWidgetVisible( d->mDetailsVisible );
00783 }
00784
00785 bool KDialog::isDetailsWidgetVisible() const
00786 {
00787 return d_func()->mDetailsVisible;
00788 }
00789
00790 void KDialog::setDetailsWidgetVisible( bool visible )
00791 {
00792 Q_D(KDialog);
00793 if ( d->mDetailsButtonText.isEmpty() )
00794 d->mDetailsButtonText = i18n( "&Details" );
00795
00796 d->mSettingDetails = true;
00797 d->mDetailsVisible = visible;
00798 if ( d->mDetailsVisible ) {
00799 emit aboutToShowDetails();
00800 setButtonText( Details, d->mDetailsButtonText + " <<" );
00801 if ( d->mDetailsWidget ) {
00802 if ( layout() )
00803 layout()->setEnabled( false );
00804
00805 d->mDetailsWidget->show();
00806
00807 adjustSize();
00808
00809 if ( layout() ) {
00810 layout()->activate();
00811 layout()->setEnabled( true );
00812 }
00813 }
00814 } else {
00815 setButtonText( Details, d->mDetailsButtonText + " >>" );
00816 if ( d->mDetailsWidget )
00817 d->mDetailsWidget->hide();
00818
00819 if ( layout() )
00820 layout()->activate();
00821
00822 adjustSize();
00823 }
00824
00825 d->mSettingDetails = false;
00826 }
00827
00828 void KDialog::delayedDestruct()
00829 {
00830 if ( isVisible() )
00831 hide();
00832
00833 deleteLater();
00834 }
00835
00836
00837 void KDialog::slotButtonClicked( int button )
00838 {
00839 Q_D(KDialog);
00840 emit buttonClicked( static_cast<KDialog::ButtonCode>(button) );
00841
00842 switch( button ) {
00843 case Ok:
00844 emit okClicked();
00845 accept();
00846 break;
00847 case Apply:
00848 emit applyClicked();
00849 break;
00850 case Try:
00851 emit tryClicked();
00852 break;
00853 case User3:
00854 emit user3Clicked();
00855 break;
00856 case User2:
00857 emit user2Clicked();
00858 break;
00859 case User1:
00860 emit user1Clicked();
00861 break;
00862 case Yes:
00863 emit yesClicked();
00864 done( Yes );
00865 break;
00866 case No:
00867 emit noClicked();
00868 done( No );
00869 break;
00870 case Cancel:
00871 emit cancelClicked();
00872 reject();
00873 break;
00874 case Close:
00875 emit closeClicked();
00876 close();
00877 break;
00878 case Help:
00879 emit helpClicked();
00880 if ( !d->mAnchor.isEmpty() || !d->mHelpApp.isEmpty() )
00881 KToolInvocation::invokeHelp( d->mAnchor, d->mHelpApp );
00882 break;
00883 case Default:
00884 emit defaultClicked();
00885 break;
00886 case Reset:
00887 emit resetClicked();
00888 break;
00889 case Details:
00890 setDetailsWidgetVisible( !d->mDetailsVisible );
00891 break;
00892 }
00893 }
00894
00895 void KDialog::enableLinkedHelp( bool state )
00896 {
00897 Q_D(KDialog);
00898 if ( ( d->mUrlHelp != 0 ) == state )
00899 return;
00900 if ( state ) {
00901 if ( d->mUrlHelp )
00902 return;
00903
00904 d->mUrlHelp = new KUrlLabel( this );
00905 d->mUrlHelp->setText( helpLinkText() );
00906 d->mUrlHelp->setFloatEnabled( true );
00907 d->mUrlHelp->setUnderline( true );
00908 d->mUrlHelp->setMinimumHeight( fontMetrics().height() + marginHint() );
00909 connect( d->mUrlHelp, SIGNAL( leftClickedUrl( const QString& ) ),
00910 SLOT( helpClickedSlot( const QString& ) ) );
00911
00912 d->mUrlHelp->show();
00913 } else {
00914 delete d->mUrlHelp;
00915 d->mUrlHelp = 0;
00916 }
00917
00918 d->setupLayout();
00919 }
00920
00921
00922 void KDialog::setHelp( const QString &anchor, const QString &appname )
00923 {
00924 Q_D(KDialog);
00925 d->mAnchor = anchor;
00926 d->mHelpApp = appname;
00927 }
00928
00929
00930 void KDialog::setHelpLinkText( const QString &text )
00931 {
00932 Q_D(KDialog);
00933 d->mHelpLinkText = text;
00934 if ( d->mUrlHelp )
00935 d->mUrlHelp->setText( helpLinkText() );
00936 }
00937
00938 QString KDialog::helpLinkText() const
00939 {
00940 Q_D(const KDialog);
00941 return ( d->mHelpLinkText.isEmpty() ? i18n( "Get help..." ) : d->mHelpLinkText );
00942 }
00943
00944 void KDialog::updateGeometry()
00945 {
00946 Q_D(KDialog);
00947 if ( d->mTopLayout ) {
00948 d->mTopLayout->setMargin( marginHint() );
00949 d->mTopLayout->setSpacing( spacingHint() );
00950 }
00951 }
00952
00953 void KDialog::hideEvent( QHideEvent *event )
00954 {
00955 emit hidden();
00956
00957 if ( !event->spontaneous() )
00958 emit finished();
00959 }
00960
00961 void KDialog::closeEvent( QCloseEvent *event )
00962 {
00963 Q_D(KDialog);
00964 KPushButton *button = this->button( d->mEscapeButton );
00965 if ( button && !isHidden() )
00966 button->animateClick();
00967 else
00968 QDialog::closeEvent( event );
00969 }
00970
00971 void KDialog::restoreDialogSize( const KConfigGroup& cfg )
00972 {
00973 int width, height;
00974 int scnum = QApplication::desktop()->screenNumber( parentWidget() );
00975 QRect desk = QApplication::desktop()->screenGeometry( scnum );
00976
00977 width = sizeHint().width();
00978 height = sizeHint().height();
00979
00980 width = cfg.readEntry( QString::fromLatin1( "Width %1" ).arg( desk.width() ), width );
00981 height = cfg.readEntry( QString::fromLatin1( "Height %1" ).arg( desk.height() ), height );
00982
00983 resize( width, height );
00984 }
00985
00986 void KDialog::saveDialogSize( KConfigGroup& config, KConfigGroup::WriteConfigFlags options ) const
00987 {
00988 int scnum = QApplication::desktop()->screenNumber( parentWidget() );
00989 QRect desk = QApplication::desktop()->screenGeometry( scnum );
00990
00991 QSize sizeToSave = size();
00992
00993 config.writeEntry( QString::fromLatin1("Width %1").arg( desk.width() ), sizeToSave.width(), options );
00994 config.writeEntry( QString::fromLatin1("Height %1").arg( desk.height() ), sizeToSave.height(), options );
00995 }
00996
00997
00998 class KDialogQueue::Private
00999 {
01000 public:
01001 Private(KDialogQueue *q): q(q) {}
01002
01003 void slotShowQueuedDialog();
01004
01005 KDialogQueue *q;
01006 QList< QPointer<QDialog> > queue;
01007 bool busy;
01008
01009 };
01010
01011 KDialogQueue* KDialogQueue::self()
01012 {
01013 K_GLOBAL_STATIC(KDialogQueue, _self)
01014 return _self;
01015 }
01016
01017 KDialogQueue::KDialogQueue()
01018 : d( new Private(this) )
01019 {
01020 d->busy = false;
01021 }
01022
01023 KDialogQueue::~KDialogQueue()
01024 {
01025 delete d;
01026 }
01027
01028
01029 void KDialogQueue::queueDialog( QDialog *dialog )
01030 {
01031 KDialogQueue *_this = self();
01032 _this->d->queue.append( dialog );
01033
01034 QTimer::singleShot( 0, _this, SLOT( slotShowQueuedDialog() ) );
01035 }
01036
01037 void KDialogQueue::Private::slotShowQueuedDialog()
01038 {
01039 if ( busy )
01040 return;
01041
01042 QDialog *dialog;
01043 do {
01044 if ( queue.isEmpty() )
01045 return;
01046 dialog = queue.first();
01047 queue.pop_front();
01048 } while( !dialog );
01049
01050 busy = true;
01051 dialog->exec();
01052 busy = false;
01053 delete dialog;
01054
01055 if ( !queue.isEmpty() )
01056 QTimer::singleShot( 20, q, SLOT( slotShowQueuedDialog() ) );
01057 }
01058
01059 #include "kdialog.moc"
01060 #include "kdialogqueue_p.moc"