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;
37 view= new QDeclarativeView();
38 view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/SettingsWidget.qml"));
39 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
40 view->setAlignment(Qt::AlignCenter);
43 mainLayout = new QVBoxLayout;
44 mainLayout->addWidget(view);
45 setLayout(mainLayout);
47 QGraphicsObject *rootObject = view->rootObject();
49 // connect(this, SIGNAL(setUrl(QVariant)),
50 // rootObject, SLOT(setUrl(QVariant)));
51 view->setWindowTitle(tr("Settings"));
55 setWindowTitle(tr("Settings"));
61 void SettingsWidget::initalizeUI() {
62 verticalLayout = new QVBoxLayout;
63 setLayout(verticalLayout);
65 historySizeLayout = new QHBoxLayout;
67 historySizeSpinBox = new SpinBox;
68 historySizeSpinBox->setMinimum(1);
69 historySizeSpinBox->setMaximum(50);
71 historySizeToolTip = tr("Limits maximum number of words saved in history");
74 historySizeInfoToolButton = new QToolButton;
75 historySizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
78 historySizeLayout->addWidget(historySizeSpinBox);
80 historySizeLayout->addWidget(historySizeInfoToolButton);
86 searchResultLayout = new QHBoxLayout;
88 searchResultSizeSpinBox = new SpinBox;
89 searchResultSizeSpinBox->setMinimum(0);
90 searchResultSizeSpinBox->setMaximum(500);
91 searchResultSizeSpinBox->setSpecialValueText(tr("Unlimited"));
93 searchResultSizeToolTip = tr("Limits maximum number of found words, affects"
94 " only when searching in file.");
97 searchResultSizeInfoToolButton = new QToolButton;
98 searchResultSizeInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
101 searchResultLayout->addWidget(searchResultSizeSpinBox);
103 searchResultLayout->addWidget(searchResultSizeInfoToolButton);
110 spinBoxesFormLayout = new QFormLayout;
111 spinBoxesFormLayout->addRow(tr("Search result size"),
113 spinBoxesFormLayout->addRow(tr("History size"),
119 verticalLayout->addLayout(spinBoxesFormLayout);
122 checkBoxesLabel = new QLabel(tr("Search in:"),this);
124 searchInBookmarksCheckBox = new QCheckBox(tr("Bookmarks"));
125 searchInDictionariesCheckBox = new QCheckBox(tr("Dictionaries"));
127 verticalLayout->addSpacing(20);
128 verticalLayout->addWidget(checkBoxesLabel);
129 verticalLayout->addWidget(searchInDictionariesCheckBox);
130 verticalLayout->addWidget(searchInBookmarksCheckBox);
133 connect(historySizeSpinBox, SIGNAL(valueChanged(int)), this,
135 connect(searchResultSizeSpinBox, SIGNAL(valueChanged(int)), this,
137 connect(searchInDictionariesCheckBox, SIGNAL(toggled(bool)), this,
139 connect(searchInBookmarksCheckBox, SIGNAL(toggled(bool)), this,
144 connect(searchResultSizeInfoToolButton, SIGNAL(clicked()),
145 this, SLOT(showSearchResultSizeInfo()));
147 connect(historySizeInfoToolButton, SIGNAL(clicked()),
148 this, SLOT(showHistorySizeInfo()));
150 historySizeSpinBox->setToolTip(historySizeToolTip);
151 searchResultSizeSpinBox->setToolTip(searchResultSizeToolTip);
158 setMinimumWidth(250);
159 setMaximumWidth(250);
160 footerLayout = new QHBoxLayout;
161 closeButton = new QPushButton(tr("Save"));
162 footerLayout->addStretch(0);
163 footerLayout->addWidget(closeButton);
164 verticalLayout->addLayout(footerLayout);
166 setMinimumHeight(sizeHint().height());
167 setMaximumHeight(sizeHint().height());
168 connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
172 void SettingsWidget::showEvent(QShowEvent *e) {
176 QDialog::showEvent(e);
183 settings = guiInterface->settings();
185 historySizeSpinBox->setValue(
186 settings->value("history_size").toInt());
188 searchResultSizeSpinBox->setValue(
189 settings->value("search_limit").toInt());
191 if(settings->value("search_bookmarks") == "true")
192 searchInBookmarksCheckBox->setChecked(true);
194 searchInBookmarksCheckBox->setChecked(false);
196 if(settings->value("search_dictionaries") == "true")
197 searchInDictionariesCheckBox->setChecked(true);
199 searchInDictionariesCheckBox->setChecked(false);
202 QDialog::showEvent(e);
206 void SettingsWidget::hideEvent(QHideEvent *e) {
207 QDialog::hideEvent(e);
210 if(settings && _save) {
212 if(settings && _changed &&
213 QMessageBox::question(this,
215 tr("Do you want to save changes?"),
216 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
219 Settings* newSettings = new Settings;
220 newSettings->setValue("history_size",
221 QString::number(historySizeSpinBox->value()));
222 newSettings->setValue("search_limit",
224 searchResultSizeSpinBox->value()));
226 if(searchInDictionariesCheckBox->isChecked())
227 newSettings->setValue("search_dictionaries", "true");
229 newSettings->setValue("search_dictionaries", "false");
231 if(searchInBookmarksCheckBox->isChecked())
232 newSettings->setValue("search_bookmarks", "true");
234 newSettings->setValue("search_bookmarks", "false");
236 //setting new settings only if they are different than old ones
238 foreach(key, newSettings->keys()) {
239 if(settings->value(key) != newSettings->value(key)) {
240 guiInterface->setSettings(newSettings);
254 void SettingsWidget::changed() {
259 void SettingsWidget::save() {
267 void SettingsWidget::showHistorySizeInfo() {
268 Q_EMIT notify(Notify::Warning, historySizeToolTip);
271 void SettingsWidget::showSearchResultSizeInfo() {
272 Q_EMIT notify(Notify::Warning, searchResultSizeToolTip);