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"
26 SettingsWidget::SettingsWidget(GUIInterface *parent) :
29 setWindowTitle(tr("Settings"));
31 verticalLayout = new QVBoxLayout;
32 setLayout(verticalLayout);
34 historySizeSpinBox = new QSpinBox;
35 searchResultSizeSpinBox = new QSpinBox;
37 spinBoxesFormLayout = new QFormLayout;
39 spinBoxesFormLayout->addRow(tr("Search result size"),
40 searchResultSizeSpinBox);
42 spinBoxesFormLayout->addRow(tr("History size"),
46 verticalLayout->addSpacing(20);
48 verticalLayout->addLayout(spinBoxesFormLayout);
51 checkBoxesLabel = new QLabel(tr("Search in:"));
53 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
54 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
56 verticalLayout->addSpacing(20);
57 verticalLayout->addWidget(checkBoxesLabel);
58 verticalLayout->addWidget(searchInDictionariesCheckBox);
59 verticalLayout->addWidget(searchInBookmarksCheckBox);
67 void SettingsWidget::showEvent(QShowEvent *e) {
68 settings = guiInterface->getSettings();
70 historySizeSpinBox->setValue(
71 settings->value("history_size").toInt());
73 searchResultSizeSpinBox->setValue(
74 settings->value("search_limit").toInt());
76 if(settings->value("search_bookmarks") == "true")
77 searchInBookmarksCheckBox->setChecked(true);
79 searchInBookmarksCheckBox->setChecked(false);
81 if(settings->value("search_dictionaries") == "true")
82 searchInDictionariesCheckBox->setChecked(true);
84 searchInDictionariesCheckBox->setChecked(false);
86 QDialog::showEvent(e);
89 void SettingsWidget::hideEvent(QHideEvent *e) {
90 Settings* newSettings;
91 newSettings->setValue("history_size",
92 QString::number(historySizeSpinBox->value()));
93 newSettings->setValue("search_limit",
94 QString::number(searchResultSizeSpinBox->value()));
96 if(searchInDictionariesCheckBox->isChecked())
97 newSettings->setValue("search_dictionaries", "true");
99 newSettings->setValue("search_dictionaries", "false");
101 if(searchInBookmarksCheckBox->isChecked())
102 newSettings->setValue("search_bookmarks", "true");
104 newSettings->setValue("search_bookmarks", "false");
107 foreach(key, newSettings->keys()) {
108 if(settings->value(key) != newSettings->value(key)) {
109 guiInterface->setSettings(newSettings);
114 QDialog::hideEvent(e);