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) : QDialog(parent) {
32 guiInterface = parent;
35 view= new QDeclarativeView();
36 view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/SettingsWidget.qml"));
37 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
38 view->setAlignment(Qt::AlignCenter);
41 view->setMinimumWidth(250);
42 view->setMaximumWidth(250);
43 view->setMinimumHeight(view->sizeHint().height());
44 view->setMaximumHeight(view->sizeHint().height());
46 mainLayout = new QVBoxLayout;
47 mainLayout->addWidget(view);
48 setLayout(mainLayout);
49 view->setWindowTitle(tr("Settings"));
51 QGraphicsObject *rootObject = view->rootObject();
53 connect(this, SIGNAL(setMinHistory(QVariant)),
54 rootObject, SLOT(setMinHistory(QVariant)));
55 connect(this, SIGNAL(setValueHistory(QVariant)),
56 rootObject, SLOT(setValueHistory(QVariant)));
57 connect(this, SIGNAL(setMaxHistory(QVariant)),
58 rootObject, SLOT(setMaxHistory(QVariant)));
59 connect(this, SIGNAL(setMinSearchResult(QVariant)),
60 rootObject, SLOT(setMinSearchResult(QVariant)));
61 connect(this, SIGNAL(setValueSearchResult(QVariant)),
62 rootObject, SLOT(setValueSearchResult(QVariant)));
63 connect(this, SIGNAL(setMaxSearchResult(QVariant)),
64 rootObject, SLOT(setMaxSearchResult(QVariant)));
65 connect(this, SIGNAL(setCheckedBookmarks(QVariant)),
66 rootObject, SLOT(setCheckedBookmarks(QVariant)));
67 connect(this, SIGNAL(setCheckedDictionaries(QVariant)),
68 rootObject, SLOT(setCheckedDictionaries(QVariant)));
70 connect(rootObject, SIGNAL(historySizeValueChanged(int)),
71 this, SLOT(historySizeValueChanged(int)));
72 connect(rootObject, SIGNAL(searchResulValueChanged(int)),
73 this, SLOT(searchResulValueChanged(int)));
74 connect(rootObject, SIGNAL(dictionariesCheckBoxChanged(bool)),
75 this, SLOT(dictionariesCheckBoxChanged(bool)));
76 connect(rootObject, SIGNAL(bookmarksCheckBoxChanged(bool)),
77 this, SLOT(bookmarksCheckBoxChanged(bool)));
78 connect(rootObject, SIGNAL(saveButtonClicked()),
82 setWindowTitle(tr("Settings"));
89 void SettingsWidget::historySizeValueChanged(int value){
94 void SettingsWidget::searchResulValueChanged(int value){
95 searchResultValue=value;
99 void SettingsWidget::dictionariesCheckBoxChanged(bool boolean){
100 dictionariesCheckBox=boolean;
104 void SettingsWidget::bookmarksCheckBoxChanged(bool boolean){
105 bookmarksCheckBox=boolean;
109 void SettingsWidget::initalizeUI() {
111 emit setMinHistory(1);
112 emit setMaxHistory(50);
113 emit setMinHistory(0);
114 emit setMaxHistory(500);
117 verticalLayout = new QVBoxLayout;
118 historySizeLayout = new QHBoxLayout;
119 historySizeSpinBox = new SpinBox;
120 searchResultLayout = new QHBoxLayout;
121 searchResultSizeSpinBox = new SpinBox;
122 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
123 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
125 historySizeSpinBox->setMinimum(1);
126 historySizeSpinBox->setMaximum(50);
127 historySizeToolTip = tr("Limits maximum number of words saved in history");
128 historySizeLayout->addWidget(historySizeSpinBox);
131 historySizeInfoToolButton = new QToolButton;
132 historySizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
133 historySizeLayout->addWidget(historySizeInfoToolButton);
134 searchResultSizeInfoToolButton = new QToolButton;
135 searchResultSizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
138 searchResultSizeSpinBox->setMinimum(0);
139 searchResultSizeSpinBox->setMaximum(500);
140 searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited"));
141 searchResultSizeToolTip = tr("Limits maximum number of found words, affects"
142 " only when searching in file.");
143 searchResultLayout->addWidget(searchResultSizeSpinBox);
146 searchResultLayout->addWidget(searchResultSizeInfoToolButton);
149 spinBoxesFormLayout = new QFormLayout;
150 spinBoxesFormLayout->addRow(tr("Search result size"), searchResultLayout);
151 spinBoxesFormLayout->addRow(tr("History size"), historySizeLayout);
153 verticalLayout->addLayout(spinBoxesFormLayout);
154 checkBoxesLabel = new QLabel(tr("Search in:"),this);
156 verticalLayout->addSpacing(20);
157 verticalLayout->addWidget(checkBoxesLabel);
158 verticalLayout->addWidget(searchInDictionariesCheckBox);
159 verticalLayout->addWidget(searchInBookmarksCheckBox);
161 setLayout(verticalLayout);
163 connect(historySizeSpinBox, SIGNAL(valueChanged(int)),
164 this,SLOT(changed()));
165 connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)),
166 this,SLOT(changed()));
167 connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)),
168 this,SLOT(changed()));
169 connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)),
170 this,SLOT(changed()));
173 connect(searchResultSizeInfoToolButton, SIGNAL(clicked()),
174 this, SLOT(showSearchResultSizeInfo()));
175 connect(historySizeInfoToolButton, SIGNAL(clicked()),
176 this, SLOT(showHistorySizeInfo()));
178 historySizeSpinBox->setToolTip(historySizeToolTip);
179 searchResultSizeSpinBox->setToolTip(searchResultSizeToolTip);
186 setMinimumWidth(250);
187 setMaximumWidth(250);
188 footerLayout = new QHBoxLayout;
189 closeButton = new QPushButton(tr("Save"));
190 footerLayout->addStretch(0);
191 footerLayout->addWidget(closeButton);
192 verticalLayout->addLayout(footerLayout);
194 setMinimumHeight(sizeHint().height());
195 setMaximumHeight(sizeHint().height());
196 connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
201 void SettingsWidget::showEvent(QShowEvent *e) {
204 settings = guiInterface->settings();
206 emit setValueHistory(settings->value("history_size").toInt());
207 emit setValueSearchResult(settings->value("search_limit").toInt());
209 if(settings->value("search_bookmarks") == "true")
210 emit setCheckedBookmarks(true);
212 emit setCheckedBookmarks(false);
214 if(settings->value("search_dictionaries") == "true")
215 emit setCheckedDictionaries(true);
217 emit setCheckedDictionaries(false);
219 QDialog::showEvent(e);
225 settings = guiInterface->settings();
227 historySizeSpinBox->setValue(
228 settings->value("history_size").toInt());
230 searchResultSizeSpinBox->setValue(
231 settings->value("search_limit").toInt());
233 if(settings->value("search_bookmarks") == "true")
234 searchInBookmarksCheckBox->setChecked(true);
236 searchInBookmarksCheckBox->setChecked(false);
238 if(settings->value("search_dictionaries") == "true")
239 searchInDictionariesCheckBox->setChecked(true);
241 searchInDictionariesCheckBox->setChecked(false);
242 QDialog::showEvent(e);
247 void SettingsWidget::hideEvent(QHideEvent *e) {
248 QDialog::hideEvent(e);
251 if(settings && _save) {
252 Settings* newSettings = new Settings;
253 newSettings->setValue("history_size",QString::number(historyValue));
254 newSettings->setValue("search_limit",QString::number(searchResultValue));
255 if(dictionariesCheckBox==true)
256 newSettings->setValue("search_dictionaries", "true");
258 newSettings->setValue("search_dictionaries", "false");
260 if(bookmarksCheckBox==true)
261 newSettings->setValue("search_bookmarks", "true");
263 newSettings->setValue("search_bookmarks", "false");
264 foreach(QString key, newSettings->keys()) {
265 if(settings->value(key) != newSettings->value(key)) {
266 guiInterface->setSettings(newSettings);
277 if(settings && _changed &&
278 QMessageBox::question(this,
280 tr("Do you want to save changes?"),
281 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
283 Settings* newSettings = new Settings;
284 newSettings->setValue("history_size",
285 QString::number(historySizeSpinBox->value()));
286 newSettings->setValue("search_limit",
288 searchResultSizeSpinBox->value()));
290 if(searchInDictionariesCheckBox->isChecked())
291 newSettings->setValue("search_dictionaries", "true");
293 newSettings->setValue("search_dictionaries", "false");
295 if(searchInBookmarksCheckBox->isChecked())
296 newSettings->setValue("search_bookmarks", "true");
298 newSettings->setValue("search_bookmarks", "false");
300 //setting new settings only if they are different than old ones
301 foreach(QString key, newSettings->keys()) {
302 if(settings->value(key) != newSettings->value(key)) {
303 guiInterface->setSettings(newSettings);
317 void SettingsWidget::changed() {
322 void SettingsWidget::save() {
330 void SettingsWidget::showHistorySizeInfo() {
331 Q_EMIT notify(Notify::Warning, historySizeToolTip);
334 void SettingsWidget::showSearchResultSizeInfo() {
335 Q_EMIT notify(Notify::Warning, searchResultSizeToolTip);