WebUI: Minor optimizations to the login page
[qBittorrent.git] / src / gui / uithemesource.h
blobcb2afbbeb9f2f37e7bac9ab898829b2433554ccb
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2019 Prince Gupta <jagannatharjun11@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program 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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 * USA.
21 * In addition, as a special exception, the copyright holders give permission to
22 * link this program with the OpenSSL project's "OpenSSL" library (or with
23 * modified versions of it that use the same license as the "OpenSSL" library),
24 * and distribute the linked executables. You must obey the GNU General Public
25 * License in all respects for all of the code used other than "OpenSSL". If
26 * you modify file(s), you may extend this exception to your version of the
27 * file(s), but you are not obligated to do so. If you do not wish to do so,
28 * delete this exception statement from your version.
31 #pragma once
33 #include <memory>
35 #include <QColor>
36 #include <QCoreApplication>
37 #include <QHash>
38 #include <QIcon>
39 #include <QString>
41 #include "base/path.h"
42 #include "uithemecommon.h"
44 enum class ColorMode
46 Light,
47 Dark
50 class UIThemeSource
52 Q_DECLARE_TR_FUNCTIONS(UIThemeSource)
54 public:
55 virtual ~UIThemeSource() = default;
57 virtual QColor getColor(const QString &colorId, ColorMode colorMode) const = 0;
58 virtual Path getIconPath(const QString &iconId, ColorMode colorMode) const = 0;
59 virtual QByteArray readStyleSheet() = 0;
62 class DefaultThemeSource final : public UIThemeSource
64 public:
65 DefaultThemeSource();
67 QByteArray readStyleSheet() override;
68 QColor getColor(const QString &colorId, ColorMode colorMode) const override;
69 Path getIconPath(const QString &iconId, ColorMode colorMode) const override;
71 private:
72 void loadColors();
74 const Path m_defaultPath;
75 const Path m_userPath;
76 QHash<QString, UIThemeColor> m_colors;
79 class CustomThemeSource : public UIThemeSource
81 public:
82 QColor getColor(const QString &colorId, ColorMode colorMode) const override;
83 Path getIconPath(const QString &iconId, ColorMode colorMode) const override;
84 QByteArray readStyleSheet() override;
86 protected:
87 explicit CustomThemeSource(const Path &themeRootPath);
89 DefaultThemeSource *defaultThemeSource() const;
91 private:
92 Path themeRootPath() const;
93 void loadColors();
95 const std::unique_ptr<DefaultThemeSource> m_defaultThemeSource = std::make_unique<DefaultThemeSource>();
96 Path m_themeRootPath;
97 QHash<QString, QColor> m_colors;
98 QHash<QString, QColor> m_darkModeColors;
101 class QRCThemeSource final : public CustomThemeSource
103 public:
104 QRCThemeSource();
107 class FolderThemeSource : public CustomThemeSource
109 public:
110 explicit FolderThemeSource(const Path &folderPath);
112 QByteArray readStyleSheet() override;
114 private:
115 const Path m_folder;