1 /* 2 Drawpile - a collaborative drawing program. 3 4 Copyright (C) 2014-2021 Calle Laakkonen 5 6 Drawpile is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Drawpile 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. 15 16 You should have received a copy of the GNU General Public License 17 along with Drawpile. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #ifndef PresetModel_H 20 #define PresetModel_H 21 22 #include "canvas/pressure.h" 23 24 #include <QAbstractListModel> 25 #include <QSettings> 26 #include <QVector> 27 28 namespace input { 29 30 struct Preset { 31 //! A unique ID for the preset 32 QString id; 33 34 //! Human readable name of the preset 35 QString name; 36 37 int smoothing; 38 PressureMapping curve; 39 40 static Preset loadFromSettings(const QSettings &cfg); 41 void saveToSettings(QSettings &cfg) const; 42 }; 43 44 } 45 46 Q_DECLARE_TYPEINFO(input::Preset, Q_MOVABLE_TYPE); 47 48 namespace input { 49 50 class PresetModel : public QAbstractListModel { 51 Q_OBJECT 52 public: 53 explicit PresetModel(QObject *parent = nullptr); 54 55 PresetModel(const PresetModel &) = delete; 56 PresetModel &operator=(const PresetModel &) = delete; 57 58 static PresetModel *getSharedInstance(); 59 60 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 61 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 62 Qt::ItemFlags flags(const QModelIndex &index) const override; 63 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 64 bool removeRows(int row, int count, const QModelIndex &parent) override; 65 66 const Preset *at(int i) const; 67 int searchIndexById(const QString &id) const; 68 const Preset *searchPresetById(const QString &id) const; 69 70 void add(const Preset &preset); 71 void update(int index, const Preset &preset); 72 73 void restoreSettings(); 74 void saveSettings(); 75 76 signals: 77 void presetChanged(const QString &id); 78 79 private: 80 QVector<Preset> m_presets; 81 }; 82 83 } 84 85 Q_DECLARE_METATYPE(input::Preset) 86 87 #endif 88