kdeui Library API Documentation

kdialogbase.cpp

00001 /*
00002  *  This file is part of the KDE Libraries
00003  *  Copyright (C) 1999-2001 Mirko Boehm (mirko@kde.org) and
00004  *  Espen Sand (espen@kde.org)
00005  *  Holger Freyther <freyther@kde.org>
00006  *
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Library General Public
00009  *  License as published by the Free Software Foundation; either
00010  *  version 2 of the License, or (at your option) any later version.
00011  *
00012  *  This library is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *  Library General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU Library General Public License
00018  *  along with this library; see the file COPYING.LIB.  If not, write to
00019  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  *  Boston, MA 02111-1307, USA.
00021  *
00022  */
00023 
00024 #include "kdialogbase.h"
00025 #include <stdlib.h>
00026 
00027 #include <qgrid.h>
00028 #include <qhbox.h>
00029 #include <qlayout.h>
00030 #include <qtooltip.h>
00031 #include <qvbox.h>
00032 #include <qwhatsthis.h>
00033 #include <qtimer.h>
00034 #include <qfocusdata.h>
00035 
00036 #include <kapplication.h>
00037 #include <klocale.h>
00038 #include <kconfig.h>
00039 #include <kiconloader.h>
00040 #include <kglobal.h>
00041 #include <kglobalsettings.h>
00042 #include <kseparator.h>
00043 #include <kurllabel.h>
00044 #include <kdebug.h>
00045 
00046 #include "kdialogbase_priv.h"
00047 #include "kdialogbase_priv.moc"
00048 
00049 KDialogBaseTile *KDialogBase::mTile = 0;
00050 
00051 int KDialogBaseButton::id()
00052 {
00053     return( mKey );
00054 }
00055 
00056 template class QPtrList<KDialogBaseButton>;
00057 
00061 namespace
00062 {
00063 struct SButton : public Qt
00064 {
00065   SButton()
00066   {
00067     box = 0;
00068     mask = 0;
00069     style = 0;
00070   }
00071 
00072   KPushButton *append( int key, const KGuiItem &item );
00073 
00074   void resize( bool sameWidth, int margin, int spacing, int orientation );
00075 
00076   KPushButton *button( int key );
00077 
00078   QWidget *box;
00079   int mask;
00080   int style;
00081   QPtrList<KDialogBaseButton> list;
00082 };
00083 }// namespace
00084 
00085 class KDialogBase::KDialogBasePrivate {
00086 public:
00087     KDialogBasePrivate() : bDetails(false), bFixed(false), bSettingDetails(false), detailsWidget(0) { }
00088 
00089     bool bDetails;
00090     bool bFixed;
00091     bool bSettingDetails;
00092     QWidget *detailsWidget;
00093     QSize incSize;
00094     QSize minSize;
00095     QString detailsButton;
00096     SButton mButton;
00097 };
00098 
00099 KDialogBase::KDialogBase( QWidget *parent, const char *name, bool modal,
00100               const QString &caption, int buttonMask,
00101               ButtonCode defaultButton, bool separator,
00102               const KGuiItem &user1, const KGuiItem &user2,
00103               const KGuiItem &user3 )
00104   :KDialog( parent, name, modal, WStyle_DialogBorder ),
00105    mTopLayout(0), mMainWidget(0), mUrlHelp(0), mJanus(0), mActionSep(0),
00106    mIsActivated(false), mShowTile(false), mMessageBoxMode(false),
00107    mButtonOrientation(Horizontal)
00108 {
00109   d = new KDialogBasePrivate;
00110   setCaption( caption );
00111 
00112   makeRelay();
00113   connect( this, SIGNAL(layoutHintChanged()), SLOT(updateGeometry()) );
00114 
00115   enableButtonSeparator( separator );
00116   makeButtonBox( buttonMask, defaultButton, user1, user2, user3 );
00117 
00118   mIsActivated = true;
00119   setupLayout();
00120 }
00121 
00122 KDialogBase::KDialogBase( int dialogFace, const QString &caption,
00123               int buttonMask, ButtonCode defaultButton,
00124               QWidget *parent, const char *name, bool modal,
00125               bool separator, const KGuiItem &user1,
00126               const KGuiItem &user2, const KGuiItem &user3 )
00127   :KDialog( parent, name, modal, WStyle_DialogBorder ),
00128    mTopLayout(0), mMainWidget(0), mUrlHelp(0), mJanus(0), mActionSep(0),
00129    mIsActivated(false), mShowTile(false), mMessageBoxMode(false),
00130    mButtonOrientation(Horizontal)
00131 {
00132   d = new KDialogBasePrivate;
00133   setCaption( caption );
00134 
00135   makeRelay();
00136   connect( this, SIGNAL(layoutHintChanged()), SLOT(updateGeometry()) );
00137 
00138   mJanus = new KJanusWidget( this, "janus", dialogFace );
00139   connect(mJanus, SIGNAL(aboutToShowPage(QWidget *)),
00140           this, SIGNAL(aboutToShowPage(QWidget *)));
00141 
00142   if( mJanus == 0 || mJanus->isValid() == false ) { return; }
00143 
00144   enableButtonSeparator( separator );
00145   makeButtonBox( buttonMask, defaultButton, user1, user2, user3 );
00146 
00147   mIsActivated = true;
00148   setupLayout();
00149 }
00150 
00151 KDialogBase::KDialogBase(  KDialogBase::DialogType dialogFace, WFlags f, QWidget *parent, const char *name,
00152                   bool modal,
00153               const QString &caption, int buttonMask,
00154               ButtonCode defaultButton, bool separator,
00155               const KGuiItem &user1, const KGuiItem &user2,
00156               const KGuiItem &user3 )
00157   :KDialog( parent, name, modal, f ),
00158    mTopLayout(0), mMainWidget(0), mUrlHelp(0), mJanus(0), mActionSep(0),
00159    mIsActivated(false), mShowTile(false), mMessageBoxMode(false),
00160    mButtonOrientation(Horizontal)
00161 {
00162   d = new KDialogBasePrivate;
00163   setCaption( caption );
00164 
00165   makeRelay();
00166   connect( this, SIGNAL(layoutHintChanged()), SLOT(updateGeometry()) );
00167 
00168   mJanus = new KJanusWidget( this, "janus", dialogFace );
00169   connect(mJanus, SIGNAL(aboutToShowPage(QWidget *)),
00170           this, SIGNAL(aboutToShowPage(QWidget *)));
00171 
00172   if( mJanus == 0 || mJanus->isValid() == false ) { return; }
00173 
00174   enableButtonSeparator( separator );
00175   makeButtonBox( buttonMask, defaultButton, user1, user2, user3 );
00176 
00177   mIsActivated = true;
00178   setupLayout();
00179 }
00180 
00181 KDialogBase::KDialogBase( const QString &caption, int buttonMask,
00182               ButtonCode defaultButton, ButtonCode escapeButton,
00183               QWidget *parent, const char *name, bool modal,
00184               bool separator, const KGuiItem &yes,
00185               const KGuiItem &no, const KGuiItem &cancel )
00186   :KDialog( parent, name, modal, WStyle_DialogBorder ),
00187    mTopLayout(0), mMainWidget(0), mUrlHelp(0), mJanus(0), mActionSep(0),
00188    mIsActivated(false), mShowTile(false), mMessageBoxMode(true),
00189    mButtonOrientation(Horizontal),mEscapeButton(escapeButton)
00190 {
00191   d = new KDialogBasePrivate;
00192 
00193   setCaption( caption );
00194 
00195   makeRelay();
00196   connect( this, SIGNAL(layoutHintChanged()), SLOT(updateGeometry()) );
00197 
00198   enableButtonSeparator( separator );
00199 
00200   buttonMask &= Details|Yes|No|Cancel;
00201 
00202   makeButtonBox( buttonMask, defaultButton,
00203                  no.text().isEmpty()  ? KStdGuiItem::no()  : no,
00204                  yes.text().isEmpty() ? KStdGuiItem::yes() : yes );
00205 
00206   setButtonCancel( cancel.text().isEmpty() ?
00207                        KStdGuiItem::cancel() : cancel );
00208 
00209   mIsActivated = true;
00210   setupLayout();
00211 }
00212 
00213 
00214 
00215 KDialogBase::~KDialogBase()
00216 {
00217   delete d;
00218 }
00219 
00220 KPushButton *SButton::append( int key, const KGuiItem &item )
00221 {
00222   KDialogBaseButton *p = new KDialogBaseButton( item, key, box );
00223   list.append( p );
00224   return( p );
00225 }
00226 
00227 void SButton::resize( bool sameWidth, int margin,
00228     int spacing, int orientation )
00229 {
00230   KDialogBaseButton *p;
00231   int h = 0;
00232   int w = 0;
00233   int t = 0;
00234 
00235   for( p = list.first(); p!=0; p =  list.next() )
00236   {
00237     const QSize s( p->sizeHint() );
00238     if( s.height() > h ) { h = s.height(); }
00239     if( s.width() > w ) { w = s.width(); }
00240   }
00241 
00242   if( orientation == Horizontal )
00243   {
00244     for( p = list.first(); p!=0; p =  list.next() )
00245     {
00246       QSize s( p->sizeHint() );
00247       if( sameWidth == true ) { s.setWidth( w ); }
00248       p->setFixedWidth( s.width() );
00249       t += s.width() + spacing;
00250     }
00251 
00252     box->setMinimumHeight( margin*2 + h );
00253     box->setMinimumWidth( margin*2 + t - spacing );
00254   }
00255   else
00256   {
00257     // sameWidth has no effect here
00258     for( p = list.first(); p!=0; p =  list.next() )
00259     {
00260       QSize s( p->sizeHint() );
00261       s.setWidth( w );
00262       p->setFixedSize( s );
00263       t += s.height() + spacing;
00264     }
00265     box->setMinimumHeight( margin*2 + t - spacing );
00266     box->setMinimumWidth( margin*2 + w );
00267   }
00268 }
00269 
00270 KPushButton *SButton::button( int key )
00271 {
00272   KDialogBaseButton *p;
00273   for( p = list.first(); p != 0; p = list.next() )
00274   {
00275     if( p->id() == key )
00276     {
00277       return( p );
00278     }
00279   }
00280   return( 0 );
00281 }
00282 
00283 void
00284 KDialogBase::delayedDestruct()
00285 {
00286    if (isVisible())
00287       hide();
00288    QTimer::singleShot( 0, this, SLOT(slotDelayedDestruct()));
00289 }
00290 
00291 void
00292 KDialogBase::slotDelayedDestruct()
00293 {
00294    delete this;
00295 }
00296 
00297 void KDialogBase::setupLayout()
00298 {
00299   if( mTopLayout != 0 )
00300   {
00301     delete mTopLayout;
00302   }
00303   // mTopLayout = new QVBoxLayout( this, marginHint(), spacingHint() );
00304 
00305 
00306   if( mButtonOrientation == Horizontal )
00307   {
00308     mTopLayout = new QBoxLayout( this, QBoxLayout::TopToBottom,
00309                  marginHint(), spacingHint() );
00310   }
00311   else
00312   {
00313     mTopLayout = new QBoxLayout( this, QBoxLayout::LeftToRight,
00314                  marginHint(), spacingHint() );
00315   }
00316 
00317   if( mUrlHelp != 0 )
00318   {
00319     mTopLayout->addWidget( mUrlHelp, 0, AlignRight );
00320   }
00321 
00322   if( mJanus != 0 )
00323   {
00324     mTopLayout->addWidget( mJanus, 10 );
00325   }
00326   else if( mMainWidget != 0 )
00327   {
00328     mTopLayout->addWidget( mMainWidget, 10 );
00329   }
00330 
00331   if ( d->detailsWidget )
00332   {
00333     mTopLayout->addWidget( d->detailsWidget );
00334   }
00335 
00336   if( mActionSep != 0 )
00337   {
00338     mTopLayout->addWidget( mActionSep );
00339   }
00340 
00341   if( d->mButton.box != 0 )
00342   {
00343     mTopLayout->addWidget( d->mButton.box );
00344   }
00345 }
00346 
00347 
00348 
00349 void KDialogBase::setButtonBoxOrientation( int orientation )
00350 {
00351   if( mButtonOrientation != orientation )
00352   {
00353     mButtonOrientation = orientation;
00354     if( mActionSep != 0 )
00355     {
00356       mActionSep->setOrientation( mButtonOrientation == Horizontal ?
00357                   QFrame::HLine : QFrame::VLine );
00358     }
00359     if( mButtonOrientation == Vertical )
00360     {
00361       enableLinkedHelp(false); // 2000-06-18 Espen: No support for this yet.
00362     }
00363     setupLayout();
00364     setButtonStyle( d->mButton.style );
00365   }
00366 }
00367 
00368 
00369 void KDialogBase::setEscapeButton( ButtonCode id )
00370 {
00371   mEscapeButton = id;
00372 }
00373 
00374 
00375 
00376 void KDialogBase::makeRelay()
00377 {
00378   if( mTile != 0 )
00379   {
00380     connect( mTile, SIGNAL(pixmapChanged()), SLOT(updateBackground()) );
00381     return;
00382   }
00383 
00384   mTile = new KDialogBaseTile;
00385   if( mTile != 0 )
00386   {
00387     connect( mTile, SIGNAL(pixmapChanged()), SLOT(updateBackground()) );
00388     connect( qApp, SIGNAL(aboutToQuit()), mTile, SLOT(cleanup()) );
00389   }
00390 }
00391 
00392 
00393 void KDialogBase::enableButtonSeparator( bool state )
00394 {
00395   if( state == true )
00396   {
00397     if( mActionSep != 0 )
00398     {
00399       return;
00400     }
00401     mActionSep = new KSeparator( this );
00402     mActionSep->setFocusPolicy(QWidget::NoFocus);
00403     mActionSep->setOrientation( mButtonOrientation == Horizontal ?
00404                 QFrame::HLine : QFrame::VLine );
00405     mActionSep->show();
00406   }
00407   else
00408   {
00409     if( mActionSep == 0 )
00410     {
00411       return;
00412     }
00413     delete mActionSep; mActionSep = 0;
00414   }
00415 
00416   if( mIsActivated == true )
00417   {
00418     setupLayout();
00419   }
00420 }
00421 
00422 
00423 
00424 QFrame *KDialogBase::plainPage()
00425 {
00426   return( mJanus == 0 ? 0 : mJanus->plainPage() );
00427 }
00428 
00429 
00430 
00431 void KDialogBase::adjustSize()
00432 {
00433 //  if (layout())
00434 //     layout()->activate();
00435   if( d->bFixed )
00436     setFixedSize( sizeHint() );
00437   else
00438     resize( sizeHint() );
00439 }
00440 
00441 QSize KDialogBase::sizeHint() const
00442 {
00443    return d->minSize.expandedTo( minimumSizeHint() ) + d->incSize;
00444 }
00445 
00446 QSize KDialogBase::minimumSizeHint() const
00447 {
00448   int m = marginHint();
00449   int s = spacingHint();
00450 
00451   QSize s1(0,0);
00452   QSize s2(0,0);
00453 
00454   //
00455   // Url help area
00456   //
00457   if( mUrlHelp != 0 )
00458   {
00459     s2 = mUrlHelp->minimumSize() + QSize( 0, s );
00460   }
00461   s1.rwidth()   = QMAX( s1.rwidth(), s2.rwidth() );
00462   s1.rheight() += s2.rheight();
00463 
00464   //
00465   // User widget
00466   //
00467   if( mJanus != 0 )
00468   {
00469     s2 = mJanus->minimumSizeHint() + QSize( 0, s );
00470   }
00471   else if( mMainWidget != 0 )
00472   {
00473     s2 = mMainWidget->sizeHint() + QSize( 0, s );
00474     s2 = s2.expandedTo( mMainWidget->minimumSize() );
00475     s2 = s2.expandedTo( mMainWidget->minimumSizeHint() );
00476     if( s2.isEmpty() == true )
00477     {
00478       s2 = QSize( 100, 100+s );
00479     }
00480   }
00481   else
00482   {
00483     s2 = QSize( 100, 100+s );
00484   }
00485   s1.rwidth()  = QMAX( s1.rwidth(), s2.rwidth() );
00486   s1.rheight() += s2.rheight();
00487 
00488   if (d->detailsWidget && d->bDetails)
00489   {
00490     s2 = d->detailsWidget->sizeHint() + QSize( 0, s );
00491     s2 = s2.expandedTo( d->detailsWidget->minimumSize() );
00492     s2 = s2.expandedTo( d->detailsWidget->minimumSizeHint() );
00493     s1.rwidth()  = QMAX( s1.rwidth(), s2.rwidth() );
00494     s1.rheight() += s2.rheight();
00495   }
00496 
00497   //
00498   // Button separator
00499   //
00500   if( mActionSep != 0 )
00501   {
00502     s1.rheight() += mActionSep->minimumSize().height() + s;
00503   }
00504 
00505   //
00506   // The button box
00507   //
00508   if( d->mButton.box != 0 )
00509   {
00510     s2 = d->mButton.box->minimumSize();
00511     if( mButtonOrientation == Horizontal )
00512     {
00513       s1.rwidth()   = QMAX( s1.rwidth(), s2.rwidth() );
00514       s1.rheight() += s2.rheight();
00515     }
00516     else
00517     {
00518       s1.rwidth() += s2.rwidth();
00519       s1.rheight() = QMAX( s1.rheight(), s2.rheight() );
00520     }
00521   }
00522 
00523   //
00524   // Outer margings
00525   //
00526   s1.rheight() += 2*m;
00527   s1.rwidth()  += 2*m;
00528 
00529   return s1;
00530 }
00531 
00532 
00533 void KDialogBase::disableResize()
00534 {
00535   setFixedSize( sizeHint() );
00536 }
00537 
00538 
00539 void KDialogBase::setInitialSize( const QSize &s, bool noResize )
00540 {
00541   d->minSize = s;
00542   d->bFixed = noResize;
00543   adjustSize();
00544 }
00545 
00546 
00547 void KDialogBase::incInitialSize( const QSize &s, bool noResize )
00548 {
00549   d->incSize = s;
00550   d->bFixed = noResize;
00551   adjustSize();
00552 }
00553 
00554 
00555 void KDialogBase::makeButtonBox( int buttonMask, ButtonCode defaultButton,
00556                  const KGuiItem &user1, const KGuiItem &user2,
00557                  const KGuiItem &user3 )
00558 {
00559   if( buttonMask == 0 )
00560   {
00561     d->mButton.box = 0;
00562     return; // When we want no button box
00563   }
00564 
00565   if( buttonMask & Cancel ) { buttonMask &= ~Close; }
00566   if( buttonMask & Apply ) { buttonMask &= ~Try; }
00567   if( buttonMask & Details ) { buttonMask &= ~Default; }
00568 
00569   if( mMessageBoxMode == false )
00570   {
00571     mEscapeButton = (buttonMask&Cancel) ? Cancel : Close;
00572   }
00573 
00574   d->mButton.box = new QWidget( this );
00575 
00576   d->mButton.mask = buttonMask;
00577   if( d->mButton.mask & Help )
00578   {
00579     KPushButton *pb = d->mButton.append( Help, KStdGuiItem::help() );
00580 
00581     connect( pb, SIGNAL(clicked()), SLOT(slotHelp()) );
00582   }
00583   if( d->mButton.mask & Default )
00584   {
00585     KPushButton *pb = d->mButton.append( Default, KStdGuiItem::defaults() );
00586 
00587     connect( pb, SIGNAL(clicked()), SLOT(slotDefault()) );
00588   }
00589   if( d->mButton.mask & Details )
00590   {
00591     KPushButton *pb = d->mButton.append( Details, QString::null );
00592     connect( pb, SIGNAL(clicked()), SLOT(slotDetails()) );
00593     setDetails(false);
00594   }
00595   if( d->mButton.mask & User3 )
00596   {
00597     KPushButton *pb = d->mButton.append( User3, user3 );
00598     connect( pb, SIGNAL(clicked()), SLOT(slotUser3()) );
00599   }
00600   if( d->mButton.mask & User2 )
00601   {
00602     KPushButton *pb = d->mButton.append( User2, user2 );
00603     if( mMessageBoxMode == true )
00604     {
00605       connect( pb, SIGNAL(clicked()), SLOT(slotYes()) );
00606     }
00607     else
00608     {
00609       connect( pb, SIGNAL(clicked()), this, SLOT(slotUser2()) );
00610     }
00611   }
00612   if( d->mButton.mask & User1 )
00613   {
00614     KPushButton *pb = d->mButton.append( User1, user1 );
00615     if( mMessageBoxMode == true )
00616     {
00617       connect( pb, SIGNAL(clicked()), this, SLOT(slotNo()) );
00618     }
00619     else
00620     {
00621       connect( pb, SIGNAL(clicked()), SLOT(slotUser1()) );
00622     }
00623   }
00624   if( d->mButton.mask & Ok )
00625   {
00626     KPushButton *pb = d->mButton.append( Ok, KStdGuiItem::ok() );
00627     connect( pb, SIGNAL(clicked()), SLOT(slotOk()) );
00628   }
00629   if( d->mButton.mask & Apply )
00630   {
00631     KPushButton *pb = d->mButton.append( Apply, KStdGuiItem::apply() );
00632     connect( pb, SIGNAL(clicked()), SLOT(slotApply()) );
00633     connect( pb, SIGNAL(clicked()), SLOT(applyPressed()) );
00634   }
00635   if( d->mButton.mask & Try )
00636   {
00637     KPushButton *pb = d->mButton.append( Try,
00638                            i18n( "&Try" ) );
00639     connect( pb, SIGNAL(clicked()), SLOT(slotTry()) );
00640   }
00641   if( d->mButton.mask & Cancel )
00642   {
00643     KPushButton *pb = d->mButton.append( Cancel, KStdGuiItem::cancel() );
00644     connect( pb, SIGNAL(clicked()), SLOT(slotCancel()) );
00645   }
00646   if( d->mButton.mask & Close )
00647   {
00648     KPushButton *pb = d->mButton.append( Close, KStdGuiItem::close() );
00649     connect( pb, SIGNAL(clicked()), SLOT(slotClose()) );
00650   }
00651 
00652   if( defaultButton != NoDefault )
00653   {
00654     QPushButton *pb = actionButton( defaultButton );
00655     if( pb != 0 )
00656     {
00657       setButtonFocus( pb, true, false );
00658     }
00659   }
00660 
00661   setButtonStyle( KGlobalSettings::buttonLayout() );
00662 }
00663 
00664 
00665 
00666 void KDialogBase::setButtonStyle( int style )
00667 {
00668   if( d->mButton.box == 0 )
00669   {
00670     return;
00671   }
00672 
00673   if( style < 0 || style > ActionStyleMAX ) { style = ActionStyle0; }
00674   d->mButton.style = style;
00675 
00676   const int *layout;
00677   int layoutMax = 0;
00678   if (mMessageBoxMode)
00679   {
00680     static const int layoutRule[5][6] =
00681     {
00682       {Details,Stretch,User2|Stretch,User1|Stretch,Cancel|Stretch, Details|Filler},
00683       {Details,Stretch,User2|Stretch,User1|Stretch,Cancel|Stretch, Details|Filler},
00684       {Details,Stretch,User2|Stretch,User1|Stretch,Cancel|Stretch, Details|Filler},
00685       {Details|Filler,Stretch,Cancel|Stretch,User2|Stretch,User1|Stretch,Details},
00686       {Details|Filler,Stretch,Cancel|Stretch,User2|Stretch,User1|Stretch,Details}
00687     };
00688     layoutMax = 6;
00689     layout = layoutRule[ d->mButton.style ];
00690   }
00691   else if (mButtonOrientation == Horizontal)
00692   {
00693     static const int layoutRule[5][10] =
00694     {
00695       {Details,Help,Default,Stretch,User3,User2,User1,Ok,Apply|Try,Cancel|Close},
00696       {Details,Help,Default,Stretch,User3,User2,User1,Cancel|Close,Apply|Try,Ok},
00697       {Details,Help,Default,Stretch,User3,User2,User1,Apply|Try,Cancel|Close,Ok},
00698       {Ok,Apply|Try,Cancel|Close,User3,User2,User1,Stretch,Default,Help,Details},
00699       {Ok,Cancel|Close,Apply|Try,User3,User2,User1,Stretch,Default,Help,Details}
00700     };
00701     layoutMax = 10;
00702     layout = layoutRule[ d->mButton.style ];
00703   }
00704   else
00705   {
00706     static const int layoutRule[5][10] =
00707     {
00708       {Ok,Apply|Try,User1,User2,User3,Stretch,Default,Cancel|Close,Help, Details},
00709       //{Ok,Apply|Try,Cancel|Close,User1,User2,User3,Stretch, Default,Help, Details},
00710       {Details,Help,Default,Stretch,User3,User2,User1,Cancel|Close,Apply|Try,Ok},
00711       {Details,Help,Default,Stretch,User3,User2,User1,Apply|Try,Cancel|Close,Ok},
00712       {Ok,Apply|Try,Cancel|Close,User3,User2,User1,Stretch,Default,Help,Details},
00713       {Ok,Cancel|Close,Apply|Try,User3,User2,User1,Stretch,Default,Help,Details}
00714     };
00715     layoutMax = 10;
00716     layout = layoutRule[ d->mButton.style ];
00717   }
00718 
00719   if( d->mButton.box->layout() )
00720   {
00721     delete d->mButton.box->layout();
00722   }
00723 
00724   QBoxLayout *lay;
00725   if( mButtonOrientation == Horizontal )
00726   {
00727     lay = new QBoxLayout( d->mButton.box, QBoxLayout::LeftToRight, 0,
00728               spacingHint());
00729   }
00730   else
00731   {
00732     lay = new QBoxLayout( d->mButton.box, QBoxLayout::TopToBottom, 0,
00733               spacingHint());
00734   }
00735 
00736   int numButton = 0;
00737   QPushButton *prevButton = 0;
00738   QPushButton *newButton;
00739 
00740   for( int i=0; i<layoutMax; i++ )
00741   {
00742     if(((ButtonCode) layout[i]) == Stretch) // Unconditional Stretch
00743     {
00744       lay->addStretch(1);
00745       continue;
00746     }
00747     else if (layout[i] & Filler) // Conditional space
00748     {
00749       if (d->mButton.mask & layout[i])
00750       {
00751         newButton = actionButton( (ButtonCode) (layout[i] & ~(Stretch | Filler)));
00752         if (newButton)
00753            lay->addSpacing(newButton->sizeHint().width());
00754       }
00755       continue;
00756     }
00757     else if( d->mButton.mask & Help & layout[i] )
00758     {
00759       newButton = actionButton( Help );
00760       lay->addWidget( newButton ); numButton++;
00761     }
00762     else if( d->mButton.mask & Default & layout[i] )
00763     {
00764       newButton = actionButton( Default );
00765       lay->addWidget( newButton ); numButton++;
00766     }
00767     else if( d->mButton.mask & User3 & layout[i] )
00768     {
00769       newButton = actionButton( User3 );
00770       lay->addWidget( newButton ); numButton++;
00771     }
00772     else if( d->mButton.mask & User2 & layout[i] )
00773     {
00774       newButton = actionButton( User2 );
00775       lay->addWidget( newButton ); numButton++;
00776     }
00777     else if( d->mButton.mask & User1 & layout[i] )
00778     {
00779       newButton = actionButton( User1 );
00780       lay->addWidget( newButton ); numButton++;
00781     }
00782     else if( d->mButton.mask & Ok & layout[i] )
00783     {
00784       newButton = actionButton( Ok );
00785       lay->addWidget( newButton ); numButton++;
00786     }
00787     else if( d->mButton.mask & Apply & layout[i] )
00788     {
00789       newButton = actionButton( Apply );
00790       lay->addWidget( newButton ); numButton++;
00791     }
00792     else if( d->mButton.mask & Try & layout[i] )
00793     {
00794       newButton = actionButton( Try );
00795       lay->addWidget( newButton ); numButton++;
00796     }
00797     else if( d->mButton.mask & Cancel & layout[i] )
00798     {
00799       newButton = actionButton( Cancel );
00800       lay->addWidget( newButton ); numButton++;
00801     }
00802     else if( d->mButton.mask & Close & layout[i] )
00803     {
00804       newButton = actionButton( Close );
00805       lay->addWidget( newButton ); numButton++;
00806     }
00807     else if( d->mButton.mask & Details & layout[i] )
00808     {
00809       newButton = actionButton( Details );
00810       lay->addWidget( newButton ); numButton++;
00811     }
00812     else
00813     {
00814       continue;
00815     }
00816 
00817     // Add conditional stretch (Only added if a button was added)
00818     if(layout[i] & Stretch)
00819     {
00820       lay->addStretch(1);
00821     }
00822 
00823     if( prevButton != 0 )
00824     {
00825       setTabOrder( prevButton, newButton );
00826     }
00827     prevButton = newButton;
00828   }
00829 
00830   d->mButton.resize( false, 0, spacingHint(), mButtonOrientation );
00831 }
00832 
00833 
00834 QPushButton *KDialogBase::actionButton( ButtonCode id )
00835 {
00836   return( d->mButton.button(id) );
00837 }
00838 
00839 
00840 void KDialogBase::enableButton( ButtonCode id, bool state )
00841 {
00842   QPushButton *pb = actionButton( id );
00843   if( pb != 0 )
00844   {
00845     pb->setEnabled( state );
00846   }
00847 }
00848 
00849 
00850 void KDialogBase::enableButtonOK( bool state )
00851 {
00852   enableButton( Ok, state );
00853 }
00854 
00855 
00856 void KDialogBase::enableButtonApply( bool state )
00857 {
00858   enableButton( Apply, state );
00859 }
00860 
00861 
00862 void KDialogBase::enableButtonCancel( bool state )
00863 {
00864   enableButton( Cancel, state );
00865 }
00866 
00867 
00868 void KDialogBase::showButton( ButtonCode id, bool state )
00869 {
00870   QPushButton *pb = actionButton( id );
00871   if( pb != 0 )
00872   {
00873     state ? pb->show() : pb->hide();
00874   }
00875 }
00876 
00877 
00878 void KDialogBase::showButtonOK( bool state )
00879 {
00880   showButton( Ok, state );
00881 }
00882 
00883 
00884 void KDialogBase::showButtonApply( bool state )
00885 {
00886   showButton( Apply, state );
00887 }
00888 
00889 
00890 void KDialogBase::showButtonCancel( bool state )
00891 {
00892   showButton( Cancel, state );
00893 }
00894 
00895 
00896 void KDialogBase::setButtonOKText( const QString &text,
00897                    const QString &tooltip,
00898                    const QString &quickhelp )
00899 {
00900   QPushButton *pb = actionButton( Ok );
00901   if( pb == 0 )
00902   {
00903     return;
00904   }
00905 
00906   const QString whatsThis = i18n( ""
00907     "If you press the <b>OK</b> button, all changes\n"
00908     "you made will be used to proceed.");
00909 
00910   pb->setText( text.isEmpty() ? i18n("&OK") : text );
00911   d->mButton.resize( false, 0, spacingHint(), mButtonOrientation );
00912 
00913   QToolTip::add( pb, tooltip.isEmpty() ? i18n("Accept settings") : tooltip );
00914   QWhatsThis::add( pb, quickhelp.isEmpty() ? whatsThis : quickhelp );
00915 }
00916 
00917 
00918 void KDialogBase::setButtonOK( const KGuiItem &item /* = KStdGuiItem::ok() */ )
00919 {
00920   setButtonGuiItem( Ok, item );
00921 }
00922 
00923 
00924 void KDialogBase::setButtonApplyText( const QString &text,
00925                       const QString &tooltip,
00926                       const QString &quickhelp )
00927 {
00928   QPushButton *pb = actionButton( Apply );
00929   if( pb == 0 )
00930   {
00931     return;
00932   }
00933 
00934   const QString whatsThis = i18n( ""
00935     "When clicking <b>Apply</b>, the settings will be\n"
00936     "handed over to the program, but the dialog\n"
00937     "will not be closed. "
00938     "Use this to try different settings. ");
00939 
00940   pb->setText( text.isEmpty() ? i18n("&Apply") : text );
00941   d->mButton.resize( false, 0, spacingHint(), mButtonOrientation );
00942 
00943   QToolTip::add( pb, tooltip.isEmpty() ? i18n("Apply settings") : tooltip );
00944   QWhatsThis::add( pb, quickhelp.isEmpty() ? whatsThis : quickhelp );
00945 }
00946 
00947 
00948 void KDialogBase::setButtonApply( const KGuiItem &item /* = KStdGuiItem::apply() */ )
00949 {
00950   setButtonGuiItem( Apply, item );
00951 }
00952 
00953 
00954 void KDialogBase::setButtonCancelText( const QString& text,
00955                        const QString& tooltip,
00956                        const QString& quickhelp )
00957 {
00958   QPushButton *pb = actionButton( Cancel );
00959   if( pb == 0 )
00960   {
00961     return;
00962   }
00963 
00964   pb->setText( text.isEmpty() ? i18n("&Cancel") : text );
00965   d->mButton.resize( false, 0, spacingHint(), mButtonOrientation );
00966 
00967   QToolTip::add( pb, tooltip );
00968   QWhatsThis::add( pb, quickhelp );
00969 }
00970 
00971 
00972 void KDialogBase::setButtonCancel( const KGuiItem &item /* = KStdGuiItem::cancel() */ )
00973 {
00974   setButtonGuiItem( Cancel, item );
00975 }
00976 
00977 void KDialogBase::setButtonGuiItem( ButtonCode id, const KGuiItem &item )
00978 {
00979   KPushButton *pb = static_cast<KPushButton *>( actionButton( id ) );
00980   if( pb == 0 )
00981     return;
00982 
00983   pb->setGuiItem( item );
00984   d->mButton.resize( false, 0, spacingHint(), mButtonOrientation );
00985 }
00986 
00987 
00988 void KDialogBase::setButtonText( ButtonCode id, const QString &text )
00989 {
00990   if (!d->bSettingDetails && (id == Details))
00991   {
00992     d->detailsButton = text;
00993     setDetails(d->bDetails);
00994     return;
00995   }
00996   QPushButton *pb = actionButton( id );
00997   if( pb != 0 )
00998   {
00999     pb->setText( text );
01000     d->mButton.resize( false, 0, spacingHint(), mButtonOrientation );
01001   }
01002 }
01003 
01004 
01005 void KDialogBase::setButtonTip( ButtonCode id, const QString &text )
01006 {
01007   QPushButton *pb = actionButton( id );
01008   if( pb != 0 )
01009   {
01010     if (text.isEmpty())
01011       QToolTip::remove( pb );
01012     else
01013       QToolTip::add( pb, text );
01014   }
01015 }
01016 
01017 
01018 void KDialogBase::setButtonWhatsThis( ButtonCode id, const QString &text )
01019 {
01020   QPushButton *pb = actionButton( id );
01021   if( pb != 0 )
01022   {
01023     if (text.isEmpty())
01024       QWhatsThis::remove( pb );
01025     else
01026       QWhatsThis::add( pb, text );
01027   }
01028 }
01029 
01030 
01031 void KDialogBase::setButtonFocus( QPushButton *p,bool isDefault, bool isFocus )
01032 {
01033   p->setDefault( isDefault );
01034   if( isFocus )
01035       p->setFocus();
01036 }
01037 
01038 
01039 void KDialogBase::setTreeListAutoResize( bool state )
01040 {
01041   if( mJanus != 0 )
01042   {
01043     mJanus->setTreeListAutoResize( state );
01044   }
01045 }
01046 
01047 void KDialogBase::setShowIconsInTreeList(bool state)
01048 {
01049   if( mJanus != 0 )
01050   {
01051     mJanus->setShowIconsInTreeList( state );
01052   }
01053 }
01054 
01055 void KDialogBase::setRootIsDecorated( bool state )
01056 {
01057   if( mJanus != 0 )
01058   {
01059     mJanus->setRootIsDecorated( state );
01060   }
01061 }
01062 
01063 void KDialogBase::unfoldTreeList( bool persist )
01064 {
01065   if( mJanus != 0 )
01066     mJanus->unfoldTreeList( persist );
01067 }
01068 
01069 void KDialogBase::addWidgetBelowList( QWidget * widget )
01070 {
01071   if( mJanus != 0 )
01072     mJanus->addWidgetBelowList( widget );
01073 }
01074 
01075 void KDialogBase::addButtonBelowList( const QString & text, QObject * recv, const char * slot )
01076 {
01077   if( mJanus != 0 )
01078     mJanus->addButtonBelowList( text, recv, slot );
01079 }
01080 
01081 void KDialogBase::addButtonBelowList( const KGuiItem & item, QObject * recv, const char * slot )
01082 {
01083   if( mJanus != 0 )
01084     mJanus->addButtonBelowList( item, recv, slot );
01085 }
01086 
01087 void KDialogBase::setIconListAllVisible( bool state )
01088 {
01089   if( mJanus != 0 )
01090   {
01091     mJanus->setIconListAllVisible( state );
01092   }
01093 }
01094 
01095 
01096 void KDialogBase::slotHelp()
01097 {
01098   emit helpClicked();
01099   if ( kapp ) // may be null when used inside designer
01100       kapp->invokeHelp( mAnchor, mHelpApp );
01101 }
01102 
01103 
01104 void KDialogBase::slotDefault()
01105 {
01106   emit defaultClicked();
01107 }
01108 
01109 void KDialogBase::slotDetails()
01110 {
01111   setDetails(!d->bDetails);
01112 }
01113 
01114 void KDialogBase::setDetailsWidget(QWidget *detailsWidget)
01115 {
01116   delete d->detailsWidget;
01117   d->detailsWidget = detailsWidget;
01118   if (d->detailsWidget->parentWidget() != this)
01119      d->detailsWidget->reparent(this, QPoint(0,0));
01120   d->detailsWidget->hide();
01121   if( mIsActivated == true )
01122   {
01123     setupLayout();
01124   }
01125   if (!d->bSettingDetails)
01126     setDetails(d->bDetails);
01127 }
01128 
01129 void KDialogBase::setDetails(bool showDetails)
01130 {
01131   if (d->detailsButton.isEmpty())
01132      d->detailsButton = i18n("&Details");
01133   d->bSettingDetails = true;
01134   d->bDetails = showDetails;
01135   if (d->bDetails)
01136   {
01137      emit aboutToShowDetails();
01138      setButtonText(Details, d->detailsButton+ " <<");
01139      if (d->detailsWidget)
01140      {
01141         if (layout())
01142            layout()->setEnabled(false);
01143         adjustSize();
01144         d->detailsWidget->show();
01145         if (layout())
01146         {
01147            layout()->activate();
01148            layout()->setEnabled(true);
01149         }
01150      }
01151   }
01152   else
01153   {
01154      setButtonText(Details, d->detailsButton+" >>");
01155      if (d->detailsWidget)
01156      {
01157         d->detailsWidget->hide();
01158      }
01159      if (layout())
01160         layout()->activate();
01161      adjustSize();
01162   }
01163   d->bSettingDetails = false;
01164 }
01165 
01166 void KDialogBase::slotOk()
01167 {
01168   emit okClicked();
01169   accept();
01170 }
01171 
01172 
01173 void KDialogBase::slotApply()
01174 {
01175   emit applyClicked();
01176 }
01177 
01178 
01179 void KDialogBase::slotTry()
01180 {
01181   emit tryClicked();
01182 }
01183 
01184 
01185 void KDialogBase::slotUser3()
01186 {
01187   emit user3Clicked();
01188 }
01189 
01190 
01191 void KDialogBase::slotUser2()
01192 {
01193   emit user2Clicked();
01194 }
01195 
01196 
01197 void KDialogBase::slotUser1()
01198 {
01199   emit user1Clicked();
01200 }
01201 
01202 
01203 void KDialogBase::slotYes()
01204 {
01205   emit yesClicked();
01206   done( Yes );
01207 }
01208 
01209 
01210 void KDialogBase::slotNo()
01211 {
01212   emit noClicked();
01213   done( No );
01214 }
01215 
01216 
01217 void KDialogBase::slotCancel()
01218 {
01219   emit cancelClicked();
01220   done( mMessageBoxMode == true ? (int)Cancel : (int)Rejected );
01221 }
01222 
01223 
01224 void KDialogBase::slotClose()
01225 {
01226   emit closeClicked();
01227   reject();
01228 }
01229 
01230 
01231 void KDialogBase::helpClickedSlot( const QString & )
01232 {
01233   slotHelp();
01234 }
01235 
01236 
01237 void KDialogBase::applyPressed()
01238 {
01239   emit apply();
01240 }
01241 
01242 
01243 void KDialogBase::enableLinkedHelp( bool state )
01244 {
01245   if( state == true )
01246   {
01247     if( mUrlHelp != 0 )
01248     {
01249       return;
01250     }
01251 
01252     mUrlHelp = new KURLLabel( this, "url" );
01253     mUrlHelp->setText( helpLinkText() );
01254     mUrlHelp->setFloat(true);
01255     mUrlHelp->setUnderline(true);
01256     if( mShowTile == true && mTile->get() != 0 )
01257     {
01258       mUrlHelp->setBackgroundPixmap(*mTile->get());
01259     }
01260     mUrlHelp->setMinimumHeight( fontMetrics().height() + marginHint() );
01261     connect(mUrlHelp,SIGNAL(leftClickedURL(const QString &)),
01262         SLOT(helpClickedSlot(const QString &)));
01263     mUrlHelp->show();
01264   }
01265   else
01266   {
01267     if( mUrlHelp == 0 )
01268     {
01269       return;
01270     }
01271     delete mUrlHelp; mUrlHelp = 0;
01272   }
01273 
01274   if( mIsActivated == true )
01275   {
01276     setupLayout();
01277   }
01278 }
01279 
01280 
01281 void KDialogBase::setHelp( const QString &anchor, const QString &appname )
01282 {
01283   mAnchor  = anchor;
01284   mHelpApp = appname;
01285 }
01286 
01287 
01288 void KDialogBase::setHelpLinkText( const QString &text )
01289 {
01290   mHelpLinkText = text;
01291   if( mUrlHelp != 0 )
01292   {
01293     mUrlHelp->setText( helpLinkText() );
01294   }
01295 }
01296 
01297 
01298 QFrame *KDialogBase::addPage( const QString &itemName, const QString &header,
01299                   const QPixmap &pixmap )
01300 {
01301   return( mJanus == 0 ? 0 : mJanus->addPage( itemName, header, pixmap ) );
01302 }
01303 
01304 QFrame *KDialogBase::addPage( const QStringList &items, const QString &header,
01305                   const QPixmap &pixmap )
01306 {
01307   return( mJanus == 0 ? 0 : mJanus->addPage( items, header, pixmap ) );
01308 }
01309 
01310 
01311 QVBox *KDialogBase::addVBoxPage( const QString &itemName,
01312                  const QString &header, const QPixmap &pixmap )
01313 {
01314   return( mJanus == 0 ? 0 : mJanus->addVBoxPage( itemName, header, pixmap) );
01315 }
01316 
01317 QVBox *KDialogBase::addVBoxPage( const QStringList &items,
01318                  const QString &header, const QPixmap &pixmap )
01319 {
01320   return( mJanus == 0 ? 0 : mJanus->addVBoxPage( items, header, pixmap) );
01321 }
01322 
01323 
01324 QHBox *KDialogBase::addHBoxPage( const QString &itemName,
01325                  const QString &header,
01326                  const QPixmap &pixmap )
01327 {
01328   return( mJanus == 0 ? 0 : mJanus->addHBoxPage( itemName, header, pixmap ) );
01329 }
01330 
01331 QHBox *KDialogBase::addHBoxPage( const QStringList &items,
01332                  const QString &header,
01333                  const QPixmap &pixmap )
01334 {
01335   return( mJanus == 0 ? 0 : mJanus->addHBoxPage( items, header, pixmap ) );
01336 }
01337 
01338 
01339 QGrid *KDialogBase::addGridPage( int n, Orientation dir,
01340                  const QString &itemName,
01341                  const QString &header, const QPixmap &pixmap )
01342 {
01343   return( mJanus == 0 ? 0 : mJanus->addGridPage( n, dir, itemName, header,
01344                          pixmap) );
01345 }
01346 
01347 QGrid *KDialogBase::addGridPage( int n, Orientation dir,
01348                  const QStringList &items,
01349                  const QString &header, const QPixmap &pixmap )
01350 {
01351   return( mJanus == 0 ? 0 : mJanus->addGridPage( n, dir, items, header,
01352                          pixmap) );
01353 }
01354 
01355 void KDialogBase::setFolderIcon(const QStringList &path, const QPixmap &pixmap)
01356 {
01357   if (mJanus == 0)
01358     return;
01359 
01360   mJanus->setFolderIcon(path,pixmap);
01361 }
01362 
01363 QFrame *KDialogBase::makeMainWidget()
01364 {
01365   if( mJanus != 0 || mMainWidget != 0 )
01366   {
01367     printMakeMainWidgetError();
01368     return( 0 );
01369   }
01370 
01371   QFrame *mainWidget = new QFrame( this );
01372   setMainWidget( mainWidget );
01373   return( mainWidget );
01374 }
01375 
01376 
01377 QVBox *KDialogBase::makeVBoxMainWidget()
01378 {
01379   if( mJanus != 0 || mMainWidget != 0 )
01380   {
01381     printMakeMainWidgetError();
01382     return( 0 );
01383   }
01384 
01385   QVBox *mainWidget = new QVBox( this );
01386   mainWidget->setSpacing( spacingHint() );
01387   setMainWidget( mainWidget );
01388   return( mainWidget );
01389 }
01390 
01391 
01392 QHBox *KDialogBase::makeHBoxMainWidget()
01393 {
01394   if( mJanus != 0 || mMainWidget != 0 )
01395   {
01396     printMakeMainWidgetError();
01397     return( 0 );
01398   }
01399 
01400   QHBox *mainWidget = new QHBox( this );
01401   mainWidget->setSpacing( spacingHint() );
01402   setMainWidget( mainWidget );
01403   return( mainWidget );
01404 }
01405 
01406 
01407 QGrid *KDialogBase::makeGridMainWidget( int n, Orientation dir )
01408 {
01409   if( mJanus != 0 || mMainWidget != 0 )
01410   {
01411     printMakeMainWidgetError();
01412     return( 0 );
01413   }
01414 
01415   QGrid *mainWidget = new QGrid( n, dir, this );
01416   mainWidget->setSpacing( spacingHint() );
01417   setMainWidget( mainWidget );
01418   return( mainWidget );
01419 }
01420 
01421 
01422 void KDialogBase::printMakeMainWidgetError()
01423 {
01424   if( mJanus != 0 )
01425   {
01426     kdDebug() << "makeMainWidget: Illegal mode (wrong constructor)" << endl;
01427   }
01428   else if( mMainWidget != 0 )
01429   {
01430     kdDebug() << "makeMainWidget: Main widget already defined" << endl;
01431   }
01432 }
01433 
01434 
01435 void KDialogBase::setMainWidget( QWidget *widget )
01436 {
01437   if( mJanus != 0 )
01438   {
01439     if( mJanus->setSwallowedWidget(widget) == true )
01440     {
01441       mMainWidget = widget;
01442     }
01443   }
01444   else
01445   {
01446     mMainWidget = widget;
01447     if( mIsActivated == true )
01448     {
01449       setupLayout();
01450     }
01451   }
01452   if( mMainWidget != NULL )
01453   {
01454     QFocusData* fd = focusData();
01455     QWidget* prev = fd->last();
01456     for( QPtrListIterator<KDialogBaseButton> it( d->mButton.list );
01457      it != NULL;
01458      ++it )
01459     {
01460       if( prev != *it )
01461     setTabOrder( prev, *it );
01462       prev = *it;
01463     }
01464   }
01465 }
01466 
01467 
01468 QWidget *KDialogBase::mainWidget()
01469 {
01470   return( mMainWidget );
01471 }
01472 
01473 
01474 bool KDialogBase::showPage( int index )
01475 {
01476   return( mJanus == 0 ? false : mJanus->showPage(index) );
01477 }
01478 
01479 
01480 int KDialogBase::activePageIndex() const
01481 {
01482   return( mJanus == 0 ? -1 : mJanus->activePageIndex() );
01483 }
01484 
01485 
01486 int KDialogBase::pageIndex( QWidget *widget ) const
01487 {
01488   return( mJanus == 0 ? -1 : mJanus->pageIndex( widget) );
01489 }
01490 
01491 
01492 // Deprecated
01493 QRect KDialogBase::getContentsRect() const
01494 {
01495   QRect r;
01496   r.setLeft( marginHint() );
01497   r.setTop( marginHint() + (mUrlHelp != 0 ? mUrlHelp->height() : 0) );
01498   r.setRight( width() - marginHint() );
01499   int h = (mActionSep==0?0:mActionSep->minimumSize().height()+marginHint());
01500   if( d->mButton.box != 0 )
01501   {
01502     r.setBottom( height() - d->mButton.box->minimumSize().height() - h );
01503   }
01504   else
01505   {
01506     r.setBottom( height() - h );
01507   }
01508 
01509   return(r);
01510 }
01511 
01512 
01513 // Deprecated
01514 void KDialogBase::getBorderWidths(int& ulx, int& uly, int& lrx, int& lry) const
01515 {
01516   ulx = marginHint();
01517   uly = marginHint();
01518   if( mUrlHelp != 0  )
01519   {
01520     uly += mUrlHelp->minimumSize().height();
01521   }
01522 
01523   lrx = marginHint();
01524   lry = d->mButton.box != 0 ? d->mButton.box->minimumSize().height() : 0;
01525   if( mActionSep != 0 )
01526   {
01527     lry += mActionSep->minimumSize().height() + marginHint();
01528   }
01529 }
01530 
01531 
01532 QSize KDialogBase::calculateSize(int w, int h) const
01533 {
01534   int ulx, uly, lrx, lry;
01535   getBorderWidths(ulx, uly, lrx, lry);
01536   return( QSize(ulx+w+lrx,uly+h+lry) );
01537 }
01538 
01539 
01540 QString KDialogBase::helpLinkText() const
01541 {
01542   return( mHelpLinkText.isNull() ? i18n("Get help...") : mHelpLinkText );
01543 }
01544 
01545 
01546 void KDialogBase::updateGeometry()
01547 {
01548   if( mTopLayout != 0 )
01549   {
01550     mTopLayout->setMargin( marginHint() );
01551     mTopLayout->setSpacing(spacingHint() );
01552   }
01553 }
01554 
01555 
01556 
01557 void KDialogBase::keyPressEvent( QKeyEvent *e )
01558 {
01559   //
01560   // Reimplemented from KDialog to remove the default behavior
01561   // and to add F1 (help) sensitivity and some animation.
01562   //
01563   if( e->state() == 0 )
01564   {
01565     if( e->key() == Key_F1 )
01566     {
01567       QPushButton *pb = actionButton( Help );
01568       if( pb != 0 )
01569       {
01570     pb->animateClick();
01571     e->accept();
01572     return;
01573       }
01574     }
01575     if( e->key() == Key_Escape )
01576     {
01577       QPushButton *pb = actionButton( mEscapeButton );
01578       if( pb != 0 )
01579       {
01580     pb->animateClick();
01581     e->accept();
01582     return;
01583       }
01584 
01585     }
01586   }
01587   else if( e->key() == Key_F1 && e->state() == ShiftButton )
01588   {
01589     QWhatsThis::enterWhatsThisMode();
01590     e->accept();
01591     return;
01592   }
01593 
01594   // accept the dialog when Ctrl-Return is pressed
01595   else if ( e->state() == ControlButton &&
01596             (e->key() == Key_Return || e->key() == Key_Enter) )
01597   {
01598     QPushButton *pb = actionButton( Ok );
01599     if ( pb )
01600     {
01601       pb->animateClick();
01602       e->accept();
01603       return;
01604     }
01605   }
01606 
01607   //
01608   // Do the default action instead. Note KDialog::keyPressEvent is bypassed
01609   //
01610   QDialog::keyPressEvent(e);
01611 }
01612 
01613 
01614 
01615 void KDialogBase::hideEvent( QHideEvent *ev )
01616 {
01617   emit hidden();
01618   if (!ev->spontaneous())
01619   {
01620      emit finished();
01621   }
01622 }
01623 
01624 
01625 
01626 void KDialogBase::closeEvent( QCloseEvent *e )
01627 {
01628     QPushButton *pb = actionButton( mEscapeButton );
01629     if( pb != 0 && isShown() ) {
01630     pb->animateClick();
01631     } else {
01632     QDialog::closeEvent( e );
01633     }
01634 }
01635 
01636 void KDialogBase::cancel()
01637 {
01638     switch ( mEscapeButton ) {
01639     case Ok:
01640         slotOk();
01641         break;
01642     case User1: // == No
01643         if ( mMessageBoxMode )
01644             slotNo();
01645         else
01646             slotUser1();
01647         break;
01648     case User2: // == Yes
01649         if ( mMessageBoxMode )
01650             slotYes();
01651         else
01652             slotUser2();
01653         break;
01654     case User3:
01655         slotUser3();
01656         break;
01657     case Close:
01658         slotClose();
01659         break;
01660     case Cancel:
01661     default:
01662     slotCancel();
01663     }
01664 }
01665 
01666 bool KDialogBase::haveBackgroundTile()
01667 {
01668   return( mTile == 0 || mTile->get() == 0 ? false : true );
01669 }
01670 
01671 // Deprecated. For compatibility only.
01672 const QPixmap *KDialogBase::getBackgroundTile() { return backgroundTile(); }
01673 
01674 const QPixmap *KDialogBase::backgroundTile()
01675 {
01676   return( mTile == 0 ? 0 : mTile->get() );
01677 }
01678 
01679 
01680 void KDialogBase::setBackgroundTile( const QPixmap *pix )
01681 {
01682   if( mTile != 0 )
01683   {
01684     mTile->set( pix );
01685   }
01686 }
01687 
01688 
01689 void KDialogBase::updateBackground()
01690 {
01691   if( mTile == 0 || mTile->get() == 0 )
01692   {
01693     QPixmap nullPixmap;
01694     setBackgroundPixmap(nullPixmap);
01695     if( d->mButton.box != 0 )
01696     {
01697       d->mButton.box->setBackgroundPixmap(nullPixmap);
01698       d->mButton.box->setBackgroundMode(PaletteBackground);
01699     }
01700     setBackgroundMode(PaletteBackground);
01701   }
01702   else
01703   {
01704     const QPixmap *pix = mTile->get();
01705     setBackgroundPixmap(*pix);
01706     if( d->mButton.box != 0 )
01707     {
01708       d->mButton.box->setBackgroundPixmap(*pix);
01709     }
01710     showTile( mShowTile );
01711   }
01712 }
01713 
01714 
01715 void KDialogBase::showTile( bool state )
01716 {
01717   mShowTile = state;
01718   if( mShowTile == false || mTile == 0 || mTile->get() == 0 )
01719   {
01720     setBackgroundMode(PaletteBackground);
01721     if( d->mButton.box != 0 )
01722     {
01723       d->mButton.box->setBackgroundMode(PaletteBackground);
01724     }
01725     if( mUrlHelp != 0 )
01726     {
01727       mUrlHelp->setBackgroundMode(PaletteBackground);
01728     }
01729   }
01730   else
01731   {
01732     const QPixmap *pix = mTile->get();
01733     setBackgroundPixmap(*pix);
01734     if( d->mButton.box != 0 )
01735     {
01736       d->mButton.box->setBackgroundPixmap(*pix);
01737     }
01738     if( mUrlHelp != 0 )
01739     {
01740       mUrlHelp->setBackgroundPixmap(*pix);
01741     }
01742   }
01743 }
01744 
01745 QSize KDialogBase::configDialogSize( const QString& groupName ) const
01746 {
01747    return configDialogSize( *KGlobal::config(), groupName );
01748 }
01749 
01750 
01751 QSize KDialogBase::configDialogSize( KConfig& config,
01752                       const QString& groupName ) const
01753 {
01754    int w, h;
01755    int scnum = QApplication::desktop()->screenNumber(parentWidget());
01756    QRect desk = QApplication::desktop()->screenGeometry(scnum);
01757 
01758    w = sizeHint().width();
01759    h = sizeHint().height();
01760 
01761    KConfigGroupSaver cs(&config, groupName);
01762    w = config.readNumEntry( QString::fromLatin1("Width %1").arg( desk.width()), w );
01763    h = config.readNumEntry( QString::fromLatin1("Height %1").arg( desk.height()), h );
01764 
01765    return( QSize( w, h ) );
01766 }
01767 
01768 
01769 void KDialogBase::saveDialogSize( const QString& groupName, bool global )
01770 {
01771    saveDialogSize( *KGlobal::config(), groupName, global );
01772 }
01773 
01774 
01775 void KDialogBase::saveDialogSize( KConfig& config, const QString& groupName,
01776                       bool global ) const
01777 {
01778    int scnum = QApplication::desktop()->screenNumber(parentWidget());
01779    QRect desk = QApplication::desktop()->screenGeometry(scnum);
01780 
01781    KConfigGroupSaver cs(&config, groupName);
01782    QSize sizeToSave = size();
01783 
01784    config.writeEntry( QString::fromLatin1("Width %1").arg( desk.width()),
01785               QString::number( sizeToSave.width()), true, global);
01786    config.writeEntry( QString::fromLatin1("Height %1").arg( desk.height()),
01787               QString::number( sizeToSave.height()), true, global);
01788 }
01789 
01790 
01791 KDialogBaseButton::KDialogBaseButton( const KGuiItem &item, int key,
01792                       QWidget *parent,  const char *name )
01793   : KPushButton( item, parent, name )
01794 {
01795   mKey = key;
01796 }
01797 
01798 
01799 
01800 
01801 KDialogBaseTile::KDialogBaseTile( QObject *parent, const char *name )
01802   : QObject( parent, name )
01803 {
01804   mPixmap = 0;
01805 }
01806 
01807 
01808 KDialogBaseTile::~KDialogBaseTile()
01809 {
01810   cleanup();
01811 }
01812 
01813 
01814 void KDialogBaseTile::set( const QPixmap *pix )
01815 {
01816   if( pix == 0 )
01817   {
01818     cleanup();
01819   }
01820   else
01821   {
01822     if( mPixmap == 0 )
01823     {
01824       mPixmap = new QPixmap(*pix);
01825     }
01826     else
01827     {
01828       *mPixmap = *pix;
01829     }
01830   }
01831 
01832   emit pixmapChanged();
01833 }
01834 
01835 
01836 const QPixmap *KDialogBaseTile::get() const
01837 {
01838   return( mPixmap );
01839 }
01840 
01841 
01842 void KDialogBaseTile::cleanup()
01843 {
01844   delete mPixmap; mPixmap = 0;
01845 }
01846 
01847 void KDialogBase::virtual_hook( int id, void* data )
01848 { KDialog::virtual_hook( id, data ); }
01849 
01850 #include "kdialogbase.moc"
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 23 17:11:53 2004 by doxygen 1.3.8-20040913 written by Dimitri van Heesch, © 1997-2003