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