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;
36 view= new QDeclarativeView();
37 view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/SettingsWidget.qml"));
38 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
39 view->setAlignment(Qt::AlignCenter);
42 view->setMinimumWidth(250);
43 view->setMaximumWidth(250);
44 view->setMinimumHeight(view->sizeHint().height());
45 view->setMaximumHeight(view->sizeHint().height());
47 mainLayout = new QVBoxLayout;
48 mainLayout->addWidget(view);
49 setLayout(mainLayout);
50 view->setWindowTitle(tr("Settings"));
52 QGraphicsObject *rootObject = view->rootObject();
54 connect(this, SIGNAL(setMinHistory(QVariant)),
55 rootObject, SLOT(setMinHistory(QVariant)));
56 connect(this, SIGNAL(setValueHistory(QVariant)),
57 rootObject, SLOT(setValueHistory(QVariant)));
58 connect(this, SIGNAL(setMaxHistory(QVariant)),
59 rootObject, SLOT(setMaxHistory(QVariant)));
60 connect(this, SIGNAL(setMinSearchResult(QVariant)),
61 rootObject, SLOT(setMinSearchResult(QVariant)));
62 connect(this, SIGNAL(setValueSearchResult(QVariant)),
63 rootObject, SLOT(setValueSearchResult(QVariant)));
64 connect(this, SIGNAL(setMaxSearchResult(QVariant)),
65 rootObject, SLOT(setMaxSearchResult(QVariant)));
66 connect(this, SIGNAL(setCheckedBookmarks(QVariant)),
67 rootObject, SLOT(setCheckedBookmarks(QVariant)));
68 connect(this, SIGNAL(setCheckedDictionaries(QVariant)),
69 rootObject, SLOT(setCheckedDictionaries(QVariant)));
71 connect(rootObject, SIGNAL(historySizeValueChanged(int)),
72 this, SLOT(historySizeValueChanged(int)));
73 connect(rootObject, SIGNAL(searchResulValueChanged(int)),
74 this, SLOT(searchResulValueChanged(int)));
75 connect(rootObject, SIGNAL(dictionariesCheckBoxChanged(bool)),
76 this, SLOT(dictionariesCheckBoxChanged(bool)));
77 connect(rootObject, SIGNAL(bookmarksCheckBoxChanged(bool)),
78 this, SLOT(bookmarksCheckBoxChanged(bool)));
79 connect(rootObject, SIGNAL(saveButtonClicked()),
83 setWindowTitle(tr("Settings"));
90 void SettingsWidget::historySizeValueChanged(int value){
95 void SettingsWidget::searchResulValueChanged(int value){
96 searchResultValue=value;
100 void SettingsWidget::dictionariesCheckBoxChanged(bool boolean){
101 dictionariesCheckBox=boolean;
105 void SettingsWidget::bookmarksCheckBoxChanged(bool boolean){
106 bookmarksCheckBox=boolean;
110 void SettingsWidget::initalizeUI() {
112 emit setMinHistory(1);
113 emit setMaxHistory(50);
114 emit setMinHistory(0);
115 emit setMaxHistory(500);
118 verticalLayout = new QVBoxLayout;
119 historySizeLayout = new QHBoxLayout;
120 historySizeSpinBox = new SpinBox;
121 searchResultLayout = new QHBoxLayout;
122 searchResultSizeSpinBox = new SpinBox;
123 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
124 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
126 historySizeSpinBox->setMinimum(1);
127 historySizeSpinBox->setMaximum(50);
128 historySizeToolTip = tr("Limits maximum number of words saved in history");
129 historySizeLayout->addWidget(historySizeSpinBox);
132 historySizeInfoToolButton = new QToolButton;
133 historySizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
134 historySizeLayout->addWidget(historySizeInfoToolButton);
135 searchResultSizeInfoToolButton = new QToolButton;
136 searchResultSizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
139 searchResultSizeSpinBox->setMinimum(0);
140 searchResultSizeSpinBox->setMaximum(500);
141 searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited"));
142 searchResultSizeToolTip = tr("Limits maximum number of found words, affects"
143 " only when searching in file.");
144 searchResultLayout->addWidget(searchResultSizeSpinBox);
147 searchResultLayout->addWidget(searchResultSizeInfoToolButton);
150 spinBoxesFormLayout = new QFormLayout;
151 spinBoxesFormLayout->addRow(tr("Search result size"), searchResultLayout);
152 spinBoxesFormLayout->addRow(tr("History size"), historySizeLayout);
154 verticalLayout->addLayout(spinBoxesFormLayout);
155 checkBoxesLabel = new QLabel(tr("Search in:"),this);
157 verticalLayout->addSpacing(20);
158 verticalLayout->addWidget(checkBoxesLabel);
159 verticalLayout->addWidget(searchInDictionariesCheckBox);
160 verticalLayout->addWidget(searchInBookmarksCheckBox);
162 setLayout(verticalLayout);
164 connect(historySizeSpinBox, SIGNAL(valueChanged(int)),
165 this,SLOT(changed()));
166 connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)),
167 this,SLOT(changed()));
168 connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)),
169 this,SLOT(changed()));
170 connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)),
171 this,SLOT(changed()));
174 connect(searchResultSizeInfoToolButton, SIGNAL(clicked()),
175 this, SLOT(showSearchResultSizeInfo()));
176 connect(historySizeInfoToolButton, SIGNAL(clicked()),
177 this, SLOT(showHistorySizeInfo()));
179 historySizeSpinBox->setToolTip(historySizeToolTip);
180 searchResultSizeSpinBox->setToolTip(searchResultSizeToolTip);
187 setMinimumWidth(250);
188 setMaximumWidth(250);
189 footerLayout = new QHBoxLayout;
190 closeButton = new QPushButton(tr("Save"));
191 footerLayout->addStretch(0);
192 footerLayout->addWidget(closeButton);
193 verticalLayout->addLayout(footerLayout);
195 setMinimumHeight(sizeHint().height());
196 setMaximumHeight(sizeHint().height());
197 connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
202 void SettingsWidget::showEvent(QShowEvent *e) {
205 settings = guiInterface->settings();
207 emit setValueHistory(settings->value("history_size").toInt());
208 emit setValueSearchResult(settings->value("search_limit").toInt());
210 if(settings->value("search_bookmarks") == "true")
211 emit setCheckedBookmarks(true);
213 emit setCheckedBookmarks(false);
215 if(settings->value("search_dictionaries") == "true")
216 emit setCheckedDictionaries(true);
218 emit setCheckedDictionaries(false);
220 QDialog::showEvent(e);
226 settings = guiInterface->settings();
228 historySizeSpinBox->setValue(
229 settings->value("history_size").toInt());
231 searchResultSizeSpinBox->setValue(
232 settings->value("search_limit").toInt());
234 if(settings->value("search_bookmarks") == "true")
235 searchInBookmarksCheckBox->setChecked(true);
237 searchInBookmarksCheckBox->setChecked(false);
239 if(settings->value("search_dictionaries") == "true")
240 searchInDictionariesCheckBox->setChecked(true);
242 searchInDictionariesCheckBox->setChecked(false);
243 QDialog::showEvent(e);
248 void SettingsWidget::hideEvent(QHideEvent *e) {
249 QDialog::hideEvent(e);
252 if(settings && _save) {
253 Settings* newSettings = new Settings;
254 newSettings->setValue("history_size",QString::number(historyValue));
255 newSettings->setValue("search_limit",QString::number(searchResultValue));
256 if(dictionariesCheckBox==true)
257 newSettings->setValue("search_dictionaries", "true");
259 newSettings->setValue("search_dictionaries", "false");
261 if(bookmarksCheckBox==true)
262 newSettings->setValue("search_bookmarks", "true");
264 newSettings->setValue("search_bookmarks", "false");
265 foreach(QString key, newSettings->keys()) {
266 if(settings->value(key) != newSettings->value(key)) {
267 guiInterface->setSettings(newSettings);
278 if(settings && _changed &&
279 QMessageBox::question(this,
281 tr("Do you want to save changes?"),
282 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
284 Settings* newSettings = new Settings;
285 newSettings->setValue("history_size",
286 QString::number(historySizeSpinBox->value()));
287 newSettings->setValue("search_limit",
289 searchResultSizeSpinBox->value()));
291 if(searchInDictionariesCheckBox->isChecked())
292 newSettings->setValue("search_dictionaries", "true");
294 newSettings->setValue("search_dictionaries", "false");
296 if(searchInBookmarksCheckBox->isChecked())
297 newSettings->setValue("search_bookmarks", "true");
299 newSettings->setValue("search_bookmarks", "false");
301 //setting new settings only if they are different than old ones
302 foreach(QString key, newSettings->keys()) {
303 if(settings->value(key) != newSettings->value(key)) {
304 guiInterface->setSettings(newSettings);
318 void SettingsWidget::changed() {
323 void SettingsWidget::save() {
331 void SettingsWidget::showHistorySizeInfo() {
332 Q_EMIT notify(Notify::Warning, historySizeToolTip);
335 void SettingsWidget::showSearchResultSizeInfo() {
336 Q_EMIT notify(Notify::Warning, searchResultSizeToolTip);