fuze+: use mdelay and not udelay in lcd sequences
[kugel-rb.git] / utils / themeeditor / gui / preferencesdialog.cpp
blob2c4acaee8440c0224c5c7cc7a53b5b5ae0d8e7ed
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"
24 #include "fontdownloader.h"
25 #include "targetdownloader.h"
27 #include <QSettings>
28 #include <QColorDialog>
29 #include <QFileDialog>
31 PreferencesDialog::PreferencesDialog(QWidget *parent) :
32 QDialog(parent),
33 ui(new Ui::PreferencesDialog)
35 ui->setupUi(this);
36 setupUI();
37 loadSettings();
40 PreferencesDialog::~PreferencesDialog()
42 delete ui;
45 void PreferencesDialog::loadSettings()
47 loadColors();
48 loadFont();
49 loadRender();
51 QSettings settings;
52 settings.beginGroup("CodeEditor");
53 ui->completionBox->setChecked(settings.value("completeSyntax",
54 true).toBool());
55 settings.endGroup();
58 void PreferencesDialog::loadColors()
61 QSettings settings;
63 /* The list of buttons from the SkinHighlighter group */
65 settings.beginGroup("SkinHighlighter");
67 commentColor = settings.value("commentColor",
68 QColor(0, 180, 0)).value<QColor>();
69 setButtonColor(ui->commentButton, commentColor);
71 escapedColor = settings.value("escapedColor",
72 QColor(120,120,120)).value<QColor>();
73 setButtonColor(ui->escapedButton, escapedColor);
75 conditionalColor = settings.value("conditionalColor",
76 QColor(0, 0, 180)).value<QColor>();
77 setButtonColor(ui->conditionalButton, conditionalColor);
79 tagColor = settings.value("tagColor",
80 QColor(180, 0, 0)).value<QColor>();
81 setButtonColor(ui->tagButton, tagColor);
83 settings.endGroup();
85 /* Buttons from the editor group */
86 settings.beginGroup("SkinDocument");
88 fgColor = settings.value("fgColor", Qt::black).value<QColor>();
89 setButtonColor(ui->fgButton, fgColor);
91 bgColor = settings.value("bgColor", Qt::white).value<QColor>();
92 setButtonColor(ui->bgButton, bgColor);
94 errorColor = settings.value("errorColor", Qt::red).value<QColor>();
95 setButtonColor(ui->errorButton, errorColor);
97 settings.endGroup();
100 void PreferencesDialog::loadFont()
102 QSettings settings;
103 settings.beginGroup("SkinDocument");
105 QFont def("Monospace");
106 def.setStyleHint(QFont::TypeWriter);
108 QVariant family = settings.value("fontFamily", def);
109 int size = settings.value("fontSize", 12).toInt();
111 settings.endGroup();
113 ui->fontSelect->setCurrentFont(family.value<QFont>());
114 ui->fontSize->setValue(size);
118 void PreferencesDialog::loadRender()
120 QSettings settings;
121 settings.beginGroup("RBFont");
123 QString confDir = QDir::homePath() + "/.rbthemeeditor";
125 ui->fontBox->setText(settings.value("fontDir", confDir + "/fonts/")
126 .toString());
128 settings.endGroup();
130 settings.beginGroup("EditorWindow");
132 ui->autoExpandBox->setChecked(settings.value("autoExpandTree",
133 false).toBool());
134 ui->autoHighlightBox->setChecked(settings.value("autoHighlightTree",
135 false).toBool());
137 settings.endGroup();
139 settings.beginGroup("TargetData");
141 ui->dbBox->setText(settings.value("targetDbPath",
142 confDir + "/targetdb")
143 .toString());
145 settings.endGroup();
148 void PreferencesDialog::saveSettings()
150 saveColors();
151 saveFont();
152 saveRender();
154 QSettings settings;
155 settings.beginGroup("CodeEditor");
156 settings.setValue("completeSyntax", ui->completionBox->isChecked());
157 settings.endGroup();
161 void PreferencesDialog::saveColors()
163 QSettings settings;
165 /* Saving the editor colors */
166 settings.beginGroup("SkinDocument");
168 settings.setValue("fgColor", fgColor);
169 settings.setValue("bgColor", bgColor);
170 settings.setValue("errorColor", errorColor);
172 settings.endGroup();
174 /* Saving the highlighting colors */
175 settings.beginGroup("SkinHighlighter");
177 settings.setValue("tagColor", tagColor);
178 settings.setValue("commentColor", commentColor);
179 settings.setValue("conditionalColor", conditionalColor);
180 settings.setValue("escapedColor", escapedColor);
182 settings.endGroup();
185 void PreferencesDialog::saveFont()
187 QSettings settings;
188 settings.beginGroup("SkinDocument");
190 settings.setValue("fontFamily", ui->fontSelect->currentFont());
191 settings.setValue("fontSize", ui->fontSize->value());
193 settings.endGroup();
196 void PreferencesDialog::saveRender()
198 QSettings settings;
199 settings.beginGroup("RBFont");
201 settings.setValue("fontDir", ui->fontBox->text());
203 settings.endGroup();
205 settings.beginGroup("EditorWindow");
207 settings.setValue("autoExpandTree", ui->autoExpandBox->isChecked());
208 settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked());
210 settings.endGroup();
212 settings.beginGroup("TargetData");
213 settings.setValue("targetDbPath", ui->dbBox->text());
214 settings.endGroup();
217 void PreferencesDialog::setupUI()
219 /* Connecting color buttons */
220 QList<QPushButton*> buttons;
221 buttons.append(ui->bgButton);
222 buttons.append(ui->fgButton);
223 buttons.append(ui->commentButton);
224 buttons.append(ui->tagButton);
225 buttons.append(ui->conditionalButton);
226 buttons.append(ui->escapedButton);
227 buttons.append(ui->errorButton);
229 for(int i = 0; i < buttons.count(); i++)
230 QObject::connect(buttons[i], SIGNAL(pressed()),
231 this, SLOT(colorClicked()));
233 QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()),
234 this, SLOT(browseFont()));
235 QObject::connect(ui->browseDB, SIGNAL(clicked()),
236 this, SLOT(browseDB()));
237 QObject::connect(ui->dlFontsButton, SIGNAL(clicked()),
238 this, SLOT(dlFonts()));
239 QObject::connect(ui->dlTargetButton, SIGNAL(clicked()),
240 this, SLOT(dlTargetDB()));
243 void PreferencesDialog::colorClicked()
245 QColor* toEdit = 0, newColor;
247 if(QObject::sender() == ui->bgButton)
248 toEdit = &bgColor;
249 else if(QObject::sender() == ui->fgButton)
250 toEdit = &fgColor;
251 else if(QObject::sender() == ui->commentButton)
252 toEdit = &commentColor;
253 else if(QObject::sender() == ui->tagButton)
254 toEdit = &tagColor;
255 else if(QObject::sender() == ui->conditionalButton)
256 toEdit = &conditionalColor;
257 else if(QObject::sender() == ui->escapedButton)
258 toEdit = &escapedColor;
259 else if(QObject::sender() == ui->errorButton)
260 toEdit = &errorColor;
262 if(!toEdit)
263 return;
265 newColor = QColorDialog::getColor(*toEdit, this);
266 if (newColor.isValid())
268 *toEdit = newColor;
269 setButtonColor(dynamic_cast<QPushButton*>(QObject::sender()), *toEdit);
273 void PreferencesDialog::browseFont()
275 QString path = QFileDialog::
276 getExistingDirectory(this, "Font Directory",
277 ui->fontBox->text());
278 ui->fontBox->setText(path);
281 void PreferencesDialog::browseDB()
283 QString path = QFileDialog::getOpenFileName(this, tr("Target DB"),
284 QDir(ui->dbBox->text()).
285 absolutePath(),
286 "All Files (*)");
287 ui->dbBox->setText(path);
290 void PreferencesDialog::dlFonts()
292 FontDownloader* dl = new FontDownloader(this, ui->fontBox->text());
293 dl->show();
296 void PreferencesDialog::dlTargetDB()
298 TargetDownloader* dl = new TargetDownloader(this, ui->dbBox->text());
299 dl->show();
302 void PreferencesDialog::accept()
304 saveSettings();
305 QDialog::accept();
308 void PreferencesDialog::reject()
310 loadSettings();
311 QDialog::reject();