1 |
capela |
3648 |
// qsamplerPaletteForm.cpp |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
capela |
3760 |
Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
capela |
3648 |
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 |
|
|
#include "qsamplerAbout.h" |
24 |
|
|
#include "qsamplerPaletteForm.h" |
25 |
|
|
|
26 |
|
|
#include "ui_qsamplerPaletteForm.h" |
27 |
|
|
|
28 |
|
|
#include <QMetaProperty> |
29 |
|
|
#include <QToolButton> |
30 |
|
|
#include <QHeaderView> |
31 |
|
|
#include <QLabel> |
32 |
|
|
|
33 |
|
|
#include <QHash> |
34 |
|
|
|
35 |
|
|
#include <QPainter> |
36 |
|
|
#include <QStyle> |
37 |
|
|
#include <QStyleOption> |
38 |
|
|
|
39 |
|
|
#include <QColorDialog> |
40 |
|
|
#include <QFileDialog> |
41 |
|
|
#include <QMessageBox> |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
namespace QSampler { |
45 |
|
|
|
46 |
|
|
// Local static consts. |
47 |
|
|
static const char *ColorThemesGroup = "/ColorThemes/"; |
48 |
|
|
|
49 |
|
|
static const char *PaletteEditorGroup = "/PaletteEditor/"; |
50 |
|
|
static const char *DefaultDirKey = "DefaultDir"; |
51 |
|
|
static const char *ShowDetailsKey = "ShowDetails"; |
52 |
|
|
static const char *DefaultSuffix = "conf"; |
53 |
|
|
|
54 |
|
|
|
55 |
|
|
static struct |
56 |
|
|
{ |
57 |
|
|
const char *key; |
58 |
|
|
QPalette::ColorRole value; |
59 |
|
|
|
60 |
|
|
} g_colorRoles[] = { |
61 |
|
|
|
62 |
|
|
{ "Window", QPalette::Window }, |
63 |
|
|
{ "WindowText", QPalette::WindowText }, |
64 |
|
|
{ "Button", QPalette::Button }, |
65 |
|
|
{ "ButtonText", QPalette::ButtonText }, |
66 |
|
|
{ "Light", QPalette::Light }, |
67 |
|
|
{ "Midlight", QPalette::Midlight }, |
68 |
|
|
{ "Dark", QPalette::Dark }, |
69 |
|
|
{ "Mid", QPalette::Mid }, |
70 |
|
|
{ "Text", QPalette::Text }, |
71 |
|
|
{ "BrightText", QPalette::BrightText }, |
72 |
|
|
{ "Base", QPalette::Base }, |
73 |
|
|
{ "AlternateBase", QPalette::AlternateBase }, |
74 |
|
|
{ "Shadow", QPalette::Shadow }, |
75 |
|
|
{ "Highlight", QPalette::Highlight }, |
76 |
|
|
{ "HighlightedText", QPalette::HighlightedText }, |
77 |
|
|
{ "Link", QPalette::Link }, |
78 |
|
|
{ "LinkVisited", QPalette::LinkVisited }, |
79 |
|
|
{ "ToolTipBase", QPalette::ToolTipBase }, |
80 |
|
|
{ "ToolTipText", QPalette::ToolTipText }, |
81 |
capela |
3760 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) |
82 |
|
|
{ "PlaceholderText", QPalette::PlaceholderText }, |
83 |
|
|
#endif |
84 |
capela |
3648 |
{ "NoRole", QPalette::NoRole }, |
85 |
|
|
|
86 |
|
|
{ nullptr, QPalette::NoRole } |
87 |
|
|
}; |
88 |
|
|
|
89 |
|
|
|
90 |
|
|
//------------------------------------------------------------------------- |
91 |
|
|
// Qsampler::PaletteForm |
92 |
|
|
|
93 |
|
|
PaletteForm::PaletteForm ( QWidget *parent, const QPalette& pal ) |
94 |
|
|
: QDialog(parent), p_ui(new Ui::qsamplerPaletteForm), m_ui(*p_ui) |
95 |
|
|
{ |
96 |
|
|
m_ui.setupUi(this); |
97 |
|
|
|
98 |
|
|
m_settings = nullptr; |
99 |
|
|
m_owner = false; |
100 |
|
|
|
101 |
|
|
m_modelUpdated = false; |
102 |
|
|
m_paletteUpdated = false; |
103 |
|
|
m_dirtyCount = 0; |
104 |
|
|
m_dirtyTotal = 0; |
105 |
|
|
|
106 |
|
|
updateGenerateButton(); |
107 |
|
|
|
108 |
|
|
m_paletteModel = new PaletteModel(this); |
109 |
|
|
m_ui.paletteView->setModel(m_paletteModel); |
110 |
|
|
ColorDelegate *delegate = new ColorDelegate(this); |
111 |
|
|
m_ui.paletteView->setItemDelegate(delegate); |
112 |
|
|
m_ui.paletteView->setEditTriggers(QAbstractItemView::AllEditTriggers); |
113 |
|
|
// m_ui.paletteView->setAlternatingRowColors(true); |
114 |
|
|
m_ui.paletteView->setSelectionBehavior(QAbstractItemView::SelectRows); |
115 |
|
|
m_ui.paletteView->setDragEnabled(true); |
116 |
|
|
m_ui.paletteView->setDropIndicatorShown(true); |
117 |
|
|
m_ui.paletteView->setRootIsDecorated(false); |
118 |
|
|
m_ui.paletteView->setColumnHidden(2, true); |
119 |
|
|
m_ui.paletteView->setColumnHidden(3, true); |
120 |
|
|
|
121 |
|
|
QObject::connect(m_ui.nameCombo, |
122 |
|
|
SIGNAL(activated(const QString&)), |
123 |
|
|
SLOT(nameComboActivated(const QString&))); |
124 |
|
|
QObject::connect(m_ui.nameCombo, |
125 |
|
|
SIGNAL(editTextChanged(const QString&)), |
126 |
|
|
SLOT(nameComboChanged(const QString&))); |
127 |
|
|
QObject::connect(m_ui.saveButton, |
128 |
|
|
SIGNAL(clicked()), |
129 |
|
|
SLOT(saveButtonClicked())); |
130 |
|
|
QObject::connect(m_ui.deleteButton, |
131 |
|
|
SIGNAL(clicked()), |
132 |
|
|
SLOT(deleteButtonClicked())); |
133 |
|
|
|
134 |
|
|
QObject::connect(m_ui.generateButton, |
135 |
|
|
SIGNAL(changed()), |
136 |
|
|
SLOT(generateButtonChanged())); |
137 |
|
|
QObject::connect(m_ui.resetButton, |
138 |
|
|
SIGNAL(clicked()), |
139 |
|
|
SLOT(resetButtonClicked())); |
140 |
|
|
QObject::connect(m_ui.detailsCheck, |
141 |
|
|
SIGNAL(clicked()), |
142 |
|
|
SLOT(detailsCheckClicked())); |
143 |
|
|
QObject::connect(m_ui.importButton, |
144 |
|
|
SIGNAL(clicked()), |
145 |
|
|
SLOT(importButtonClicked())); |
146 |
|
|
QObject::connect(m_ui.exportButton, |
147 |
|
|
SIGNAL(clicked()), |
148 |
|
|
SLOT(exportButtonClicked())); |
149 |
|
|
|
150 |
|
|
QObject::connect(m_paletteModel, |
151 |
|
|
SIGNAL(paletteChanged(const QPalette&)), |
152 |
|
|
SLOT(paletteChanged(const QPalette&))); |
153 |
|
|
|
154 |
|
|
QObject::connect(m_ui.dialogButtons, |
155 |
|
|
SIGNAL(accepted()), |
156 |
|
|
SLOT(accept())); |
157 |
|
|
QObject::connect(m_ui.dialogButtons, |
158 |
|
|
SIGNAL(rejected()), |
159 |
|
|
SLOT(reject())); |
160 |
|
|
|
161 |
|
|
setPalette(pal, pal); |
162 |
|
|
|
163 |
|
|
QDialog::adjustSize(); |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
|
167 |
|
|
PaletteForm::~PaletteForm (void) |
168 |
|
|
{ |
169 |
|
|
setSettings(nullptr); |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
|
173 |
|
|
void PaletteForm::setPalette ( const QPalette& pal ) |
174 |
|
|
{ |
175 |
|
|
m_palette = pal; |
176 |
|
|
|
177 |
|
|
const uint mask = pal.resolve(); |
178 |
|
|
for (int i = 0; g_colorRoles[i].key; ++i) { |
179 |
|
|
if ((mask & (1 << i)) == 0) { |
180 |
|
|
const QPalette::ColorRole cr = QPalette::ColorRole(i); |
181 |
|
|
m_palette.setBrush(QPalette::Active, cr, |
182 |
|
|
m_parentPalette.brush(QPalette::Active, cr)); |
183 |
|
|
m_palette.setBrush(QPalette::Inactive, cr, |
184 |
|
|
m_parentPalette.brush(QPalette::Inactive, cr)); |
185 |
|
|
m_palette.setBrush(QPalette::Disabled, cr, |
186 |
|
|
m_parentPalette.brush(QPalette::Disabled, cr)); |
187 |
|
|
} |
188 |
|
|
} |
189 |
|
|
m_palette.resolve(mask); |
190 |
|
|
|
191 |
|
|
updateGenerateButton(); |
192 |
|
|
|
193 |
|
|
m_paletteUpdated = true; |
194 |
|
|
if (!m_modelUpdated) |
195 |
|
|
m_paletteModel->setPalette(m_palette, m_parentPalette); |
196 |
|
|
m_paletteUpdated = false; |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
|
200 |
|
|
void PaletteForm::setPalette ( const QPalette& pal, const QPalette& parentPal ) |
201 |
|
|
{ |
202 |
|
|
m_parentPalette = parentPal; |
203 |
|
|
|
204 |
|
|
setPalette(pal); |
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
|
208 |
|
|
const QPalette& PaletteForm::palette (void) const |
209 |
|
|
{ |
210 |
|
|
return m_palette; |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
|
214 |
|
|
void PaletteForm::setSettings ( QSettings *settings, bool owner ) |
215 |
|
|
{ |
216 |
|
|
if (m_settings && m_owner) |
217 |
|
|
delete m_settings; |
218 |
|
|
|
219 |
|
|
m_settings = settings; |
220 |
|
|
m_owner = owner; |
221 |
|
|
|
222 |
|
|
m_ui.detailsCheck->setChecked(isShowDetails()); |
223 |
|
|
|
224 |
|
|
updateNamedPaletteList(); |
225 |
|
|
updateDialogButtons(); |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
|
229 |
|
|
QSettings *PaletteForm::settings (void) const |
230 |
|
|
{ |
231 |
|
|
return m_settings; |
232 |
|
|
} |
233 |
|
|
|
234 |
|
|
|
235 |
|
|
void PaletteForm::nameComboActivated ( const QString& name ) |
236 |
|
|
{ |
237 |
|
|
setPaletteName(name); |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
|
241 |
|
|
void PaletteForm::nameComboChanged ( const QString& name ) |
242 |
|
|
{ |
243 |
|
|
if (m_dirtyCount > 0 || m_ui.nameCombo->findText(name) < 0) |
244 |
|
|
updateDialogButtons(); |
245 |
|
|
else |
246 |
|
|
setPaletteName(name); |
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
|
250 |
|
|
void PaletteForm::saveButtonClicked (void) |
251 |
|
|
{ |
252 |
|
|
const QString& name = m_ui.nameCombo->currentText(); |
253 |
|
|
if (!name.isEmpty()) { |
254 |
|
|
saveNamedPalette(name, m_palette); |
255 |
|
|
setPalette(m_palette, m_palette); |
256 |
|
|
updateNamedPaletteList(); |
257 |
|
|
resetButtonClicked(); |
258 |
|
|
} |
259 |
|
|
} |
260 |
|
|
|
261 |
|
|
|
262 |
|
|
void PaletteForm::deleteButtonClicked (void) |
263 |
|
|
{ |
264 |
|
|
const QString& name = m_ui.nameCombo->currentText(); |
265 |
|
|
if (m_ui.nameCombo->findText(name) >= 0) { |
266 |
|
|
deleteNamedPalette(name); |
267 |
|
|
updateNamedPaletteList(); |
268 |
|
|
updateDialogButtons(); |
269 |
|
|
} |
270 |
|
|
} |
271 |
|
|
|
272 |
|
|
|
273 |
|
|
void PaletteForm::generateButtonChanged (void) |
274 |
|
|
{ |
275 |
|
|
const QColor& color |
276 |
|
|
= m_ui.generateButton->brush().color(); |
277 |
|
|
const QPalette& pal = QPalette(color); |
278 |
|
|
setPalette(pal); |
279 |
|
|
|
280 |
|
|
++m_dirtyCount; |
281 |
|
|
updateDialogButtons(); |
282 |
|
|
} |
283 |
|
|
|
284 |
|
|
|
285 |
|
|
void PaletteForm::resetButtonClicked (void) |
286 |
|
|
{ |
287 |
|
|
const bool blocked = blockSignals(true); |
288 |
|
|
|
289 |
|
|
for (int i = 0; g_colorRoles[i].key; ++i) { |
290 |
|
|
const QPalette::ColorRole cr = g_colorRoles[i].value; |
291 |
|
|
const QModelIndex& index = m_paletteModel->index(cr, 0); |
292 |
|
|
m_paletteModel->setData(index, false, Qt::EditRole); |
293 |
|
|
} |
294 |
|
|
|
295 |
|
|
m_dirtyCount = 0; |
296 |
|
|
updateDialogButtons(); |
297 |
|
|
|
298 |
|
|
blockSignals(blocked); |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
|
302 |
|
|
void PaletteForm::detailsCheckClicked (void) |
303 |
|
|
{ |
304 |
|
|
const int cw = (m_ui.paletteView->viewport()->width() >> 2); |
305 |
|
|
QHeaderView *header = m_ui.paletteView->header(); |
306 |
|
|
header->resizeSection(0, cw); |
307 |
|
|
if (m_ui.detailsCheck->isChecked()) { |
308 |
|
|
m_ui.paletteView->setColumnHidden(2, false); |
309 |
|
|
m_ui.paletteView->setColumnHidden(3, false); |
310 |
|
|
header->resizeSection(1, cw); |
311 |
|
|
header->resizeSection(2, cw); |
312 |
|
|
header->resizeSection(3, cw); |
313 |
|
|
m_paletteModel->setGenerate(false); |
314 |
|
|
} else { |
315 |
|
|
m_ui.paletteView->setColumnHidden(2, true); |
316 |
|
|
m_ui.paletteView->setColumnHidden(3, true); |
317 |
|
|
header->resizeSection(1, cw * 3); |
318 |
|
|
m_paletteModel->setGenerate(true); |
319 |
|
|
} |
320 |
|
|
} |
321 |
|
|
|
322 |
|
|
|
323 |
|
|
void PaletteForm::importButtonClicked (void) |
324 |
|
|
{ |
325 |
|
|
const QString& title |
326 |
|
|
= tr("Import File - %1").arg(QDialog::windowTitle()); |
327 |
|
|
|
328 |
|
|
QStringList filters; |
329 |
|
|
filters.append(tr("Palette files (*.%1)").arg(DefaultSuffix)); |
330 |
|
|
filters.append(tr("All files (*.*)")); |
331 |
|
|
|
332 |
|
|
const QString& filename |
333 |
|
|
= QFileDialog::getOpenFileName(this, |
334 |
|
|
title, defaultDir(), filters.join(";;")); |
335 |
|
|
|
336 |
|
|
if (filename.isEmpty()) |
337 |
|
|
return; |
338 |
|
|
|
339 |
|
|
int imported = 0; |
340 |
|
|
QSettings settings(filename, QSettings::IniFormat); |
341 |
|
|
settings.beginGroup(ColorThemesGroup); |
342 |
|
|
QStringListIterator name_iter(settings.childGroups()); |
343 |
|
|
while (name_iter.hasNext()) { |
344 |
|
|
const QString& name = name_iter.next(); |
345 |
|
|
if (!name.isEmpty()) { |
346 |
|
|
QPalette pal; |
347 |
|
|
int result = 0; |
348 |
|
|
uint mask = pal.resolve(); |
349 |
|
|
settings.beginGroup(name + '/'); |
350 |
|
|
QStringListIterator iter(settings.childKeys()); |
351 |
|
|
while (iter.hasNext()) { |
352 |
|
|
const QString& key = iter.next(); |
353 |
|
|
const QPalette::ColorRole cr |
354 |
|
|
= PaletteForm::colorRole(key); |
355 |
|
|
const QStringList& clist |
356 |
|
|
= settings.value(key).toStringList(); |
357 |
|
|
if (clist.count() == 3) { |
358 |
|
|
pal.setColor(QPalette::Active, cr, QColor(clist.at(0))); |
359 |
|
|
pal.setColor(QPalette::Inactive, cr, QColor(clist.at(1))); |
360 |
|
|
pal.setColor(QPalette::Disabled, cr, QColor(clist.at(2))); |
361 |
|
|
mask &= ~(1 << int(cr)); |
362 |
|
|
++result; |
363 |
|
|
} |
364 |
|
|
} |
365 |
|
|
pal.resolve(mask); |
366 |
|
|
settings.endGroup(); |
367 |
|
|
if (result > 0) { |
368 |
|
|
saveNamedPalette(name, pal); |
369 |
|
|
setPaletteName(name); |
370 |
|
|
++imported; |
371 |
|
|
} |
372 |
|
|
} |
373 |
|
|
} |
374 |
|
|
settings.endGroup(); |
375 |
|
|
|
376 |
|
|
if (imported > 0) { |
377 |
|
|
updateNamedPaletteList(); |
378 |
|
|
resetButtonClicked(); |
379 |
|
|
setDefaultDir(QFileInfo(filename).absolutePath()); |
380 |
|
|
} else { |
381 |
|
|
QMessageBox::warning(this, |
382 |
|
|
tr("Warning - %1").arg(QDialog::windowTitle()), |
383 |
|
|
tr("Could not import from file:\n\n" |
384 |
|
|
"%1\n\nSorry.").arg(filename)); |
385 |
|
|
} |
386 |
|
|
} |
387 |
|
|
|
388 |
|
|
|
389 |
|
|
void PaletteForm::exportButtonClicked (void) |
390 |
|
|
{ |
391 |
|
|
const QString& title |
392 |
|
|
= tr("Export File - %1").arg(QDialog::windowTitle()); |
393 |
|
|
|
394 |
|
|
QStringList filters; |
395 |
|
|
filters.append(tr("Palette files (*.%1)").arg(DefaultSuffix)); |
396 |
|
|
filters.append(tr("All files (*.*)")); |
397 |
|
|
|
398 |
|
|
QString dirname = defaultDir(); |
399 |
|
|
if (!dirname.isEmpty()) |
400 |
|
|
dirname.append(QDir::separator()); |
401 |
|
|
dirname.append(paletteName() + '.' + DefaultSuffix); |
402 |
|
|
|
403 |
|
|
const QString& filename |
404 |
|
|
= QFileDialog::getSaveFileName(this, |
405 |
|
|
title, dirname, filters.join(";;")); |
406 |
|
|
|
407 |
|
|
if (filename.isEmpty()) |
408 |
|
|
return; |
409 |
|
|
|
410 |
|
|
const QPalette& pal = m_palette; |
411 |
|
|
|
412 |
|
|
QSettings settings(filename, QSettings::IniFormat); |
413 |
|
|
settings.beginGroup(ColorThemesGroup); |
414 |
|
|
settings.beginGroup(QFileInfo(filename).baseName() + '/'); |
415 |
|
|
for (int i = 0; g_colorRoles[i].key; ++i) { |
416 |
|
|
const QString& key |
417 |
|
|
= QString::fromLatin1(g_colorRoles[i].key); |
418 |
|
|
const QPalette::ColorRole cr |
419 |
|
|
= g_colorRoles[i].value; |
420 |
|
|
QStringList clist; |
421 |
|
|
clist.append(pal.color(QPalette::Active, cr).name()); |
422 |
|
|
clist.append(pal.color(QPalette::Inactive, cr).name()); |
423 |
|
|
clist.append(pal.color(QPalette::Disabled, cr).name()); |
424 |
|
|
settings.setValue(key, clist); |
425 |
|
|
} |
426 |
|
|
settings.endGroup(); |
427 |
|
|
settings.endGroup(); |
428 |
|
|
|
429 |
|
|
setDefaultDir(QFileInfo(filename).absolutePath()); |
430 |
|
|
} |
431 |
|
|
|
432 |
|
|
|
433 |
|
|
void PaletteForm::paletteChanged ( const QPalette& pal ) |
434 |
|
|
{ |
435 |
|
|
m_modelUpdated = true; |
436 |
|
|
if (!m_paletteUpdated) |
437 |
|
|
setPalette(pal); |
438 |
|
|
m_modelUpdated = false; |
439 |
|
|
|
440 |
|
|
++m_dirtyCount; |
441 |
|
|
updateDialogButtons(); |
442 |
|
|
} |
443 |
|
|
|
444 |
|
|
|
445 |
|
|
void PaletteForm::setPaletteName ( const QString& name ) |
446 |
|
|
{ |
447 |
|
|
const bool blocked = m_ui.nameCombo->blockSignals(true); |
448 |
|
|
|
449 |
|
|
m_ui.nameCombo->setEditText(name); |
450 |
|
|
|
451 |
|
|
QPalette pal; |
452 |
|
|
|
453 |
|
|
if (namedPalette(m_settings, name, pal, true)) |
454 |
|
|
setPalette(pal, pal); |
455 |
|
|
|
456 |
|
|
m_dirtyCount = 0; |
457 |
|
|
updateDialogButtons(); |
458 |
|
|
|
459 |
|
|
m_ui.nameCombo->blockSignals(blocked); |
460 |
|
|
} |
461 |
|
|
|
462 |
|
|
|
463 |
|
|
QString PaletteForm::paletteName (void) const |
464 |
|
|
{ |
465 |
|
|
return m_ui.nameCombo->currentText(); |
466 |
|
|
} |
467 |
|
|
|
468 |
|
|
|
469 |
|
|
void PaletteForm::updateNamedPaletteList (void) |
470 |
|
|
{ |
471 |
|
|
const bool blocked = m_ui.nameCombo->blockSignals(true); |
472 |
|
|
const QString old_name = m_ui.nameCombo->currentText(); |
473 |
|
|
|
474 |
|
|
m_ui.nameCombo->clear(); |
475 |
|
|
m_ui.nameCombo->insertItems(0, namedPaletteList()); |
476 |
|
|
// m_ui.nameCombo->model()->sort(0); |
477 |
|
|
|
478 |
|
|
const int i = m_ui.nameCombo->findText(old_name); |
479 |
|
|
if (i >= 0) |
480 |
|
|
m_ui.nameCombo->setCurrentIndex(i); |
481 |
|
|
else |
482 |
|
|
m_ui.nameCombo->setEditText(old_name); |
483 |
|
|
|
484 |
|
|
m_ui.nameCombo->blockSignals(blocked); |
485 |
|
|
} |
486 |
|
|
|
487 |
|
|
|
488 |
|
|
void PaletteForm::updateGenerateButton (void) |
489 |
|
|
{ |
490 |
|
|
m_ui.generateButton->setBrush( |
491 |
|
|
m_palette.brush(QPalette::Active, QPalette::Button)); |
492 |
|
|
} |
493 |
|
|
|
494 |
|
|
|
495 |
|
|
void PaletteForm::updateDialogButtons (void) |
496 |
|
|
{ |
497 |
|
|
const QString& name = m_ui.nameCombo->currentText(); |
498 |
|
|
const int i = m_ui.nameCombo->findText(name); |
499 |
|
|
m_ui.saveButton->setEnabled(!name.isEmpty() && (m_dirtyCount > 0 || i < 0)); |
500 |
|
|
m_ui.deleteButton->setEnabled(i >= 0); |
501 |
|
|
m_ui.resetButton->setEnabled(m_dirtyCount > 0); |
502 |
|
|
m_ui.exportButton->setEnabled(!name.isEmpty() || i >= 0); |
503 |
|
|
m_ui.dialogButtons->button(QDialogButtonBox::Ok)->setEnabled(i >= 0); |
504 |
|
|
if (name == "Wonton Soup" || name == "KXStudio") { |
505 |
|
|
m_ui.saveButton->setEnabled(false); |
506 |
|
|
m_ui.deleteButton->setEnabled(false); |
507 |
|
|
m_ui.exportButton->setEnabled(false); |
508 |
|
|
} |
509 |
|
|
} |
510 |
|
|
|
511 |
|
|
|
512 |
|
|
bool PaletteForm::namedPalette ( const QString& name, QPalette& pal ) |
513 |
|
|
{ |
514 |
|
|
return namedPalette(m_settings, name, pal); |
515 |
|
|
} |
516 |
|
|
|
517 |
|
|
|
518 |
|
|
bool PaletteForm::namedPalette ( |
519 |
|
|
QSettings *settings, const QString& name, QPalette& pal, bool fixup ) |
520 |
|
|
{ |
521 |
|
|
int result = 0; |
522 |
capela |
3760 |
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) |
523 |
capela |
3648 |
uint mask = pal.resolve(); |
524 |
capela |
3760 |
#endif |
525 |
capela |
3648 |
|
526 |
|
|
// Custom color themes... |
527 |
|
|
if (name == "Wonton Soup") { |
528 |
|
|
pal.setColor(QPalette::Active, QPalette::Window, QColor(73, 78, 88)); |
529 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Window, QColor(73, 78, 88)); |
530 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Window, QColor(64, 68, 77)); |
531 |
|
|
pal.setColor(QPalette::Active, QPalette::WindowText, QColor(182, 193, 208)); |
532 |
|
|
pal.setColor(QPalette::Inactive, QPalette::WindowText, QColor(182, 193, 208)); |
533 |
|
|
pal.setColor(QPalette::Disabled, QPalette::WindowText, QColor(97, 104, 114)); |
534 |
|
|
pal.setColor(QPalette::Active, QPalette::Base, QColor(60, 64, 72)); |
535 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Base, QColor(60, 64, 72)); |
536 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Base, QColor(52, 56, 63)); |
537 |
|
|
pal.setColor(QPalette::Active, QPalette::AlternateBase, QColor(67, 71, 80)); |
538 |
|
|
pal.setColor(QPalette::Inactive, QPalette::AlternateBase, QColor(67, 71, 80)); |
539 |
|
|
pal.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(59, 62, 70)); |
540 |
|
|
pal.setColor(QPalette::Active, QPalette::ToolTipBase, QColor(182, 193, 208)); |
541 |
|
|
pal.setColor(QPalette::Inactive, QPalette::ToolTipBase, QColor(182, 193, 208)); |
542 |
|
|
pal.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(182, 193, 208)); |
543 |
|
|
pal.setColor(QPalette::Active, QPalette::ToolTipText, QColor(42, 44, 48)); |
544 |
|
|
pal.setColor(QPalette::Inactive, QPalette::ToolTipText, QColor(42, 44, 48)); |
545 |
|
|
pal.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(42, 44, 48)); |
546 |
|
|
pal.setColor(QPalette::Active, QPalette::Text, QColor(210, 222, 240)); |
547 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Text, QColor(210, 222, 240)); |
548 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Text, QColor(99, 105, 115)); |
549 |
|
|
pal.setColor(QPalette::Active, QPalette::Button, QColor(82, 88, 99)); |
550 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Button, QColor(82, 88, 99)); |
551 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Button, QColor(72, 77, 87)); |
552 |
|
|
pal.setColor(QPalette::Active, QPalette::ButtonText, QColor(210, 222, 240)); |
553 |
|
|
pal.setColor(QPalette::Inactive, QPalette::ButtonText, QColor(210, 222, 240)); |
554 |
|
|
pal.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(111, 118, 130)); |
555 |
|
|
pal.setColor(QPalette::Active, QPalette::BrightText, QColor(255, 255, 255)); |
556 |
|
|
pal.setColor(QPalette::Inactive, QPalette::BrightText, QColor(255, 255, 255)); |
557 |
|
|
pal.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255)); |
558 |
|
|
pal.setColor(QPalette::Active, QPalette::Light, QColor(95, 101, 114)); |
559 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Light, QColor(95, 101, 114)); |
560 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Light, QColor(86, 92, 104)); |
561 |
|
|
pal.setColor(QPalette::Active, QPalette::Midlight, QColor(84, 90, 101)); |
562 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Midlight, QColor(84, 90, 101)); |
563 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Midlight, QColor(75, 81, 91)); |
564 |
|
|
pal.setColor(QPalette::Active, QPalette::Dark, QColor(40, 43, 49)); |
565 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Dark, QColor(40, 43, 49)); |
566 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Dark, QColor(35, 38, 43)); |
567 |
|
|
pal.setColor(QPalette::Active, QPalette::Mid, QColor(63, 68, 76)); |
568 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Mid, QColor(63, 68, 76)); |
569 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Mid, QColor(56, 59, 67)); |
570 |
|
|
pal.setColor(QPalette::Active, QPalette::Shadow, QColor(29, 31, 35)); |
571 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Shadow, QColor(29, 31, 35)); |
572 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Shadow, QColor(25, 27, 30)); |
573 |
|
|
pal.setColor(QPalette::Active, QPalette::Highlight, QColor(120, 136, 156)); |
574 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Highlight, QColor(81, 90, 103)); |
575 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Highlight, QColor(64, 68, 77)); |
576 |
|
|
pal.setColor(QPalette::Active, QPalette::HighlightedText, QColor(209, 225, 244)); |
577 |
|
|
pal.setColor(QPalette::Inactive, QPalette::HighlightedText, QColor(182, 193, 208)); |
578 |
|
|
pal.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(97, 104, 114)); |
579 |
|
|
pal.setColor(QPalette::Active, QPalette::Link, QColor(156, 212, 255)); |
580 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Link, QColor(156, 212, 255)); |
581 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Link, QColor(82, 102, 119)); |
582 |
|
|
pal.setColor(QPalette::Active, QPalette::LinkVisited, QColor(64, 128, 255)); |
583 |
|
|
pal.setColor(QPalette::Inactive, QPalette::LinkVisited, QColor(64, 128, 255)); |
584 |
|
|
pal.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(54, 76, 119)); |
585 |
capela |
3760 |
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) |
586 |
capela |
3648 |
mask = 0; |
587 |
capela |
3760 |
#endif |
588 |
capela |
3648 |
++result; |
589 |
|
|
} |
590 |
|
|
else |
591 |
|
|
if (name == "KXStudio") { |
592 |
|
|
pal.setColor(QPalette::Active, QPalette::Window, QColor(17, 17, 17)); |
593 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Window, QColor(17, 17, 17)); |
594 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Window, QColor(14, 14, 14)); |
595 |
|
|
pal.setColor(QPalette::Active, QPalette::WindowText, QColor(240, 240, 240)); |
596 |
|
|
pal.setColor(QPalette::Inactive, QPalette::WindowText, QColor(240, 240, 240)); |
597 |
|
|
pal.setColor(QPalette::Disabled, QPalette::WindowText, QColor(83, 83, 83)); |
598 |
|
|
pal.setColor(QPalette::Active, QPalette::Base, QColor(7, 7, 7)); |
599 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Base, QColor(7, 7, 7)); |
600 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Base, QColor(6, 6, 6)); |
601 |
|
|
pal.setColor(QPalette::Active, QPalette::AlternateBase, QColor(14, 14, 14)); |
602 |
|
|
pal.setColor(QPalette::Inactive, QPalette::AlternateBase, QColor(14, 14, 14)); |
603 |
|
|
pal.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(12, 12, 12)); |
604 |
|
|
pal.setColor(QPalette::Active, QPalette::ToolTipBase, QColor(4, 4, 4)); |
605 |
|
|
pal.setColor(QPalette::Inactive, QPalette::ToolTipBase, QColor(4, 4, 4)); |
606 |
|
|
pal.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(4, 4, 4)); |
607 |
|
|
pal.setColor(QPalette::Active, QPalette::ToolTipText, QColor(230, 230, 230)); |
608 |
|
|
pal.setColor(QPalette::Inactive, QPalette::ToolTipText, QColor(230, 230, 230)); |
609 |
|
|
pal.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(230, 230, 230)); |
610 |
|
|
pal.setColor(QPalette::Active, QPalette::Text, QColor(230, 230, 230)); |
611 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Text, QColor(230, 230, 230)); |
612 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Text, QColor(74, 74, 74)); |
613 |
|
|
pal.setColor(QPalette::Active, QPalette::Button, QColor(28, 28, 28)); |
614 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Button, QColor(28, 28, 28)); |
615 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Button, QColor(24, 24, 24)); |
616 |
|
|
pal.setColor(QPalette::Active, QPalette::ButtonText, QColor(240, 240, 240)); |
617 |
|
|
pal.setColor(QPalette::Inactive, QPalette::ButtonText, QColor(240, 240, 240)); |
618 |
|
|
pal.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(90, 90, 90)); |
619 |
|
|
pal.setColor(QPalette::Active, QPalette::BrightText, QColor(255, 255, 255)); |
620 |
|
|
pal.setColor(QPalette::Inactive, QPalette::BrightText, QColor(255, 255, 255)); |
621 |
|
|
pal.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255)); |
622 |
|
|
pal.setColor(QPalette::Active, QPalette::Light, QColor(191, 191, 191)); |
623 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Light, QColor(191, 191, 191)); |
624 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Light, QColor(191, 191, 191)); |
625 |
|
|
pal.setColor(QPalette::Active, QPalette::Midlight, QColor(155, 155, 155)); |
626 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Midlight, QColor(155, 155, 155)); |
627 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Midlight, QColor(155, 155, 155)); |
628 |
|
|
pal.setColor(QPalette::Active, QPalette::Dark, QColor(129, 129, 129)); |
629 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Dark, QColor(129, 129, 129)); |
630 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Dark, QColor(129, 129, 129)); |
631 |
|
|
pal.setColor(QPalette::Active, QPalette::Mid, QColor(94, 94, 94)); |
632 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Mid, QColor(94, 94, 94)); |
633 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Mid, QColor(94, 94, 94)); |
634 |
|
|
pal.setColor(QPalette::Active, QPalette::Shadow, QColor(155, 155, 155)); |
635 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Shadow, QColor(155, 155, 155)); |
636 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Shadow, QColor(155, 155, 155)); |
637 |
|
|
pal.setColor(QPalette::Active, QPalette::Highlight, QColor(60, 60, 60)); |
638 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Highlight, QColor(34, 34, 34)); |
639 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Highlight, QColor(14, 14, 14)); |
640 |
|
|
pal.setColor(QPalette::Active, QPalette::HighlightedText, QColor(255, 255, 255)); |
641 |
|
|
pal.setColor(QPalette::Inactive, QPalette::HighlightedText, QColor(240, 240, 240)); |
642 |
|
|
pal.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(83, 83, 83)); |
643 |
|
|
pal.setColor(QPalette::Active, QPalette::Link, QColor(100, 100, 230)); |
644 |
|
|
pal.setColor(QPalette::Inactive, QPalette::Link, QColor(100, 100, 230)); |
645 |
|
|
pal.setColor(QPalette::Disabled, QPalette::Link, QColor(34, 34, 74)); |
646 |
|
|
pal.setColor(QPalette::Active, QPalette::LinkVisited, QColor(230, 100, 230)); |
647 |
|
|
pal.setColor(QPalette::Inactive, QPalette::LinkVisited, QColor(230, 100, 230)); |
648 |
|
|
pal.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(74, 34, 74)); |
649 |
capela |
3760 |
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) |
650 |
capela |
3648 |
mask = 0; |
651 |
capela |
3760 |
#endif |
652 |
capela |
3648 |
++result; |
653 |
|
|
} |
654 |
|
|
else |
655 |
|
|
if (settings) { |
656 |
|
|
settings->beginGroup(ColorThemesGroup); |
657 |
|
|
settings->beginGroup(name + '/'); |
658 |
|
|
QStringListIterator iter(settings->childKeys()); |
659 |
|
|
while (iter.hasNext()) { |
660 |
|
|
const QString& key = iter.next(); |
661 |
|
|
const QPalette::ColorRole cr |
662 |
|
|
= PaletteForm::colorRole(key); |
663 |
|
|
const QStringList& clist |
664 |
|
|
= settings->value(key).toStringList(); |
665 |
|
|
if (clist.count() == 3) { |
666 |
|
|
pal.setColor(QPalette::Active, cr, QColor(clist.at(0))); |
667 |
|
|
pal.setColor(QPalette::Inactive, cr, QColor(clist.at(1))); |
668 |
|
|
pal.setColor(QPalette::Disabled, cr, QColor(clist.at(2))); |
669 |
capela |
3760 |
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) |
670 |
capela |
3648 |
mask &= ~(1 << int(cr)); |
671 |
capela |
3760 |
#endif |
672 |
capela |
3648 |
++result; |
673 |
|
|
} |
674 |
|
|
} |
675 |
|
|
settings->endGroup(); |
676 |
|
|
settings->endGroup(); |
677 |
|
|
} |
678 |
|
|
|
679 |
|
|
// Dark themes grayed/disabled color group fix... |
680 |
|
|
if (!fixup && pal.base().color().value() < 0x7f) { |
681 |
|
|
const QColor& color = pal.window().color(); |
682 |
|
|
const int groups = int(QPalette::Active | QPalette::Inactive) + 1; |
683 |
|
|
for (int i = 0; i < groups; ++i) { |
684 |
|
|
const QPalette::ColorGroup cg = QPalette::ColorGroup(i); |
685 |
|
|
pal.setBrush(cg, QPalette::Light, color.lighter(140)); |
686 |
|
|
pal.setBrush(cg, QPalette::Midlight, color.lighter(100)); |
687 |
|
|
pal.setBrush(cg, QPalette::Mid, color.lighter(90)); |
688 |
|
|
pal.setBrush(cg, QPalette::Dark, color.darker(160)); |
689 |
|
|
pal.setBrush(cg, QPalette::Shadow, color.darker(180)); |
690 |
|
|
} |
691 |
|
|
pal.setColorGroup(QPalette::Disabled, |
692 |
|
|
pal.windowText().color().darker(), |
693 |
|
|
pal.button(), |
694 |
|
|
pal.light(), |
695 |
|
|
pal.dark(), |
696 |
|
|
pal.mid(), |
697 |
|
|
pal.text().color().darker(), |
698 |
|
|
pal.text().color().lighter(), |
699 |
|
|
pal.base(), |
700 |
|
|
pal.window()); |
701 |
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
702 |
|
|
pal.setColor(QPalette::Disabled, |
703 |
|
|
QPalette::Highlight, pal.mid().color()); |
704 |
|
|
pal.setColor(QPalette::Disabled, |
705 |
|
|
QPalette::ButtonText, pal.mid().color()); |
706 |
|
|
#endif |
707 |
|
|
++result; |
708 |
|
|
} |
709 |
|
|
|
710 |
capela |
3760 |
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) |
711 |
capela |
3648 |
pal.resolve(mask); |
712 |
capela |
3760 |
#endif |
713 |
capela |
3648 |
return (result > 0); |
714 |
|
|
} |
715 |
|
|
|
716 |
|
|
|
717 |
|
|
void PaletteForm::saveNamedPalette ( |
718 |
|
|
const QString& name, const QPalette& pal ) |
719 |
|
|
{ |
720 |
|
|
if (m_settings && name != "KXStudio" && name != "Wonton Soup") { |
721 |
|
|
m_settings->beginGroup(ColorThemesGroup); |
722 |
|
|
m_settings->beginGroup(name + '/'); |
723 |
|
|
for (int i = 0; g_colorRoles[i].key; ++i) { |
724 |
|
|
const QString& key |
725 |
|
|
= QString::fromLatin1(g_colorRoles[i].key); |
726 |
|
|
const QPalette::ColorRole cr |
727 |
|
|
= g_colorRoles[i].value; |
728 |
|
|
QStringList clist; |
729 |
|
|
clist.append(pal.color(QPalette::Active, cr).name()); |
730 |
|
|
clist.append(pal.color(QPalette::Inactive, cr).name()); |
731 |
|
|
clist.append(pal.color(QPalette::Disabled, cr).name()); |
732 |
|
|
m_settings->setValue(key, clist); |
733 |
|
|
} |
734 |
|
|
m_settings->endGroup(); |
735 |
|
|
m_settings->endGroup(); |
736 |
|
|
++m_dirtyTotal; |
737 |
|
|
} |
738 |
|
|
} |
739 |
|
|
|
740 |
|
|
|
741 |
|
|
void PaletteForm::deleteNamedPalette ( const QString& name ) |
742 |
|
|
{ |
743 |
|
|
if (m_settings) { |
744 |
|
|
m_settings->beginGroup(ColorThemesGroup); |
745 |
|
|
m_settings->remove(name); |
746 |
|
|
m_settings->endGroup(); |
747 |
|
|
++m_dirtyTotal; |
748 |
|
|
} |
749 |
|
|
} |
750 |
|
|
|
751 |
|
|
|
752 |
|
|
QStringList PaletteForm::namedPaletteList (void) |
753 |
|
|
{ |
754 |
|
|
return namedPaletteList(m_settings); |
755 |
|
|
} |
756 |
|
|
|
757 |
|
|
|
758 |
|
|
QStringList PaletteForm::namedPaletteList ( QSettings *settings ) |
759 |
|
|
{ |
760 |
|
|
QStringList list; |
761 |
|
|
list.append("Wonton Soup"); |
762 |
|
|
list.append("KXStudio"); |
763 |
|
|
|
764 |
|
|
if (settings) { |
765 |
|
|
settings->beginGroup(ColorThemesGroup); |
766 |
|
|
list.append(settings->childGroups()); |
767 |
|
|
settings->endGroup(); |
768 |
|
|
} |
769 |
|
|
|
770 |
|
|
return list; |
771 |
|
|
} |
772 |
|
|
|
773 |
|
|
|
774 |
|
|
QPalette::ColorRole PaletteForm::colorRole ( const QString& name ) |
775 |
|
|
{ |
776 |
|
|
static QHash<QString, QPalette::ColorRole> s_colorRoles; |
777 |
|
|
|
778 |
|
|
if (s_colorRoles.isEmpty()) { |
779 |
|
|
for (int i = 0; g_colorRoles[i].key; ++i) { |
780 |
|
|
const QString& key |
781 |
|
|
= QString::fromLatin1(g_colorRoles[i].key); |
782 |
|
|
const QPalette::ColorRole value |
783 |
|
|
= g_colorRoles[i].value; |
784 |
|
|
s_colorRoles.insert(key, value); |
785 |
|
|
} |
786 |
|
|
} |
787 |
|
|
|
788 |
|
|
return s_colorRoles.value(name, QPalette::NoRole); |
789 |
|
|
} |
790 |
|
|
|
791 |
|
|
|
792 |
|
|
bool PaletteForm::isDirty (void) const |
793 |
|
|
{ |
794 |
|
|
return (m_dirtyTotal > 0); |
795 |
|
|
} |
796 |
|
|
|
797 |
|
|
|
798 |
|
|
void PaletteForm::accept (void) |
799 |
|
|
{ |
800 |
|
|
setShowDetails(m_ui.detailsCheck->isChecked()); |
801 |
|
|
|
802 |
|
|
if (m_dirtyCount > 0) |
803 |
|
|
saveButtonClicked(); |
804 |
|
|
|
805 |
|
|
QDialog::accept(); |
806 |
|
|
} |
807 |
|
|
|
808 |
|
|
|
809 |
|
|
void PaletteForm::reject (void) |
810 |
|
|
{ |
811 |
|
|
if (m_dirtyCount > 0) { |
812 |
|
|
const QString& name = paletteName(); |
813 |
|
|
if (name.isEmpty()) { |
814 |
|
|
if (QMessageBox::warning(this, |
815 |
|
|
tr("Warning - %1").arg(QDialog::windowTitle()), |
816 |
|
|
tr("Some settings have been changed.\n\n" |
817 |
|
|
"Do you want to discard the changes?"), |
818 |
|
|
QMessageBox::Discard | |
819 |
|
|
QMessageBox::Cancel) == QMessageBox::Cancel) |
820 |
|
|
return; |
821 |
|
|
} else { |
822 |
|
|
switch (QMessageBox::warning(this, |
823 |
|
|
tr("Warning - %1").arg(QDialog::windowTitle()), |
824 |
|
|
tr("Some settings have been changed:\n\n" |
825 |
|
|
"\"%1\".\n\nDo you want to save the changes?") |
826 |
|
|
.arg(name), |
827 |
|
|
QMessageBox::Save | |
828 |
|
|
QMessageBox::Discard | |
829 |
|
|
QMessageBox::Cancel)) { |
830 |
|
|
case QMessageBox::Save: |
831 |
|
|
saveButtonClicked(); |
832 |
|
|
// Fall thru... |
833 |
|
|
case QMessageBox::Discard: |
834 |
|
|
break; |
835 |
|
|
default: // Cancel... |
836 |
|
|
return; |
837 |
|
|
} |
838 |
|
|
} |
839 |
|
|
} |
840 |
|
|
|
841 |
|
|
QDialog::reject(); |
842 |
|
|
} |
843 |
|
|
|
844 |
|
|
|
845 |
|
|
void PaletteForm::setDefaultDir ( const QString& dir ) |
846 |
|
|
{ |
847 |
|
|
if (m_settings) { |
848 |
|
|
m_settings->beginGroup(PaletteEditorGroup); |
849 |
|
|
m_settings->setValue(DefaultDirKey, dir); |
850 |
|
|
m_settings->endGroup(); |
851 |
|
|
} |
852 |
|
|
} |
853 |
|
|
|
854 |
|
|
|
855 |
|
|
QString PaletteForm::defaultDir (void) const |
856 |
|
|
{ |
857 |
|
|
QString dir; |
858 |
|
|
|
859 |
|
|
if (m_settings) { |
860 |
|
|
m_settings->beginGroup(PaletteEditorGroup); |
861 |
|
|
dir = m_settings->value(DefaultDirKey).toString(); |
862 |
|
|
m_settings->endGroup(); |
863 |
|
|
} |
864 |
|
|
|
865 |
|
|
return dir; |
866 |
|
|
} |
867 |
|
|
|
868 |
|
|
|
869 |
|
|
void PaletteForm::setShowDetails ( bool on ) |
870 |
|
|
{ |
871 |
|
|
if (m_settings) { |
872 |
|
|
m_settings->beginGroup(PaletteEditorGroup); |
873 |
|
|
m_settings->setValue(ShowDetailsKey, on); |
874 |
|
|
m_settings->endGroup(); |
875 |
|
|
} |
876 |
|
|
} |
877 |
|
|
|
878 |
|
|
|
879 |
|
|
bool PaletteForm::isShowDetails (void) const |
880 |
|
|
{ |
881 |
|
|
bool on = false; |
882 |
|
|
|
883 |
|
|
if (m_settings) { |
884 |
|
|
m_settings->beginGroup(PaletteEditorGroup); |
885 |
|
|
on = m_settings->value(ShowDetailsKey).toBool(); |
886 |
|
|
m_settings->endGroup(); |
887 |
|
|
} |
888 |
|
|
|
889 |
|
|
return on; |
890 |
|
|
} |
891 |
|
|
|
892 |
|
|
|
893 |
|
|
void PaletteForm::showEvent ( QShowEvent *event ) |
894 |
|
|
{ |
895 |
|
|
QDialog::showEvent(event); |
896 |
|
|
|
897 |
|
|
detailsCheckClicked(); |
898 |
|
|
} |
899 |
|
|
|
900 |
|
|
|
901 |
|
|
void PaletteForm::resizeEvent ( QResizeEvent *event ) |
902 |
|
|
{ |
903 |
|
|
QDialog::resizeEvent(event); |
904 |
|
|
|
905 |
|
|
detailsCheckClicked(); |
906 |
|
|
} |
907 |
|
|
|
908 |
|
|
|
909 |
|
|
//------------------------------------------------------------------------- |
910 |
|
|
// PaletteForm::PaletteModel |
911 |
|
|
|
912 |
|
|
PaletteForm::PaletteModel::PaletteModel ( QObject *parent ) |
913 |
|
|
: QAbstractTableModel(parent) |
914 |
|
|
{ |
915 |
|
|
for (m_nrows = 0; g_colorRoles[m_nrows].key; ++m_nrows) { |
916 |
|
|
const QPalette::ColorRole value |
917 |
|
|
= g_colorRoles[m_nrows].value; |
918 |
|
|
const QString& key |
919 |
|
|
= QString::fromLatin1(g_colorRoles[m_nrows].key); |
920 |
|
|
m_roleNames.insert(value, key); |
921 |
|
|
} |
922 |
|
|
|
923 |
|
|
m_generate = true; |
924 |
|
|
} |
925 |
|
|
|
926 |
|
|
|
927 |
|
|
int PaletteForm::PaletteModel::rowCount ( const QModelIndex& ) const |
928 |
|
|
{ |
929 |
|
|
return m_nrows; |
930 |
|
|
} |
931 |
|
|
|
932 |
|
|
|
933 |
|
|
int PaletteForm::PaletteModel::columnCount ( const QModelIndex& ) const |
934 |
|
|
{ |
935 |
|
|
return 4; |
936 |
|
|
} |
937 |
|
|
|
938 |
|
|
|
939 |
|
|
QVariant PaletteForm::PaletteModel::data ( const QModelIndex& index, int role ) const |
940 |
|
|
{ |
941 |
|
|
if (!index.isValid()) |
942 |
|
|
return QVariant(); |
943 |
|
|
if (index.row() < 0 || index.row() >= m_nrows) |
944 |
|
|
return QVariant(); |
945 |
|
|
if (index.column() < 0 || index.column() >= 4) |
946 |
|
|
return QVariant(); |
947 |
|
|
|
948 |
|
|
if (index.column() == 0) { |
949 |
|
|
if (role == Qt::DisplayRole) |
950 |
|
|
return m_roleNames.value(QPalette::ColorRole(index.row())); |
951 |
|
|
if (role == Qt::EditRole) { |
952 |
|
|
const uint mask = m_palette.resolve(); |
953 |
|
|
return bool(mask & (1 << index.row())); |
954 |
|
|
} |
955 |
|
|
} |
956 |
|
|
else |
957 |
|
|
if (role == Qt::BackgroundRole) { |
958 |
|
|
return m_palette.color( |
959 |
|
|
columnToGroup(index.column()), |
960 |
|
|
QPalette::ColorRole(index.row())); |
961 |
|
|
} |
962 |
|
|
|
963 |
|
|
return QVariant(); |
964 |
|
|
} |
965 |
|
|
|
966 |
|
|
|
967 |
|
|
bool PaletteForm::PaletteModel::setData ( |
968 |
|
|
const QModelIndex& index, const QVariant& value, int role ) |
969 |
|
|
{ |
970 |
|
|
if (!index.isValid()) |
971 |
|
|
return false; |
972 |
|
|
|
973 |
|
|
if (index.column() != 0 && role == Qt::BackgroundRole) { |
974 |
|
|
const QColor& color = value.value<QColor>(); |
975 |
|
|
const QPalette::ColorRole cr = QPalette::ColorRole(index.row()); |
976 |
|
|
const QPalette::ColorGroup cg = columnToGroup(index.column()); |
977 |
|
|
m_palette.setBrush(cg, cr, color); |
978 |
|
|
QModelIndex index_begin = PaletteModel::index(cr, 0); |
979 |
|
|
QModelIndex index_end = PaletteModel::index(cr, 3); |
980 |
|
|
if (m_generate) { |
981 |
|
|
m_palette.setBrush(QPalette::Inactive, cr, color); |
982 |
|
|
switch (cr) { |
983 |
|
|
case QPalette::Foreground: |
984 |
|
|
case QPalette::Text: |
985 |
|
|
case QPalette::ButtonText: |
986 |
|
|
case QPalette::Base: |
987 |
|
|
break; |
988 |
|
|
case QPalette::Dark: |
989 |
|
|
m_palette.setBrush(QPalette::Disabled, QPalette::Foreground, color); |
990 |
|
|
m_palette.setBrush(QPalette::Disabled, QPalette::Dark, color); |
991 |
|
|
m_palette.setBrush(QPalette::Disabled, QPalette::Text, color); |
992 |
|
|
m_palette.setBrush(QPalette::Disabled, QPalette::ButtonText, color); |
993 |
|
|
index_begin = PaletteModel::index(0, 0); |
994 |
|
|
index_end = PaletteModel::index(m_nrows - 1, 3); |
995 |
|
|
break; |
996 |
|
|
case QPalette::Background: |
997 |
|
|
m_palette.setBrush(QPalette::Disabled, QPalette::Base, color); |
998 |
|
|
m_palette.setBrush(QPalette::Disabled, QPalette::Background, color); |
999 |
|
|
index_begin = PaletteModel::index(QPalette::Base, 0); |
1000 |
|
|
break; |
1001 |
|
|
case QPalette::Highlight: |
1002 |
|
|
m_palette.setBrush(QPalette::Disabled, QPalette::Highlight, color.darker(120)); |
1003 |
|
|
break; |
1004 |
|
|
default: |
1005 |
|
|
m_palette.setBrush(QPalette::Disabled, cr, color); |
1006 |
|
|
break; |
1007 |
|
|
} |
1008 |
|
|
} |
1009 |
|
|
emit paletteChanged(m_palette); |
1010 |
|
|
emit dataChanged(index_begin, index_end); |
1011 |
|
|
return true; |
1012 |
|
|
} |
1013 |
|
|
|
1014 |
|
|
if (index.column() == 0 && role == Qt::EditRole) { |
1015 |
|
|
uint mask = m_palette.resolve(); |
1016 |
|
|
const bool masked = value.value<bool>(); |
1017 |
|
|
const int i = index.row(); |
1018 |
|
|
if (masked) { |
1019 |
|
|
mask |= (1 << i); |
1020 |
|
|
} else { |
1021 |
|
|
const QPalette::ColorRole cr = QPalette::ColorRole(i); |
1022 |
|
|
m_palette.setBrush(QPalette::Active, cr, |
1023 |
|
|
m_parentPalette.brush(QPalette::Active, cr)); |
1024 |
|
|
m_palette.setBrush(QPalette::Inactive, cr, |
1025 |
|
|
m_parentPalette.brush(QPalette::Inactive, cr)); |
1026 |
|
|
m_palette.setBrush(QPalette::Disabled, cr, |
1027 |
|
|
m_parentPalette.brush(QPalette::Disabled, cr)); |
1028 |
|
|
mask &= ~(1 << i); |
1029 |
|
|
} |
1030 |
|
|
m_palette.resolve(mask); |
1031 |
|
|
emit paletteChanged(m_palette); |
1032 |
|
|
const QModelIndex& index_end = PaletteModel::index(i, 3); |
1033 |
|
|
emit dataChanged(index, index_end); |
1034 |
|
|
return true; |
1035 |
|
|
} |
1036 |
|
|
|
1037 |
|
|
return false; |
1038 |
|
|
} |
1039 |
|
|
|
1040 |
|
|
|
1041 |
|
|
Qt::ItemFlags PaletteForm::PaletteModel::flags ( const QModelIndex& index ) const |
1042 |
|
|
{ |
1043 |
|
|
if (!index.isValid()) |
1044 |
|
|
return Qt::ItemIsEnabled; |
1045 |
|
|
else |
1046 |
|
|
return Qt::ItemIsEditable | Qt::ItemIsEnabled; |
1047 |
|
|
} |
1048 |
|
|
|
1049 |
|
|
|
1050 |
|
|
QVariant PaletteForm::PaletteModel::headerData ( |
1051 |
|
|
int section, Qt::Orientation orientation, int role ) const |
1052 |
|
|
{ |
1053 |
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
1054 |
|
|
if (section == 0) |
1055 |
|
|
return tr("Color Role"); |
1056 |
|
|
else |
1057 |
|
|
if (section == groupToColumn(QPalette::Active)) |
1058 |
|
|
return tr("Active"); |
1059 |
|
|
else |
1060 |
|
|
if (section == groupToColumn(QPalette::Inactive)) |
1061 |
|
|
return tr("Inactive"); |
1062 |
|
|
else |
1063 |
|
|
if (section == groupToColumn(QPalette::Disabled)) |
1064 |
|
|
return tr("Disabled"); |
1065 |
|
|
} |
1066 |
|
|
|
1067 |
|
|
return QVariant(); |
1068 |
|
|
} |
1069 |
|
|
|
1070 |
|
|
|
1071 |
|
|
const QPalette& PaletteForm::PaletteModel::palette(void) const |
1072 |
|
|
{ |
1073 |
|
|
return m_palette; |
1074 |
|
|
} |
1075 |
|
|
|
1076 |
|
|
|
1077 |
|
|
void PaletteForm::PaletteModel::setPalette ( |
1078 |
|
|
const QPalette& palette, const QPalette& parentPalette ) |
1079 |
|
|
{ |
1080 |
|
|
m_palette = palette; |
1081 |
|
|
m_parentPalette = parentPalette; |
1082 |
|
|
|
1083 |
|
|
const QModelIndex& index_begin = index(0, 0); |
1084 |
|
|
const QModelIndex& index_end = index(m_nrows - 1, 3); |
1085 |
|
|
emit dataChanged(index_begin, index_end); |
1086 |
|
|
} |
1087 |
|
|
|
1088 |
|
|
|
1089 |
|
|
QPalette::ColorGroup PaletteForm::PaletteModel::columnToGroup ( int index ) const |
1090 |
|
|
{ |
1091 |
|
|
if (index == 1) |
1092 |
|
|
return QPalette::Active; |
1093 |
|
|
else |
1094 |
|
|
if (index == 2) |
1095 |
|
|
return QPalette::Inactive; |
1096 |
|
|
|
1097 |
|
|
return QPalette::Disabled; |
1098 |
|
|
} |
1099 |
|
|
|
1100 |
|
|
|
1101 |
|
|
int PaletteForm::PaletteModel::groupToColumn ( QPalette::ColorGroup group ) const |
1102 |
|
|
{ |
1103 |
|
|
if (group == QPalette::Active) |
1104 |
|
|
return 1; |
1105 |
|
|
else |
1106 |
|
|
if (group == QPalette::Inactive) |
1107 |
|
|
return 2; |
1108 |
|
|
|
1109 |
|
|
return 3; |
1110 |
|
|
} |
1111 |
|
|
|
1112 |
|
|
|
1113 |
|
|
//------------------------------------------------------------------------- |
1114 |
|
|
// QSampler::PaletteForm::ColorDelegate |
1115 |
|
|
|
1116 |
|
|
QWidget *PaletteForm::ColorDelegate::createEditor ( QWidget *parent, |
1117 |
|
|
const QStyleOptionViewItem&, const QModelIndex& index ) const |
1118 |
|
|
{ |
1119 |
|
|
QWidget *editor = nullptr; |
1120 |
|
|
|
1121 |
|
|
if (index.column() == 0) { |
1122 |
|
|
RoleEditor *ed = new RoleEditor(parent); |
1123 |
|
|
QObject::connect(ed, |
1124 |
|
|
SIGNAL(changed(QWidget *)), |
1125 |
|
|
SIGNAL(commitData(QWidget *))); |
1126 |
|
|
// ed->setFocusPolicy(Qt::NoFocus); |
1127 |
|
|
// ed->installEventFilter(const_cast<ColorDelegate *>(this)); |
1128 |
|
|
editor = ed; |
1129 |
|
|
} else { |
1130 |
|
|
ColorEditor *ed = new ColorEditor(parent); |
1131 |
|
|
QObject::connect(ed, |
1132 |
|
|
SIGNAL(changed(QWidget *)), |
1133 |
|
|
SIGNAL(commitData(QWidget *))); |
1134 |
|
|
ed->setFocusPolicy(Qt::NoFocus); |
1135 |
|
|
ed->installEventFilter(const_cast<ColorDelegate *>(this)); |
1136 |
|
|
editor = ed; |
1137 |
|
|
} |
1138 |
|
|
|
1139 |
|
|
return editor; |
1140 |
|
|
} |
1141 |
|
|
|
1142 |
|
|
|
1143 |
|
|
void PaletteForm::ColorDelegate::setEditorData ( |
1144 |
|
|
QWidget *editor, const QModelIndex& index ) const |
1145 |
|
|
{ |
1146 |
|
|
if (index.column() == 0) { |
1147 |
|
|
const bool masked |
1148 |
|
|
= index.model()->data(index, Qt::EditRole).value<bool>(); |
1149 |
|
|
RoleEditor *ed = static_cast<RoleEditor *>(editor); |
1150 |
|
|
ed->setEdited(masked); |
1151 |
|
|
const QString& colorName |
1152 |
|
|
= index.model()->data(index, Qt::DisplayRole).value<QString>(); |
1153 |
|
|
ed->setLabel(colorName); |
1154 |
|
|
} else { |
1155 |
|
|
const QColor& color |
1156 |
|
|
= index.model()->data(index, Qt::BackgroundRole).value<QColor>(); |
1157 |
|
|
ColorEditor *ed = static_cast<ColorEditor *>(editor); |
1158 |
|
|
ed->setColor(color); |
1159 |
|
|
} |
1160 |
|
|
} |
1161 |
|
|
|
1162 |
|
|
|
1163 |
|
|
void PaletteForm::ColorDelegate::setModelData ( QWidget *editor, |
1164 |
|
|
QAbstractItemModel *model, const QModelIndex& index ) const |
1165 |
|
|
{ |
1166 |
|
|
if (index.column() == 0) { |
1167 |
|
|
RoleEditor *ed = static_cast<RoleEditor *>(editor); |
1168 |
|
|
const bool masked = ed->edited(); |
1169 |
|
|
model->setData(index, masked, Qt::EditRole); |
1170 |
|
|
} else { |
1171 |
|
|
ColorEditor *ed = static_cast<ColorEditor *>(editor); |
1172 |
|
|
if (ed->changed()) { |
1173 |
|
|
const QColor& color = ed->color(); |
1174 |
|
|
model->setData(index, color, Qt::BackgroundRole); |
1175 |
|
|
} |
1176 |
|
|
} |
1177 |
|
|
} |
1178 |
|
|
|
1179 |
|
|
|
1180 |
|
|
void PaletteForm::ColorDelegate::updateEditorGeometry ( QWidget *editor, |
1181 |
|
|
const QStyleOptionViewItem& option, const QModelIndex& index ) const |
1182 |
|
|
{ |
1183 |
|
|
QItemDelegate::updateEditorGeometry(editor, option, index); |
1184 |
|
|
editor->setGeometry(editor->geometry().adjusted(0, 0, -1, -1)); |
1185 |
|
|
} |
1186 |
|
|
|
1187 |
|
|
|
1188 |
|
|
void PaletteForm::ColorDelegate::paint ( QPainter *painter, |
1189 |
|
|
const QStyleOptionViewItem& option, const QModelIndex& index ) const |
1190 |
|
|
{ |
1191 |
|
|
QStyleOptionViewItem opt = option; |
1192 |
|
|
|
1193 |
|
|
const bool masked |
1194 |
|
|
= index.model()->data(index, Qt::EditRole).value<bool>(); |
1195 |
|
|
if (index.column() == 0 && masked) |
1196 |
|
|
opt.font.setBold(true); |
1197 |
|
|
|
1198 |
|
|
QItemDelegate::paint(painter, opt, index); |
1199 |
|
|
|
1200 |
|
|
// painter->setPen(opt.palette.midlight().color()); |
1201 |
|
|
painter->setPen(Qt::darkGray); |
1202 |
|
|
painter->drawLine(opt.rect.right(), opt.rect.y(), |
1203 |
|
|
opt.rect.right(), opt.rect.bottom()); |
1204 |
|
|
painter->drawLine(opt.rect.x(), opt.rect.bottom(), |
1205 |
|
|
opt.rect.right(), opt.rect.bottom()); |
1206 |
|
|
} |
1207 |
|
|
|
1208 |
|
|
|
1209 |
|
|
QSize PaletteForm::ColorDelegate::sizeHint ( |
1210 |
|
|
const QStyleOptionViewItem& option, const QModelIndex &index) const |
1211 |
|
|
{ |
1212 |
|
|
return QItemDelegate::sizeHint(option, index) + QSize(4, 4); |
1213 |
|
|
} |
1214 |
|
|
|
1215 |
|
|
|
1216 |
|
|
//------------------------------------------------------------------------- |
1217 |
|
|
// QSampler::PaletteForm::ColorButton |
1218 |
|
|
|
1219 |
|
|
PaletteForm::ColorButton::ColorButton ( QWidget *parent ) |
1220 |
|
|
: QPushButton(parent), m_brush(Qt::darkGray) |
1221 |
|
|
{ |
1222 |
|
|
QPushButton::setMinimumWidth(48); |
1223 |
|
|
|
1224 |
|
|
QObject::connect(this, |
1225 |
|
|
SIGNAL(clicked()), |
1226 |
|
|
SLOT(chooseColor())); |
1227 |
|
|
} |
1228 |
|
|
|
1229 |
|
|
|
1230 |
|
|
const QBrush& PaletteForm::ColorButton::brush (void) const |
1231 |
|
|
{ |
1232 |
|
|
return m_brush; |
1233 |
|
|
} |
1234 |
|
|
|
1235 |
|
|
|
1236 |
|
|
void PaletteForm::ColorButton::setBrush ( const QBrush& brush ) |
1237 |
|
|
{ |
1238 |
|
|
m_brush = brush; |
1239 |
|
|
update(); |
1240 |
|
|
} |
1241 |
|
|
|
1242 |
|
|
|
1243 |
|
|
void PaletteForm::ColorButton::paintEvent ( QPaintEvent *event ) |
1244 |
|
|
{ |
1245 |
|
|
QPushButton::paintEvent(event); |
1246 |
|
|
|
1247 |
|
|
QStyleOptionButton opt; |
1248 |
|
|
opt.init(this); |
1249 |
|
|
|
1250 |
|
|
const QRect& rect |
1251 |
|
|
= style()->subElementRect(QStyle::SE_PushButtonContents, &opt, this); |
1252 |
|
|
|
1253 |
|
|
QPainter paint(this); |
1254 |
|
|
paint.setBrush(QBrush(m_brush.color())); |
1255 |
|
|
paint.drawRect(rect.adjusted(+1, +1, -2, -2)); |
1256 |
|
|
} |
1257 |
|
|
|
1258 |
|
|
|
1259 |
|
|
void PaletteForm::ColorButton::chooseColor (void) |
1260 |
|
|
{ |
1261 |
|
|
const QColor color |
1262 |
|
|
= QColorDialog::getColor(m_brush.color(), this); |
1263 |
|
|
if (color.isValid()) { |
1264 |
|
|
m_brush.setColor(color); |
1265 |
|
|
emit changed(); |
1266 |
|
|
} |
1267 |
|
|
} |
1268 |
|
|
|
1269 |
|
|
|
1270 |
|
|
//------------------------------------------------------------------------- |
1271 |
|
|
// QSampler::PaletteForm::ColorEditor |
1272 |
|
|
|
1273 |
|
|
PaletteForm::ColorEditor::ColorEditor ( QWidget *parent ) |
1274 |
|
|
: QWidget(parent) |
1275 |
|
|
{ |
1276 |
|
|
QLayout *layout = new QHBoxLayout(this); |
1277 |
|
|
layout->setMargin(0); |
1278 |
|
|
m_button = new PaletteForm::ColorButton(this); |
1279 |
|
|
layout->addWidget(m_button); |
1280 |
|
|
QObject::connect(m_button, |
1281 |
|
|
SIGNAL(changed()), |
1282 |
|
|
SLOT(colorChanged())); |
1283 |
|
|
setFocusProxy(m_button); |
1284 |
|
|
m_changed = false; |
1285 |
|
|
} |
1286 |
|
|
|
1287 |
|
|
|
1288 |
|
|
void PaletteForm::ColorEditor::setColor ( const QColor& color ) |
1289 |
|
|
{ |
1290 |
|
|
m_button->setBrush(color); |
1291 |
|
|
m_changed = false; |
1292 |
|
|
} |
1293 |
|
|
|
1294 |
|
|
|
1295 |
|
|
QColor PaletteForm::ColorEditor::color (void) const |
1296 |
|
|
{ |
1297 |
|
|
return m_button->brush().color(); |
1298 |
|
|
} |
1299 |
|
|
|
1300 |
|
|
|
1301 |
|
|
void PaletteForm::ColorEditor::colorChanged (void) |
1302 |
|
|
{ |
1303 |
|
|
m_changed = true; |
1304 |
|
|
emit changed(this); |
1305 |
|
|
} |
1306 |
|
|
|
1307 |
|
|
|
1308 |
|
|
bool PaletteForm::ColorEditor::changed (void) const |
1309 |
|
|
{ |
1310 |
|
|
return m_changed; |
1311 |
|
|
} |
1312 |
|
|
|
1313 |
|
|
|
1314 |
|
|
//------------------------------------------------------------------------- |
1315 |
|
|
// QSampler::PaletteForm::RoleEditor |
1316 |
|
|
|
1317 |
|
|
PaletteForm::RoleEditor::RoleEditor ( QWidget *parent ) |
1318 |
|
|
: QWidget(parent) |
1319 |
|
|
{ |
1320 |
|
|
m_edited = false; |
1321 |
|
|
|
1322 |
|
|
QHBoxLayout *layout = new QHBoxLayout(this); |
1323 |
|
|
layout->setMargin(0); |
1324 |
|
|
layout->setSpacing(0); |
1325 |
|
|
|
1326 |
|
|
m_label = new QLabel(this); |
1327 |
|
|
layout->addWidget(m_label); |
1328 |
|
|
m_label->setAutoFillBackground(true); |
1329 |
|
|
m_label->setIndent(3); // HACK: it should have the same value of textMargin in QItemDelegate |
1330 |
|
|
setFocusProxy(m_label); |
1331 |
|
|
|
1332 |
|
|
m_button = new QToolButton(this); |
1333 |
|
|
m_button->setToolButtonStyle(Qt::ToolButtonIconOnly); |
1334 |
|
|
m_button->setIcon(QPixmap(":/images/itemReset.png")); |
1335 |
|
|
m_button->setIconSize(QSize(8, 8)); |
1336 |
|
|
m_button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding)); |
1337 |
|
|
layout->addWidget(m_button); |
1338 |
|
|
|
1339 |
|
|
QObject::connect(m_button, |
1340 |
|
|
SIGNAL(clicked()), |
1341 |
|
|
SLOT(resetProperty())); |
1342 |
|
|
} |
1343 |
|
|
|
1344 |
|
|
|
1345 |
|
|
void PaletteForm::RoleEditor::setLabel ( const QString& label ) |
1346 |
|
|
{ |
1347 |
|
|
m_label->setText(label); |
1348 |
|
|
} |
1349 |
|
|
|
1350 |
|
|
|
1351 |
|
|
void PaletteForm::RoleEditor::setEdited ( bool on ) |
1352 |
|
|
{ |
1353 |
|
|
QFont font; |
1354 |
|
|
if (on) |
1355 |
|
|
font.setBold(on); |
1356 |
|
|
m_label->setFont(font); |
1357 |
|
|
m_button->setEnabled(on); |
1358 |
|
|
m_edited = on; |
1359 |
|
|
} |
1360 |
|
|
|
1361 |
|
|
|
1362 |
|
|
bool PaletteForm::RoleEditor::edited (void) const |
1363 |
|
|
{ |
1364 |
|
|
return m_edited; |
1365 |
|
|
} |
1366 |
|
|
|
1367 |
|
|
|
1368 |
|
|
void PaletteForm::RoleEditor::resetProperty (void) |
1369 |
|
|
{ |
1370 |
|
|
setEdited(false); |
1371 |
|
|
emit changed(this); |
1372 |
|
|
} |
1373 |
|
|
|
1374 |
|
|
|
1375 |
|
|
} // namespace QSampler |
1376 |
|
|
|
1377 |
|
|
// end of qsamplerPaletteForm.cpp |