File indexing completed on 2024-04-28 04:05:21

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jakob Gruber <jakob.gruber@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef SETTINGS_H
0008 #define SETTINGS_H
0009 
0010 #include <QList>
0011 #include <QSettings>
0012 #include <QSharedPointer>
0013 #include <KGameDifficulty>
0014 
0015 class Settings : public QObject
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     enum SettingsType {
0021         Width = 0,
0022         Height,
0023         BoxDensity,
0024         PreventMistakes,
0025         Level,
0026         CustomBgEnabled,
0027         CustomBgPath,
0028         FontColorSolved,
0029         FontColorUnsolved
0030     };
0031 
0032     int width() const;
0033     int height() const;
0034     double boxDensity() const;
0035     bool preventMistakes() const;
0036     KGameDifficultyLevel::StandardLevel level() const;
0037     bool customBgEnabled() const;
0038     QString customBgPath() const;
0039     QString fontColorSolved() const;
0040     QString fontColorUnsolved() const;
0041 
0042     void setWidth(int width);
0043     void setHeight(int height);
0044     void setBoxDensity(double box_density);
0045     void setPreventMistakes(bool prevent_mistakes);
0046     void setLevel(KGameDifficultyLevel::StandardLevel level);
0047     void setCustomBgEnabled(bool enabled);
0048     void setCustomBgPath(const QString &path);
0049     void setFontColorSolved(const QString &color);
0050     void setFontColorUnsolved(const QString & color);
0051 
0052     void sync();
0053 
0054     /** Raw access to the underlying QSettings object.
0055      *  TODO: Wrap all accesses in custom functions and remove this. */
0056     QSharedPointer<QSettings> qSettings() const { return m_qsettings; }
0057 
0058     static Settings *instance();
0059 
0060 Q_SIGNALS:
0061     void settingChanged(Settings::SettingsType type);
0062 
0063 private:
0064     Settings();
0065     Q_DISABLE_COPY(Settings)
0066 
0067     void restore();
0068     void setValue(SettingsType type, const QVariant &value);
0069 
0070     QList<QString> m_keys;
0071 
0072     int m_width, m_height;
0073     double m_box_density;
0074     bool m_prevent_mistakes;
0075     KGameDifficultyLevel::StandardLevel m_level;
0076     bool m_custom_bg_enabled;
0077     QString m_custom_bg_path;
0078     QString m_font_color_unsolved, m_font_color_solved;
0079 
0080     QSharedPointer<QSettings> m_qsettings;
0081 };
0082 
0083 #endif // SETTINGS_H