Line data Source code
1 : // Author: Ruud Koolen 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : 9 : #ifndef MCRL2_UTILITIES_SETTING_H 10 : #define MCRL2_UTILITIES_SETTING_H 11 : 12 : #include <QColor> 13 : #include <QList> 14 : #include <QObject> 15 : #include <QPair> 16 : 17 : namespace mcrl2 18 : { 19 : namespace gui 20 : { 21 : namespace qt 22 : { 23 : 24 : /* 25 : * Unfortunately, MOC doesn't understand templates or macros, or this would be a whole lot cleaner. 26 : */ 27 : class SettingInt : public QObject 28 : { 29 : Q_OBJECT 30 : public: 31 : SettingInt(int value): m_value(value) {} 32 : int value() { return m_value; } 33 : public slots: 34 0 : void setValue(int value) { if (value != m_value) { m_value = value; emit changed(value); } } 35 : signals: 36 : void changed(int value); 37 : private: 38 : int m_value; 39 : }; 40 : 41 : class SettingBool : public QObject 42 : { 43 : Q_OBJECT 44 : public: 45 : SettingBool(bool value): m_value(value) {} 46 : bool value() { return m_value; } 47 : public slots: 48 0 : void setValue(bool value) { if (value != m_value) { m_value = value; emit changed(value); } } 49 : signals: 50 : void changed(bool value); 51 : private: 52 : bool m_value; 53 : }; 54 : 55 : class SettingFloat : public QObject 56 : { 57 : Q_OBJECT 58 : public: 59 : SettingFloat(float value): m_value(value) {} 60 : float value() { return m_value; } 61 : public slots: 62 0 : void setValue(float value) { if (value != m_value) { m_value = value; emit changed(value); } } 63 : signals: 64 : void changed(float value); 65 : private: 66 : float m_value; 67 : }; 68 : 69 : class SettingColor : public QObject 70 : { 71 : Q_OBJECT 72 : public: 73 : SettingColor(QColor value): m_value(value) {} 74 : QColor value() { return m_value; } 75 : public slots: 76 0 : void setValue(QColor value) { if (value != m_value) { m_value = value; emit changed(value); } } 77 : signals: 78 : void changed(QColor value); 79 : private: 80 : QColor m_value; 81 : }; 82 : 83 : class SettingEnum : public SettingInt 84 : { 85 : Q_OBJECT 86 : public: 87 : typedef QPair<int, QString> Item; 88 : SettingEnum(QList<Item> items, int value = -1): SettingInt(value == -1 ? items.first().first : value), m_items(items) {} 89 : QList<Item> items() const { return m_items; } 90 : private: 91 : QList<Item> m_items; 92 : }; 93 : 94 : } // namespace qt 95 : } // namespace gui 96 : } // namespace mcrl2 97 : 98 : #endif // MCRL2_UTILITIES_SETTING_H