1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 or (at your option) any later version
20 ** approved by the KDE Free Qt Foundation. The licenses are as published by
21 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
22 ** included in the packaging of this file. Please review the following
23 ** information to ensure the GNU General Public License requirements will
24 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25 **
26 ** $QT_END_LICENSE$
27 **
28 ****************************************************************************/
29 
30 #include "thememanager_p.h"
31 #include "q3dtheme_p.h"
32 
33 QT_BEGIN_NAMESPACE_DATAVISUALIZATION
34 
35 const float defaultBuiltInColorLevel = 0.7f; // for built-in gradient themes
36 const float defaultColorLevel = 0.5f; // for built-in uniform themes
37 
ThemeManager(Abstract3DController * controller)38 ThemeManager::ThemeManager(Abstract3DController *controller)
39     : m_activeTheme(0),
40       m_controller(controller)
41 {
42 }
43 
~ThemeManager()44 ThemeManager::~ThemeManager()
45 {
46 }
47 
addTheme(Q3DTheme * theme)48 void ThemeManager::addTheme(Q3DTheme *theme)
49 {
50     Q_ASSERT(theme);
51     ThemeManager *owner = qobject_cast<ThemeManager *>(theme->parent());
52     if (owner != this) {
53         Q_ASSERT_X(!owner, "addTheme", "Theme already attached to a graph.");
54         theme->setParent(this);
55     }
56     if (!m_themes.contains(theme))
57         m_themes.append(theme);
58 }
59 
releaseTheme(Q3DTheme * theme)60 void ThemeManager::releaseTheme(Q3DTheme *theme)
61 {
62     if (theme && m_themes.contains(theme)) {
63         // Clear the default status from released default theme
64         if (theme->d_ptr->isDefaultTheme())
65             theme->d_ptr->setDefaultTheme(false);
66 
67         // If the theme is in use, replace it with a temporary one
68         if (theme == m_activeTheme)
69             setActiveTheme(0);
70 
71         m_themes.removeAll(theme);
72         theme->setParent(0);
73     }
74 }
75 
setActiveTheme(Q3DTheme * theme)76 void ThemeManager::setActiveTheme(Q3DTheme *theme)
77 {
78     // Setting null theme indicates using default theme
79     if (!theme) {
80         theme = new Q3DTheme;
81         theme->d_ptr->setDefaultTheme(true);
82     }
83 
84     // If the old theme is default theme, delete it
85     Q3DTheme *oldTheme = m_activeTheme;
86     if (oldTheme) {
87         if (oldTheme->d_ptr->isDefaultTheme()) {
88             m_themes.removeAll(oldTheme);
89             delete oldTheme;
90             oldTheme = 0;
91         } else {
92             // Disconnect the old theme from use
93             disconnect(m_activeTheme->d_ptr.data(), 0, m_controller, 0);
94             disconnect(m_activeTheme, 0, m_controller, 0);
95         }
96     }
97 
98     // Assume ownership
99     addTheme(theme);
100 
101     m_activeTheme = theme;
102 
103     // Reset all bits to dirty for sync
104     m_activeTheme->d_ptr->resetDirtyBits();
105 
106     // Connect signals from new one
107     connectThemeSignals();
108 }
109 
activeTheme() const110 Q3DTheme *ThemeManager::activeTheme() const
111 {
112     return m_activeTheme;
113 }
114 
themes() const115 QList<Q3DTheme *> ThemeManager::themes() const
116 {
117     return m_themes;
118 }
119 
connectThemeSignals()120 void ThemeManager::connectThemeSignals()
121 {
122     connect(m_activeTheme, &Q3DTheme::colorStyleChanged,
123             m_controller, &Abstract3DController::handleThemeColorStyleChanged);
124     connect(m_activeTheme, &Q3DTheme::baseColorsChanged,
125             m_controller, &Abstract3DController::handleThemeBaseColorsChanged);
126     connect(m_activeTheme, &Q3DTheme::singleHighlightColorChanged,
127             m_controller, &Abstract3DController::handleThemeSingleHighlightColorChanged);
128     connect(m_activeTheme, &Q3DTheme::multiHighlightColorChanged,
129             m_controller, &Abstract3DController::handleThemeMultiHighlightColorChanged);
130     connect(m_activeTheme, &Q3DTheme::baseGradientsChanged,
131             m_controller, &Abstract3DController::handleThemeBaseGradientsChanged);
132     connect(m_activeTheme, &Q3DTheme::singleHighlightGradientChanged,
133             m_controller, &Abstract3DController::handleThemeSingleHighlightGradientChanged);
134     connect(m_activeTheme, &Q3DTheme::multiHighlightGradientChanged,
135             m_controller, &Abstract3DController::handleThemeMultiHighlightGradientChanged);
136     connect(m_activeTheme, &Q3DTheme::typeChanged,
137             m_controller, &Abstract3DController::handleThemeTypeChanged);
138 
139     connect(m_activeTheme->d_ptr.data(), &Q3DThemePrivate::needRender,
140             m_controller, &Abstract3DController::needRender);
141 }
142 
setPredefinedPropertiesToTheme(Q3DTheme * theme,Q3DTheme::Theme type)143 void ThemeManager::setPredefinedPropertiesToTheme(Q3DTheme *theme, Q3DTheme::Theme type)
144 {
145     QList<QColor> baseColors;
146     QList<QLinearGradient> baseGradients;
147     switch (type) {
148     case Q3DTheme::ThemeQt: {
149         baseColors.append(QColor(QRgb(0x80c342)));
150         baseColors.append(QColor(QRgb(0x469835)));
151         baseColors.append(QColor(QRgb(0x006325)));
152         baseColors.append(QColor(QRgb(0x5caa15)));
153         baseColors.append(QColor(QRgb(0x328930)));
154 
155         baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
156         baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
157         baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
158         baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
159         baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
160 
161         setBackgroundEnabled(theme, true);
162         setGridEnabled(theme, true);
163         setFont(theme, QFont(QStringLiteral("Arial")));
164         setLabelBackgroundEnabled(theme, true);
165         setLightColor(theme, Qt::white);
166         setBaseColors(theme, baseColors);
167         setBackgroundColor(theme, QColor(QRgb(0xffffff)));
168         setWindowColor(theme, QColor(QRgb(0xffffff)));
169         setTextColor(theme, QColor(QRgb(0x35322f)));
170         setTextBackgroundColor(theme, QColor(0xff, 0xff, 0xff, 0x99));
171         setGridLineColor(theme, QColor(QRgb(0xd7d6d5)));
172         setSingleHighlightColor(theme, QColor(QRgb(0x14aaff)));
173         setMultiHighlightColor(theme, QColor(QRgb(0x6400aa)));
174         setLightStrength(theme, 5.0f);
175         setAmbientLightStrength(theme, 0.5f);
176         setHighlightLightStrength(theme, 5.0f);
177         setLabelBorderEnabled(theme, true);
178         setColorStyle(theme, Q3DTheme::ColorStyleUniform);
179         setBaseGradients(theme, baseGradients);
180         setSingleHighlightGradient(theme, createGradient(QColor(QRgb(0x14aaff)),
181                                                          defaultColorLevel));
182         setMultiHighlightGradient(theme, createGradient(QColor(QRgb(0x6400aa)),
183                                                         defaultColorLevel));
184         break;
185     }
186 
187     case Q3DTheme::ThemePrimaryColors: {
188         baseColors.append(QColor(QRgb(0xffe400)));
189         baseColors.append(QColor(QRgb(0xfaa106)));
190         baseColors.append(QColor(QRgb(0xf45f0d)));
191         baseColors.append(QColor(QRgb(0xfcba04)));
192         baseColors.append(QColor(QRgb(0xf7800a)));
193 
194         baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
195         baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
196         baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
197         baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
198         baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
199 
200         setBackgroundEnabled(theme, true);
201         setGridEnabled(theme, true);
202         setFont(theme, QFont(QStringLiteral("Arial")));
203         setLabelBackgroundEnabled(theme, true);
204         setLightColor(theme, Qt::white);
205         setBaseColors(theme, baseColors);
206         setBackgroundColor(theme, QColor(QRgb(0xffffff)));
207         setWindowColor(theme, QColor(QRgb(0xffffff)));
208         setTextColor(theme, QColor(QRgb(0x000000)));
209         setTextBackgroundColor(theme, QColor(0xff, 0xff, 0xff, 0x99));
210         setGridLineColor(theme, QColor(QRgb(0xd7d6d5)));
211         setSingleHighlightColor(theme, QColor(QRgb(0x27beee)));
212         setMultiHighlightColor(theme, QColor(QRgb(0xee1414)));
213         setLightStrength(theme, 5.0f);
214         setAmbientLightStrength(theme, 0.5f);
215         setHighlightLightStrength(theme, 5.0f);
216         setLabelBorderEnabled(theme, false);
217         setColorStyle(theme, Q3DTheme::ColorStyleUniform);
218         setBaseGradients(theme, baseGradients);
219         setSingleHighlightGradient(theme, createGradient(QColor(QRgb(0x27beee)),
220                                                          defaultColorLevel));
221         setMultiHighlightGradient(theme, createGradient(QColor(QRgb(0xee1414)),
222                                                         defaultColorLevel));
223         break;
224     }
225 
226     case Q3DTheme::ThemeDigia: {
227         baseColors.append(QColor(QRgb(0xeaeaea)));
228         baseColors.append(QColor(QRgb(0xa0a0a0)));
229         baseColors.append(QColor(QRgb(0x626262)));
230         baseColors.append(QColor(QRgb(0xbebebe)));
231         baseColors.append(QColor(QRgb(0x818181)));
232 
233         baseGradients.append(createGradient(baseColors.at(0), defaultBuiltInColorLevel));
234         baseGradients.append(createGradient(baseColors.at(1), defaultBuiltInColorLevel));
235         baseGradients.append(createGradient(baseColors.at(2), defaultBuiltInColorLevel));
236         baseGradients.append(createGradient(baseColors.at(3), defaultBuiltInColorLevel));
237         baseGradients.append(createGradient(baseColors.at(4), defaultBuiltInColorLevel));
238 
239         setBackgroundEnabled(theme, true);
240         setGridEnabled(theme, true);
241         setFont(theme, QFont(QStringLiteral("Arial")));
242         setLabelBackgroundEnabled(theme, true);
243         setLightColor(theme, Qt::white);
244         setBaseColors(theme, baseColors);
245         setBackgroundColor(theme, QColor(QRgb(0xffffff)));
246         setWindowColor(theme, QColor(QRgb(0xffffff)));
247         setTextColor(theme, QColor(QRgb(0x000000)));
248         setTextBackgroundColor(theme, QColor(0xff, 0xff, 0xff, 0x80));
249         setGridLineColor(theme, QColor(QRgb(0xd7d6d5)));
250         setSingleHighlightColor(theme, QColor(QRgb(0xfa0000)));
251         setMultiHighlightColor(theme, QColor(QRgb(0x333333)));
252         setLightStrength(theme, 5.0f);
253         setAmbientLightStrength(theme, 0.5f);
254         setHighlightLightStrength(theme, 5.0f);
255         setLabelBorderEnabled(theme, false);
256         setColorStyle(theme, Q3DTheme::ColorStyleObjectGradient);
257         setBaseGradients(theme, baseGradients);
258         setSingleHighlightGradient(theme, createGradient(QColor(QRgb(0xfa0000)),
259                                                          defaultBuiltInColorLevel));
260         setMultiHighlightGradient(theme, createGradient(QColor(QRgb(0x333333)),
261                                                         defaultBuiltInColorLevel));
262         break;
263     }
264 
265     case Q3DTheme::ThemeStoneMoss: {
266         baseColors.append(QColor(QRgb(0xbeb32b)));
267         baseColors.append(QColor(QRgb(0x928327)));
268         baseColors.append(QColor(QRgb(0x665423)));
269         baseColors.append(QColor(QRgb(0xa69929)));
270         baseColors.append(QColor(QRgb(0x7c6c25)));
271 
272         baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
273         baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
274         baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
275         baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
276         baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
277 
278         setBackgroundEnabled(theme, true);
279         setGridEnabled(theme, true);
280         setFont(theme, QFont(QStringLiteral("Arial")));
281         setLabelBackgroundEnabled(theme, true);
282         setLightColor(theme, Qt::white);
283         setBaseColors(theme, baseColors);
284         setBackgroundColor(theme, QColor(QRgb(0x4d4d4f)));
285         setWindowColor(theme, QColor(QRgb(0x4d4d4f)));
286         setTextColor(theme, QColor(QRgb(0xffffff)));
287         setTextBackgroundColor(theme, QColor(0x4d, 0x4d, 0x4f, 0xcd));
288         setGridLineColor(theme, QColor(QRgb(0x3e3e40)));
289         setSingleHighlightColor(theme, QColor(QRgb(0xfbf6d6)));
290         setMultiHighlightColor(theme, QColor(QRgb(0x442f20)));
291         setLightStrength(theme, 5.0f);
292         setAmbientLightStrength(theme, 0.5f);
293         setHighlightLightStrength(theme, 5.0f);
294         setLabelBorderEnabled(theme, true);
295         setColorStyle(theme, Q3DTheme::ColorStyleUniform);
296         setBaseGradients(theme, baseGradients);
297         setSingleHighlightGradient(theme, createGradient(QColor(QRgb(0xfbf6d6)),
298                                                          defaultColorLevel));
299         setMultiHighlightGradient(theme, createGradient(QColor(QRgb(0x442f20)),
300                                                         defaultColorLevel));
301         break;
302     }
303 
304     case Q3DTheme::ThemeArmyBlue: {
305         baseColors.append(QColor(QRgb(0x495f76)));
306         baseColors.append(QColor(QRgb(0x81909f)));
307         baseColors.append(QColor(QRgb(0xbec5cd)));
308         baseColors.append(QColor(QRgb(0x687a8d)));
309         baseColors.append(QColor(QRgb(0xa3aeb9)));
310 
311         baseGradients.append(createGradient(baseColors.at(0), defaultBuiltInColorLevel));
312         baseGradients.append(createGradient(baseColors.at(1), defaultBuiltInColorLevel));
313         baseGradients.append(createGradient(baseColors.at(2), defaultBuiltInColorLevel));
314         baseGradients.append(createGradient(baseColors.at(3), defaultBuiltInColorLevel));
315         baseGradients.append(createGradient(baseColors.at(4), defaultBuiltInColorLevel));
316 
317         setBackgroundEnabled(theme, true);
318         setGridEnabled(theme, true);
319         setFont(theme, QFont(QStringLiteral("Arial")));
320         setLabelBackgroundEnabled(theme, true);
321         setLightColor(theme, Qt::white);
322         setBaseColors(theme, baseColors);
323         setBackgroundColor(theme, QColor(QRgb(0xd5d6d7)));
324         setWindowColor(theme, QColor(QRgb(0xd5d6d7)));
325         setTextColor(theme, QColor(QRgb(0x000000)));
326         setTextBackgroundColor(theme, QColor(0xd5, 0xd6, 0xd7, 0xcd));
327         setGridLineColor(theme, QColor(QRgb(0xaeadac)));
328         setSingleHighlightColor(theme, QColor(QRgb(0x2aa2f9)));
329         setMultiHighlightColor(theme, QColor(QRgb(0x103753)));
330         setLightStrength(theme, 5.0f);
331         setAmbientLightStrength(theme, 0.5f);
332         setHighlightLightStrength(theme, 5.0f);
333         setLabelBorderEnabled(theme, false);
334         setColorStyle(theme, Q3DTheme::ColorStyleObjectGradient);
335         setBaseGradients(theme, baseGradients);
336         setSingleHighlightGradient(theme, createGradient(QColor(QRgb(0x2aa2f9)),
337                                                          defaultBuiltInColorLevel));
338         setMultiHighlightGradient(theme, createGradient(QColor(QRgb(0x103753)),
339                                                         defaultBuiltInColorLevel));
340         break;
341     }
342 
343     case Q3DTheme::ThemeRetro: {
344         baseColors.append(QColor(QRgb(0x533b23)));
345         baseColors.append(QColor(QRgb(0x83715a)));
346         baseColors.append(QColor(QRgb(0xb3a690)));
347         baseColors.append(QColor(QRgb(0x6b563e)));
348         baseColors.append(QColor(QRgb(0x9b8b75)));
349 
350         baseGradients.append(createGradient(baseColors.at(0), defaultBuiltInColorLevel));
351         baseGradients.append(createGradient(baseColors.at(1), defaultBuiltInColorLevel));
352         baseGradients.append(createGradient(baseColors.at(2), defaultBuiltInColorLevel));
353         baseGradients.append(createGradient(baseColors.at(3), defaultBuiltInColorLevel));
354         baseGradients.append(createGradient(baseColors.at(4), defaultBuiltInColorLevel));
355 
356         setBackgroundEnabled(theme, true);
357         setGridEnabled(theme, true);
358         setFont(theme, QFont(QStringLiteral("Arial")));
359         setLabelBackgroundEnabled(theme, true);
360         setLightColor(theme, Qt::white);
361         setBaseColors(theme, baseColors);
362         setBackgroundColor(theme, QColor(QRgb(0xe9e2ce)));
363         setWindowColor(theme, QColor(QRgb(0xe9e2ce)));
364         setTextColor(theme, QColor(QRgb(0x000000)));
365         setTextBackgroundColor(theme, QColor(0xe9, 0xe2, 0xce, 0xc0));
366         setGridLineColor(theme, QColor(QRgb(0xd0c0b0)));
367         setSingleHighlightColor(theme, QColor(QRgb(0x8ea317)));
368         setMultiHighlightColor(theme, QColor(QRgb(0xc25708)));
369         setLightStrength(theme, 5.0f);
370         setAmbientLightStrength(theme, 0.5f);
371         setHighlightLightStrength(theme, 5.0f);
372         setLabelBorderEnabled(theme, false);
373         setColorStyle(theme, Q3DTheme::ColorStyleObjectGradient);
374         setBaseGradients(theme, baseGradients);
375         setSingleHighlightGradient(theme, createGradient(QColor(QRgb(0x8ea317)),
376                                                          defaultBuiltInColorLevel));
377         setMultiHighlightGradient(theme, createGradient(QColor(QRgb(0xc25708)),
378                                                         defaultBuiltInColorLevel));
379         break;
380     }
381 
382     case Q3DTheme::ThemeEbony: {
383         baseColors.append(QColor(QRgb(0xffffff)));
384         baseColors.append(QColor(QRgb(0x999999)));
385         baseColors.append(QColor(QRgb(0x474747)));
386         baseColors.append(QColor(QRgb(0xc7c7c7)));
387         baseColors.append(QColor(QRgb(0x6b6b6b)));
388 
389         baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
390         baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
391         baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
392         baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
393         baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
394 
395         setBackgroundEnabled(theme, true);
396         setGridEnabled(theme, true);
397         setFont(theme, QFont(QStringLiteral("Arial")));
398         setLabelBackgroundEnabled(theme, true);
399         setLightColor(theme, Qt::white);
400         setBaseColors(theme, baseColors);
401         setBackgroundColor(theme, QColor(QRgb(0x000000)));
402         setWindowColor(theme, QColor(QRgb(0x000000)));
403         setTextColor(theme, QColor(QRgb(0xaeadac)));
404         setTextBackgroundColor(theme, QColor(0x00, 0x00, 0x00, 0xcd));
405         setGridLineColor(theme, QColor(QRgb(0x35322f)));
406         setSingleHighlightColor(theme, QColor(QRgb(0xf5dc0d)));
407         setMultiHighlightColor(theme, QColor(QRgb(0xd72222)));
408         setLightStrength(theme, 5.0f);
409         setAmbientLightStrength(theme, 0.5f);
410         setHighlightLightStrength(theme, 5.0f);
411         setLabelBorderEnabled(theme, false);
412         setColorStyle(theme, Q3DTheme::ColorStyleUniform);
413         setBaseGradients(theme, baseGradients);
414         setSingleHighlightGradient(theme, createGradient(QColor(QRgb(0xf5dc0d)),
415                                                          defaultColorLevel));
416         setMultiHighlightGradient(theme, createGradient(QColor(QRgb(0xd72222)),
417                                                         defaultColorLevel));
418         break;
419     }
420 
421     case Q3DTheme::ThemeIsabelle: {
422         baseColors.append(QColor(QRgb(0xf9d900)));
423         baseColors.append(QColor(QRgb(0xf09603)));
424         baseColors.append(QColor(QRgb(0xe85506)));
425         baseColors.append(QColor(QRgb(0xf5b802)));
426         baseColors.append(QColor(QRgb(0xec7605)));
427 
428         baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
429         baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
430         baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
431         baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
432         baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
433 
434         setBackgroundEnabled(theme, true);
435         setGridEnabled(theme, true);
436         setFont(theme, QFont(QStringLiteral("Arial")));
437         setLabelBackgroundEnabled(theme, true);
438         setLightColor(theme, Qt::white);
439         setBaseColors(theme, baseColors);
440         setBackgroundColor(theme, QColor(QRgb(0x000000)));
441         setWindowColor(theme, QColor(QRgb(0x000000)));
442         setTextColor(theme, QColor(QRgb(0xaeadac)));
443         setTextBackgroundColor(theme, QColor(0x00, 0x00, 0x00, 0xc0));
444         setGridLineColor(theme, QColor(QRgb(0x35322f)));
445         setSingleHighlightColor(theme, QColor(QRgb(0xfff7cc)));
446         setMultiHighlightColor(theme, QColor(QRgb(0xde0a0a)));
447         setLightStrength(theme, 5.0f);
448         setAmbientLightStrength(theme, 0.5f);
449         setHighlightLightStrength(theme, 5.0f);
450         setLabelBorderEnabled(theme, false);
451         setColorStyle(theme, Q3DTheme::ColorStyleUniform);
452         setBaseGradients(theme, baseGradients);
453         setSingleHighlightGradient(theme, createGradient(QColor(QRgb(0xfff7cc)),
454                                                          defaultColorLevel));
455         setMultiHighlightGradient(theme, createGradient(QColor(QRgb(0xde0a0a)),
456                                                         defaultColorLevel));
457         break;
458     }
459     default:
460         break;
461     }
462 }
463 
createGradient(const QColor & color,float colorLevel)464 QLinearGradient ThemeManager::createGradient(const QColor &color, float colorLevel)
465 {
466     QColor startColor;
467     QLinearGradient gradient = QLinearGradient(qreal(gradientTextureWidth),
468                                                qreal(gradientTextureHeight),
469                                                0.0, 0.0);;
470     startColor.setRed(color.red() * colorLevel);
471     startColor.setGreen(color.green() * colorLevel);
472     startColor.setBlue(color.blue() * colorLevel);
473     gradient.setColorAt(0.0, startColor);
474     gradient.setColorAt(1.0, color);
475     return gradient;
476 }
477 
setBaseColors(Q3DTheme * theme,const QList<QColor> & colors)478 void ThemeManager::setBaseColors(Q3DTheme *theme, const QList<QColor> &colors)
479 {
480     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.baseColorDirty)
481         theme->setBaseColors(colors);
482 }
483 
setBackgroundColor(Q3DTheme * theme,const QColor & color)484 void ThemeManager::setBackgroundColor(Q3DTheme *theme, const QColor &color)
485 {
486     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.backgroundColorDirty)
487         theme->setBackgroundColor(color);
488 }
489 
setWindowColor(Q3DTheme * theme,const QColor & color)490 void ThemeManager::setWindowColor(Q3DTheme *theme, const QColor &color)
491 {
492     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.windowColorDirty)
493         theme->setWindowColor(color);
494 }
495 
setTextColor(Q3DTheme * theme,const QColor & color)496 void ThemeManager::setTextColor(Q3DTheme *theme, const QColor &color)
497 {
498     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.labelTextColorDirty)
499         theme->setLabelTextColor(color);
500 }
501 
setTextBackgroundColor(Q3DTheme * theme,const QColor & color)502 void ThemeManager::setTextBackgroundColor(Q3DTheme *theme, const QColor &color)
503 {
504     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.labelBackgroundColorDirty)
505         theme->setLabelBackgroundColor(color);
506 }
507 
setGridLineColor(Q3DTheme * theme,const QColor & color)508 void ThemeManager::setGridLineColor(Q3DTheme *theme, const QColor &color)
509 {
510     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.gridLineColorDirty)
511         theme->setGridLineColor(color);
512 }
513 
setSingleHighlightColor(Q3DTheme * theme,const QColor & color)514 void ThemeManager::setSingleHighlightColor(Q3DTheme *theme, const QColor &color)
515 {
516     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.singleHighlightColorDirty)
517         theme->setSingleHighlightColor(color);
518 }
519 
setMultiHighlightColor(Q3DTheme * theme,const QColor & color)520 void ThemeManager::setMultiHighlightColor(Q3DTheme *theme, const QColor &color)
521 {
522     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.multiHighlightColorDirty)
523         theme->setMultiHighlightColor(color);
524 }
525 
setLightColor(Q3DTheme * theme,const QColor & color)526 void ThemeManager::setLightColor(Q3DTheme *theme, const QColor &color)
527 {
528     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.lightColorDirty)
529         theme->setLightColor(color);
530 }
531 
setBaseGradients(Q3DTheme * theme,const QList<QLinearGradient> & gradients)532 void ThemeManager::setBaseGradients(Q3DTheme *theme, const QList<QLinearGradient> &gradients)
533 {
534     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.baseGradientDirty)
535         theme->setBaseGradients(gradients);
536 }
537 
setSingleHighlightGradient(Q3DTheme * theme,const QLinearGradient & gradient)538 void ThemeManager::setSingleHighlightGradient(Q3DTheme *theme, const QLinearGradient &gradient)
539 {
540     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.singleHighlightGradientDirty)
541         theme->setSingleHighlightGradient(gradient);
542 }
543 
setMultiHighlightGradient(Q3DTheme * theme,const QLinearGradient & gradient)544 void ThemeManager::setMultiHighlightGradient(Q3DTheme *theme, const QLinearGradient &gradient)
545 {
546     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.multiHighlightGradientDirty)
547         theme->setMultiHighlightGradient(gradient);
548 }
549 
setLightStrength(Q3DTheme * theme,float strength)550 void ThemeManager::setLightStrength(Q3DTheme *theme, float strength)
551 {
552     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.lightStrengthDirty)
553         theme->setLightStrength(strength);
554 }
555 
setAmbientLightStrength(Q3DTheme * theme,float strength)556 void ThemeManager::setAmbientLightStrength(Q3DTheme *theme, float strength)
557 {
558     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.ambientLightStrengthDirty)
559         theme->setAmbientLightStrength(strength);
560 }
561 
setHighlightLightStrength(Q3DTheme * theme,float strength)562 void ThemeManager::setHighlightLightStrength(Q3DTheme *theme, float strength)
563 {
564     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.highlightLightStrengthDirty)
565         theme->setHighlightLightStrength(strength);
566 }
567 
setLabelBorderEnabled(Q3DTheme * theme,bool enabled)568 void ThemeManager::setLabelBorderEnabled(Q3DTheme *theme, bool enabled)
569 {
570     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.labelBorderEnabledDirty)
571         theme->setLabelBorderEnabled(enabled);
572 }
573 
setFont(Q3DTheme * theme,const QFont & font)574 void ThemeManager::setFont(Q3DTheme *theme, const QFont &font)
575 {
576     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.fontDirty)
577         theme->setFont(font);
578 }
579 
setBackgroundEnabled(Q3DTheme * theme,bool enabled)580 void ThemeManager::setBackgroundEnabled(Q3DTheme *theme, bool enabled)
581 {
582     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.backgroundEnabledDirty)
583         theme->setBackgroundEnabled(enabled);
584 }
585 
setGridEnabled(Q3DTheme * theme,bool enabled)586 void ThemeManager::setGridEnabled(Q3DTheme *theme, bool enabled)
587 {
588     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.gridEnabledDirty)
589         theme->setGridEnabled(enabled);
590 }
591 
setLabelBackgroundEnabled(Q3DTheme * theme,bool enabled)592 void ThemeManager::setLabelBackgroundEnabled(Q3DTheme *theme, bool enabled)
593 {
594     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.labelBackgroundEnabledDirty)
595         theme->setLabelBackgroundEnabled(enabled);
596 }
597 
setColorStyle(Q3DTheme * theme,Q3DTheme::ColorStyle style)598 void ThemeManager::setColorStyle(Q3DTheme *theme, Q3DTheme::ColorStyle style)
599 {
600     if (theme->d_ptr->isForcePredefinedType() || !theme->d_ptr->m_dirtyBits.colorStyleDirty)
601         theme->setColorStyle(style);
602 }
603 
604 QT_END_NAMESPACE_DATAVISUALIZATION
605