File indexing completed on 2024-05-19 05:40:24

0001 /***************************************************************************
0002  *  Copyright (C) 2020 by Renaud Guezennec                               *
0003  *   http://www.rolisteam.org/contact                                      *
0004  *                                                                         *
0005  *   This software is free software; you can redistribute it and/or modify *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef THEME_H
0021 #define THEME_H
0022 
0023 #include <QFont>
0024 #include <QObject>
0025 #include <QQmlPropertyMap>
0026 #include <common_qml/common_qml_global.h>
0027 #include <map>
0028 
0029 namespace customization
0030 {
0031 class Theme;
0032 class COMMON_QML_EXPORT StyleSheet : public QQmlPropertyMap
0033 {
0034     Q_OBJECT
0035 public:
0036     explicit StyleSheet(Theme* parent);
0037     void insertOrUpdate(const QString& key, const QVariant& value);
0038 
0039     // protected:
0040     //    QVariant updateProperty(const QString& key, const QVariant& input);
0041 };
0042 
0043 class COMMON_QML_EXPORT Theme : public QObject
0044 {
0045     Q_OBJECT
0046     Q_PROPERTY(bool nightMode READ nightMode WRITE setNightMode NOTIFY nightModeChanged)
0047     Q_PROPERTY(QString folder READ folder NOTIFY folderChanged)
0048     Q_PROPERTY(QFont imFont READ imFont WRITE setImFont NOTIFY imFontChanged FINAL)
0049     Q_PROPERTY(QFont imLittleFont READ imLittleFont NOTIFY imFontChanged FINAL)
0050     Q_PROPERTY(QFont imBigFont READ imBigFont NOTIFY imFontChanged FINAL)
0051 public:
0052     explicit Theme(QObject* parent= nullptr);
0053 
0054     Q_INVOKABLE customization::StyleSheet* styleSheet(const QString& id);
0055     bool nightMode() const;
0056 
0057     QString folder() const;
0058 
0059     static Theme* instance();
0060 
0061     static void setPath(const QString& path);
0062 
0063     QFont imFont() const;
0064     void setImFont(const QFont& newImFont);
0065 
0066     QFont imLittleFont() const;
0067     QFont imBigFont() const;
0068 
0069 public slots:
0070     void setNightMode(bool b);
0071 
0072 signals:
0073     void nightModeChanged(bool b);
0074     void folderChanged(QString f);
0075     void imFontChanged();
0076 
0077 private:
0078     void loadData(const QString& source);
0079     StyleSheet* addStyleSheet(const QString& name);
0080     QColor darkColor(const QColor& color);
0081 
0082 private:
0083     static QString m_dataPath;
0084     std::map<QString, StyleSheet*> m_styleSheets;
0085     bool m_nightMode= false;
0086     QFont m_imFont;
0087 };
0088 } // namespace customization
0089 
0090 #endif // THEME_H