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 DictManagerWidget.cpp
23 \brief Implements applications settings widget
24 \author Mateusz Półrola <mateusz.polrola@comarch.pl>
27 #include "SettingsWidget.h"
30 SettingsWidget::SettingsWidget(GUIInterface *parent) :
33 guiInterface = parent;
35 setWindowTitle(tr("Settings"));
42 void SettingsWidget::initalizeUI() {
43 verticalLayout = new QVBoxLayout;
44 setLayout(verticalLayout);
46 historySizeLayout = new QHBoxLayout;
48 historySizeSpinBox = new SpinBox;
49 historySizeSpinBox->setMinimum(1);
50 historySizeSpinBox->setMaximum(50);
52 historySizeToolTip = tr("Limits maximum number of words saved in history");
55 historySizeInfoToolButton = new QToolButton;
56 historySizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
59 historySizeLayout->addWidget(historySizeSpinBox);
61 historySizeLayout->addWidget(historySizeInfoToolButton);
67 searchResultLayout = new QHBoxLayout;
69 searchResultSizeSpinBox = new SpinBox;
70 searchResultSizeSpinBox->setMinimum(0);
71 searchResultSizeSpinBox->setMaximum(500);
72 searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited"));
74 searchResultSizeToolTip = tr("Limits maximum number of found words, affects"
75 " only when searching in file.");
78 searchResultSizeInfoToolButton = new QToolButton;
79 searchResultSizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
82 searchResultLayout->addWidget(searchResultSizeSpinBox);
84 searchResultLayout->addWidget(searchResultSizeInfoToolButton);
91 spinBoxesFormLayout = new QFormLayout;
92 spinBoxesFormLayout->addRow(tr("Search result size"),
94 spinBoxesFormLayout->addRow(tr("History size"),
100 verticalLayout->addLayout(spinBoxesFormLayout);
103 checkBoxesLabel = new QLabel(tr("Search in:"),this);
105 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
106 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
108 verticalLayout->addSpacing(20);
109 verticalLayout->addWidget(checkBoxesLabel);
110 verticalLayout->addWidget(searchInDictionariesCheckBox);
111 verticalLayout->addWidget(searchInBookmarksCheckBox);
114 connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
116 connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
118 connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
120 connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
125 connect(searchResultSizeInfoToolButton, SIGNAL(clicked()),
126 this, SLOT(showSearchResultSizeInfo()));
128 connect(historySizeInfoToolButton, SIGNAL(clicked()),
129 this, SLOT(showHistorySizeInfo()));
131 historySizeSpinBox->setToolTip(historySizeToolTip);
132 searchResultSizeSpinBox->setToolTip(searchResultSizeToolTip);
139 setMinimumWidth(250);
140 setMaximumWidth(250);
141 footerLayout = new QHBoxLayout;
142 closeButton = new QPushButton(tr("Save"));
143 footerLayout->addStretch(0);
144 footerLayout->addWidget(closeButton);
145 verticalLayout->addLayout(footerLayout);
147 setMinimumHeight(sizeHint().height());
148 setMaximumHeight(sizeHint().height());
149 connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
153 void SettingsWidget::showEvent(QShowEvent *e) {
159 settings = guiInterface->settings();
161 historySizeSpinBox->setValue(
162 settings->value("history_size").toInt());
164 searchResultSizeSpinBox->setValue(
165 settings->value("search_limit").toInt());
167 if(settings->value("search_bookmarks") == "true")
168 searchInBookmarksCheckBox->setChecked(true);
170 searchInBookmarksCheckBox->setChecked(false);
172 if(settings->value("search_dictionaries") == "true")
173 searchInDictionariesCheckBox->setChecked(true);
175 searchInDictionariesCheckBox->setChecked(false);
178 QDialog::showEvent(e);
181 void SettingsWidget::hideEvent(QHideEvent *e) {
182 QDialog::hideEvent(e);
185 if(settings && _save) {
187 if(settings && _changed &&
188 QMessageBox::question(this,
190 tr("Do you want to save changes?"),
191 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
194 Settings* newSettings = new Settings;
195 newSettings->setValue("history_size",
196 QString::number(historySizeSpinBox->value()));
197 newSettings->setValue("search_limit",
199 searchResultSizeSpinBox->value()));
201 if(searchInDictionariesCheckBox->isChecked())
202 newSettings->setValue("search_dictionaries", "true");
204 newSettings->setValue("search_dictionaries", "false");
206 if(searchInBookmarksCheckBox->isChecked())
207 newSettings->setValue("search_bookmarks", "true");
209 newSettings->setValue("search_bookmarks", "false");
211 //setting new settings only if they are different than old ones
213 foreach(key, newSettings->keys()) {
214 if(settings->value(key) != newSettings->value(key)) {
215 guiInterface->setSettings(newSettings);
229 void SettingsWidget::changed() {
234 void SettingsWidget::save() {
242 void SettingsWidget::showHistorySizeInfo() {
243 Q_EMIT notify(Notify::Warning, historySizeToolTip);
246 void SettingsWidget::showSearchResultSizeInfo() {
247 Q_EMIT notify(Notify::Warning, searchResultSizeToolTip);