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"),
48 searchResultSizeSpinBox->setMinimum(1);
49 historySizeSpinBox->setMinimum(1);
52 verticalLayout->addSpacing(20);
54 verticalLayout->addLayout(spinBoxesFormLayout);
57 checkBoxesLabel = new QLabel(tr("Search in:"));
59 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
60 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
62 verticalLayout->addSpacing(20);
63 verticalLayout->addWidget(checkBoxesLabel);
64 verticalLayout->addWidget(searchInDictionariesCheckBox);
65 verticalLayout->addWidget(searchInBookmarksCheckBox);
75 void SettingsWidget::showEvent(QShowEvent *e) {
77 settings = guiInterface->settings();
79 historySizeSpinBox->setValue(
80 settings->value("history_size").toInt());
82 searchResultSizeSpinBox->setValue(
83 settings->value("search_limit").toInt());
85 if(settings->value("search_bookmarks") == "true")
86 searchInBookmarksCheckBox->setChecked(true);
88 searchInBookmarksCheckBox->setChecked(false);
90 if(settings->value("search_dictionaries") == "true")
91 searchInDictionariesCheckBox->setChecked(true);
93 searchInDictionariesCheckBox->setChecked(false);
95 QDialog::showEvent(e);
98 void SettingsWidget::hideEvent(QHideEvent *e) {
99 Settings* newSettings = new Settings;
100 newSettings->setValue("history_size",
101 QString::number(historySizeSpinBox->value()));
102 newSettings->setValue("search_limit",
103 QString::number(searchResultSizeSpinBox->value()));
105 if(searchInDictionariesCheckBox->isChecked())
106 newSettings->setValue("search_dictionaries", "true");
108 newSettings->setValue("search_dictionaries", "false");
110 if(searchInBookmarksCheckBox->isChecked())
111 newSettings->setValue("search_bookmarks", "true");
113 newSettings->setValue("search_bookmarks", "false");
116 foreach(key, newSettings->keys()) {
117 if(settings->value(key) != newSettings->value(key)) {
118 guiInterface->setSettings(newSettings);
123 QDialog::hideEvent(e);