summaryrefslogtreecommitdiffabout
path: root/microkde/kdialogbase.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /microkde/kdialogbase.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'microkde/kdialogbase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdialogbase.cpp278
1 files changed, 278 insertions, 0 deletions
diff --git a/microkde/kdialogbase.cpp b/microkde/kdialogbase.cpp
new file mode 100644
index 0000000..2ea2053
--- a/dev/null
+++ b/microkde/kdialogbase.cpp
@@ -0,0 +1,278 @@
1#include <qtabwidget.h>
2#include <qpushbutton.h>
3#include <qlayout.h>
4#include <qframe.h>
5
6
7#include "klocale.h"
8#include "kdebug.h"
9
10#include "kdialogbase.h"
11
12KDialogBase::KDialogBase()
13{
14}
15
16KDialogBase::KDialogBase( QWidget *parent, const char *name, bool modal,
17 const QString &caption,
18 int buttonMask, ButtonCode defaultButton,
19 bool separator,
20 const QString &user1,
21 const QString &user2,
22 const QString &user3) :
23 KDialog( parent, name, modal )
24{
25 init( caption, buttonMask, user1, user2 );
26 if (findButton( defaultButton ) )
27 (findButton( defaultButton ) )->setFocus();
28
29}
30
31KDialogBase::KDialogBase( int dialogFace, const QString &caption,
32 int buttonMask, ButtonCode defaultButton,
33 QWidget *parent, const char *name, bool modal,
34 bool separator,
35 const QString &user1,
36 const QString &user2,
37 const QString &user3) :
38 KDialog( parent, name, modal )
39{
40 init( caption, buttonMask, user1, user2 );
41 if (findButton( defaultButton ) )
42 (findButton( defaultButton ) )->setFocus();
43
44}
45
46KDialogBase::~KDialogBase()
47{
48}
49
50void KDialogBase::init( const QString &caption, int buttonMask,
51 const QString &user1 ,const QString &user2 )
52{
53 mMainWidget = 0;
54 mTabWidget = 0;
55 mPlainPage = 0;
56 mTopLayout = 0;
57 if ( !caption.isEmpty() ) {
58 setCaption( caption );
59 }
60
61 if ( buttonMask & User1 ) {
62 mUser1Button = new QPushButton( user1, this );
63 connect( mUser1Button, SIGNAL( clicked() ), SLOT( slotUser1() ) );
64 } else {
65 mUser1Button = 0;
66 }
67 if ( buttonMask & User2 ) {
68 mUser2Button = new QPushButton( user2, this );
69 connect( mUser2Button, SIGNAL( clicked() ), SLOT( slotUser2() ) );
70 } else {
71 mUser2Button = 0;
72 }
73
74 if ( buttonMask & Ok ) {
75 mOkButton = new QPushButton( i18n("Ok"), this );
76 connect( mOkButton, SIGNAL( clicked() ), SLOT( slotOk() ) );
77 } else {
78 mOkButton = 0;
79 }
80
81 if ( buttonMask & Apply ) {
82 mApplyButton = new QPushButton( i18n("Apply"), this );
83 connect( mApplyButton, SIGNAL( clicked() ), SLOT( slotApply() ) );
84 } else {
85 mApplyButton = 0;
86 }
87
88 if ( buttonMask & Cancel ) {
89 mCancelButton = new QPushButton( i18n("Cancel"), this );
90 connect( mCancelButton, SIGNAL( clicked() ), SLOT( slotCancel() ) );
91 } else {
92 mCancelButton = 0;
93 }
94
95 if ( buttonMask & Close ) {
96 mCloseButton = new QPushButton( i18n("Close"), this );
97 connect( mCloseButton, SIGNAL( clicked() ), SLOT( slotClose() ) );
98 } else {
99 mCloseButton = 0;
100 }
101}
102
103QTabWidget *KDialogBase::tabWidget()
104{
105 if ( !mTabWidget ) {
106 mTabWidget = new QTabWidget( this );
107 setMainWidget( mTabWidget );
108 }
109 return mTabWidget;
110}
111
112void KDialogBase::hideButtons()
113{
114 if ( mUser1Button ) mUser1Button->hide() ;
115 if ( mUser2Button ) mUser2Button->hide() ;
116 if ( mOkButton ) mOkButton->hide() ;
117 if ( mApplyButton ) mApplyButton->hide() ;
118 if ( mCancelButton ) mCancelButton->hide() ;
119 if ( mCloseButton ) mCloseButton->hide() ;
120
121}
122void KDialogBase::initLayout()
123{
124
125 delete mTopLayout;
126 mTopLayout = new QVBoxLayout( this );
127 mTopLayout->setMargin( marginHint() );
128 mTopLayout->setSpacing( spacingHint() );
129
130 mTopLayout->addWidget( mMainWidget );
131
132 QBoxLayout *buttonLayout = new QHBoxLayout;
133 mTopLayout->addLayout( buttonLayout );
134
135 if ( mUser1Button ) buttonLayout->addWidget( mUser1Button );
136 if ( mUser2Button ) buttonLayout->addWidget( mUser2Button );
137 if ( mOkButton ) buttonLayout->addWidget( mOkButton );
138 if ( mApplyButton ) buttonLayout->addWidget( mApplyButton );
139 if ( mCancelButton ) buttonLayout->addWidget( mCancelButton );
140 if ( mCloseButton ) buttonLayout->addWidget( mCloseButton );
141}
142
143QFrame *KDialogBase::addPage( const QString &name )
144{
145// kdDebug() << "KDialogBase::addPage(): " << name << endl;
146 QFrame *frame = new QFrame( tabWidget() );
147 tabWidget()->addTab( frame, name );
148 return frame;
149}
150
151QFrame *KDialogBase::addPage( const QString &name, int, const QPixmap & )
152{
153 return addPage( name );
154}
155
156
157void KDialogBase::setMainWidget( QWidget *widget )
158{
159 kdDebug() << "KDialogBase::setMainWidget()" << endl;
160
161 mMainWidget = widget;
162 initLayout();
163}
164
165void KDialogBase::setButtonText( ButtonCode id, const QString &text )
166{
167 QPushButton *button = findButton( id );
168 if ( button ) {
169 button->setText( text );
170 }
171}
172
173void KDialogBase::enableButton( ButtonCode id, bool state )
174{
175 QPushButton *button = findButton( id );
176 if ( button ) {
177 button->setEnabled( state );
178 }
179}
180
181QPushButton *KDialogBase::findButton( ButtonCode id )
182{
183 QPushButton *button = 0;
184 switch ( id ) {
185 case Ok:
186 button = mOkButton;
187 break;
188 case Apply:
189 button = mApplyButton;
190 break;
191 case User1:
192 button = mUser1Button;
193 break;
194 case User2:
195 button = mUser2Button;
196 break;
197 case Cancel:
198 button = mCancelButton;
199 break;
200 case Close:
201 button = mCloseButton;
202 break;
203 default:
204 break;
205 }
206 return button;
207}
208
209void KDialogBase::enableButtonOK( bool state )
210{
211 enableButton( Ok, state );
212}
213
214void KDialogBase::enableButtonApply( bool state )
215{
216 enableButton( Apply, state );
217}
218
219void KDialogBase::showButton( ButtonCode id, bool show )
220{
221 QPushButton *button = findButton( id );
222 if ( button ) {
223 if ( show ) button->show();
224 else button->hide();
225 }
226}
227
228int KDialogBase::pageIndex( QWidget *widget ) const
229{
230 return 0;
231}
232
233
234bool KDialogBase::showPage( int index )
235{
236 tabWidget()->setCurrentPage( index );return false;
237}
238
239QFrame *KDialogBase::plainPage()
240{
241 if ( !mPlainPage ) {
242 mPlainPage = new QFrame( this );
243 setMainWidget( mPlainPage );
244 }
245 return mPlainPage;
246}
247
248void KDialogBase::slotOk()
249{
250 emit okClicked();
251 accept();
252}
253
254void KDialogBase::slotApply()
255{
256 emit applyClicked();
257}
258
259void KDialogBase::slotCancel()
260{
261 emit cancelClicked();
262 reject();
263}
264
265void KDialogBase::slotClose()
266{
267 emit closeClicked();
268 reject();
269}
270
271void KDialogBase::slotUser1()
272{
273 emit user1Clicked();
274}
275void KDialogBase::slotUser2()
276{
277 emit user2Clicked();
278}