Theme Editor: Implemented download and decompression of font pack in the preferences...
[kugel-rb.git] / utils / themeeditor / gui / preferencesdialog.cpp
blobb8d0a0a6d61ff579ec0b73ed7808962e1fbd672d
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"
26 #include <QSettings>
27 #include <QColorDialog>
28 #include <QFileDialog>
30 PreferencesDialog::PreferencesDialog(QWidget *parent) :
31 QDialog(parent),
32 ui(new Ui::PreferencesDialog)
34 ui->setupUi(this);
35 setupUI();
36 loadSettings();
39 PreferencesDialog::~PreferencesDialog()
41 delete ui;
44 void PreferencesDialog::loadSettings()
46 loadColors();
47 loadFont();
48 loadRender();
51 void PreferencesDialog::loadColors()
54 QSettings settings;
56 /* The list of buttons from the SkinHighlighter group */
58 settings.beginGroup("SkinHighlighter");
60 commentColor = settings.value("commentColor",
61 QColor(0, 180, 0)).value<QColor>();
62 setButtonColor(ui->commentButton, commentColor);
64 escapedColor = settings.value("escapedColor",
65 QColor(120,120,120)).value<QColor>();
66 setButtonColor(ui->escapedButton, escapedColor);
68 conditionalColor = settings.value("conditionalColor",
69 QColor(0, 0, 180)).value<QColor>();
70 setButtonColor(ui->conditionalButton, conditionalColor);
72 tagColor = settings.value("tagColor",
73 QColor(180, 0, 0)).value<QColor>();
74 setButtonColor(ui->tagButton, tagColor);
76 settings.endGroup();
78 /* Buttons from the editor group */
79 settings.beginGroup("SkinDocument");
81 fgColor = settings.value("fgColor", Qt::black).value<QColor>();
82 setButtonColor(ui->fgButton, fgColor);
84 bgColor = settings.value("bgColor", Qt::white).value<QColor>();
85 setButtonColor(ui->bgButton, bgColor);
87 errorColor = settings.value("errorColor", Qt::red).value<QColor>();
88 setButtonColor(ui->errorButton, errorColor);
90 settings.endGroup();
93 void PreferencesDialog::loadFont()
95 QSettings settings;
96 settings.beginGroup("SkinDocument");
98 QFont def("Monospace");
99 def.setStyleHint(QFont::TypeWriter);
101 QVariant family = settings.value("fontFamily", def);
102 int size = settings.value("fontSize", 12).toInt();
104 settings.endGroup();
106 ui->fontSelect->setCurrentFont(family.value<QFont>());
107 ui->fontSize->setValue(size);
111 void PreferencesDialog::loadRender()
113 QSettings settings;
114 settings.beginGroup("RBFont");
116 ui->fontBox->setText(settings.value("fontDir", "/").toString());
118 settings.endGroup();
120 settings.beginGroup("EditorWindow");
122 ui->autoExpandBox->setChecked(settings.value("autoExpandTree",
123 false).toBool());
124 ui->autoHighlightBox->setChecked(settings.value("autoHighlightTree",
125 false).toBool());
127 settings.endGroup();
129 settings.beginGroup("TargetData");
131 ui->dbBox->setText(settings.value("targetDbPath",
132 QDir::homePath() + "/.targetdb")
133 .toString());
135 settings.endGroup();
138 void PreferencesDialog::saveSettings()
140 saveColors();
141 saveFont();
142 saveRender();
145 void PreferencesDialog::saveColors()
147 QSettings settings;
149 /* Saving the editor colors */
150 settings.beginGroup("SkinDocument");
152 settings.setValue("fgColor", fgColor);
153 settings.setValue("bgColor", bgColor);
154 settings.setValue("errorColor", errorColor);
156 settings.endGroup();
158 /* Saving the highlighting colors */
159 settings.beginGroup("SkinHighlighter");
161 settings.setValue("tagColor", tagColor);
162 settings.setValue("commentColor", commentColor);
163 settings.setValue("conditionalColor", conditionalColor);
164 settings.setValue("escapedColor", escapedColor);
166 settings.endGroup();
169 void PreferencesDialog::saveFont()
171 QSettings settings;
172 settings.beginGroup("SkinDocument");
174 settings.setValue("fontFamily", ui->fontSelect->currentFont());
175 settings.setValue("fontSize", ui->fontSize->value());
177 settings.endGroup();
180 void PreferencesDialog::saveRender()
182 QSettings settings;
183 settings.beginGroup("RBFont");
185 settings.setValue("fontDir", ui->fontBox->text());
187 settings.endGroup();
189 settings.beginGroup("EditorWindow");
191 settings.setValue("autoExpandTree", ui->autoExpandBox->isChecked());
192 settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked());
194 settings.endGroup();
196 settings.beginGroup("TargetData");
197 settings.setValue("targetDbPath", ui->dbBox->text());
198 settings.endGroup();
201 void PreferencesDialog::setupUI()
203 /* Connecting color buttons */
204 QList<QPushButton*> buttons;
205 buttons.append(ui->bgButton);
206 buttons.append(ui->fgButton);
207 buttons.append(ui->commentButton);
208 buttons.append(ui->tagButton);
209 buttons.append(ui->conditionalButton);
210 buttons.append(ui->escapedButton);
211 buttons.append(ui->errorButton);
213 for(int i = 0; i < buttons.count(); i++)
214 QObject::connect(buttons[i], SIGNAL(pressed()),
215 this, SLOT(colorClicked()));
217 QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()),
218 this, SLOT(browseFont()));
219 QObject::connect(ui->browseDB, SIGNAL(clicked()),
220 this, SLOT(browseDB()));
221 QObject::connect(ui->dlFontsButton, SIGNAL(clicked()),
222 this, SLOT(dlFonts()));
225 void PreferencesDialog::colorClicked()
227 QColor* toEdit = 0, newColor;
229 if(QObject::sender() == ui->bgButton)
230 toEdit = &bgColor;
231 else if(QObject::sender() == ui->fgButton)
232 toEdit = &fgColor;
233 else if(QObject::sender() == ui->commentButton)
234 toEdit = &commentColor;
235 else if(QObject::sender() == ui->tagButton)
236 toEdit = &tagColor;
237 else if(QObject::sender() == ui->conditionalButton)
238 toEdit = &conditionalColor;
239 else if(QObject::sender() == ui->escapedButton)
240 toEdit = &escapedColor;
241 else if(QObject::sender() == ui->errorButton)
242 toEdit = &errorColor;
244 if(!toEdit)
245 return;
247 newColor = QColorDialog::getColor(*toEdit, this);
248 if (newColor.isValid())
250 *toEdit = newColor;
251 setButtonColor(dynamic_cast<QPushButton*>(QObject::sender()), *toEdit);
255 void PreferencesDialog::browseFont()
257 QString path = QFileDialog::
258 getExistingDirectory(this, "Font Directory",
259 ui->fontBox->text());
260 ui->fontBox->setText(path);
263 void PreferencesDialog::browseDB()
265 QString path = QFileDialog::getOpenFileName(this, tr("Target DB"),
266 QDir(ui->dbBox->text()).
267 absolutePath(),
268 "All Files (*)");
269 ui->dbBox->setText(path);
272 void PreferencesDialog::dlFonts()
274 FontDownloader* dl = new FontDownloader(this, ui->fontBox->text());
275 dl->show();
278 void PreferencesDialog::accept()
280 saveSettings();
281 QDialog::accept();
284 void PreferencesDialog::reject()
286 loadSettings();
287 QDialog::reject();