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 //! \file SettingsWidget.cpp
23 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
25 #include "SettingsWidget.h"
28 SettingsWidget::SettingsWidget(GUIInterface *parent) :
31 guiInterface = parent;
33 setWindowTitle(tr("Settings"));
38 void SettingsWidget::initalizeUI() {
39 verticalLayout = new QVBoxLayout;
40 setLayout(verticalLayout);
42 historySizeSpinBox = new QSpinBox;
43 searchResultSizeSpinBox = new QSpinBox;
45 limitTip = "Limit maximal number of finded words, affect only when "
47 searchResultSizeSpinBox->setToolTip(limitTip);
50 spinBoxesFormLayout = new QFormLayout;
51 spinBoxesFormLayout->addRow(tr("Search result size"),
52 searchResultSizeSpinBox);
53 spinBoxesFormLayout->addRow(tr("History size"),
56 searchResultSizeSpinBox->setMinimum(0);
57 searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited"));
58 historySizeSpinBox->setMinimum(1);
60 searchResultSizeSpinBox->setMaximum(500);
61 historySizeSpinBox->setMaximum(50);
64 verticalLayout->addSpacing(20);
66 verticalLayout->addLayout(spinBoxesFormLayout);
69 checkBoxesLabel = new QLabel(tr("Search in:"),this);
71 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"),this);
72 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"),this);
74 verticalLayout->addSpacing(20);
75 verticalLayout->addWidget(checkBoxesLabel);
76 verticalLayout->addWidget(searchInDictionariesCheckBox);
77 verticalLayout->addWidget(searchInBookmarksCheckBox);
80 connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
82 connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
84 connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
86 connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
95 footerLayout = new QHBoxLayout;
96 closeButton = new QPushButton(tr("Save"));
97 footerLayout->addStretch(0);
98 footerLayout->addWidget(closeButton);
99 verticalLayout->addLayout(footerLayout);
100 connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
104 void SettingsWidget::showEvent(QShowEvent *e) {
110 settings = guiInterface->settings();
112 historySizeSpinBox->setValue(
113 settings->value("history_size").toInt());
115 searchResultSizeSpinBox->setValue(
116 settings->value("search_limit").toInt());
118 if(settings->value("search_bookmarks") == "true")
119 searchInBookmarksCheckBox->setChecked(true);
121 searchInBookmarksCheckBox->setChecked(false);
123 if(settings->value("search_dictionaries") == "true")
124 searchInDictionariesCheckBox->setChecked(true);
126 searchInDictionariesCheckBox->setChecked(false);
129 QDialog::showEvent(e);
132 void SettingsWidget::hideEvent(QHideEvent *e) {
133 QDialog::hideEvent(e);
136 if(settings && _save) {
138 if(settings && _changed &&
139 QMessageBox::question(this,
141 tr("Do you want to save changes?"),
142 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
145 Settings* newSettings = new Settings;
146 newSettings->setValue("history_size",
147 QString::number(historySizeSpinBox->value()));
148 newSettings->setValue("search_limit",
150 searchResultSizeSpinBox->value()));
152 if(searchInDictionariesCheckBox->isChecked())
153 newSettings->setValue("search_dictionaries", "true");
155 newSettings->setValue("search_dictionaries", "false");
157 if(searchInBookmarksCheckBox->isChecked())
158 newSettings->setValue("search_bookmarks", "true");
160 newSettings->setValue("search_bookmarks", "false");
162 //setting new settings only if they are different that old ones
164 foreach(key, newSettings->keys()) {
165 if(settings->value(key) != newSettings->value(key)) {
166 guiInterface->setSettings(newSettings);
180 void SettingsWidget::changed() {
185 void SettingsWidget::save() {