1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, http://www.bibletime.info/.
6 *
7 * Copyright 1999-2016 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "btstyle.h"
14 #include <QGuiApplication>
15 #include <QList>
16 #include <QPointer>
17 #include <QScreen>
18 #include "backend/config/btconfig.h"
19 #include "backend/models/btmoduletextmodel.h"
20 
21 // BtStyle is a class that is registered at a QML item. It can be placed into
22 // QML files and its properties are available to be used in QML. It contains
23 // colors, sizes, etc. that affect the look of the UI. You can have multipe
24 // instances of the item. Changing a property on one of them changes all of them
25 /*
26    import BibleTime 1.0
27 
28     BtStyle {
29        id: btStyle
30     }
31 
32     Rectangle {
33         color: btStyle.button
34     }
35 */
36 
37 namespace btm {
38 
39 // Only one copy of properties so they are the same everywhere used.
40 static QColor textColor               = QColor();
41 static QColor linkColor               = QColor();
42 static QColor textBackgroundColor     = QColor();
43 static QColor textBackgroundHighlightColor= QColor();
44 
45 static QColor buttonColor             = QColor();
46 static QColor buttonBackground        = QColor();
47 static QColor buttonTextColor         = QColor();
48 static QColor buttonHighlightedText   = QColor();
49 static QColor buttonBorder            = QColor();
50 static int buttonRadius               = 0;
51 static QColor buttonGradient0;
52 static QColor buttonGradient1;
53 static QColor buttonGradient2;
54 static QColor buttonGradient3;
55 
56 static QColor windowTab               = QColor();
57 static QColor windowTabSelected       = QColor();
58 static QColor windowTabText           = QColor();
59 static QColor windowTabTextSelected   = QColor();
60 
61 static QColor menu                    = QColor();
62 static QColor menuBorder              = QColor();
63 static QColor menuText                = QColor();
64 static int menuHeight                 = 0;
65 
66 static QColor toolbarColor            = QColor();
67 static QColor toolbarTextColor        = QColor();
68 static QColor toolbarButtonText       = QColor();
69 static double toolbarTextPointSize    = 6;
70 
71 int currentStyle = BtStyle::darkTheme;
72 
73 static QList<QPointer<BtStyle> > styles;
74 
75 static double millimeterPerInch = 25.4;
76 
emitChanged()77 static void emitChanged() {
78     for (int i=0; i<styles.count(); ++i) {
79         QPointer<BtStyle> style = styles.at(i);
80         if (style != nullptr)
81             style->changed();
82     }
83 }
84 
getCurrentStyle()85 int BtStyle::getCurrentStyle() {
86     return currentStyle;
87 }
88 
setStyle(int style)89 void BtStyle::setStyle(int style) {
90     setCurrentStyle(style);
91     emitChanged();
92 }
93 
setCurrentStyle(int style)94 void BtStyle::setCurrentStyle(int style) {
95     if (style == BtStyle::darkTheme) {
96 
97         currentStyle = style;
98 
99         BtModuleTextModel::setLinkColor(QColor(0,191,255));
100         BtModuleTextModel::setHighlightColor(QColor(255,255,0));
101         BtModuleTextModel::setJesusWordsColor(QColor(255,0,0));
102 
103         setTextColor(QColor(255,255,255));
104         setLinkColor(QColor(0,0,80));
105         setTextBackgroundColor(QColor(0,0,0));
106         setTextBackgroundHighlightColor(QColor(184,135,11));
107 
108         setButtonColor(QColor(0,0,0));
109         setButtonBackground(QColor(35,35,100));
110         setButtonTextColor(QColor(255,210,0));
111         setButtonHighlightedText(QColor(255,255,0));
112         setButtonBorder(QColor(110,110,110));
113         setButtonRadius(3);
114         setButtonGradient0(QColor(125,125,125));
115         setButtonGradient1(QColor(60,60,60));
116         setButtonGradient2(QColor(50,50,50));
117         setButtonGradient3(QColor(20,20,20));
118 
119         setWindowTab(QColor(100,100,100));
120         setWindowTabSelected(QColor(218,165,3));
121         setWindowTabText(QColor(255,255,255));
122         setWindowTabTextSelected(QColor(0,0,0));
123 
124         setMenu(QColor(255,255,255));
125         setMenuBorder(QColor(60,60,60));
126         setMenuText(QColor(0,0,0));
127         setMenuHeight(34);
128 
129         setToolbarColor(QColor(0,0,0));
130         setToolbarTextColor(QColor(218,165,3));
131         setToolbarButtonText(QColor(255,255,255));
132         setToolbarTextPointSize(10);
133     }
134     else if (style == BtStyle::lightBlueTheme) {
135 
136         currentStyle = style;
137 
138         BtModuleTextModel::setLinkColor(QColor(0,0,255));
139         BtModuleTextModel::setHighlightColor(QColor(0,0,255));
140         BtModuleTextModel::setJesusWordsColor(QColor(255,0,0));
141 
142         setTextColor(QColor(0,0,0));
143         setLinkColor(QColor(0,0,220));
144         setTextBackgroundColor(QColor(255,255,255));
145         setTextBackgroundHighlightColor(QColor(255,240,170));
146 
147         setButtonColor(QColor(0,0,0));
148         setButtonBackground(QColor(190,220,255));
149         setButtonTextColor(QColor(0,0,0));
150         setButtonHighlightedText(QColor(0,0,255));
151         setButtonBorder(QColor(80,80,0));
152         setButtonRadius(3);
153         setButtonGradient0(QColor(180,180,255));
154         setButtonGradient1(QColor(255,255,255));
155         setButtonGradient2(QColor(255,255,255));
156         setButtonGradient3(QColor(180,180,255));
157 
158         setWindowTab(QColor(245,245,245));
159         setWindowTabSelected(QColor(65,105,225));
160         setWindowTabText(QColor(100,100,100));
161         setWindowTabTextSelected(QColor(255,255,255));
162 
163         setMenu(QColor(255,255,255));
164         setMenuBorder(QColor(220,220,220));
165         setMenuText(QColor(0,0,0));
166         setMenuHeight(40);
167 
168         setToolbarColor(QColor(190,220,255));
169         setToolbarTextColor(QColor(0,0,0));
170         setToolbarButtonText(QColor(0,0,0));
171         setToolbarTextPointSize(10);
172     }
173     else if (style == BtStyle::crimsonTheme) {
174 
175         currentStyle = style;
176 
177         BtModuleTextModel::setLinkColor(QColor(0,0,255));
178         BtModuleTextModel::setHighlightColor(QColor(0,0,255));
179         BtModuleTextModel::setJesusWordsColor(QColor(170,0,0));
180 
181         setTextColor(QColor(0,0,0));
182         setLinkColor(QColor(0,0,220));
183         setTextBackgroundColor(QColor(255,255,255));
184         setTextBackgroundHighlightColor(QColor(255,240,170));
185 
186         setButtonColor(QColor(0,0,0));
187         setButtonBackground(QColor(190,220,255));
188         setButtonTextColor(QColor(0,0,0));
189         setButtonHighlightedText(QColor(0,0,255));
190         setButtonBorder(QColor(80,80,0));
191         setButtonRadius(3);
192         setButtonGradient0(QColor(180,180,255));
193         setButtonGradient1(QColor(255,255,255));
194         setButtonGradient2(QColor(255,255,255));
195         setButtonGradient3(QColor(180,180,255));
196 
197         setWindowTab(QColor(245,245,245));
198         setWindowTabSelected(QColor(218,165,3));
199         setWindowTabText(QColor(100,100,100));
200         setWindowTabTextSelected(QColor(0,0,0));
201 
202         setMenu(QColor(255,255,255));
203         setMenuBorder(QColor(220,220,220));
204         setMenuText(QColor(0,0,0));
205         setMenuHeight(40);
206 
207         setToolbarColor(QColor(99,0,0));
208         setToolbarTextColor(QColor(255,255,255));
209         setToolbarButtonText(QColor(0,0,0));
210         setToolbarTextPointSize(10);
211     }
212 }
213 
BtStyle(QObject * parent)214 BtStyle::BtStyle(QObject* parent)
215     : QObject(parent) {
216     styles.append(this);
217 }
218 
getTextColor()219 QColor BtStyle::getTextColor() {
220     return textColor;
221 }
setTextColor(const QColor & color)222 void BtStyle::setTextColor(const QColor& color) {
223     textColor = color;
224     emitChanged();
225 }
226 
227 
getLinkColor()228 QColor BtStyle::getLinkColor() {
229     return linkColor;
230 }
setLinkColor(const QColor & color)231 void BtStyle::setLinkColor(const QColor& color) {
232     linkColor = color;
233     emitChanged();
234 }
235 
236 
getTextBackgroundColor()237 QColor BtStyle::getTextBackgroundColor() {
238     return textBackgroundColor;
239 }
setTextBackgroundColor(const QColor & color)240 void BtStyle::setTextBackgroundColor(const QColor& color) {
241     textBackgroundColor = color;
242     emitChanged();
243 }
244 
245 
getTextBackgroundHighlightColor()246 QColor BtStyle::getTextBackgroundHighlightColor() {
247     return textBackgroundHighlightColor;
248 }
setTextBackgroundHighlightColor(const QColor & color)249 void BtStyle::setTextBackgroundHighlightColor(const QColor& color) {
250     textBackgroundHighlightColor = color;
251     emitChanged();
252 }
253 
254 
getButtonColor()255 QColor BtStyle::getButtonColor() {
256     return buttonColor;
257 }
setButtonColor(const QColor & color)258 void BtStyle::setButtonColor(const QColor& color) {
259     buttonColor = color;
260     emitChanged();
261 }
262 
263 
getButtonBackground()264 QColor BtStyle::getButtonBackground() {
265     return buttonBackground;
266 }
setButtonBackground(const QColor & color)267 void BtStyle::setButtonBackground(const QColor& color) {
268     buttonBackground = color;
269     emitChanged();
270 }
271 
272 
getButtonTextColor()273 QColor BtStyle::getButtonTextColor() {
274     return buttonTextColor;
275 }
setButtonTextColor(const QColor & color)276 void BtStyle::setButtonTextColor(const QColor& color) {
277     buttonTextColor = color;
278     emitChanged();
279 }
280 
281 
getButtonHighlightedText()282 QColor BtStyle::getButtonHighlightedText() {
283     return buttonHighlightedText;
284 }
setButtonHighlightedText(const QColor & color)285 void BtStyle::setButtonHighlightedText(const QColor& color) {
286     buttonHighlightedText = color;
287     emitChanged();
288 }
289 
290 
getButtonBorder()291 QColor BtStyle::getButtonBorder() {
292     return buttonBorder;
293 }
setButtonBorder(const QColor & color)294 void BtStyle::setButtonBorder(const QColor& color) {
295     buttonBorder = color;
296     emitChanged();
297 }
298 
getButtonRadius()299 int BtStyle::getButtonRadius() {
300     return buttonRadius;
301 }
setButtonRadius(int radius)302 void BtStyle::setButtonRadius(int radius) {
303     buttonRadius = radius;
304     emitChanged();
305 }
306 
getButtonGradient0()307 QColor BtStyle::getButtonGradient0() {
308     return buttonGradient0;
309 }
setButtonGradient0(const QColor & color)310 void BtStyle::setButtonGradient0(const QColor& color) {
311     buttonGradient0 = color;
312     emitChanged();
313 }
314 
getButtonGradient1()315 QColor BtStyle::getButtonGradient1() {
316     return buttonGradient1;
317 }
setButtonGradient1(const QColor & color)318 void BtStyle::setButtonGradient1(const QColor& color) {
319     buttonGradient1 = color;
320     emitChanged();
321 }
322 
getButtonGradient2()323 QColor BtStyle::getButtonGradient2() {
324     return buttonGradient2;
325 }
setButtonGradient2(const QColor & color)326 void BtStyle::setButtonGradient2(const QColor& color) {
327     buttonGradient2 = color;
328     emitChanged();
329 }
330 
getButtonGradient3()331 QColor BtStyle::getButtonGradient3() {
332     return buttonGradient3;
333 }
setButtonGradient3(const QColor & color)334 void BtStyle::setButtonGradient3(const QColor& color) {
335     buttonGradient3 = color;
336     emitChanged();
337 }
338 
getWindowTab()339 QColor BtStyle::getWindowTab() {
340     return windowTab;
341 }
342 
setWindowTab(const QColor & color)343 void BtStyle::setWindowTab(const QColor& color) {
344     windowTab = color;
345     emitChanged();
346 }
347 
getWindowTabSelected()348 QColor BtStyle::getWindowTabSelected() {
349     return windowTabSelected;
350 }
351 
setWindowTabSelected(const QColor & color)352 void BtStyle::setWindowTabSelected(const QColor& color) {
353     windowTabSelected = color;
354     emitChanged();
355 }
356 
getWindowTabText()357 QColor BtStyle::getWindowTabText() {
358     return windowTabText;
359 }
360 
setWindowTabText(const QColor & color)361 void BtStyle::setWindowTabText(const QColor& color) {
362     windowTabText = color;
363     emitChanged();
364 }
365 
getWindowTabTextSelected()366 QColor BtStyle::getWindowTabTextSelected() {
367     return windowTabTextSelected;
368 }
369 
setWindowTabTextSelected(const QColor & color)370 void BtStyle::setWindowTabTextSelected(const QColor& color) {
371     windowTabTextSelected = color;
372     emitChanged();
373 }
374 
getMenu()375 QColor BtStyle::getMenu() {
376     return menu;
377 }
378 
setMenu(const QColor & color)379 void BtStyle::setMenu(const QColor& color) {
380     menu = color;
381     emitChanged();
382 }
383 
getMenuBorder()384 QColor BtStyle::getMenuBorder() {
385     return menuBorder;
386 }
387 
setMenuBorder(const QColor & color)388 void BtStyle::setMenuBorder(const QColor& color) {
389     menuBorder = color;
390     emitChanged();
391 }
392 
getMenuText()393 QColor BtStyle::getMenuText() {
394     return menuText;
395 }
396 
setMenuText(const QColor & color)397 void BtStyle::setMenuText(const QColor& color) {
398     menuText = color;
399     emitChanged();
400 }
401 
getMenuHeight()402 int BtStyle::getMenuHeight() {
403     return menuHeight;
404 }
setMenuHeight(int height)405 void BtStyle::setMenuHeight(int height) {
406     menuHeight = height;
407     emitChanged();
408 }
409 
getToolbarColor()410 QColor BtStyle::getToolbarColor() {
411     return toolbarColor;
412 }
setToolbarColor(const QColor & color)413 void BtStyle::setToolbarColor(const QColor& color) {
414     toolbarColor = color;
415     emitChanged();
416 }
417 
getToolbarTextColor()418 QColor BtStyle::getToolbarTextColor() {
419     return toolbarTextColor;
420 }
setToolbarTextColor(const QColor & color)421 void BtStyle::setToolbarTextColor(const QColor& color) {
422     toolbarTextColor = color;
423     emitChanged();
424 }
425 
getToolbarButtonText()426 QColor BtStyle::getToolbarButtonText() {
427     return toolbarButtonText;
428 }
setToolbarButtonText(const QColor & color)429 void BtStyle::setToolbarButtonText(const QColor& color) {
430     toolbarButtonText = color;
431     emitChanged();
432 }
433 
getToolbarTextPointSize()434 double BtStyle::getToolbarTextPointSize() {
435     return toolbarTextPointSize;
436 }
437 
setToolbarTextPointSize(double pointSize)438 void BtStyle::setToolbarTextPointSize(double pointSize) {
439     toolbarTextPointSize = pointSize;
440     emitChanged();
441 }
442 
getUiFontPointSize()443 double BtStyle::getUiFontPointSize() {
444     return btConfig().value<int>("ui/uiFontSize",18);
445 }
446 
setUiFontPointSize(double pointSize)447 void BtStyle::setUiFontPointSize(double pointSize) {
448     btConfig().setValue<int>("ui/uiFontSize", pointSize);
449     emitChanged();
450 }
451 
pixelsPerMillimeterX()452 int BtStyle::pixelsPerMillimeterX() {
453     QScreen* screen = QGuiApplication::screens().at(0);
454     return screen->physicalDotsPerInchX() / millimeterPerInch;
455 }
456 
pixelsPerMillimeterY()457 int BtStyle::pixelsPerMillimeterY() {
458     QScreen* screen = QGuiApplication::screens().at(0);
459     int dpm = screen->physicalDotsPerInchY() / millimeterPerInch;
460     return dpm;
461 }
462 
getAppVersion()463 QString BtStyle::getAppVersion() {
464     return  "1.09";
465 }
466 
getGitVersion() const467 QString BtStyle::getGitVersion() const {
468 #ifdef BT_GIT_VERSION
469     return  BT_GIT_VERSION;
470 #else
471     return "";
472 #endif
473 }
474 
getQtVersion() const475 QString BtStyle::getQtVersion() const {
476     QString version =  qVersion();
477         return  version;
478 }
479 
getSwordVersion() const480 QString BtStyle::getSwordVersion() const {
481     QString version(sword::SWVersion::currentVersion.getText());
482     return  version;
483 }
484 
485 } // end namespace
486 
487