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