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