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

Annotation of /qsampler/trunk/src/qsamplerPaletteForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC