Theme Editor: Made auto-expand/highlight of parse tree optional (through preferences...
[kugel-rb.git] / utils / themeeditor / gui / preferencesdialog.cpp
blobdbb3249e9f008a1b10ad60ab0cdb611123504b55
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Robert Bieber
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "preferencesdialog.h"
23 #include "ui_preferencesdialog.h"
25 #include <QSettings>
26 #include <QColorDialog>
27 #include <QFileDialog>
29 PreferencesDialog::PreferencesDialog(QWidget *parent) :
30 QDialog(parent),
31 ui(new Ui::PreferencesDialog)
33 ui->setupUi(this);
34 setupUI();
35 loadSettings();
38 PreferencesDialog::~PreferencesDialog()
40 delete ui;
43 void PreferencesDialog::loadSettings()
45 loadColors();
46 loadFont();
47 loadRender();
50 void PreferencesDialog::loadColors()
53 QSettings settings;
55 /* The list of buttons from the SkinHighlighter group */
57 settings.beginGroup("SkinHighlighter");
59 commentColor = settings.value("commentColor",
60 QColor(0, 180, 0)).value<QColor>();
61 setButtonColor(ui->commentButton, commentColor);
63 escapedColor = settings.value("escapedColor",
64 QColor(120,120,120)).value<QColor>();
65 setButtonColor(ui->escapedButton, escapedColor);
67 conditionalColor = settings.value("conditionalColor",
68 QColor(0, 0, 180)).value<QColor>();
69 setButtonColor(ui->conditionalButton, conditionalColor);
71 tagColor = settings.value("tagColor",
72 QColor(180, 0, 0)).value<QColor>();
73 setButtonColor(ui->tagButton, tagColor);
75 settings.endGroup();
77 /* Buttons from the editor group */
78 settings.beginGroup("SkinDocument");
80 fgColor = settings.value("fgColor", Qt::black).value<QColor>();
81 setButtonColor(ui->fgButton, fgColor);
83 bgColor = settings.value("bgColor", Qt::white).value<QColor>();
84 setButtonColor(ui->bgButton, bgColor);
86 errorColor = settings.value("errorColor", Qt::red).value<QColor>();
87 setButtonColor(ui->errorButton, errorColor);
89 settings.endGroup();
92 void PreferencesDialog::loadFont()
94 QSettings settings;
95 settings.beginGroup("SkinDocument");
97 QFont def("Monospace");
98 def.setStyleHint(QFont::TypeWriter);
100 QVariant family = settings.value("fontFamily", def);
101 int size = settings.value("fontSize", 12).toInt();
103 settings.endGroup();
105 ui->fontSelect->setCurrentFont(family.value<QFont>());
106 ui->fontSize->setValue(size);
110 void PreferencesDialog::loadRender()
112 QSettings settings;
113 settings.beginGroup("RBFont");
115 ui->fontBox->setText(settings.value("fontDir", "/").toString());
117 settings.endGroup();
119 settings.beginGroup("EditorWindow");
121 ui->autoExpandBox->setChecked(settings.value("autoExpandTree",
122 false).toBool());
123 ui->autoHighlightBox->setChecked(settings.value("autoHighlightTree",
124 false).toBool());
126 settings.endGroup();
129 void PreferencesDialog::saveSettings()
131 saveColors();
132 saveFont();
133 saveRender();
136 void PreferencesDialog::saveColors()
138 QSettings settings;
140 /* Saving the editor colors */
141 settings.beginGroup("SkinDocument");
143 settings.setValue("fgColor", fgColor);
144 settings.setValue("bgColor", bgColor);
145 settings.setValue("errorColor", errorColor);
147 settings.endGroup();
149 /* Saving the highlighting colors */
150 settings.beginGroup("SkinHighlighter");
152 settings.setValue("tagColor", tagColor);
153 settings.setValue("commentColor", commentColor);
154 settings.setValue("conditionalColor", conditionalColor);
155 settings.setValue("escapedColor", escapedColor);
157 settings.endGroup();
160 void PreferencesDialog::saveFont()
162 QSettings settings;
163 settings.beginGroup("SkinDocument");
165 settings.setValue("fontFamily", ui->fontSelect->currentFont());
166 settings.setValue("fontSize", ui->fontSize->value());
168 settings.endGroup();
171 void PreferencesDialog::saveRender()
173 QSettings settings;
174 settings.beginGroup("RBFont");
176 settings.setValue("fontDir", ui->fontBox->text());
178 settings.endGroup();
180 settings.beginGroup("EditorWindow");
182 settings.setValue("autoExpandTree", ui->autoExpandBox->isChecked());
183 settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked());
185 settings.endGroup();
188 void PreferencesDialog::setupUI()
190 /* Connecting color buttons */
191 QList<QPushButton*> buttons;
192 buttons.append(ui->bgButton);
193 buttons.append(ui->fgButton);
194 buttons.append(ui->commentButton);
195 buttons.append(ui->tagButton);
196 buttons.append(ui->conditionalButton);
197 buttons.append(ui->escapedButton);
198 buttons.append(ui->errorButton);
200 for(int i = 0; i < buttons.count(); i++)
201 QObject::connect(buttons[i], SIGNAL(pressed()),
202 this, SLOT(colorClicked()));
204 QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()),
205 this, SLOT(browseFont()));
208 void PreferencesDialog::colorClicked()
210 QColor* toEdit = 0, newColor;
212 if(QObject::sender() == ui->bgButton)
213 toEdit = &bgColor;
214 else if(QObject::sender() == ui->fgButton)
215 toEdit = &fgColor;
216 else if(QObject::sender() == ui->commentButton)
217 toEdit = &commentColor;
218 else if(QObject::sender() == ui->tagButton)
219 toEdit = &tagColor;
220 else if(QObject::sender() == ui->conditionalButton)
221 toEdit = &conditionalColor;
222 else if(QObject::sender() == ui->escapedButton)
223 toEdit = &escapedColor;
224 else if(QObject::sender() == ui->errorButton)
225 toEdit = &errorColor;
227 if(!toEdit)
228 return;
230 newColor = QColorDialog::getColor(*toEdit, this);
231 if (newColor.isValid())
233 *toEdit = newColor;
234 setButtonColor(dynamic_cast<QPushButton*>(QObject::sender()), *toEdit);
238 void PreferencesDialog::browseFont()
240 QString path = QFileDialog::
241 getExistingDirectory(this, "Font Directory",
242 ui->fontBox->text());
243 ui->fontBox->setText(path);
246 void PreferencesDialog::accept()
248 saveSettings();
249 QDialog::accept();
252 void PreferencesDialog::reject()
254 loadSettings();
255 QDialog::reject();