makeversion: Fix permission problem with version.cpp
[skype-call-recorder.git] / smartwidgets.h
blobf2dd2b4e728e9197a76c88367831597e354ea4ca
1 /*
2 Skype Call Recorder
3 Copyright (C) 2008 jlh (jlh at gmx dot ch)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2 of the License, version 3 of
8 the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 The GNU General Public License version 2 is included with the source of
20 this program under the file name COPYING. You can also get a copy on
21 http://www.fsf.org/
24 #ifndef SMARTWIDGETS_H
25 #define SMARTWIDGETS_H
27 #include <QRadioButton>
28 #include <QCheckBox>
29 #include <QLineEdit>
30 #include <QComboBox>
31 #include "preferences.h"
33 // Smart widgets that automatically load preferences and set them
35 // Note: Smart widgets that need to be set up with addItem()/insertItem() can
36 // not automatically load the current preference. you need to call setupDone()
37 // on them after you set them up, so they load the current preference and make the
38 // widget reflect that.
40 class SmartRadioButton : public QRadioButton {
41 Q_OBJECT
42 public:
43 SmartRadioButton(const QString &label, Preference &p, const char *v) : QRadioButton(label), preference(p), value(v) {
44 setChecked(preference.toString() == value);
45 connect(this, SIGNAL(toggled(bool)), this, SLOT(set(bool)));
48 private slots:
49 void set(bool active) { if (active) preference.set(value); }
51 private:
52 Preference &preference;
53 const char * const value;
56 // --------
58 class SmartCheckBox : public QCheckBox {
59 Q_OBJECT
60 public:
61 SmartCheckBox(const QString &label, Preference &p) : QCheckBox(label), preference(p) {
62 setChecked(preference.toBool());
63 connect(this, SIGNAL(toggled(bool)), this, SLOT(set(bool)));
66 private slots:
67 void set(bool active) { preference.set(active); }
69 private:
70 Preference &preference;
73 // --------
75 class SmartLineEdit : public QLineEdit {
76 Q_OBJECT
77 public:
78 SmartLineEdit(Preference &p) : preference(p) {
79 setText(preference.toString());
80 connect(this, SIGNAL(editingFinished()), this, SLOT(set()));
83 private slots:
84 void set() { preference.set(text()); }
86 private:
87 Preference &preference;
90 // --------
92 class SmartComboBox : public QComboBox {
93 Q_OBJECT
94 public:
95 SmartComboBox(Preference &p) : preference(p) { }
96 void setupDone() {
97 int i = findData(preference.toString());
98 if (i < 0)
99 // TODO: what to do here?
100 return;
101 setCurrentIndex(i);
102 connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(set(int)));
105 private slots:
106 void set(int i) {
107 QVariant v = itemData(i);
108 if (v.type() == QVariant::Int)
109 preference.set(v.toInt());
110 else
111 preference.set(v.toString());
114 private:
115 Preference &preference;
118 // --------
120 class SmartEditableComboBox : public QComboBox {
121 Q_OBJECT
122 public:
123 SmartEditableComboBox(Preference &p) : preference(p) {
124 setEditable(true);
125 lineEdit()->setText(preference.toString());
127 // qt 4.3.2 would overwrite any text set in the constructor, during the
128 // first call to addItem
129 void setupDone() {
130 lineEdit()->setText(preference.toString());
131 connect(lineEdit(), SIGNAL(editingFinished()), this, SLOT(set()));
134 private slots:
135 void set() { preference.set(lineEdit()->text()); }
137 private:
138 Preference &preference;
141 #endif