1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #ifndef _SETTINGSPAGE_H_
22 #define _SETTINGSPAGE_H_
28 //! A SettingsPage is a page in the settings dialog.
29 /** The SettingsDlg provides suitable standard buttons, such as Ok, Apply, Cancel, Restore Defaults and Reset.
30 * Some pages might also be used in standalone dialogs or other containers. A SettingsPage provides suitable
31 * slots and signals to allow interaction with the container.
33 class SettingsPage : public QWidget {
37 SettingsPage(const QString &category, const QString &name, QWidget *parent = 0);
38 virtual ~SettingsPage() {};
40 //! The category of this settings page.
41 inline virtual QString category() const { return _category; }
43 //! The title of this settings page.
44 inline virtual QString title() const { return _title; }
46 //! Derived classes need to define this and return true if they have default settings.
47 /** If this method returns true, the "Restore Defaults" button in the SettingsDlg is
48 * enabled. You also need to provide an implementation of defaults() then.
50 * The default implementation returns false.
52 inline virtual bool hasDefaults() const { return false; }
54 //! Check if there are changes in the page, compared to the state saved in permanent storage.
55 inline bool hasChanged() const { return _changed; }
57 //! Called immediately before save() is called.
58 /** Derived classes should return false if saving is not possible (e.g. the current settings are invalid).
59 * \return false, if the SettingsPage cannot be saved in its current state.
61 inline virtual bool aboutToSave() { return true; }
63 //! sets checked state depending on \checked and stores the value for later comparision
64 static void load(QCheckBox *box, bool checked);
65 static bool hasChanged(QCheckBox *box);
68 //! Save settings to permanent storage.
69 virtual void save() = 0;
71 //! Load settings from permanent storage, overriding any changes the user might have made in the dialog.
72 virtual void load() = 0;
74 //! Restore defaults, overriding any changes the user might have made in the dialog.
75 /** The default implementation does nothing.
77 inline virtual void defaults() {}
80 //! Calling this slot is equivalent to calling setChangedState(true).
81 inline void changed() { setChangedState(true); }
83 //! This should be called whenever the widget state changes from unchanged to change or the other way round.
84 void setChangedState(bool hasChanged = true);
87 //! Emitted whenever the widget state changes.
88 void changed(bool hasChanged);
91 QString _category, _title;