Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

kdialogbase.cpp

Go to the documentation of this file.
00001 #include <qtabwidget.h>
00002 #include <qpushbutton.h>
00003 #include <qlayout.h>
00004 #include <qframe.h>
00005 
00006 #include "klocale.h"
00007 #include "kdebug.h"
00008 
00009 #include "kdialogbase.h"
00010 
00011 KDialogBase::KDialogBase()
00012 {
00013 }
00014 
00015 KDialogBase::KDialogBase( QWidget *parent, const char *name, bool modal,
00016              const QString &caption,
00017              int buttonMask, ButtonCode defaultButton,
00018              bool separator, 
00019              const QString &user1,
00020              const QString &user2,
00021              const QString &user3) :
00022     KDialog( parent, name, modal )
00023 {
00024   init( caption, buttonMask, user1 );
00025 }
00026 
00027 KDialogBase::KDialogBase( int dialogFace, const QString &caption, 
00028              int buttonMask, ButtonCode defaultButton, 
00029              QWidget *parent, const char *name, bool modal, 
00030              bool separator,
00031              const QString &user1,
00032              const QString &user2,
00033              const QString &user3) :
00034     KDialog( parent, name, modal )
00035 {
00036   init( caption, buttonMask, user1 );
00037 }
00038 
00039 KDialogBase::~KDialogBase()
00040 {
00041 }
00042 
00043 void KDialogBase::init( const QString &caption, int buttonMask,
00044                         const QString &user1 )
00045 {
00046   mMainWidget = 0;
00047   mTabWidget = 0;
00048   mPlainPage = 0;
00049   mTopLayout = 0;
00050 
00051   if ( !caption.isEmpty() ) {
00052     setCaption( caption );
00053   }
00054 
00055   if ( buttonMask & User1 ) {
00056     mUser1Button = new QPushButton( user1, this );
00057     connect( mUser1Button, SIGNAL( clicked() ), SLOT( slotUser1() ) );
00058   } else {
00059     mUser1Button = 0;
00060   }
00061 
00062   if ( buttonMask & Ok ) {
00063     mOkButton = new QPushButton( i18n("Ok"), this );
00064     connect( mOkButton, SIGNAL( clicked() ), SLOT( slotOk() ) );
00065   } else {
00066     mOkButton = 0;
00067   }
00068 
00069   if ( buttonMask & Apply ) {
00070     mApplyButton = new QPushButton( i18n("Apply"), this );
00071     connect( mApplyButton, SIGNAL( clicked() ), SLOT( slotApply() ) );
00072   } else {
00073     mApplyButton = 0;
00074   }
00075 
00076   if ( buttonMask & Cancel ) {
00077     mCancelButton = new QPushButton( i18n("Cancel"), this );
00078     connect( mCancelButton, SIGNAL( clicked() ), SLOT( slotCancel() ) );
00079   } else {
00080     mCancelButton = 0;
00081   }
00082 
00083   if ( buttonMask & Close ) {
00084     mCloseButton = new QPushButton( i18n("Close"), this );
00085     connect( mCloseButton, SIGNAL( clicked() ), SLOT( slotClose() ) );
00086   } else {
00087     mCloseButton = 0;
00088   }
00089 }
00090 
00091 QTabWidget *KDialogBase::tabWidget()
00092 {
00093   if ( !mTabWidget ) {
00094     mTabWidget = new QTabWidget( this );
00095     setMainWidget( mTabWidget );
00096   }
00097   return mTabWidget;
00098 }
00099 
00100 void KDialogBase::initLayout()
00101 {
00102   delete mTopLayout;
00103   mTopLayout = new QVBoxLayout( this );
00104   mTopLayout->setMargin( marginHint() );
00105   mTopLayout->setSpacing( spacingHint() );
00106   
00107   mTopLayout->addWidget( mMainWidget );
00108   
00109   QBoxLayout *buttonLayout = new QHBoxLayout;
00110   mTopLayout->addLayout( buttonLayout );
00111   
00112   if ( mUser1Button ) buttonLayout->addWidget( mUser1Button );
00113   if ( mOkButton ) buttonLayout->addWidget( mOkButton );
00114   if ( mApplyButton ) buttonLayout->addWidget( mApplyButton );
00115   if ( mCancelButton ) buttonLayout->addWidget( mCancelButton );
00116   if ( mCloseButton ) buttonLayout->addWidget( mCloseButton );
00117 }
00118 
00119 QFrame *KDialogBase::addPage( const QString &name )
00120 {
00121 //  kdDebug() << "KDialogBase::addPage(): " << name << endl;
00122 
00123   QFrame *frame = new QFrame( tabWidget() );
00124   tabWidget()->addTab( frame, name );
00125   return frame;
00126 }
00127 
00128 QFrame *KDialogBase::addPage( const QString &name, int, const QPixmap & )
00129 {
00130   return addPage( name );
00131 }
00132 
00133 
00134 void KDialogBase::setMainWidget( QWidget *widget )
00135 {
00136   kdDebug() << "KDialogBase::setMainWidget()" << endl;
00137 
00138   mMainWidget = widget;
00139   initLayout();
00140 }
00141 
00142 
00143 void KDialogBase::enableButton( ButtonCode id, bool state )
00144 {
00145   QPushButton *button = 0;
00146   switch ( id ) {
00147     case Ok:
00148       button = mOkButton;
00149       break;
00150     case Apply:
00151       button = mApplyButton;
00152       break;
00153     default:
00154       break;      
00155   }
00156   if ( button ) {
00157     button->setEnabled( state );
00158   }
00159 }
00160 
00161 void KDialogBase::enableButtonOK( bool state )
00162 {
00163   enableButton( Ok, state );
00164 }
00165 
00166 void KDialogBase::enableButtonApply( bool state )
00167 {
00168   enableButton( Apply, state );
00169 }
00170 
00171 
00172 int KDialogBase::pageIndex( QWidget *widget ) const
00173 {
00174   return 0;
00175 }
00176 
00177 
00178 bool KDialogBase::showPage( int index )
00179 {
00180   return false;
00181 }
00182 
00183 QFrame *KDialogBase::plainPage()
00184 {
00185   if ( !mPlainPage ) {
00186     mPlainPage = new QFrame( this );
00187     setMainWidget( mPlainPage );
00188   }
00189   return mPlainPage;
00190 }
00191 
00192 void KDialogBase::slotOk()
00193 {
00194   accept();
00195 }
00196 
00197 void KDialogBase::slotApply()
00198 {
00199 }
00200 
00201 void KDialogBase::slotCancel()
00202 {
00203   reject();
00204 }
00205 
00206 void KDialogBase::slotClose()
00207 {
00208   accept();
00209 }
00210 
00211 void KDialogBase::slotUser1()
00212 {
00213   emit user1Clicked();
00214 }

Generated on Sat Nov 5 16:17:11 2005 for OPIE by  doxygen 1.4.2