MuseScore  3.4
Music composition and notation
preferenceslistwidget.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2002-2017 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __PREFERENCESLISTWIDGET_H__
21 #define __PREFERENCESLISTWIDGET_H__
22 
23 #include "awl/colorlabel.h"
24 #include "preferences.h"
25 
26 #define PREF_VALUE_COLUMN 1
27 
28 namespace Ms {
29 
30 //---------------------------------------------------------
31 // PreferenceItem
32 //---------------------------------------------------------
33 class PreferenceItem : public QTreeWidgetItem, public QObject {
34 
35  QString _name;
36 
37  protected:
38  void save(QVariant value);
39 
40  public:
42  PreferenceItem(QString name);
43 
44  virtual void save() = 0;
45  virtual void update() = 0;
46  virtual void setDefaultValue() = 0;
47  virtual QWidget* editor() const = 0;
48  virtual bool isModified() const = 0;
49 
50  QString name() const {return _name;}
51 
52  };
53 
54 //---------------------------------------------------------
55 // BoolPreferenceItem
56 //---------------------------------------------------------
58  private:
60  QCheckBox* _editor;
61 
62  public:
63  BoolPreferenceItem(QString name);
64 
65  void save();
66  void update();
67  void setDefaultValue();
68  QWidget* editor() const {return _editor;}
69  bool isModified() const;
70 
71  };
72 
73 
74 //---------------------------------------------------------
75 // IntPreferenceItem
76 //---------------------------------------------------------
79  QSpinBox* _editor;
80 
81  public:
82  IntPreferenceItem(QString name);
83 
84  void save();
85  void update();
86  void setDefaultValue();
87  QWidget* editor() const {return _editor;}
88  bool isModified() const;
89  };
90 
91 //---------------------------------------------------------
92 // DoublePreferenceItem
93 //---------------------------------------------------------
95  double _initialValue;
96  QDoubleSpinBox* _editor;
97 
98  public:
99  DoublePreferenceItem(QString name);
100 
101  void save();
102  void update();
103  void setDefaultValue();
104  QWidget* editor() const {return _editor;}
105  bool isModified() const;
106  };
107 
108 //---------------------------------------------------------
109 // StringPreferenceItem
110 //---------------------------------------------------------
112  QString _initialValue;
113  QLineEdit* _editor;
114 
115  public:
116  StringPreferenceItem(QString name);
117 
118  void save();
119  void update();
120  void setDefaultValue();
121  QWidget* editor() const {return _editor;}
122  bool isModified() const;
123  };
124 
125 //---------------------------------------------------------
126 // ColorPreferenceItem
127 //---------------------------------------------------------
131 
132  public:
133  ColorPreferenceItem(QString name);
134 
135  void save();
136  void update();
137  void setDefaultValue();
138  QWidget* editor() const {return _editor;}
139  bool isModified() const;
140  };
141 
142 
143 //---------------------------------------------------------
144 // PreferencesListWidget
145 //---------------------------------------------------------
146 
147 class PreferencesListWidget : public QTreeWidget, public PreferenceVisitor {
148  Q_OBJECT
149 
150  QHash<QString, PreferenceItem*> preferenceItems;
151 
152  void addPreference(PreferenceItem* item);
153 
154  public:
155  explicit PreferencesListWidget(QWidget* parent = 0);
156  void loadPreferences();
157  void updatePreferences();
158 
159  std::vector<QString> save();
160 
161  void visit(QString key, IntPreference*);
162  void visit(QString key, DoublePreference*);
163  void visit(QString key, BoolPreference*);
164  void visit(QString key, StringPreference*);
165  void visit(QString key, ColorPreference*);
166 
167 };
168 
169 } // namespace Ms
170 
171 #endif // __PREFERENCESLISTWIDGET_H__
PreferenceItem()
Definition: preferenceslistwidget.cpp:114
QColor _initialValue
Definition: preferenceslistwidget.h:129
Definition: preferenceslistwidget.h:57
QWidget * editor() const
Definition: preferenceslistwidget.h:121
Definition: preferences.h:118
Definition: preferences.h:106
virtual void save()=0
Definition: preferenceslistwidget.h:111
Definition: colorlabel.h:29
virtual bool isModified() const =0
Definition: preferenceslistwidget.h:77
QWidget * editor() const
Definition: preferenceslistwidget.h:68
Definition: preferences.h:100
QString _name
Definition: preferenceslistwidget.h:35
QDoubleSpinBox * _editor
Definition: preferenceslistwidget.h:96
int _initialValue
Definition: preferenceslistwidget.h:78
Definition: preferences.h:124
double _initialValue
Definition: preferenceslistwidget.h:95
QSpinBox * _editor
Definition: preferenceslistwidget.h:79
QCheckBox * _editor
Definition: preferenceslistwidget.h:60
QWidget * editor() const
Definition: preferenceslistwidget.h:87
virtual void update()=0
bool _initialValue
Definition: preferenceslistwidget.h:59
virtual QWidget * editor() const =0
Definition: preferenceslistwidget.h:94
Definition: aeolus.cpp:26
QWidget * editor() const
Definition: preferenceslistwidget.h:138
Definition: preferenceslistwidget.h:33
QString _initialValue
Definition: preferenceslistwidget.h:112
Definition: preferences.h:112
virtual void setDefaultValue()=0
Definition: preferences.h:282
QLineEdit * _editor
Definition: preferenceslistwidget.h:113
Definition: preferenceslistwidget.h:128
QString name() const
Definition: preferenceslistwidget.h:50
Definition: preferenceslistwidget.h:147
QWidget * editor() const
Definition: preferenceslistwidget.h:104
QHash< QString, PreferenceItem * > preferenceItems
Definition: preferenceslistwidget.h:150
Awl::ColorLabel * _editor
Definition: preferenceslistwidget.h:130