1 /*******************************************************************************
3 This file is part of mDictionary.
5 mDictionary is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 mDictionary is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 //Created by Mateusz Półrola
24 #include "SettingsWidget.h"
27 SettingsWidget::SettingsWidget(GUIInterface *parent) :
30 guiInterface = parent;
32 setWindowTitle(tr("Settings"));
34 verticalLayout = new QVBoxLayout;
35 setLayout(verticalLayout);
37 historySizeSpinBox = new QSpinBox;
38 searchResultSizeSpinBox = new QSpinBox;
40 spinBoxesFormLayout = new QFormLayout;
42 spinBoxesFormLayout->addRow(tr("Search result size"),
43 searchResultSizeSpinBox);
45 spinBoxesFormLayout->addRow(tr("History size"),
49 verticalLayout->addSpacing(20);
51 verticalLayout->addLayout(spinBoxesFormLayout);
54 checkBoxesLabel = new QLabel(tr("Search in:"));
56 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
57 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
59 verticalLayout->addSpacing(20);
60 verticalLayout->addWidget(checkBoxesLabel);
61 verticalLayout->addWidget(searchInDictionariesCheckBox);
62 verticalLayout->addWidget(searchInBookmarksCheckBox);
70 void SettingsWidget::showEvent(QShowEvent *e) {
72 settings = guiInterface->settings();
74 historySizeSpinBox->setValue(
75 settings->value("history_size").toInt());
77 searchResultSizeSpinBox->setValue(
78 settings->value("search_limit").toInt());
80 if(settings->value("search_bookmarks") == "true")
81 searchInBookmarksCheckBox->setChecked(true);
83 searchInBookmarksCheckBox->setChecked(false);
85 if(settings->value("search_dictionaries") == "true")
86 searchInDictionariesCheckBox->setChecked(true);
88 searchInDictionariesCheckBox->setChecked(false);
90 QDialog::showEvent(e);
93 void SettingsWidget::hideEvent(QHideEvent *e) {
94 Settings* newSettings = new Settings;
95 newSettings->setValue("history_size",
96 QString::number(historySizeSpinBox->value()));
97 newSettings->setValue("search_limit",
98 QString::number(searchResultSizeSpinBox->value()));
100 if(searchInDictionariesCheckBox->isChecked())
101 newSettings->setValue("search_dictionaries", "true");
103 newSettings->setValue("search_dictionaries", "false");
105 if(searchInBookmarksCheckBox->isChecked())
106 newSettings->setValue("search_bookmarks", "true");
108 newSettings->setValue("search_bookmarks", "false");
111 foreach(key, newSettings->keys()) {
112 if(settings->value(key) != newSettings->value(key)) {
113 guiInterface->setSettings(newSettings);
118 QDialog::hideEvent(e);