/[svn]/qsampler/trunk/src/qsamplerPaletteForm.h
ViewVC logotype

Contents of /qsampler/trunk/src/qsamplerPaletteForm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4098 - (show annotations) (download) (as text)
Sun Mar 3 10:13:39 2024 UTC (8 weeks ago) by capela
File MIME type: text/x-c++hdr
File size: 7750 byte(s)
- Custom color themes are now file based (*.conf);
  legacy preserved ntl. (EXPERIMENTAL)
1 // qsamplerPaletteForm.h
2 //
3 /****************************************************************************
4 Copyright (C) 2004-2024, rncbc aka Rui Nuno Capela. All rights reserved.
5 Copyright (C) 2007, Christian Schoenebeck
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 *****************************************************************************/
22
23 #ifndef __qsamplerPaletteForm_h
24 #define __qsamplerPaletteForm_h
25
26 #include <QDialog>
27 #include <QPushButton>
28 #include <QAbstractTableModel>
29 #include <QItemDelegate>
30 #include <QSettings>
31 #include <QMap>
32
33
34 // Forward decls.
35 class QListView;
36 class QLabel;
37 class QToolButton;
38
39 namespace Ui { class qsamplerPaletteForm; }
40
41
42 namespace QSampler {
43
44 //-------------------------------------------------------------------------
45 // QSampler::PaletteForm
46
47 class PaletteForm: public QDialog
48 {
49 Q_OBJECT
50
51 public:
52
53 PaletteForm(QWidget *parent = nullptr,
54 const QPalette& pal = QPalette());
55
56 virtual ~PaletteForm();
57
58 void setPalette(const QPalette& pal);
59 const QPalette& palette() const;
60
61 void setSettings(QSettings *settings, bool owner = false);
62 QSettings *settings() const;
63
64 void setPaletteName(const QString& name);
65 QString paletteName() const;
66
67 bool isDirty() const;
68
69 static bool namedPalette(QSettings *settings,
70 const QString& name, QPalette& pal, bool fixup = false);
71 static QStringList namedPaletteList(QSettings *settings);
72
73 static QString namedPaletteConf(
74 QSettings *settings, const QString& name);
75 static void addNamedPaletteConf(
76 QSettings *settings, const QString& name, const QString& filename);
77
78 static QPalette::ColorRole colorRole(const QString& name);
79
80 class PaletteModel;
81 class ColorDelegate;
82 class ColorButton;
83 class ColorEditor;
84 class RoleEditor;
85
86 protected slots:
87
88 void nameComboChanged(const QString& name);
89 void saveButtonClicked();
90 void deleteButtonClicked();
91
92 void generateButtonChanged();
93 void resetButtonClicked();
94 void detailsCheckClicked();
95 void importButtonClicked();
96 void exportButtonClicked();
97
98 void paletteChanged(const QPalette& pal);
99
100 void accept();
101 void reject();
102
103 protected:
104
105 void setPalette(const QPalette& pal, const QPalette& parentPal);
106
107 bool namedPalette(const QString& name, QPalette& pal) const;
108 QStringList namedPaletteList() const;
109
110 QString namedPaletteConf(const QString& name) const;
111 void addNamedPaletteConf(const QString& name, const QString& filename);
112 void deleteNamedPaletteConf(const QString& name);
113
114 static bool loadNamedPaletteConf(
115 const QString& name, const QString& filename, QPalette& pal);
116 static bool saveNamedPaletteConf(
117 const QString& name, const QString& filename, const QPalette& pal);
118
119 static bool loadNamedPalette(
120 QSettings *settings, const QString& name, QPalette& pal);
121 static bool saveNamedPalette(
122 QSettings *settings, const QString& name, const QPalette& pal);
123
124 void updateNamedPaletteList();
125 void updateGenerateButton();
126 void updateDialogButtons();
127
128 void setDefaultDir(const QString& dir);
129 QString defaultDir() const;
130
131 void setShowDetails(bool on);
132 bool isShowDetails() const;
133
134 void showEvent(QShowEvent *event);
135 void resizeEvent(QResizeEvent *event);
136
137 private:
138
139 Ui::qsamplerPaletteForm *p_ui;
140 Ui::qsamplerPaletteForm& m_ui;
141
142 QSettings *m_settings;
143 bool m_owner;
144
145 QPalette m_palette;
146 QPalette m_parentPalette;
147 PaletteModel *m_paletteModel;
148 bool m_modelUpdated;
149 bool m_paletteUpdated;
150 int m_dirtyCount;
151 int m_dirtyTotal;
152 };
153
154
155 //-------------------------------------------------------------------------
156 // QSampler::PaletteForm::PaletteModel
157
158 class PaletteForm::PaletteModel : public QAbstractTableModel
159 {
160 Q_OBJECT
161 Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
162
163 public:
164
165 PaletteModel(QObject *parent = nullptr);
166
167 int rowCount(const QModelIndex &parent = QModelIndex()) const;
168 int columnCount(const QModelIndex &parent = QModelIndex()) const;
169 QVariant data(const QModelIndex &index, int role) const;
170 bool setData(const QModelIndex &index, const QVariant &value, int role);
171 Qt::ItemFlags flags(const QModelIndex &index) const;
172 QVariant headerData(int section, Qt::Orientation orientation,
173 int role = Qt::DisplayRole) const;
174
175 void setPalette(const QPalette &palette, const QPalette &parentPalette);
176 const QPalette& palette() const;
177
178 void setGenerate(bool on) { m_generate = on; }
179
180 QPalette::ColorRole colorRole() const { return QPalette::NoRole; }
181
182 signals:
183
184 void paletteChanged(const QPalette &palette);
185
186 protected:
187
188 QPalette::ColorGroup columnToGroup(int index) const;
189 int groupToColumn(QPalette::ColorGroup group) const;
190
191 private:
192
193 QPalette m_palette;
194 QPalette m_parentPalette;
195 QMap<QPalette::ColorRole, QString> m_roleNames;
196 int m_nrows;
197 bool m_generate;
198 };
199
200
201 //-------------------------------------------------------------------------
202 // QSampler::PaletteForm::ColorDelegate
203
204 class PaletteForm::ColorDelegate : public QItemDelegate
205 {
206 public:
207
208 ColorDelegate(QObject *parent = nullptr)
209 : QItemDelegate(parent) {}
210
211 QWidget *createEditor(QWidget *parent,
212 const QStyleOptionViewItem& option,
213 const QModelIndex& index) const;
214
215 void setEditorData(QWidget *editor,
216 const QModelIndex& index) const;
217 void setModelData(QWidget *editor,
218 QAbstractItemModel *model,
219 const QModelIndex& index) const;
220
221 void updateEditorGeometry(QWidget *editor,
222 const QStyleOptionViewItem& option,
223 const QModelIndex &index) const;
224
225 virtual void paint(QPainter *painter,
226 const QStyleOptionViewItem& option,
227 const QModelIndex& index) const;
228
229 virtual QSize sizeHint(const QStyleOptionViewItem& option,
230 const QModelIndex& index) const;
231 };
232
233
234 //-------------------------------------------------------------------------
235 // QSampler::PaletteForm::ColorButton
236
237 class PaletteForm::ColorButton : public QPushButton
238 {
239 Q_OBJECT
240 Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
241
242 public:
243
244 ColorButton (QWidget *parent = nullptr);
245
246 const QBrush& brush() const;
247 void setBrush(const QBrush& b);
248
249 signals:
250
251 void changed();
252
253 protected slots:
254
255 void chooseColor();
256
257 protected:
258
259 void paintEvent(QPaintEvent *event);
260
261 private:
262
263 QBrush m_brush;
264 };
265
266
267 //-------------------------------------------------------------------------
268 // QSampler::PaleteEditor::ColorEditor
269
270 class PaletteForm::ColorEditor : public QWidget
271 {
272 Q_OBJECT
273
274 public:
275
276 ColorEditor(QWidget *parent = nullptr);
277
278 void setColor(const QColor &color);
279 QColor color() const;
280 bool changed() const;
281
282 signals:
283
284 void changed(QWidget *widget);
285
286 protected slots:
287
288 void colorChanged();
289
290 private:
291
292 PaletteForm::ColorButton *m_button;
293 bool m_changed;
294 };
295
296
297 //-------------------------------------------------------------------------
298 // QSampler::PaleteEditor::RoleEditor
299
300 class PaletteForm::RoleEditor : public QWidget
301 {
302 Q_OBJECT
303
304 public:
305
306 RoleEditor(QWidget *parent = nullptr);
307
308 void setLabel(const QString &label);
309 void setEdited(bool on);
310 bool edited() const;
311
312 signals:
313
314 void changed(QWidget *widget);
315
316 protected slots:
317
318 void resetProperty();
319
320 private:
321
322 QLabel *m_label;
323 QToolButton *m_button;
324 bool m_edited;
325 };
326
327 } // namespace QSampler
328
329 #endif // __qsamplerPaletteForm_h
330
331 // end of qsamplerPaletteForm.h

  ViewVC Help
Powered by ViewVC