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"));
40 void SettingsWidget::initalizeUI() {
41 verticalLayout = new QVBoxLayout;
42 setLayout(verticalLayout);
44 historySizeLayout = new QHBoxLayout;
46 historySizeSpinBox = new SpinBox;
47 historySizeSpinBox->setMinimum(1);
48 historySizeSpinBox->setMaximum(50);
50 historySizeToolTip = tr("Limits maximum number of words saved in history");
53 historySizeInfoToolButton = new QToolButton;
54 historySizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
57 historySizeLayout->addWidget(historySizeSpinBox);
59 historySizeLayout->addWidget(historySizeInfoToolButton);
65 searchResultLayout = new QHBoxLayout;
67 searchResultSizeSpinBox = new SpinBox;
68 searchResultSizeSpinBox->setMinimum(0);
69 searchResultSizeSpinBox->setMaximum(500);
70 searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited"));
72 searchResultSizeToolTip = tr("Limits maximum number of found words, affects"
73 " only when searching in file.");
76 searchResultSizeInfoToolButton = new QToolButton;
77 searchResultSizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
80 searchResultLayout->addWidget(searchResultSizeSpinBox);
82 searchResultLayout->addWidget(searchResultSizeInfoToolButton);
89 spinBoxesFormLayout = new QFormLayout;
90 spinBoxesFormLayout->addRow(tr("Search result size"),
92 spinBoxesFormLayout->addRow(tr("History size"),
98 verticalLayout->addLayout(spinBoxesFormLayout);
101 checkBoxesLabel = new QLabel(tr("Search in:"),this);
103 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
104 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
106 verticalLayout->addSpacing(20);
107 verticalLayout->addWidget(checkBoxesLabel);
108 verticalLayout->addWidget(searchInDictionariesCheckBox);
109 verticalLayout->addWidget(searchInBookmarksCheckBox);
112 connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
114 connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
116 connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
118 connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
123 connect(searchResultSizeInfoToolButton, SIGNAL(clicked()),
124 this, SLOT(showSearchResultSizeInfo()));
126 connect(historySizeInfoToolButton, SIGNAL(clicked()),
127 this, SLOT(showHistorySizeInfo()));
129 historySizeSpinBox->setToolTip(historySizeToolTip);
130 searchResultSizeSpinBox->setToolTip(searchResultSizeToolTip);
137 setMinimumWidth(250);
138 setMaximumWidth(250);
139 footerLayout = new QHBoxLayout;
140 closeButton = new QPushButton(tr("Save"));
141 footerLayout->addStretch(0);
142 footerLayout->addWidget(closeButton);
143 verticalLayout->addLayout(footerLayout);
145 setMinimumHeight(sizeHint().height());
146 setMaximumHeight(sizeHint().height());
147 connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
151 void SettingsWidget::showEvent(QShowEvent *e) {
157 settings = guiInterface->settings();
159 historySizeSpinBox->setValue(
160 settings->value("history_size").toInt());
162 searchResultSizeSpinBox->setValue(
163 settings->value("search_limit").toInt());
165 if(settings->value("search_bookmarks") == "true")
166 searchInBookmarksCheckBox->setChecked(true);
168 searchInBookmarksCheckBox->setChecked(false);
170 if(settings->value("search_dictionaries") == "true")
171 searchInDictionariesCheckBox->setChecked(true);
173 searchInDictionariesCheckBox->setChecked(false);
176 QDialog::showEvent(e);
179 void SettingsWidget::hideEvent(QHideEvent *e) {
180 QDialog::hideEvent(e);
183 if(settings && _save) {
185 if(settings && _changed &&
186 QMessageBox::question(this,
188 tr("Do you want to save changes?"),
189 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
192 Settings* newSettings = new Settings;
193 newSettings->setValue("history_size",
194 QString::number(historySizeSpinBox->value()));
195 newSettings->setValue("search_limit",
197 searchResultSizeSpinBox->value()));
199 if(searchInDictionariesCheckBox->isChecked())
200 newSettings->setValue("search_dictionaries", "true");
202 newSettings->setValue("search_dictionaries", "false");
204 if(searchInBookmarksCheckBox->isChecked())
205 newSettings->setValue("search_bookmarks", "true");
207 newSettings->setValue("search_bookmarks", "false");
209 //setting new settings only if they are different than old ones
211 foreach(key, newSettings->keys()) {
212 if(settings->value(key) != newSettings->value(key)) {
213 guiInterface->setSettings(newSettings);
227 void SettingsWidget::changed() {
232 void SettingsWidget::save() {
240 void SettingsWidget::showHistorySizeInfo() {
241 Q_EMIT notify(Notify::Warning, historySizeToolTip);
244 void SettingsWidget::showSearchResultSizeInfo() {
245 Q_EMIT notify(Notify::Warning, searchResultSizeToolTip);