File indexing completed on 2024-05-12 05:39:48
0001 /*************************************************************************** 0002 * Copyright (C) 2019 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 PREFERENCESCONTROLLER_H 0021 #define PREFERENCESCONTROLLER_H 0022 0023 #include "controllerinterface.h" 0024 #include "model/thememodel.h" 0025 #include <QObject> 0026 #include <core_global.h> 0027 #include <memory> 0028 0029 #include <QAbstractItemModel> 0030 0031 class PaletteModel; 0032 class RolisteamTheme; 0033 class LanguageModel; 0034 class QStyle; 0035 class PreferencesManager; 0036 class GameController; 0037 class CORE_EXPORT PreferencesController : public AbstractControllerInterface 0038 { 0039 Q_OBJECT 0040 // Q_PROPERTY(QAbstractItemModel* paletteModel READ paletteModel CONSTANT) 0041 Q_PROPERTY(ThemeModel* themeModel READ themeModel CONSTANT) 0042 Q_PROPERTY(QAbstractItemModel* languageModel READ languageModel CONSTANT) 0043 Q_PROPERTY( 0044 std::size_t currentThemeIndex READ currentThemeIndex WRITE setCurrentThemeIndex NOTIFY currentThemeIndexChanged) 0045 Q_PROPERTY(bool systemLang READ systemLang WRITE setSystemLang NOTIFY systemLangChanged) 0046 Q_PROPERTY(bool hasCustomFile READ hasCustomFile WRITE setHasCustomFile NOTIFY hasCustomFileChanged) 0047 Q_PROPERTY(QString customFilePath READ customFilePath WRITE setCustomFile NOTIFY customFileChanged) 0048 Q_PROPERTY(int currentLangIndex READ currentLangIndex WRITE setCurrentLangIndex NOTIFY currentLangIndexChanged) 0049 Q_PROPERTY(QStringList currentLangPath READ currentLangPath NOTIFY currentLangIndexChanged) 0050 0051 public: 0052 explicit PreferencesController(QObject* parent= nullptr); 0053 virtual ~PreferencesController() override; 0054 0055 void setGameController(GameController*) override; 0056 0057 // QAbstractItemModel* paletteModel() const; 0058 ThemeModel* themeModel() const; 0059 QAbstractItemModel* languageModel() const; 0060 0061 // i18n 0062 int currentLangIndex() const; 0063 bool systemLang() const; 0064 bool hasCustomFile() const; 0065 QString customFilePath() const; 0066 QStringList currentLangPath() const; 0067 0068 // theme 0069 QString themeName(int i) const; 0070 RolisteamTheme* currentTheme() const; 0071 std::size_t currentThemeIndex() const; 0072 RolisteamTheme* currentEditableTheme(); 0073 0074 void setDiceHighLightColor(const QColor& color); 0075 0076 signals: 0077 void currentThemeIndexChanged(); 0078 void currentLangIndexChanged(); 0079 void systemLangChanged(); 0080 void hasCustomFileChanged(); 0081 void customFileChanged(); 0082 0083 public slots: 0084 void savePreferences(); 0085 void loadPreferences(); 0086 0087 void importData(const QString& filename); 0088 void exportData(const QString& filename); 0089 0090 // i18n 0091 void setSystemLang(bool b); 0092 void setHasCustomFile(bool b); 0093 void setCustomFile(const QString& string); 0094 void setCurrentLangIndex(int index); 0095 0096 // theme 0097 void setCurrentThemeIndex(std::size_t pos); 0098 void setCurrentThemeStyle(QStyle* style); 0099 void setColorCurrentTheme(const QColor& color, int palettePos); 0100 void setCurrentThemeBackground(const QString& path, int pos, const QColor& color); 0101 void setCurrentThemeCss(const QString& css); 0102 void exportTheme(const QString& filename, int pos); 0103 void importTheme(const QString& filename); 0104 void dupplicateTheme(int pos, bool selectNew); 0105 void removeTheme(int i); 0106 void setCurrentThemeTitle(const QString& title); 0107 0108 private: 0109 // std::unique_ptr<PaletteModel> m_paletteModel; 0110 std::unique_ptr<ThemeModel> m_themeModel; 0111 std::unique_ptr<LanguageModel> m_languageModel; 0112 0113 std::size_t m_currentThemeIndex= 0; 0114 int m_currentLangIndex= -1; 0115 bool m_systemLang= true; 0116 bool m_customFile= false; 0117 QString m_customFilePath; 0118 0119 PreferencesManager* m_preferences; 0120 }; 0121 0122 #endif // PREFERENCESCONTROLLER_H