summaryrefslogtreecommitdiffabout
path: root/libkdepim/kprefswidget.cpp
Unidiff
Diffstat (limited to 'libkdepim/kprefswidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kprefswidget.cpp427
1 files changed, 427 insertions, 0 deletions
diff --git a/libkdepim/kprefswidget.cpp b/libkdepim/kprefswidget.cpp
new file mode 100644
index 0000000..be9ad30
--- a/dev/null
+++ b/libkdepim/kprefswidget.cpp
@@ -0,0 +1,427 @@
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 "kprefswidget.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 connect( mCheck, SIGNAL( toggled( bool ) ), SIGNAL( modified() ) );
68
69}
70
71void KPrefsWidBool::readConfig()
72{
73 mCheck->setChecked(*mReference);
74}
75
76void KPrefsWidBool::writeConfig()
77{
78 *mReference = mCheck->isChecked();
79}
80
81QCheckBox *KPrefsWidBool::checkBox()
82{
83 return mCheck;
84}
85
86
87KPrefsWidColor::KPrefsWidColor(const QString &text,QColor *reference,
88 QWidget *parent)
89{
90 mReference = reference;
91
92 mButton = new KColorButton(parent);
93 mLabel = new QLabel(mButton, text, parent);
94 mButton->setColor( *mReference );
95 mButton->setColor( Qt::red );
96
97 connect( mButton, SIGNAL( changed(const QColor &)), SIGNAL( modified() ) );
98
99}
100
101KPrefsWidColor::~KPrefsWidColor()
102{
103// kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl;
104}
105
106void KPrefsWidColor::readConfig()
107{
108 mButton->setColor(*mReference);
109}
110
111void KPrefsWidColor::writeConfig()
112{
113 *mReference = mButton->color();
114}
115
116QLabel *KPrefsWidColor::label()
117{
118 return mLabel;
119}
120
121KColorButton *KPrefsWidColor::button()
122{
123 return mButton;
124}
125
126KPrefsWidFont::KPrefsWidFont(const QString &sampleText,const QString &labelText,
127 QFont *reference,QWidget *parent)
128{
129 mReference = reference;
130
131 mLabel = new QLabel(labelText, parent);
132
133 mPreview = new QLabel(sampleText,parent);
134 mPreview->setFrameStyle(QFrame::Panel|QFrame::Sunken);
135
136 mButton = new QPushButton(i18n("Choose..."), parent);
137 connect(mButton,SIGNAL(clicked()),SLOT(selectFont()));
138 mPreview->setMaximumHeight( QApplication::desktop()->height() / 12 );
139 mPreview->setMaximumWidth( (QApplication::desktop()->width() / 2)-10 );
140}
141
142KPrefsWidFont::~KPrefsWidFont()
143{
144}
145
146void KPrefsWidFont::readConfig()
147{
148 mPreview->setFont(*mReference);
149}
150
151void KPrefsWidFont::writeConfig()
152{
153 *mReference = mPreview->font();
154}
155
156QLabel *KPrefsWidFont::label()
157{
158 return mLabel;
159}
160
161QLabel *KPrefsWidFont::preview()
162{
163 return mPreview;
164}
165
166QPushButton *KPrefsWidFont::button()
167{
168 return mButton;
169}
170
171void KPrefsWidFont::selectFont()
172{
173 QFont myFont(mPreview->font());
174 bool ok;
175 myFont = KFontDialog::getFont(myFont, ok);
176 if ( ok ) {
177 mPreview->setFont(myFont);
178 emit modified();
179 }
180}
181
182
183KPrefsWidTime::KPrefsWidTime(const QString &text,int *reference,
184 QWidget *parent)
185{
186 mReference = reference;
187
188 mLabel = new QLabel(text,parent);
189 mSpin = new QSpinBox(0,23,1,parent);
190 mSpin->setSuffix(":00");
191 connect( mSpin, SIGNAL( valueChanged(int)), SIGNAL( modified() ) );
192
193}
194
195void KPrefsWidTime::readConfig()
196{
197 mSpin->setValue(*mReference);
198}
199
200void KPrefsWidTime::writeConfig()
201{
202 *mReference = mSpin->value();
203}
204
205QLabel *KPrefsWidTime::label()
206{
207 return mLabel;
208}
209
210QSpinBox *KPrefsWidTime::spinBox()
211{
212 return mSpin;
213}
214
215
216KPrefsWidRadios::KPrefsWidRadios(const QString &text,int *reference,
217 QWidget *parent)
218{
219 mReference = reference;
220
221 mBox = new QButtonGroup(1,Qt::Horizontal,text,parent);
222 connect( mBox, SIGNAL( clicked(int)), SIGNAL( modified() ) );
223}
224
225KPrefsWidRadios::~KPrefsWidRadios()
226{
227}
228
229void KPrefsWidRadios::addRadio(const QString &text)
230{
231 new QRadioButton(text,mBox);
232}
233
234QButtonGroup *KPrefsWidRadios::groupBox()
235{
236 return mBox;
237}
238
239void KPrefsWidRadios::readConfig()
240{
241 mBox->setButton(*mReference);
242}
243
244void KPrefsWidRadios::writeConfig()
245{
246 *mReference = mBox->id(mBox->selected());
247}
248
249
250KPrefsWidString::KPrefsWidString(const QString &text,QString *reference,
251 QWidget *parent, QLineEdit::EchoMode echomode)
252{
253 mReference = reference;
254
255 mLabel = new QLabel(text,parent);
256 mEdit = new QLineEdit(parent);
257 mEdit->setEchoMode( echomode );
258 connect( mEdit, SIGNAL( textChanged(const QString&) ), SIGNAL( modified() ) );
259
260}
261
262KPrefsWidString::~KPrefsWidString()
263{
264}
265
266void KPrefsWidString::readConfig()
267{
268 mEdit->setText(*mReference);
269}
270
271void KPrefsWidString::writeConfig()
272{
273 *mReference = mEdit->text();
274}
275
276QLabel *KPrefsWidString::label()
277{
278 return mLabel;
279}
280
281QLineEdit *KPrefsWidString::lineEdit()
282{
283 return mEdit;
284}
285
286
287KPrefsWidget::KPrefsWidget(KPrefs *prefs,QWidget *parent,const char *name) :
288 QWidget(parent, name )
289{
290 mPrefs = prefs;
291}
292
293KPrefsWidget::~KPrefsWidget()
294{
295}
296
297void KPrefsWidget::addWid(KPrefsWid *wid)
298{
299 mPrefsWids.append(wid);
300 connect( wid, SIGNAL( modified() ), this, SLOT( modified() ) );
301
302}
303
304KPrefsWidBool *KPrefsWidget::addWidBool(const QString &text,bool *reference,QWidget *parent)
305{
306 KPrefsWidBool *w = new KPrefsWidBool(text,reference,parent);
307 addWid(w);
308 return w;
309}
310
311KPrefsWidTime *KPrefsWidget::addWidTime(const QString &text,int *reference,QWidget *parent)
312{
313 KPrefsWidTime *w = new KPrefsWidTime(text,reference,parent);
314 addWid(w);
315 return w;
316}
317
318KPrefsWidColor *KPrefsWidget::addWidColor(const QString &text,QColor *reference,QWidget *parent)
319{
320 KPrefsWidColor *w = new KPrefsWidColor(text,reference,parent);
321 addWid(w);
322 return w;
323}
324
325KPrefsWidRadios *KPrefsWidget::addWidRadios(const QString &text,int *reference,QWidget *parent)
326{
327 KPrefsWidRadios *w = new KPrefsWidRadios(text,reference,parent);
328 addWid(w);
329 return w;
330}
331
332KPrefsWidString *KPrefsWidget::addWidString(const QString &text,QString *reference,QWidget *parent)
333{
334 KPrefsWidString *w = new KPrefsWidString(text,reference,parent);
335 addWid(w);
336 return w;
337}
338
339KPrefsWidString *KPrefsWidget::addWidPassword(const QString &text,QString *reference,QWidget *parent)
340{
341 KPrefsWidString *w = new KPrefsWidString(text,reference,parent,QLineEdit::Password);
342 addWid(w);
343 return w;
344}
345
346KPrefsWidFont *KPrefsWidget::addWidFont(const QString &sampleText,const QString &buttonText,
347 QFont *reference,QWidget *parent)
348{
349 KPrefsWidFont *w = new KPrefsWidFont(sampleText,buttonText,reference,parent);
350 addWid(w);
351 return w;
352}
353
354void KPrefsWidget::setDefaults()
355{
356 mPrefs->setDefaults();
357
358 readConfig();
359}
360
361void KPrefsWidget::readConfig()
362{
363// kdDebug(5300) << "KPrefsDialog::readConfig()" << endl;
364
365 KPrefsWid *wid;
366 for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) {
367 wid->readConfig();
368 }
369
370 usrReadConfig();
371
372 emit changed( false );
373
374}
375
376void KPrefsWidget::writeConfig()
377{
378// kdDebug(5300) << "KPrefsDialog::writeConfig()" << endl;
379
380 KPrefsWid *wid;
381 for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) {
382 wid->writeConfig();
383 }
384
385 usrWriteConfig();
386
387// kdDebug(5300) << "KPrefsDialog::writeConfig() now writing..." << endl;
388
389 mPrefs->writeConfig();
390
391 emit changed( false );
392
393// kdDebug(5300) << "KPrefsDialog::writeConfig() done" << endl;
394}
395
396/*US
397void KPrefsWidget::slotApply()
398{
399 writeConfig();
400 emit configChanged();
401}
402
403void KPrefsDialog::slotOk()
404{
405 slotApply();
406 QDialog::accept();
407}
408void KPrefsDialog::accept()
409{
410 slotOk();
411}
412
413void KPrefsDialog::slotDefault()
414{
415 if (KMessageBox::warningContinueCancel(this,
416 i18n("You are about to set all\npreferences to default values.\nAll "
417 "custom modifications will be lost."),i18n("Setting Default Preferences"),
418 i18n("Continue"))
419 == KMessageBox::Continue) setDefaults();
420}
421*/
422
423void KPrefsWidget::modified()
424{
425 emit changed( true );
426}
427