1 |
// qsamplerPaletteForm.h |
2 |
// |
3 |
/**************************************************************************** |
4 |
Copyright (C) 2004-2019, 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 QStringList namedPaletteList(QSettings *settings); |
70 |
static bool namedPalette(QSettings *settings, |
71 |
const QString& name, QPalette& pal, bool fixup = false); |
72 |
|
73 |
static QPalette::ColorRole colorRole(const QString& name); |
74 |
|
75 |
class PaletteModel; |
76 |
class ColorDelegate; |
77 |
class ColorButton; |
78 |
class ColorEditor; |
79 |
class RoleEditor; |
80 |
|
81 |
protected slots: |
82 |
|
83 |
void nameComboActivated(const QString& name); |
84 |
void nameComboChanged(const QString& name); |
85 |
void saveButtonClicked(); |
86 |
void deleteButtonClicked(); |
87 |
|
88 |
void generateButtonChanged(); |
89 |
void resetButtonClicked(); |
90 |
void detailsCheckClicked(); |
91 |
void importButtonClicked(); |
92 |
void exportButtonClicked(); |
93 |
|
94 |
void paletteChanged(const QPalette& pal); |
95 |
|
96 |
void accept(); |
97 |
void reject(); |
98 |
|
99 |
protected: |
100 |
|
101 |
void setPalette(const QPalette& pal, const QPalette& parentPal); |
102 |
|
103 |
bool namedPalette(const QString& name, QPalette& pal); |
104 |
void saveNamedPalette(const QString& name, const QPalette& pal); |
105 |
void deleteNamedPalette(const QString& name); |
106 |
QStringList namedPaletteList(); |
107 |
|
108 |
void updateNamedPaletteList(); |
109 |
void updateGenerateButton(); |
110 |
void updateDialogButtons(); |
111 |
|
112 |
void setDefaultDir(const QString& dir); |
113 |
QString defaultDir() const; |
114 |
|
115 |
void setShowDetails(bool on); |
116 |
bool isShowDetails() const; |
117 |
|
118 |
void showEvent(QShowEvent *event); |
119 |
void resizeEvent(QResizeEvent *event); |
120 |
|
121 |
private: |
122 |
|
123 |
Ui::qsamplerPaletteForm *p_ui; |
124 |
Ui::qsamplerPaletteForm& m_ui; |
125 |
|
126 |
QSettings *m_settings; |
127 |
bool m_owner; |
128 |
|
129 |
QPalette m_palette; |
130 |
QPalette m_parentPalette; |
131 |
PaletteModel *m_paletteModel; |
132 |
bool m_modelUpdated; |
133 |
bool m_paletteUpdated; |
134 |
int m_dirtyCount; |
135 |
int m_dirtyTotal; |
136 |
}; |
137 |
|
138 |
|
139 |
//------------------------------------------------------------------------- |
140 |
// QSampler::PaletteForm::PaletteModel |
141 |
|
142 |
class PaletteForm::PaletteModel : public QAbstractTableModel |
143 |
{ |
144 |
Q_OBJECT |
145 |
Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole) |
146 |
|
147 |
public: |
148 |
|
149 |
PaletteModel(QObject *parent = nullptr); |
150 |
|
151 |
int rowCount(const QModelIndex &parent = QModelIndex()) const; |
152 |
int columnCount(const QModelIndex &parent = QModelIndex()) const; |
153 |
QVariant data(const QModelIndex &index, int role) const; |
154 |
bool setData(const QModelIndex &index, const QVariant &value, int role); |
155 |
Qt::ItemFlags flags(const QModelIndex &index) const; |
156 |
QVariant headerData(int section, Qt::Orientation orientation, |
157 |
int role = Qt::DisplayRole) const; |
158 |
|
159 |
void setPalette(const QPalette &palette, const QPalette &parentPalette); |
160 |
const QPalette& palette() const; |
161 |
|
162 |
void setGenerate(bool on) { m_generate = on; } |
163 |
|
164 |
QPalette::ColorRole colorRole() const { return QPalette::NoRole; } |
165 |
|
166 |
signals: |
167 |
|
168 |
void paletteChanged(const QPalette &palette); |
169 |
|
170 |
protected: |
171 |
|
172 |
QPalette::ColorGroup columnToGroup(int index) const; |
173 |
int groupToColumn(QPalette::ColorGroup group) const; |
174 |
|
175 |
private: |
176 |
|
177 |
QPalette m_palette; |
178 |
QPalette m_parentPalette; |
179 |
QMap<QPalette::ColorRole, QString> m_roleNames; |
180 |
int m_nrows; |
181 |
bool m_generate; |
182 |
}; |
183 |
|
184 |
|
185 |
//------------------------------------------------------------------------- |
186 |
// QSampler::PaletteForm::ColorDelegate |
187 |
|
188 |
class PaletteForm::ColorDelegate : public QItemDelegate |
189 |
{ |
190 |
public: |
191 |
|
192 |
ColorDelegate(QObject *parent = nullptr) |
193 |
: QItemDelegate(parent) {} |
194 |
|
195 |
QWidget *createEditor(QWidget *parent, |
196 |
const QStyleOptionViewItem& option, |
197 |
const QModelIndex& index) const; |
198 |
|
199 |
void setEditorData(QWidget *editor, |
200 |
const QModelIndex& index) const; |
201 |
void setModelData(QWidget *editor, |
202 |
QAbstractItemModel *model, |
203 |
const QModelIndex& index) const; |
204 |
|
205 |
void updateEditorGeometry(QWidget *editor, |
206 |
const QStyleOptionViewItem& option, |
207 |
const QModelIndex &index) const; |
208 |
|
209 |
virtual void paint(QPainter *painter, |
210 |
const QStyleOptionViewItem& option, |
211 |
const QModelIndex& index) const; |
212 |
|
213 |
virtual QSize sizeHint(const QStyleOptionViewItem& option, |
214 |
const QModelIndex& index) const; |
215 |
}; |
216 |
|
217 |
|
218 |
//------------------------------------------------------------------------- |
219 |
// QSampler::PaletteForm::ColorButton |
220 |
|
221 |
class PaletteForm::ColorButton : public QPushButton |
222 |
{ |
223 |
Q_OBJECT |
224 |
Q_PROPERTY(QBrush brush READ brush WRITE setBrush) |
225 |
|
226 |
public: |
227 |
|
228 |
ColorButton (QWidget *parent = nullptr); |
229 |
|
230 |
const QBrush& brush() const; |
231 |
void setBrush(const QBrush& b); |
232 |
|
233 |
signals: |
234 |
|
235 |
void changed(); |
236 |
|
237 |
protected slots: |
238 |
|
239 |
void chooseColor(); |
240 |
|
241 |
protected: |
242 |
|
243 |
void paintEvent(QPaintEvent *event); |
244 |
|
245 |
private: |
246 |
|
247 |
QBrush m_brush; |
248 |
}; |
249 |
|
250 |
|
251 |
//------------------------------------------------------------------------- |
252 |
// QSampler::PaleteEditor::ColorEditor |
253 |
|
254 |
class PaletteForm::ColorEditor : public QWidget |
255 |
{ |
256 |
Q_OBJECT |
257 |
|
258 |
public: |
259 |
|
260 |
ColorEditor(QWidget *parent = nullptr); |
261 |
|
262 |
void setColor(const QColor &color); |
263 |
QColor color() const; |
264 |
bool changed() const; |
265 |
|
266 |
signals: |
267 |
|
268 |
void changed(QWidget *widget); |
269 |
|
270 |
protected slots: |
271 |
|
272 |
void colorChanged(); |
273 |
|
274 |
private: |
275 |
|
276 |
PaletteForm::ColorButton *m_button; |
277 |
bool m_changed; |
278 |
}; |
279 |
|
280 |
|
281 |
//------------------------------------------------------------------------- |
282 |
// QSampler::PaleteEditor::RoleEditor |
283 |
|
284 |
class PaletteForm::RoleEditor : public QWidget |
285 |
{ |
286 |
Q_OBJECT |
287 |
|
288 |
public: |
289 |
|
290 |
RoleEditor(QWidget *parent = nullptr); |
291 |
|
292 |
void setLabel(const QString &label); |
293 |
void setEdited(bool on); |
294 |
bool edited() const; |
295 |
|
296 |
signals: |
297 |
|
298 |
void changed(QWidget *widget); |
299 |
|
300 |
protected slots: |
301 |
|
302 |
void resetProperty(); |
303 |
|
304 |
private: |
305 |
|
306 |
QLabel *m_label; |
307 |
QToolButton *m_button; |
308 |
bool m_edited; |
309 |
}; |
310 |
|
311 |
} // namespace QSampler |
312 |
|
313 |
#endif // __qsamplerPaletteForm_h |
314 |
|
315 |
// end of qsamplerPaletteForm.h |