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;
44 limitTip = tr("Limits maximum number of found words, affects only when "
45 "searching in file.");
46 searchResultSizeSpinBox->setToolTip(limitTip);
49 spinBoxesFormLayout = new QFormLayout;
50 spinBoxesFormLayout->addRow(tr("Search result size"),
51 searchResultSizeSpinBox);
52 spinBoxesFormLayout->addRow(tr("History size"),
55 searchResultSizeSpinBox->setMinimum(0);
56 searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited"));
57 historySizeSpinBox->setMinimum(1);
59 searchResultSizeSpinBox->setMaximum(500);
60 historySizeSpinBox->setMaximum(50);
63 verticalLayout->addSpacing(20);
65 verticalLayout->addLayout(spinBoxesFormLayout);
68 checkBoxesLabel = new QLabel(tr("Search in:"),this);
70 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"),this);
71 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"),this);
73 verticalLayout->addSpacing(20);
74 verticalLayout->addWidget(checkBoxesLabel);
75 verticalLayout->addWidget(searchInDictionariesCheckBox);
76 verticalLayout->addWidget(searchInBookmarksCheckBox);
79 connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
81 connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
83 connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
85 connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
94 footerLayout = new QHBoxLayout;
95 closeButton = new QPushButton(tr("Save"));
96 footerLayout->addStretch(0);
97 footerLayout->addWidget(closeButton);
98 verticalLayout->addLayout(footerLayout);
99 connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
103 void SettingsWidget::showEvent(QShowEvent *e) {
109 settings = guiInterface->settings();
111 historySizeSpinBox->setValue(
112 settings->value("history_size").toInt());
114 searchResultSizeSpinBox->setValue(
115 settings->value("search_limit").toInt());
117 if(settings->value("search_bookmarks") == "true")
118 searchInBookmarksCheckBox->setChecked(true);
120 searchInBookmarksCheckBox->setChecked(false);
122 if(settings->value("search_dictionaries") == "true")
123 searchInDictionariesCheckBox->setChecked(true);
125 searchInDictionariesCheckBox->setChecked(false);
128 QDialog::showEvent(e);
131 void SettingsWidget::hideEvent(QHideEvent *e) {
132 QDialog::hideEvent(e);
135 if(settings && _save) {
137 if(settings && _changed &&
138 QMessageBox::question(this,
140 tr("Do you want to save changes?"),
141 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
144 Settings* newSettings = new Settings;
145 newSettings->setValue("history_size",
146 QString::number(historySizeSpinBox->value()));
147 newSettings->setValue("search_limit",
149 searchResultSizeSpinBox->value()));
151 if(searchInDictionariesCheckBox->isChecked())
152 newSettings->setValue("search_dictionaries", "true");
154 newSettings->setValue("search_dictionaries", "false");
156 if(searchInBookmarksCheckBox->isChecked())
157 newSettings->setValue("search_bookmarks", "true");
159 newSettings->setValue("search_bookmarks", "false");
161 //setting new settings only if they are different than old ones
163 foreach(key, newSettings->keys()) {
164 if(settings->value(key) != newSettings->value(key)) {
165 guiInterface->setSettings(newSettings);
179 void SettingsWidget::changed() {
184 void SettingsWidget::save() {