Merge pull request #18104 from sledgehammer999/remove_dead_code
[qBittorrent.git] / src / gui / uithememanager.h
blob3b3c18cde8e3da0d9a3c85da41bf151cca7d39d8
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2019 Prince Gupta <jagannatharjun11@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 * USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If
25 * you modify file(s), you may extend this exception to your version of the
26 * file(s), but you are not obligated to do so. If you do not wish to do so,
27 * delete this exception statement from your version.
30 #pragma once
32 #include <QtGlobal>
33 #include <QColor>
34 #include <QHash>
35 #include <QIcon>
36 #include <QObject>
37 #include <QString>
39 #include "base/pathfwd.h"
41 class UIThemeSource
43 public:
44 virtual ~UIThemeSource() = default;
46 virtual QByteArray readStyleSheet() = 0;
47 virtual QByteArray readConfig() = 0;
48 virtual Path iconPath(const QString &iconId) const = 0;
51 class UIThemeManager : public QObject
53 Q_OBJECT
54 Q_DISABLE_COPY_MOVE(UIThemeManager)
56 public:
57 static void initInstance();
58 static void freeInstance();
59 static UIThemeManager *instance();
61 Path getIconPath(const QString &iconId) const;
62 QIcon getIcon(const QString &iconId, const QString &fallback = {}) const;
63 QIcon getFlagIcon(const QString &countryIsoCode) const;
65 QColor getColor(const QString &id, const QColor &defaultColor) const;
67 #ifndef Q_OS_MACOS
68 QIcon getSystrayIcon() const;
69 #endif
71 private:
72 UIThemeManager(); // singleton class
73 Path getIconPathFromResources(const QString &iconId, const QString &fallback = {}) const;
74 void loadColorsFromJSONConfig();
75 void applyPalette() const;
76 void applyStyleSheet() const;
78 static UIThemeManager *m_instance;
79 const bool m_useCustomTheme;
80 std::unique_ptr<UIThemeSource> m_themeSource;
81 QHash<QString, QColor> m_colors;
82 mutable QHash<QString, QIcon> m_iconCache;
83 mutable QHash<QString, QIcon> m_flagCache;