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>
28 PreferencesDialog::PreferencesDialog(QWidget
*parent
) :
30 ui(new Ui::PreferencesDialog
)
37 PreferencesDialog::~PreferencesDialog()
42 void PreferencesDialog::loadSettings()
48 void PreferencesDialog::loadColors()
53 /* The list of buttons from the SkinHighlighter group */
55 settings
.beginGroup("SkinHighlighter");
57 commentColor
= settings
.value("commentColor",
58 QColor(0, 180, 0)).value
<QColor
>();
59 setButtonColor(ui
->commentButton
, commentColor
);
61 escapedColor
= settings
.value("escapedColor",
62 QColor(120,120,120)).value
<QColor
>();
63 setButtonColor(ui
->escapedButton
, escapedColor
);
65 conditionalColor
= settings
.value("conditionalColor",
66 QColor(0, 0, 180)).value
<QColor
>();
67 setButtonColor(ui
->conditionalButton
, conditionalColor
);
69 tagColor
= settings
.value("tagColor",
70 QColor(180, 0, 0)).value
<QColor
>();
71 setButtonColor(ui
->tagButton
, tagColor
);
75 /* Buttons from the editor group */
76 settings
.beginGroup("SkinDocument");
78 fgColor
= settings
.value("fgColor", Qt::black
).value
<QColor
>();
79 setButtonColor(ui
->fgButton
, fgColor
);
81 bgColor
= settings
.value("bgColor", Qt::white
).value
<QColor
>();
82 setButtonColor(ui
->bgButton
, bgColor
);
84 errorColor
= settings
.value("errorColor", Qt::red
).value
<QColor
>();
85 setButtonColor(ui
->errorButton
, errorColor
);
90 void PreferencesDialog::loadFont()
93 settings
.beginGroup("SkinDocument");
95 QFont
def("Monospace");
96 def
.setStyleHint(QFont::TypeWriter
);
98 QVariant family
= settings
.value("fontFamily", def
);
99 int size
= settings
.value("fontSize", 12).toInt();
103 ui
->fontSelect
->setCurrentFont(family
.value
<QFont
>());
104 ui
->fontSize
->setValue(size
);
108 void PreferencesDialog::saveSettings()
114 void PreferencesDialog::saveColors()
118 /* Saving the editor colors */
119 settings
.beginGroup("SkinDocument");
121 settings
.setValue("fgColor", fgColor
);
122 settings
.setValue("bgColor", bgColor
);
123 settings
.setValue("errorColor", errorColor
);
127 /* Saving the highlighting colors */
128 settings
.beginGroup("SkinHighlighter");
130 settings
.setValue("tagColor", tagColor
);
131 settings
.setValue("commentColor", commentColor
);
132 settings
.setValue("conditionalColor", conditionalColor
);
133 settings
.setValue("escapedColor", escapedColor
);
138 void PreferencesDialog::saveFont()
141 settings
.beginGroup("SkinDocument");
143 settings
.setValue("fontFamily", ui
->fontSelect
->currentFont());
144 settings
.setValue("fontSize", ui
->fontSize
->value());
149 void PreferencesDialog::setupUI()
151 /* Connecting color buttons */
152 QList
<QPushButton
*> buttons
;
153 buttons
.append(ui
->bgButton
);
154 buttons
.append(ui
->fgButton
);
155 buttons
.append(ui
->commentButton
);
156 buttons
.append(ui
->tagButton
);
157 buttons
.append(ui
->conditionalButton
);
158 buttons
.append(ui
->escapedButton
);
159 buttons
.append(ui
->errorButton
);
161 for(int i
= 0; i
< buttons
.count(); i
++)
162 QObject::connect(buttons
[i
], SIGNAL(pressed()),
163 this, SLOT(colorClicked()));
166 void PreferencesDialog::colorClicked()
168 QColor
* toEdit
= 0, newColor
;
170 if(QObject::sender() == ui
->bgButton
)
172 else if(QObject::sender() == ui
->fgButton
)
174 else if(QObject::sender() == ui
->commentButton
)
175 toEdit
= &commentColor
;
176 else if(QObject::sender() == ui
->tagButton
)
178 else if(QObject::sender() == ui
->conditionalButton
)
179 toEdit
= &conditionalColor
;
180 else if(QObject::sender() == ui
->escapedButton
)
181 toEdit
= &escapedColor
;
182 else if(QObject::sender() == ui
->errorButton
)
183 toEdit
= &errorColor
;
188 newColor
= QColorDialog::getColor(*toEdit
, this);
189 if (newColor
.isValid())
192 setButtonColor(dynamic_cast<QPushButton
*>(QObject::sender()), *toEdit
);
196 void PreferencesDialog::accept()
202 void PreferencesDialog::reject()