1 /*
2    Drawpile - a collaborative drawing program.
3 
4    Copyright (C) 2015-2019 Calle Laakkonen
5 
6    Drawpile is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10 
11    Drawpile is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with Drawpile.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "icon.h"
21 #include "../libshared/util/paths.h"
22 
23 #include <QDir>
24 #include <QPalette>
25 
26 namespace icon {
27 
28 static bool is_dark_theme = false;
29 
isDark(const QColor & c)30 bool isDark(const QColor &c)
31 {
32 	const qreal luminance = c.redF() * 0.216 + c.greenF() * 0.7152 + c.blueF() * 0.0722;
33 
34 	return luminance <= 0.5;
35 }
36 
isDarkThemeSelected()37 bool isDarkThemeSelected() { return is_dark_theme; }
38 
selectThemeVariant()39 void selectThemeVariant()
40 {
41 	is_dark_theme = isDark(QPalette().color(QPalette::Window));
42 
43 	const QString themePath = is_dark_theme ? QStringLiteral("/theme/dark") : QStringLiteral("/theme/light");
44 
45 	QStringList themePaths;
46 	for(const QString &path : utils::paths::dataPaths()) {
47 		themePaths.append(path + themePath);
48 	}
49 
50 #if 0
51 	// We can use this after we no longer support anything older than Qt 5.11
52 	// The nice thing about fallback search path is that the icons are automagically
53 	// reloaded when it changes.
54 	// Note: On Windows and Mac, we need to explicitly select a theme too. (A dummy theme should do.)
55 	QIcon::setFallbackSearchPaths(themePaths);
56 #endif
57 
58 	QDir::setSearchPaths("theme", themePaths);
59 }
60 
61 }
62 
63