summaryrefslogtreecommitdiff
path: root/utils/themeeditor/preferencesdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/preferencesdialog.cpp')
-rw-r--r--utils/themeeditor/preferencesdialog.cpp164
1 files changed, 164 insertions, 0 deletions
diff --git a/utils/themeeditor/preferencesdialog.cpp b/utils/themeeditor/preferencesdialog.cpp
new file mode 100644
index 0000000000..4d3ad04495
--- /dev/null
+++ b/utils/themeeditor/preferencesdialog.cpp
@@ -0,0 +1,164 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "preferencesdialog.h"
23#include "ui_preferencesdialog.h"
24
25#include <QSettings>
26#include <QColorDialog>
27
28PreferencesDialog::PreferencesDialog(QWidget *parent) :
29 QDialog(parent),
30 ui(new Ui::PreferencesDialog)
31{
32 ui->setupUi(this);
33 setupUI();
34 loadSettings();
35}
36
37PreferencesDialog::~PreferencesDialog()
38{
39 delete ui;
40}
41
42void PreferencesDialog::loadSettings()
43{
44 loadColors();
45}
46
47void PreferencesDialog::loadColors()
48{
49
50 QSettings settings;
51
52 /* The list of buttons from the SkinHighlighter group */
53
54 settings.beginGroup("SkinHighlighter");
55
56 commentColor = settings.value("commentColor",
57 QColor(0, 180, 0)).value<QColor>();
58 setButtonColor(ui->commentButton, commentColor);
59
60 escapedColor = settings.value("escapedColor",
61 QColor(120,120,120)).value<QColor>();
62 setButtonColor(ui->escapedButton, escapedColor);
63
64 conditionalColor = settings.value("conditionalColor",
65 QColor(0, 0, 180)).value<QColor>();
66 setButtonColor(ui->conditionalButton, conditionalColor);
67
68 tagColor = settings.value("tagColor",
69 QColor(180, 0, 0)).value<QColor>();
70 setButtonColor(ui->tagButton, tagColor);
71
72 settings.endGroup();
73
74 /* Buttons from the editor group */
75 settings.beginGroup("SkinDocument");
76
77 fgColor = settings.value("fgColor", Qt::black).value<QColor>();
78 setButtonColor(ui->fgButton, fgColor);
79
80 bgColor = settings.value("bgColor", Qt::white).value<QColor>();
81 setButtonColor(ui->bgButton, bgColor);
82
83 settings.endGroup();
84}
85
86void PreferencesDialog::saveSettings()
87{
88 saveColors();
89}
90
91void PreferencesDialog::saveColors()
92{
93 QSettings settings;
94
95 /* Saving the editor colors */
96 settings.beginGroup("SkinDocument");
97
98 settings.setValue("fgColor", fgColor);
99 settings.setValue("bgColor", bgColor);
100
101 settings.endGroup();
102
103 /* Saving the highlighting colors */
104 settings.beginGroup("SkinHighlighter");
105
106 settings.setValue("tagColor", tagColor);
107 settings.setValue("commentColor", commentColor);
108 settings.setValue("conditionalColor", conditionalColor);
109 settings.setValue("escapedColor", escapedColor);
110
111 settings.endGroup();
112}
113
114void PreferencesDialog::setupUI()
115{
116 /* Connecting color buttons */
117 QList<QPushButton*> buttons;
118 buttons.append(ui->bgButton);
119 buttons.append(ui->fgButton);
120 buttons.append(ui->commentButton);
121 buttons.append(ui->tagButton);
122 buttons.append(ui->conditionalButton);
123 buttons.append(ui->escapedButton);
124
125 for(int i = 0; i < buttons.count(); i++)
126 QObject::connect(buttons[i], SIGNAL(pressed()),
127 this, SLOT(colorClicked()));
128}
129
130void PreferencesDialog::colorClicked()
131{
132 QColor* toEdit = 0;
133
134 if(QObject::sender() == ui->bgButton)
135 toEdit = &bgColor;
136 else if(QObject::sender() == ui->fgButton)
137 toEdit = &fgColor;
138 else if(QObject::sender() == ui->commentButton)
139 toEdit = &commentColor;
140 else if(QObject::sender() == ui->tagButton)
141 toEdit = &tagColor;
142 else if(QObject::sender() == ui->conditionalButton)
143 toEdit = &conditionalColor;
144 else if(QObject::sender() == ui->escapedButton)
145 toEdit = &escapedColor;
146
147 if(!toEdit)
148 return;
149
150 *toEdit = QColorDialog::getColor(*toEdit, this);
151 setButtonColor(dynamic_cast<QPushButton*>(QObject::sender()), *toEdit);
152}
153
154void PreferencesDialog::accept()
155{
156 saveSettings();
157 QDialog::accept();
158}
159
160void PreferencesDialog::reject()
161{
162 loadSettings();
163 QDialog::reject();
164}