Enable customizing the save statistics time interval
[qBittorrent.git] / src / gui / uithemesource.h
blobcd7870595102bb82d66467cbb4e1b25edc5c5702
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 Q_DECLARE_TR_FUNCTIONS(DefaultThemeSource)
66 public:
67 DefaultThemeSource();
69 QByteArray readStyleSheet() override;
70 QColor getColor(const QString &colorId, ColorMode colorMode) const override;
71 Path getIconPath(const QString &iconId, ColorMode colorMode) const override;
73 private:
74 void loadColors();
76 const Path m_defaultPath;
77 const Path m_userPath;
78 QHash<QString, UIThemeColor> m_colors;
81 class CustomThemeSource : public UIThemeSource
83 Q_DECLARE_TR_FUNCTIONS(CustomThemeSource)
85 public:
86 QColor getColor(const QString &colorId, ColorMode colorMode) const override;
87 Path getIconPath(const QString &iconId, ColorMode colorMode) const override;
88 QByteArray readStyleSheet() override;
90 protected:
91 explicit CustomThemeSource(const Path &themeRootPath);
93 DefaultThemeSource *defaultThemeSource() const;
95 private:
96 Path themeRootPath() const;
97 void loadColors();
99 const std::unique_ptr<DefaultThemeSource> m_defaultThemeSource = std::make_unique<DefaultThemeSource>();
100 Path m_themeRootPath;
101 QHash<QString, QColor> m_colors;
102 QHash<QString, QColor> m_darkModeColors;
105 class QRCThemeSource final : public CustomThemeSource
107 public:
108 QRCThemeSource();
111 class FolderThemeSource : public CustomThemeSource
113 public:
114 explicit FolderThemeSource(const Path &folderPath);
116 QByteArray readStyleSheet() override;
118 private:
119 const Path m_folder;