summaryrefslogtreecommitdiffabout
path: root/libkdepim/kprefsdialog.h
blob: cc95dd483ee6b5dc88298555f394af451757d069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/*
    This file is part of KOrganizer.
    Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/
#ifndef _KPREFSDIALOG_H
#define _KPREFSDIALOG_H
// $Id$

#include <q3ptrlist.h>
#include <qlineedit.h>
//Added by qt3to4:
#include <QLabel>

#include <kdialogbase.h>

class KPrefs;
class KPrefsDialog;

class KColorButton;
class QCheckBox;
class QLabel;
class QSpinBox;
class Q3ButtonGroup;

/**
  @short Base class for widgets used by @ref KPrefsDialog.
  @author Cornelius Schumacher
  @see KPrefsDialog

  This class provides the interface for the preferences widgets used by
  KPrefsDialog.
*/
class KPrefsDialogWid : public QObject
{
  public:
    /**
      This function is called to read value of the setting from the
      stored configuration and display it in the widget.
    */
    virtual void readConfig() = 0;
    /**
      This function is called to write the current setting of the widget to the
      stored configuration.
    */
    virtual void writeConfig() = 0;
};

/**
  @short Widget for bool settings in @ref KPrefsDialog.
  
  This class provides a widget for configuring bool values. It is meant to be
  used by KPrefsDialog. The user is responsible for the layout management.
*/
class KPrefsDialogWidBool : public KPrefsDialogWid
{
  public:
    /**
      Create a bool widget consisting of a QCheckbox.
      
      @param text      Text of QCheckBox.
      @param reference Pointer to variable read and written by this widget.
      @param parent    Parent widget.
    */
    KPrefsDialogWidBool(const QString &text,bool *reference,QWidget *parent);
    
    /**
      Return the QCheckbox used by this widget.
    */
    QCheckBox *checkBox();
    
    void readConfig();
    void writeConfig();
    
  private:
    bool *mReference;
    
    QCheckBox *mCheck;
};

/**
  @short Widget for time settings in @ref KPrefsDialog.
  
  This class provides a widget for configuring time values. It is meant to be
  used by KPrefsDialog. The user is responsible for the layout management.
*/
class KPrefsDialogWidTime : public KPrefsDialogWid
{
  public:
    /**
      Create a time widget consisting of a label and a spinbox.
      
      @param text      Text of Label.
      @param reference Pointer to variable read and written by this widget.
      @param parent    Parent widget.
    */
    KPrefsDialogWidTime(const QString &text,int *reference,QWidget *parent);
    
    /**
      Return QLabel used by this widget.
    */
    QLabel *label();
    /**
      Return QSpinBox used by this widget.
    */
    QSpinBox *spinBox();
    
    void readConfig();
    void writeConfig();
    
  private:
    int *mReference;
    
    QLabel *mLabel;
    QSpinBox *mSpin;
};

/**
  @short Widget for color settings in @ref KPrefsDialog.
  
  This class provides a widget for configuring color values. It is meant to be
  used by KPrefsDialog. The user is responsible for the layout management.
*/
class KPrefsDialogWidColor : public KPrefsDialogWid
{
  public:
    /**
      Create a color widget consisting of a test field and a button for opening
      a color dialog.
      
      @param text      Text of button.
      @param reference Pointer to variable read and written by this widget.
      @param parent    Parent widget.
    */
    KPrefsDialogWidColor(const QString &text,QColor *reference,QWidget *parent);
    /**
      Destruct color setting widget.
    */
    ~KPrefsDialogWidColor();
    
    /**
      Return QLabel for the button
    */
    QLabel *label();
    /**
      Return button opening the color dialog.
    */
    KColorButton *button();
    
    void readConfig();
    void writeConfig();
    
  private:
    QColor *mReference;
    
    QLabel *mLabel;
    KColorButton *mButton;
};

/**
  @short Widget for font settings in @ref KPrefsDialog.
  
  This class provides a widget for configuring font values. It is meant to be
  used by KPrefsDialog. The user is responsible for the layout management.
*/
class KPrefsDialogWidFont : public KPrefsDialogWid
{
    Q_OBJECT
  public:
    /**
      Create a font widget consisting of a test field and a button for opening
      a font dialog.
      
      @param label     Text of label.
      @param reference Pointer to variable read and written by this widget.
      @param parent    Parent widget.
    */
    KPrefsDialogWidFont(const QString &sampleText,const QString &labelText,
                  QFont *reference,QWidget *parent);
    /**
      Destruct font setting widget.
    */
    ~KPrefsDialogWidFont();
    
    /**
      Return label.
    */
    QLabel *label();
    /**
      Return QFrame used as preview field.
    */
    QLabel *preview();
    /**
      Return button opening the font dialog.
    */
    QPushButton *button();
    
    void readConfig();
    void writeConfig();

  protected slots:
    void selectFont();
    
  private:
    QFont *mReference;
    
    QLabel *mLabel;
    QLabel *mPreview;
    QPushButton *mButton;
};

/**
  @short Widget for settings represented by a group of radio buttons in
  @ref KPrefsDialog.
  
  This class provides a widget for configuring selections. It is meant to be
  used by KPrefsDialog. The user is responsible for the layout management. The
  setting is interpreted as an int value, corresponding to the position of the
  radio button. The position of the button is defined by the sequence of @ref
  addRadio() calls, starting with 0.
*/
class KPrefsDialogWidRadios : public KPrefsDialogWid
{
  public:
    /**
      Create a widget for selection of an option. It consists of a box with
      several radio buttons.
      
      @param text      Text of main box.
      @param reference Pointer to variable read and written by this widget.
      @param parent    Parent widget.
    */
    KPrefsDialogWidRadios(const QString &text,int *reference,QWidget *parent);
    virtual ~KPrefsDialogWidRadios();

    /**
      Add a radio button.
      
      @param text Text of the button.
    */
    void addRadio(const QString &text);
    
    /**
      Return the box widget used by this widget.
    */
    Q3ButtonGroup *groupBox();
    
    void readConfig();
    void writeConfig();
    
  private:
    int *mReference;

    Q3ButtonGroup *mBox;
};


/**
  @short Widget for string settings in @ref KPrefsDialog.
  
  This class provides a widget for configuring string values. It is meant to be
  used by KPrefsDialog. The user is responsible for the layout management.
*/
class KPrefsDialogWidString : public KPrefsDialogWid
{
  public:
    /**
      Create a string widget consisting of a test label and a line edit.
      
      @param text      Text of label.
      @param reference Pointer to variable read and written by this widget.
      @param parent    Parent widget.
    */
    KPrefsDialogWidString(const QString &text,QString *reference,QWidget *parent,QLineEdit::EchoMode echomode=QLineEdit::Normal);
    /**
      Destructor.
    */
    virtual ~KPrefsDialogWidString();

    /**
      Return label used by this widget.
    */
    QLabel *label();
    /**
      Return QLineEdit used by this widget.
    */
    QLineEdit *lineEdit();
    
    void readConfig();
    void writeConfig();
    
  private:
    QString *mReference;

    QLabel *mLabel;
    QLineEdit *mEdit;
};


/**
  @short Base class for a preferences dialog.
  
  This class provides the framework for a preferences dialog. You have to
  subclass it and add the code to create the actual configuration widgets and
  do the layout management.
  
  KPrefsDialog provides functions to add subclasses of @ref KPrefsDialogWid. For
  these widgets the reading, writing and setting to default values is handled
  automatically. Custom widgets have to be handled in the functions @ref
  usrReadConfig() and @ref usrWriteConfig().
*/
class KPrefsDialog : public KDialogBase
{
    Q_OBJECT
  public:
    /**
      Create a KPrefsDialog for a KPrefs object.
      
      @param prefs  KPrefs object used to access te configuration.
      @param parent Parent widget.
      @param name   Widget name.
      @param modal  true, if dialog has to be modal, false for non-modal.
    */
    KPrefsDialog(KPrefs *prefs,QWidget *parent=0,char *name=0,bool modal=false);
    /**
      Destructor.
    */
    virtual ~KPrefsDialog();

    /**
      Register a custom KPrefsDialogWid object.
    */
    void addWid(KPrefsDialogWid *);
    /**
      Register a @ref KPrefsDialogWidBool object.
      
      @param text      Text of bool widget.
      @param reference Reference to variable storing the setting.
      @param parent    Parent widget.
    */
    KPrefsDialogWidBool *addWidBool(const QString &text,bool *reference,QWidget *parent);
    /**
      Register a @ref KPrefsDialogWidTime object.
      
      @param text      Text of time widget.
      @param reference Reference to variable storing the setting.
      @param parent    Parent widget.
    */
    KPrefsDialogWidTime *addWidTime(const QString &text,int *reference,QWidget *parent);
    /**
      Register a @ref KPrefsDialogWidColor object.
      
      @param text      Text of color widget.
      @param reference Reference to variable storing the setting.
      @param parent    Parent widget.
    */
    KPrefsDialogWidColor *addWidColor(const QString &text,QColor *reference,QWidget *parent);
    /**
      Register a @ref KPrefsDialogWidRadios object.
      
      @param text      Text of radio button box widget.
      @param reference Reference to variable storing the setting.
      @param parent    Parent widget.
    */
    KPrefsDialogWidRadios *addWidRadios(const QString &text,int *reference,QWidget *parent);
    /**
      Register a @ref KPrefsDialogWidString object.
      
      @param text      Text of string widget.
      @param reference Reference to variable storing the setting.
      @param parent    Parent widget.
    */
    KPrefsDialogWidString *addWidString(const QString &text,QString *reference,QWidget *parent);
    /**
      Register a password @ref KPrefsDialogWidString object, with echomode set to QLineEdit::Password.
      
      @param text      Text of string widget.
      @param reference Reference to variable storing the setting.
      @param parent    Parent widget.
    */
    KPrefsDialogWidString *addWidPassword (const QString &text,QString *reference,QWidget *parent);
    /**
      Register a @ref KPrefsDialogWidFont object.
      
      @param sampleText Sample text of font widget.
      @param buttonText Button text of font widget.
      @param reference  Reference to variable storing the setting.
      @param parent     Parent widget.
    */
    KPrefsDialogWidFont *addWidFont(const QString &sampleText,const QString &buttonText,
                              QFont *reference,QWidget *parent);

  public slots:
    /** Set all widgets to default values. */
    void setDefaults();
  
    /** Read preferences from config file. */
    void readConfig();

    /** Write preferences to config file. */
    void writeConfig();

  signals:
    /** Emitted when the a changed configuration has been stored. */
    void configChanged();

  protected slots:
    /** Apply changes to preferences */
    void slotApply();  

    void accept();
    /** Accept changes to preferences and close dialog */
    void slotOk();
  
    /** Set preferences to default values */
    void slotDefault();
  
  protected:
    /** Implement this to read custom configuration widgets. */
    virtual void usrReadConfig() {}
    /** Implement this to write custom configuration widgets. */
    virtual void usrWriteConfig() {}

  private:
    KPrefs *mPrefs;

    Q3PtrList<KPrefsDialogWid> mPrefsWids;
};


#include "kcmconfigs/kdepimconfigwidget.h"
class KPimPrefsGlobalDialog : public KPrefsDialog
{
    Q_OBJECT
        public:
    KPimPrefsGlobalDialog(QWidget *parent=0,char *name=0,bool modal=true);
        /**
           Destructor.
        */
        void showTZconfig();

        public slots:

 signals:
        protected slots:
        
 protected:
        void usrReadConfig();
        virtual void usrWriteConfig() ;

 private:
        KDEPIMConfigWidget* kdelibcfg;
    
};

#endif