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 historySizeLayout = new QHBoxLayout;
44 historySizeSpinBox = new SpinBox;
45 historySizeSpinBox->setMinimum(1);
46 historySizeSpinBox->setMaximum(50);
48 historySizeToolTip = tr("Limits maximum number of words saved in history");
51 historySizeInfoToolButton = new QToolButton;
52 historySizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
55 historySizeLayout->addWidget(historySizeSpinBox);
57 historySizeLayout->addWidget(historySizeInfoToolButton);
63 searchResultLayout = new QHBoxLayout;
65 searchResultSizeSpinBox = new SpinBox;
66 searchResultSizeSpinBox->setMinimum(0);
67 searchResultSizeSpinBox->setMaximum(500);
68 searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited"));
70 searchResultSizeToolTip = tr("Limits maximum number of found words, affects"
71 " only when searching in file.");
74 searchResultSizeInfoToolButton = new QToolButton;
75 searchResultSizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
78 searchResultLayout->addWidget(searchResultSizeSpinBox);
80 searchResultLayout->addWidget(searchResultSizeInfoToolButton);
87 spinBoxesFormLayout = new QFormLayout;
88 spinBoxesFormLayout->addRow(tr("Search result size"),
90 spinBoxesFormLayout->addRow(tr("History size"),
96 verticalLayout->addLayout(spinBoxesFormLayout);
99 checkBoxesLabel = new QLabel(tr("Search in:"),this);
101 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"),this);
102 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"),this);
104 verticalLayout->addSpacing(20);
105 verticalLayout->addWidget(checkBoxesLabel);
106 verticalLayout->addWidget(searchInDictionariesCheckBox);
107 verticalLayout->addWidget(searchInBookmarksCheckBox);
110 connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
112 connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
114 connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
116 connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
121 connect(searchResultSizeInfoToolButton, SIGNAL(clicked()),
122 this, SLOT(showSearchResultSizeInfo()));
124 connect(historySizeInfoToolButton, SIGNAL(clicked()),
125 this, SLOT(showHistorySizeInfo()));
127 historySizeSpinBox->setToolTip(historySizeToolTip);
128 searchResultSizeSpinBox->setToolTip(searchResultSizeToolTip);
135 setMinimumWidth(250);
136 setMaximumWidth(250);
137 footerLayout = new QHBoxLayout;
138 closeButton = new QPushButton(tr("Save"));
139 footerLayout->addStretch(0);
140 footerLayout->addWidget(closeButton);
141 verticalLayout->addLayout(footerLayout);
142 connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
146 void SettingsWidget::showEvent(QShowEvent *e) {
152 settings = guiInterface->settings();
154 historySizeSpinBox->setValue(
155 settings->value("history_size").toInt());
157 searchResultSizeSpinBox->setValue(
158 settings->value("search_limit").toInt());
160 if(settings->value("search_bookmarks") == "true")
161 searchInBookmarksCheckBox->setChecked(true);
163 searchInBookmarksCheckBox->setChecked(false);
165 if(settings->value("search_dictionaries") == "true")
166 searchInDictionariesCheckBox->setChecked(true);
168 searchInDictionariesCheckBox->setChecked(false);
171 QDialog::showEvent(e);
174 void SettingsWidget::hideEvent(QHideEvent *e) {
175 QDialog::hideEvent(e);
178 if(settings && _save) {
180 if(settings && _changed &&
181 QMessageBox::question(this,
183 tr("Do you want to save changes?"),
184 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
187 Settings* newSettings = new Settings;
188 newSettings->setValue("history_size",
189 QString::number(historySizeSpinBox->value()));
190 newSettings->setValue("search_limit",
192 searchResultSizeSpinBox->value()));
194 if(searchInDictionariesCheckBox->isChecked())
195 newSettings->setValue("search_dictionaries", "true");
197 newSettings->setValue("search_dictionaries", "false");
199 if(searchInBookmarksCheckBox->isChecked())
200 newSettings->setValue("search_bookmarks", "true");
202 newSettings->setValue("search_bookmarks", "false");
204 //setting new settings only if they are different than old ones
206 foreach(key, newSettings->keys()) {
207 if(settings->value(key) != newSettings->value(key)) {
208 guiInterface->setSettings(newSettings);
222 void SettingsWidget::changed() {
227 void SettingsWidget::save() {
235 void SettingsWidget::showHistorySizeInfo() {
236 Q_EMIT notify(Notify::Warning, historySizeToolTip);
239 void SettingsWidget::showSearchResultSizeInfo() {
240 Q_EMIT notify(Notify::Warning, searchResultSizeToolTip);