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"
26 #include <QColorDialog>
27 #include <QFileDialog>
29 PreferencesDialog::PreferencesDialog(QWidget
*parent
) :
31 ui(new Ui::PreferencesDialog
)
38 PreferencesDialog::~PreferencesDialog()
43 void PreferencesDialog::loadSettings()
50 void PreferencesDialog::loadColors()
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
);
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
);
92 void PreferencesDialog::loadFont()
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();
105 ui
->fontSelect
->setCurrentFont(family
.value
<QFont
>());
106 ui
->fontSize
->setValue(size
);
110 void PreferencesDialog::loadRender()
113 settings
.beginGroup("RBFont");
115 ui
->fontBox
->setText(settings
.value("fontDir", "/").toString());
119 settings
.beginGroup("EditorWindow");
121 ui
->autoExpandBox
->setChecked(settings
.value("autoExpandTree",
123 ui
->autoHighlightBox
->setChecked(settings
.value("autoHighlightTree",
129 void PreferencesDialog::saveSettings()
136 void PreferencesDialog::saveColors()
140 /* Saving the editor colors */
141 settings
.beginGroup("SkinDocument");
143 settings
.setValue("fgColor", fgColor
);
144 settings
.setValue("bgColor", bgColor
);
145 settings
.setValue("errorColor", errorColor
);
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
);
160 void PreferencesDialog::saveFont()
163 settings
.beginGroup("SkinDocument");
165 settings
.setValue("fontFamily", ui
->fontSelect
->currentFont());
166 settings
.setValue("fontSize", ui
->fontSize
->value());
171 void PreferencesDialog::saveRender()
174 settings
.beginGroup("RBFont");
176 settings
.setValue("fontDir", ui
->fontBox
->text());
180 settings
.beginGroup("EditorWindow");
182 settings
.setValue("autoExpandTree", ui
->autoExpandBox
->isChecked());
183 settings
.setValue("autoHighlightTree", ui
->autoHighlightBox
->isChecked());
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
)
214 else if(QObject::sender() == ui
->fgButton
)
216 else if(QObject::sender() == ui
->commentButton
)
217 toEdit
= &commentColor
;
218 else if(QObject::sender() == ui
->tagButton
)
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
;
230 newColor
= QColorDialog::getColor(*toEdit
, this);
231 if (newColor
.isValid())
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()
252 void PreferencesDialog::reject()