Theme Editor: Made allll destructors virtual
[kugel-rb.git] / utils / themeeditor / gui / preferencesdialog.cpp
blob8cd9665779905505639fb760035a74ce0bd50fd3
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"
25 #include <QSettings>
26 #include <QColorDialog>
28 PreferencesDialog::PreferencesDialog(QWidget *parent) :
29 QDialog(parent),
30 ui(new Ui::PreferencesDialog)
32 ui->setupUi(this);
33 setupUI();
34 loadSettings();
37 PreferencesDialog::~PreferencesDialog()
39 delete ui;
42 void PreferencesDialog::loadSettings()
44 loadColors();
45 loadFont();
48 void PreferencesDialog::loadColors()
51 QSettings settings;
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);
73 settings.endGroup();
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);
87 settings.endGroup();
90 void PreferencesDialog::loadFont()
92 QSettings settings;
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();
101 settings.endGroup();
103 ui->fontSelect->setCurrentFont(family.value<QFont>());
104 ui->fontSize->setValue(size);
108 void PreferencesDialog::saveSettings()
110 saveColors();
111 saveFont();
114 void PreferencesDialog::saveColors()
116 QSettings settings;
118 /* Saving the editor colors */
119 settings.beginGroup("SkinDocument");
121 settings.setValue("fgColor", fgColor);
122 settings.setValue("bgColor", bgColor);
123 settings.setValue("errorColor", errorColor);
125 settings.endGroup();
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);
135 settings.endGroup();
138 void PreferencesDialog::saveFont()
140 QSettings settings;
141 settings.beginGroup("SkinDocument");
143 settings.setValue("fontFamily", ui->fontSelect->currentFont());
144 settings.setValue("fontSize", ui->fontSize->value());
146 settings.endGroup();
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)
171 toEdit = &bgColor;
172 else if(QObject::sender() == ui->fgButton)
173 toEdit = &fgColor;
174 else if(QObject::sender() == ui->commentButton)
175 toEdit = &commentColor;
176 else if(QObject::sender() == ui->tagButton)
177 toEdit = &tagColor;
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;
185 if(!toEdit)
186 return;
188 newColor = QColorDialog::getColor(*toEdit, this);
189 if (newColor.isValid())
191 *toEdit = newColor;
192 setButtonColor(dynamic_cast<QPushButton*>(QObject::sender()), *toEdit);
196 void PreferencesDialog::accept()
198 saveSettings();
199 QDialog::accept();
202 void PreferencesDialog::reject()
204 loadSettings();
205 QDialog::reject();