-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.h
executable file
·167 lines (127 loc) · 4.55 KB
/
settings.h
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
/*
* Copyright 2012 Yury Makarevich
*
* This file is part of Tomodoro.
*
* Tomodoro 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 3 of the License, or
* (at your option) any later version.
*
* Tomodoro 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 Tomodoro. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QSettings>
#include <QWidget>
//
// Some cool useful macros
//
#define SETTING_NAMES \
SETTING_NAME(interval); \
SETTING_NAME(default_view); \
SETTING_NAME(op_normal); \
SETTING_NAME(op_focused); \
SETTING_NAME(buzz_int); \
SETTING_NAME(buzz_dev); \
SETTING_NAME(text_size); \
SETTING_NAME(main_dir); \
SETTING_NAME(inverted); \
SETTING_NAME(border); \
SETTING_NAME(filling); \
SETTING_NAME(text_border); \
SETTING_NAME(text_filling); \
SETTING_NAME(text_color); \
SETTING_NAME(pie_radius); \
SETTING_NAME(pie_grow_dir); \
SETTING_NAME(bar_length); \
SETTING_NAME(bar_width);
#define VIEW_COLORS \
VIEW_COLOR("Border", border); \
VIEW_COLOR("Filling", filling); \
VIEW_COLOR("Text", text_color); \
VIEW_COLOR("Text border", text_border); \
VIEW_COLOR("Text filling", text_filling);
class Settings : public QObject
{
Q_OBJECT
private:
#define SETTING_NAME(name) static const char name_ ## name[];
SETTING_NAMES
#undef SETTING_NAME
public:
explicit Settings(QObject *parent = 0) : QObject(parent) {
}
template<const char* name>
class StrRef {
public:
operator QString() const {
return QSettings().value(name, "").toString();
}
StrRef& operator = (QString i) {
QSettings().setValue(name, i);
return *this;
}
};
template<const char* name, int deflt = 0>
class IntRef {
public:
operator int() const {
return QSettings().value(name, deflt).toInt();
}
IntRef& operator = (int i) {
QSettings().setValue(name, i);
return *this;
}
};
template<const char* name, int deflt_nom = 0, int deflt_denom = 1>
class RealRef {
public:
operator qreal() const {
return QSettings().value(name, static_cast<qreal>(deflt_nom) / deflt_denom).toReal();
}
RealRef& operator = (qreal v) {
QSettings().setValue(name, v);
return *this;
}
};
/////
QColor defaultToText(const QWidget* w, QColor c) const {
return c.isValid() ? c : w->palette().text().color();
}
QColor defaultToButton(const QWidget* w, QColor c) const {
return c.isValid() ? c : w->palette().button().color();
}
///////
IntRef<name_interval, 25 * 60> interval;
IntRef<name_default_view, 0> default_view;
struct {
IntRef<name_op_normal, 50> op_normal;
IntRef<name_op_focused, 80> op_focused;
IntRef<name_buzz_int, 30> buzz_int;
IntRef<name_buzz_dev, 5> buzz_dev;
IntRef<name_text_size, 12> text_size;
IntRef<name_main_dir, 0> main_dir; // main direction (0 - top, 1 - right, 2 - bottom, 3 - left)
IntRef<name_inverted, 0> inverted; // waxing (0) or waning (1)
StrRef<name_border> border;
StrRef<name_filling> filling;
StrRef<name_text_border> text_border;
StrRef<name_text_filling> text_filling;
StrRef<name_text_color> text_color;
} view;
struct {
IntRef<name_pie_radius, 100> radius;
IntRef<name_pie_grow_dir, 0> grow_dir; // clockwise (1) or counterclockwise (0)
} pie;
struct {
IntRef<name_bar_length, 100> length;
IntRef<name_bar_width, 20> width;
} bar;
};
#endif // SETTINGS_H