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"
25 #include "targetdownloader.h"
28 #include <QColorDialog>
29 #include <QFileDialog>
31 PreferencesDialog::PreferencesDialog(QWidget
*parent
) :
33 ui(new Ui::PreferencesDialog
)
40 PreferencesDialog::~PreferencesDialog()
45 void PreferencesDialog::loadSettings()
52 settings
.beginGroup("CodeEditor");
53 ui
->completionBox
->setChecked(settings
.value("completeSyntax",
58 void PreferencesDialog::loadColors()
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
);
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
);
100 void PreferencesDialog::loadFont()
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();
113 ui
->fontSelect
->setCurrentFont(family
.value
<QFont
>());
114 ui
->fontSize
->setValue(size
);
118 void PreferencesDialog::loadRender()
121 settings
.beginGroup("RBFont");
123 QString confDir
= QDir::homePath() + "/.rbthemeeditor";
125 ui
->fontBox
->setText(settings
.value("fontDir", confDir
+ "/fonts/")
130 settings
.beginGroup("EditorWindow");
132 ui
->autoExpandBox
->setChecked(settings
.value("autoExpandTree",
134 ui
->autoHighlightBox
->setChecked(settings
.value("autoHighlightTree",
139 settings
.beginGroup("TargetData");
141 ui
->dbBox
->setText(settings
.value("targetDbPath",
142 confDir
+ "/targetdb")
148 void PreferencesDialog::saveSettings()
155 settings
.beginGroup("CodeEditor");
156 settings
.setValue("completeSyntax", ui
->completionBox
->isChecked());
161 void PreferencesDialog::saveColors()
165 /* Saving the editor colors */
166 settings
.beginGroup("SkinDocument");
168 settings
.setValue("fgColor", fgColor
);
169 settings
.setValue("bgColor", bgColor
);
170 settings
.setValue("errorColor", errorColor
);
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
);
185 void PreferencesDialog::saveFont()
188 settings
.beginGroup("SkinDocument");
190 settings
.setValue("fontFamily", ui
->fontSelect
->currentFont());
191 settings
.setValue("fontSize", ui
->fontSize
->value());
196 void PreferencesDialog::saveRender()
199 settings
.beginGroup("RBFont");
201 settings
.setValue("fontDir", ui
->fontBox
->text());
205 settings
.beginGroup("EditorWindow");
207 settings
.setValue("autoExpandTree", ui
->autoExpandBox
->isChecked());
208 settings
.setValue("autoHighlightTree", ui
->autoHighlightBox
->isChecked());
212 settings
.beginGroup("TargetData");
213 settings
.setValue("targetDbPath", ui
->dbBox
->text());
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
)
249 else if(QObject::sender() == ui
->fgButton
)
251 else if(QObject::sender() == ui
->commentButton
)
252 toEdit
= &commentColor
;
253 else if(QObject::sender() == ui
->tagButton
)
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
;
265 newColor
= QColorDialog::getColor(*toEdit
, this);
266 if (newColor
.isValid())
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()).
287 ui
->dbBox
->setText(path
);
290 void PreferencesDialog::dlFonts()
292 FontDownloader
* dl
= new FontDownloader(this, ui
->fontBox
->text());
296 void PreferencesDialog::dlTargetDB()
298 TargetDownloader
* dl
= new TargetDownloader(this, ui
->dbBox
->text());
302 void PreferencesDialog::accept()
308 void PreferencesDialog::reject()