-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiqthemes.cpp
375 lines (307 loc) · 8.93 KB
/
iqthemes.cpp
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
/*
* This file is part of IQ Notifier.
*
* IQ Notifier 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
* any later version.
*
* IQ Notifier 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 IQ Notifier. If not, see <http://www.gnu.org/licenses/>.
*/
#include "iqthemes.h"
#include <QApplication>
#include <QScreen>
#include <QtQml/qqml.h>
namespace
{
static QRect availableGeometry()
{
QScreen *screen = QApplication::screens().at(0);
return screen->availableGeometry();
}
} // anonymouse namespace
IQThemes::IQThemes()
: config{"theme"},
themeName{
config.value(CONFIG_THEME_NAME, CONFIG_THEME_NAME_DEFAULT).toString()}
{
registerThemeTypes();
loadTheme(themeConfigFile());
auto themeDir = IQConfig::configDir() + '/' + themeConfigDir();
notificationsTheme_ =
std::make_unique<NotificationsTheme>(themeConfig, themeDir);
trayIconTheme_ = std::make_unique<TrayIconTheme>(themeConfig, themeDir);
historyWindowTheme_ =
std::make_unique<HistoryWindowTheme>(themeConfig, themeDir);
}
NotificationsTheme *IQThemes::notificationsTheme() const
{
return notificationsTheme_.get();
}
TrayIconTheme *IQThemes::trayIconTheme() const { return trayIconTheme_.get(); }
HistoryWindowTheme *IQThemes::historyWindowTheme() const
{
return historyWindowTheme_.get();
}
QString IQThemes::themeConfigDir() const { return "themes/" + themeName; }
QString IQThemes::themeConfigFile() const
{
return themeConfigDir() + "/theme";
}
void IQThemes::loadTheme(const QString &fileName)
{
themeConfig = std::make_shared<IQConfig>(QString{}, fileName);
}
void IQThemes::registerThemeTypes() const
{
qmlRegisterType<NotificationsTheme>("IQNotifier", 1, 0,
"NotificationsTheme");
qmlRegisterType<TrayIconTheme>("IQNotifier", 1, 0, "TrayIconTheme");
qmlRegisterType<HistoryWindowTheme>("IQNotifier", 1, 0,
"HistoryWindowTheme");
}
IQTheme::IQTheme(const std::shared_ptr<IQConfig> &config_,
const QString &themeDir_, QObject *parent)
: QObject(parent), themeConfig{config_}, themeDir{themeDir_}
{
}
QUrl IQTheme::toRelativeUrl(const QString &str) const
{
return "file:///" + themeDir + '/' + str;
}
/*
*
* THEMES NEXT
*
*/
#define IQ_THEME_UINT(KEY__) themeConfig->value(KEY__, KEY__##_DEFAULT).toUInt()
#define IQ_THEME_DOUBLE(KEY__) \
themeConfig->value(KEY__, KEY__##_DEFAULT).toDouble()
#define IQ_THEME_STRING(KEY__) \
themeConfig->value(KEY__, KEY__##_DEFAULT).toString()
#define IQ_THEME_COLOR(KEY__) IQ_THEME_STRING(KEY__)
#define IQ_THEME_IMAGE(KEY__) \
auto str = IQ_THEME_STRING(KEY__); \
if (str == KEY__##_DEFAULT) \
return str; \
auto url = toRelativeUrl(str); \
if (url.isValid()) \
return url; \
else \
return QString{KEY__##_DEFAULT};
bool NotificationsTheme::iconPosition() const
{
auto pos =
themeConfig
->value(CONFIG_ICON_POSITION, CONFIG_ICON_POSITION_DEFAULT)
.toString();
return pos.compare("left", Qt::CaseInsensitive) == 0;
}
uint NotificationsTheme::fontSize() const
{
return IQ_THEME_UINT(CONFIG_FONT_SIZE);
}
uint NotificationsTheme::barFontSize() const
{
return IQ_THEME_UINT(CONFIG_BAR_FONT_SIZE);
}
uint NotificationsTheme::iconSize() const
{
return IQ_THEME_UINT(CONFIG_ICON_SIZE);
}
uint NotificationsTheme::barHeight() const
{
return IQ_THEME_UINT(CONFIG_BAR_HEIGHT);
}
uint NotificationsTheme::expirationBarHeight() const
{
return IQ_THEME_UINT(CONFIG_EXPIRATION_BAR_HEIGHT);
}
uint NotificationsTheme::showAnimationDuration() const
{
return IQ_THEME_UINT(CONFIG_SHOW_DURATION);
}
uint NotificationsTheme::dropAnimationDuration() const
{
return IQ_THEME_UINT(CONFIG_DROP_DURATION);
}
double NotificationsTheme::closeButtonImageScale() const
{
return IQ_THEME_DOUBLE(CONFIG_CLOSE_BUTTON_IMAGE_SCALE);
}
double NotificationsTheme::extraButtonImageScale() const
{
return IQ_THEME_DOUBLE(CONFIG_EXTRA_BUTTON_IMAGE_SCALE);
}
QColor NotificationsTheme::bgColor() const
{
return IQ_THEME_COLOR(CONFIG_BG_COLOR);
}
QColor NotificationsTheme::barBgColor() const
{
return IQ_THEME_COLOR(CONFIG_BAR_BG_COLOR);
}
QColor NotificationsTheme::barTextColor() const
{
return IQ_THEME_COLOR(CONFIG_BAR_TEXT_COLOR);
}
QColor NotificationsTheme::expirationBarColor() const
{
return IQ_THEME_COLOR(CONFIG_EXPIRATION_BAR_COLOR);
}
QColor NotificationsTheme::titleTextColor() const
{
return IQ_THEME_COLOR(CONFIG_TITLE_TEXT_COLOR);
}
QColor NotificationsTheme::bodyTextColor() const
{
return IQ_THEME_COLOR(CONFIG_BODY_TEXT_COLOR);
}
QColor NotificationsTheme::buttonBgColor() const
{
return IQ_THEME_COLOR(CONFIG_BUTTON_BG_COLOR);
}
QColor NotificationsTheme::buttonTextColor() const
{
return IQ_THEME_COLOR(CONFIG_BUTTON_TEXT_COLOR);
}
QColor NotificationsTheme::extraBgColor() const
{
return IQ_THEME_COLOR(CONFIG_EXTRA_BG_COLOR);
}
QColor NotificationsTheme::extraUreadCircleColor() const
{
return IQ_THEME_COLOR(CONFIG_EXTRA_UNREAD_CIRCLE_COLOR);
}
QColor NotificationsTheme::extraUreadTextColor() const
{
return IQ_THEME_COLOR(CONFIG_EXTRA_UNREAD_TEXT_COLOR);
}
QUrl NotificationsTheme::bgImage() const { IQ_THEME_IMAGE(CONFIG_BG_IMAGE) }
QUrl NotificationsTheme::closeButtonImage() const
{
IQ_THEME_IMAGE(CONFIG_CLOSE_BUTTON_IMAGE)
}
QUrl NotificationsTheme::extraCloseButtonImage() const
{
IQ_THEME_IMAGE(CONFIG_EXTRA_CLOSE_BUTTON_IMAGE)
}
QUrl NotificationsTheme::extraCloseAllButtonImage() const
{
IQ_THEME_IMAGE(CONFIG_EXTRA_CLOSE_ALL_BUTTON_IMAGE)
}
QUrl NotificationsTheme::extraCloseVisibleButtonImage() const
{
IQ_THEME_IMAGE(CONFIG_EXTRA_CLOSE_VISIBLE_BUTTON_IMAGE)
}
QUrl TrayIconTheme::icon() const { IQ_THEME_IMAGE(CONFIG_ICON) }
QUrl HistoryWindowTheme::closeIcon() const { IQ_THEME_IMAGE(CONFIG_CLOSE_ICON) }
QUrl HistoryWindowTheme::bgImage() const { IQ_THEME_IMAGE(CONFIG_BG_IMAGE) }
QString HistoryWindowTheme::windowTitle() const
{
return IQ_THEME_STRING(CONFIG_WINDOW_TITLE);
}
uint HistoryWindowTheme::x() const
{
switch (windowPosition()) {
case LEFT_BOT:
case LEFT_TOP:
return availableGeometry().left();
break;
case RIGHT_BOT:
case RIGHT_TOP:
return availableGeometry().x() + availableGeometry().width() -
width();
break;
default:
break;
}
return IQ_THEME_UINT(CONFIG_X);
}
uint HistoryWindowTheme::y() const
{
switch (windowPosition()) {
case RIGHT_TOP:
case LEFT_TOP:
return availableGeometry().top();
break;
case RIGHT_BOT:
case LEFT_BOT:
return availableGeometry().y() + availableGeometry().height() -
height();
break;
default:
break;
}
return IQ_THEME_UINT(CONFIG_Y);
}
uint HistoryWindowTheme::height() const { return IQ_THEME_UINT(CONFIG_HEIGHT); }
uint HistoryWindowTheme::width() const { return IQ_THEME_UINT(CONFIG_WIDTH); }
uint HistoryWindowTheme::barHeight() const
{
return IQ_THEME_UINT(CONFIG_BAR_HEIGHT);
}
uint HistoryWindowTheme::notificationHeight() const
{
return IQ_THEME_UINT(CONFIG_NOTIFICATION_HEIGHT);
}
uint HistoryWindowTheme::barFontSize() const
{
return IQ_THEME_UINT(CONFIG_BAR_FONT_SIZE);
}
uint HistoryWindowTheme::nappFontSize() const
{
return IQ_THEME_UINT(CONFIG_NAPP_FONT_SIZE);
}
uint HistoryWindowTheme::ntitleFontSize() const
{
return IQ_THEME_UINT(CONFIG_NTITLE_FONT_SIZE);
}
uint HistoryWindowTheme::nbodyFontSize() const
{
return IQ_THEME_UINT(CONFIG_NBODY_FONT_SIZE);
}
QString HistoryWindowTheme::bgColor() const
{
return IQ_THEME_STRING(CONFIG_BG_COLOR);
}
QString HistoryWindowTheme::barBgColor() const
{
return IQ_THEME_STRING(CONFIG_BAR_BG_COLOR);
}
QString HistoryWindowTheme::barTextColor() const
{
return IQ_THEME_STRING(CONFIG_BAR_TEXT_COLOR);
}
QString HistoryWindowTheme::nbgColor() const
{
return IQ_THEME_STRING(CONFIG_NBG_COLOR);
}
QString HistoryWindowTheme::nappTextColor() const
{
return IQ_THEME_STRING(CONFIG_NAPP_TEXT_COLOR);
}
QString HistoryWindowTheme::ntitleTextColor() const
{
return IQ_THEME_STRING(CONFIG_NTITLE_TEXT_COLOR);
}
QString HistoryWindowTheme::nbodyTextColor() const
{
return IQ_THEME_STRING(CONFIG_NBODY_TEXT_COLOR);
}
HistoryWindowTheme::pos_t HistoryWindowTheme::windowPosition() const
{
return static_cast<HistoryWindowTheme::pos_t>(
IQ_THEME_UINT(CONFIG_WINDOW_POSITION));
}
#undef IQ_THEME_IMAGE
#undef IQ_THEME_STRING
#undef IQ_THEME_COLOR
#undef IQ_THEME_DOUBLE
#undef IQ_THEME_UINT