summaryrefslogtreecommitdiffabout
path: root/libkdepim/kprefsdialog.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libkdepim/kprefsdialog.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'libkdepim/kprefsdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kprefsdialog.cpp410
1 files changed, 410 insertions, 0 deletions
diff --git a/libkdepim/kprefsdialog.cpp b/libkdepim/kprefsdialog.cpp
new file mode 100644
index 0000000..3a39ea9
--- a/dev/null
+++ b/libkdepim/kprefsdialog.cpp
@@ -0,0 +1,410 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24// $Id$
25
26#include <qlayout.h>
27#include <qlabel.h>
28#include <qgroupbox.h>
29#include <qbuttongroup.h>
30#include <qlineedit.h>
31#include <qfont.h>
32#include <qslider.h>
33#include <qfile.h>
34#include <qtextstream.h>
35#include <qvbox.h>
36#include <qhbox.h>
37#include <qspinbox.h>
38#include <qdatetime.h>
39#include <qframe.h>
40#include <qcombobox.h>
41#include <qcheckbox.h>
42#include <qradiobutton.h>
43#include <qpushbutton.h>
44#include <qapplication.h>
45
46#include <kcolorbutton.h>
47#include <kdebug.h>
48#include <klocale.h>
49#include <kglobal.h>
50#include <kfontdialog.h>
51#include <kmessagebox.h>
52#include <kcolordialog.h>
53#include <kiconloader.h>
54
55#include "kprefs.h"
56
57#include "kprefsdialog.h"
58#include "kprefsdialog.moc"
59
60KPrefsWidBool::KPrefsWidBool(const QString &text,bool *reference,
61 QWidget *parent)
62{
63 mReference = reference;
64
65 mCheck = new QCheckBox(text,parent);
66}
67
68void KPrefsWidBool::readConfig()
69{
70 mCheck->setChecked(*mReference);
71}
72
73void KPrefsWidBool::writeConfig()
74{
75 *mReference = mCheck->isChecked();
76}
77
78QCheckBox *KPrefsWidBool::checkBox()
79{
80 return mCheck;
81}
82
83
84KPrefsWidColor::KPrefsWidColor(const QString &text,QColor *reference,
85 QWidget *parent)
86{
87 mReference = reference;
88
89 mButton = new KColorButton(parent);
90 mLabel = new QLabel(mButton, text, parent);
91 mButton->setColor( *mReference );
92 mButton->setColor( Qt::red );
93
94}
95
96KPrefsWidColor::~KPrefsWidColor()
97{
98// kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl;
99}
100
101void KPrefsWidColor::readConfig()
102{
103 mButton->setColor(*mReference);
104}
105
106void KPrefsWidColor::writeConfig()
107{
108 *mReference = mButton->color();
109}
110
111QLabel *KPrefsWidColor::label()
112{
113 return mLabel;
114}
115
116KColorButton *KPrefsWidColor::button()
117{
118 return mButton;
119}
120
121KPrefsWidFont::KPrefsWidFont(const QString &sampleText,const QString &labelText,
122 QFont *reference,QWidget *parent)
123{
124 mReference = reference;
125
126 mLabel = new QLabel(labelText, parent);
127
128 mPreview = new QLabel(sampleText,parent);
129 mPreview->setFrameStyle(QFrame::Panel|QFrame::Sunken);
130
131 mButton = new QPushButton(i18n("Choose..."), parent);
132 connect(mButton,SIGNAL(clicked()),SLOT(selectFont()));
133 mPreview->setMaximumHeight( QApplication::desktop()->height() / 12 );
134 mPreview->setMaximumWidth( (QApplication::desktop()->width() / 2)-10 );
135}
136
137KPrefsWidFont::~KPrefsWidFont()
138{
139}
140
141void KPrefsWidFont::readConfig()
142{
143 mPreview->setFont(*mReference);
144}
145
146void KPrefsWidFont::writeConfig()
147{
148 *mReference = mPreview->font();
149}
150
151QLabel *KPrefsWidFont::label()
152{
153 return mLabel;
154}
155
156QLabel *KPrefsWidFont::preview()
157{
158 return mPreview;
159}
160
161QPushButton *KPrefsWidFont::button()
162{
163 return mButton;
164}
165
166void KPrefsWidFont::selectFont()
167{
168 QFont myFont(mPreview->font());
169 bool ok;
170 myFont = KFontDialog::getFont(myFont, ok);
171 if ( ok ) {
172 mPreview->setFont(myFont);
173 }
174}
175
176
177KPrefsWidTime::KPrefsWidTime(const QString &text,int *reference,
178 QWidget *parent)
179{
180 mReference = reference;
181
182 mLabel = new QLabel(text,parent);
183 mSpin = new QSpinBox(0,23,1,parent);
184 mSpin->setSuffix(":00");
185}
186
187void KPrefsWidTime::readConfig()
188{
189 mSpin->setValue(*mReference);
190}
191
192void KPrefsWidTime::writeConfig()
193{
194 *mReference = mSpin->value();
195}
196
197QLabel *KPrefsWidTime::label()
198{
199 return mLabel;
200}
201
202QSpinBox *KPrefsWidTime::spinBox()
203{
204 return mSpin;
205}
206
207
208KPrefsWidRadios::KPrefsWidRadios(const QString &text,int *reference,
209 QWidget *parent)
210{
211 mReference = reference;
212
213 mBox = new QButtonGroup(1,Qt::Horizontal,text,parent);
214}
215
216KPrefsWidRadios::~KPrefsWidRadios()
217{
218}
219
220void KPrefsWidRadios::addRadio(const QString &text)
221{
222 new QRadioButton(text,mBox);
223}
224
225QButtonGroup *KPrefsWidRadios::groupBox()
226{
227 return mBox;
228}
229
230void KPrefsWidRadios::readConfig()
231{
232 mBox->setButton(*mReference);
233}
234
235void KPrefsWidRadios::writeConfig()
236{
237 *mReference = mBox->id(mBox->selected());
238}
239
240
241KPrefsWidString::KPrefsWidString(const QString &text,QString *reference,
242 QWidget *parent, QLineEdit::EchoMode echomode)
243{
244 mReference = reference;
245
246 mLabel = new QLabel(text,parent);
247 mEdit = new QLineEdit(parent);
248 mEdit->setEchoMode( echomode );
249}
250
251KPrefsWidString::~KPrefsWidString()
252{
253}
254
255void KPrefsWidString::readConfig()
256{
257 mEdit->setText(*mReference);
258}
259
260void KPrefsWidString::writeConfig()
261{
262 *mReference = mEdit->text();
263}
264
265QLabel *KPrefsWidString::label()
266{
267 return mLabel;
268}
269
270QLineEdit *KPrefsWidString::lineEdit()
271{
272 return mEdit;
273}
274
275
276KPrefsDialog::KPrefsDialog(KPrefs *prefs,QWidget *parent,char *name,bool modal) :
277 KDialogBase(IconList,i18n("Preferences"),Ok|Cancel|Default,Ok,parent,
278 name,modal,true)
279{
280 mPrefs = prefs;
281
282// This seems to cause a crash on exit. Investigate later.
283// mPrefsWids.setAutoDelete(true);
284
285 connect(this,SIGNAL(defaultClicked()),SLOT(slotDefault()));
286 //connect(this,SIGNAL(cancelClicked()),SLOT(slotDefault()));
287 //connect(this,SIGNAL(cancelClicked()),SLOT(reject()));
288}
289
290KPrefsDialog::~KPrefsDialog()
291{
292}
293
294void KPrefsDialog::addWid(KPrefsWid *wid)
295{
296 mPrefsWids.append(wid);
297}
298
299KPrefsWidBool *KPrefsDialog::addWidBool(const QString &text,bool *reference,QWidget *parent)
300{
301 KPrefsWidBool *w = new KPrefsWidBool(text,reference,parent);
302 addWid(w);
303 return w;
304}
305
306KPrefsWidTime *KPrefsDialog::addWidTime(const QString &text,int *reference,QWidget *parent)
307{
308 KPrefsWidTime *w = new KPrefsWidTime(text,reference,parent);
309 addWid(w);
310 return w;
311}
312
313KPrefsWidColor *KPrefsDialog::addWidColor(const QString &text,QColor *reference,QWidget *parent)
314{
315 KPrefsWidColor *w = new KPrefsWidColor(text,reference,parent);
316 addWid(w);
317 return w;
318}
319
320KPrefsWidRadios *KPrefsDialog::addWidRadios(const QString &text,int *reference,QWidget *parent)
321{
322 KPrefsWidRadios *w = new KPrefsWidRadios(text,reference,parent);
323 addWid(w);
324 return w;
325}
326
327KPrefsWidString *KPrefsDialog::addWidString(const QString &text,QString *reference,QWidget *parent)
328{
329 KPrefsWidString *w = new KPrefsWidString(text,reference,parent);
330 addWid(w);
331 return w;
332}
333
334KPrefsWidString *KPrefsDialog::addWidPassword(const QString &text,QString *reference,QWidget *parent)
335{
336 KPrefsWidString *w = new KPrefsWidString(text,reference,parent,QLineEdit::Password);
337 addWid(w);
338 return w;
339}
340
341KPrefsWidFont *KPrefsDialog::addWidFont(const QString &sampleText,const QString &buttonText,
342 QFont *reference,QWidget *parent)
343{
344 KPrefsWidFont *w = new KPrefsWidFont(sampleText,buttonText,reference,parent);
345 addWid(w);
346 return w;
347}
348
349void KPrefsDialog::setDefaults()
350{
351 mPrefs->setDefaults();
352
353 readConfig();
354}
355
356void KPrefsDialog::readConfig()
357{
358// kdDebug(5300) << "KPrefsDialog::readConfig()" << endl;
359
360 KPrefsWid *wid;
361 for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) {
362 wid->readConfig();
363 }
364
365 usrReadConfig();
366}
367
368void KPrefsDialog::writeConfig()
369{
370// kdDebug(5300) << "KPrefsDialog::writeConfig()" << endl;
371
372 KPrefsWid *wid;
373 for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) {
374 wid->writeConfig();
375 }
376
377 usrWriteConfig();
378
379// kdDebug(5300) << "KPrefsDialog::writeConfig() now writing..." << endl;
380
381 mPrefs->writeConfig();
382
383// kdDebug(5300) << "KPrefsDialog::writeConfig() done" << endl;
384}
385
386
387void KPrefsDialog::slotApply()
388{
389 writeConfig();
390 emit configChanged();
391}
392
393void KPrefsDialog::slotOk()
394{
395 slotApply();
396 QDialog::accept();
397}
398void KPrefsDialog::accept()
399{
400 slotOk();
401}
402
403void KPrefsDialog::slotDefault()
404{
405 if (KMessageBox::warningContinueCancel(this,
406 i18n("You are about to set all\npreferences to default values.\nAll "
407 "custom modifications will be lost."),i18n("Setting Default Preferences"),
408 i18n("Continue"))
409 == KMessageBox::Continue) setDefaults();
410}