author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /microkde/kdialogbase.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
-rw-r--r-- | microkde/kdialogbase.cpp | 278 |
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 | |||
12 | KDialogBase::KDialogBase() | ||
13 | { | ||
14 | } | ||
15 | |||
16 | KDialogBase::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 | |||
31 | KDialogBase::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 | |||
46 | KDialogBase::~KDialogBase() | ||
47 | { | ||
48 | } | ||
49 | |||
50 | void 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 | |||
103 | QTabWidget *KDialogBase::tabWidget() | ||
104 | { | ||
105 | if ( !mTabWidget ) { | ||
106 | mTabWidget = new QTabWidget( this ); | ||
107 | setMainWidget( mTabWidget ); | ||
108 | } | ||
109 | return mTabWidget; | ||
110 | } | ||
111 | |||
112 | void 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 | } | ||
122 | void 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 | |||
143 | QFrame *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 | |||
151 | QFrame *KDialogBase::addPage( const QString &name, int, const QPixmap & ) | ||
152 | { | ||
153 | return addPage( name ); | ||
154 | } | ||
155 | |||
156 | |||
157 | void KDialogBase::setMainWidget( QWidget *widget ) | ||
158 | { | ||
159 | kdDebug() << "KDialogBase::setMainWidget()" << endl; | ||
160 | |||
161 | mMainWidget = widget; | ||
162 | initLayout(); | ||
163 | } | ||
164 | |||
165 | void KDialogBase::setButtonText( ButtonCode id, const QString &text ) | ||
166 | { | ||
167 | QPushButton *button = findButton( id ); | ||
168 | if ( button ) { | ||
169 | button->setText( text ); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | void KDialogBase::enableButton( ButtonCode id, bool state ) | ||
174 | { | ||
175 | QPushButton *button = findButton( id ); | ||
176 | if ( button ) { | ||
177 | button->setEnabled( state ); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | QPushButton *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 | |||
209 | void KDialogBase::enableButtonOK( bool state ) | ||
210 | { | ||
211 | enableButton( Ok, state ); | ||
212 | } | ||
213 | |||
214 | void KDialogBase::enableButtonApply( bool state ) | ||
215 | { | ||
216 | enableButton( Apply, state ); | ||
217 | } | ||
218 | |||
219 | void 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 | |||
228 | int KDialogBase::pageIndex( QWidget *widget ) const | ||
229 | { | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | |||
234 | bool KDialogBase::showPage( int index ) | ||
235 | { | ||
236 | tabWidget()->setCurrentPage( index );return false; | ||
237 | } | ||
238 | |||
239 | QFrame *KDialogBase::plainPage() | ||
240 | { | ||
241 | if ( !mPlainPage ) { | ||
242 | mPlainPage = new QFrame( this ); | ||
243 | setMainWidget( mPlainPage ); | ||
244 | } | ||
245 | return mPlainPage; | ||
246 | } | ||
247 | |||
248 | void KDialogBase::slotOk() | ||
249 | { | ||
250 | emit okClicked(); | ||
251 | accept(); | ||
252 | } | ||
253 | |||
254 | void KDialogBase::slotApply() | ||
255 | { | ||
256 | emit applyClicked(); | ||
257 | } | ||
258 | |||
259 | void KDialogBase::slotCancel() | ||
260 | { | ||
261 | emit cancelClicked(); | ||
262 | reject(); | ||
263 | } | ||
264 | |||
265 | void KDialogBase::slotClose() | ||
266 | { | ||
267 | emit closeClicked(); | ||
268 | reject(); | ||
269 | } | ||
270 | |||
271 | void KDialogBase::slotUser1() | ||
272 | { | ||
273 | emit user1Clicked(); | ||
274 | } | ||
275 | void KDialogBase::slotUser2() | ||
276 | { | ||
277 | emit user2Clicked(); | ||
278 | } | ||