1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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"
27 #include <QColorDialog>
28 #include <QFileDialog>
30 PreferencesDialog::PreferencesDialog(QWidget
*parent
) :
32 ui(new Ui::PreferencesDialog
)
39 PreferencesDialog::~PreferencesDialog()
44 void PreferencesDialog::loadSettings()
51 void PreferencesDialog::loadColors()
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
);
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
);
93 void PreferencesDialog::loadFont()
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();
106 ui
->fontSelect
->setCurrentFont(family
.value
<QFont
>());
107 ui
->fontSize
->setValue(size
);
111 void PreferencesDialog::loadRender()
114 settings
.beginGroup("RBFont");
116 ui
->fontBox
->setText(settings
.value("fontDir", "/").toString());
120 settings
.beginGroup("EditorWindow");
122 ui
->autoExpandBox
->setChecked(settings
.value("autoExpandTree",
124 ui
->autoHighlightBox
->setChecked(settings
.value("autoHighlightTree",
129 settings
.beginGroup("TargetData");
131 ui
->dbBox
->setText(settings
.value("targetDbPath",
132 QDir::homePath() + "/.targetdb")
138 void PreferencesDialog::saveSettings()
145 void PreferencesDialog::saveColors()
149 /* Saving the editor colors */
150 settings
.beginGroup("SkinDocument");
152 settings
.setValue("fgColor", fgColor
);
153 settings
.setValue("bgColor", bgColor
);
154 settings
.setValue("errorColor", errorColor
);
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
);
169 void PreferencesDialog::saveFont()
172 settings
.beginGroup("SkinDocument");
174 settings
.setValue("fontFamily", ui
->fontSelect
->currentFont());
175 settings
.setValue("fontSize", ui
->fontSize
->value());
180 void PreferencesDialog::saveRender()
183 settings
.beginGroup("RBFont");
185 settings
.setValue("fontDir", ui
->fontBox
->text());
189 settings
.beginGroup("EditorWindow");
191 settings
.setValue("autoExpandTree", ui
->autoExpandBox
->isChecked());
192 settings
.setValue("autoHighlightTree", ui
->autoHighlightBox
->isChecked());
196 settings
.beginGroup("TargetData");
197 settings
.setValue("targetDbPath", ui
->dbBox
->text());
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
)
231 else if(QObject::sender() == ui
->fgButton
)
233 else if(QObject::sender() == ui
->commentButton
)
234 toEdit
= &commentColor
;
235 else if(QObject::sender() == ui
->tagButton
)
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
;
247 newColor
= QColorDialog::getColor(*toEdit
, this);
248 if (newColor
.isValid())
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()).
269 ui
->dbBox
->setText(path
);
272 void PreferencesDialog::dlFonts()
274 FontDownloader
* dl
= new FontDownloader(this, ui
->fontBox
->text());
278 void PreferencesDialog::accept()
284 void PreferencesDialog::reject()