making the requester type configurable
[quassel.git] / src / uisupport / settingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.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) version 3.                                           *
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                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _SETTINGSPAGE_H_
22 #define _SETTINGSPAGE_H_
23
24 #include <QWidget>
25
26 class QCheckBox;
27 class QComboBox;
28 class QSpinBox;
29
30 //! A SettingsPage is a page in the settings dialog.
31 /** The SettingsDlg provides suitable standard buttons, such as Ok, Apply, Cancel, Restore Defaults and Reset.
32  *  Some pages might also be used in standalone dialogs or other containers. A SettingsPage provides suitable
33  *  slots and signals to allow interaction with the container.
34  */
35 class SettingsPage : public QWidget {
36   Q_OBJECT
37
38 public:
39   SettingsPage(const QString &category, const QString &name, QWidget *parent = 0);
40   virtual ~SettingsPage() {};
41   
42   //! The category of this settings page.
43   inline virtual QString category() const { return _category; }
44   
45   //! The title of this settings page.
46   inline virtual QString title() const { return _title; }
47   
48   //! Derived classes need to define this and return true if they have default settings.
49   /** If this method returns true, the "Restore Defaults" button in the SettingsDlg is
50    *  enabled. You also need to provide an implementation of defaults() then.
51    *
52    * The default implementation returns false.
53      */
54   inline virtual bool hasDefaults() const { return false; }
55   
56   //! Check if there are changes in the page, compared to the state saved in permanent storage.
57   inline bool hasChanged() const { return _changed; }
58   
59   //! Called immediately before save() is called.
60   /** Derived classes should return false if saving is not possible (e.g. the current settings are invalid).
61    *  \return false, if the SettingsPage cannot be saved in its current state.
62    */
63   inline virtual bool aboutToSave() { return true; }
64
65   //! sets checked state depending on \checked and stores the value for later comparision
66   static void load(QCheckBox *box, bool checked);
67   static bool hasChanged(QCheckBox *box);
68   static void load(QComboBox *box, int index);
69   static bool hasChanged(QComboBox *box);
70   static void load(QSpinBox *box, int value);
71   static bool hasChanged(QSpinBox *box);
72
73 public slots:
74   //! Save settings to permanent storage.
75   virtual void save() = 0;
76   
77   //! Load settings from permanent storage, overriding any changes the user might have made in the dialog.
78   virtual void load() = 0;
79
80   //! Restore defaults, overriding any changes the user might have made in the dialog.
81   /** The default implementation does nothing.
82    */
83   inline virtual void defaults() {}
84                          
85 protected slots:
86   //! Calling this slot is equivalent to calling setChangedState(true).
87   inline void changed() { setChangedState(true); }
88   
89   //! This should be called whenever the widget state changes from unchanged to change or the other way round.
90   void setChangedState(bool hasChanged = true);
91   
92 signals:
93   //! Emitted whenever the widget state changes.
94   void changed(bool hasChanged);
95   
96 private:
97   QString _category, _title;
98   bool _changed;
99 };
100
101
102
103 #endif