source: tspsg/src/settingsdialog.cpp @ 6beb157497

0.1.3.145-beta1-symbian0.1.4.170-beta2-bb10appveyorimgbotreadme
Last change on this file since 6beb157497 was 6beb157497, checked in by Oleksii Serdiuk, 14 years ago

+ Preliminary Symbian support.

  • Property mode set to 100644
File size: 10.7 KB
Line 
1/*
2 *  TSPSG: TSP Solver and Generator
3 *  Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name>
4 *
5 *  $Id$
6 *  $URL$
7 *
8 *  This file is part of TSPSG.
9 *
10 *  TSPSG is free software: you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License as published by
12 *  the Free Software Foundation, either version 3 of the License, or
13 *  (at your option) any later version.
14 *
15 *  TSPSG is distributed in the hope that it will be useful,
16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 *  GNU General Public License for more details.
19 *
20 *  You should have received a copy of the GNU General Public License
21 *  along with TSPSG.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include "settingsdialog.h"
25
26/*!
27 * \brief Class constructor.
28 * \param parent Settings Dialog parent widget.
29 *
30 * Initializes Settings Dialog and creates its layout based on target OS.
31 */
32SettingsDialog::SettingsDialog(QWidget *parent)
33        : QDialog(parent), _newFont(false), _newColor(false), _translucency(0)
34{
35        setupUi(this);
36
37        buttonBox->button(QDialogButtonBox::Save)->setIcon(QIcon(":/images/icons/button_ok.png"));
38        buttonBox->button(QDialogButtonBox::Save)->setStatusTip(tr("Save new preferences"));
39        buttonBox->button(QDialogButtonBox::Save)->setCursor(QCursor(Qt::PointingHandCursor));
40        buttonBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":/images/icons/button_cancel.png"));
41        buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Close without saving preferences"));
42        buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor));
43
44#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
45        // Layout helper elements
46QVBoxLayout *vbox1;
47QHBoxLayout *hbox1;
48
49        bgWhite->layout()->setMargin(0);
50
51        // Bottom part (with grey bg)
52        hbox1 = new QHBoxLayout(bgGrey);
53        hbox1->setMargin(6);
54        hbox1->setSpacing(6);
55        hbox1->addWidget(buttonHelp);
56        hbox1->addStretch();
57
58        // Central layout
59        vbox1 = new QVBoxLayout(this);
60        vbox1->setMargin(0);
61        vbox1->setSpacing(0);
62        vbox1->addWidget(bgWhite);
63        vbox1->addWidget(lineHorizontal);
64        vbox1->addWidget(bgGrey);
65#else
66        // Layout helper elements
67QVBoxLayout *vbox1, *vbox2;
68QHBoxLayout *hbox1, *hbox2;
69
70        if (QtWin::isCompositionEnabled()) {
71                cbUseTranslucency = new QCheckBox(bgWhite);
72                cbUseTranslucency->setObjectName("cbUseTranslucency");
73#ifndef QT_NO_STATUSTIP
74                cbUseTranslucency->setStatusTip(tr("Use translucent effect on the Main Window under Windows Vista and 7"));
75#endif // QT_NO_STATUSTIP
76                cbUseTranslucency->setText(tr("Use translucency effects"));
77                cbUseTranslucency->setCursor(QCursor(Qt::PointingHandCursor));
78        }
79
80        cbSaveState = new QCheckBox(bgWhite);
81        cbSaveState->setObjectName("cbSaveState");
82#ifndef QT_NO_STATUSTIP
83        cbSaveState->setStatusTip(tr("Restore main window state and position on application restart"));
84#endif // QT_NO_STATUSTIP
85        cbSaveState->setText(tr("Save main window state and position"));
86        cbSaveState->setCursor(QCursor(Qt::PointingHandCursor));
87
88        imgIcon = new QLabel(this);
89        imgIcon->setObjectName("imgIcon");
90        imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
91        imgIcon->setFrameShape(QFrame::Panel);
92        imgIcon->setLineWidth(0);
93        imgIcon->setPixmap(QPixmap(":/images/icons/preferences_system.png"));
94        imgIcon->setStyleSheet("background-color: #0080C0; padding-top: 11px;");
95        imgIcon->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
96        imgIcon->setMinimumWidth(150);
97
98        labelHint = new QLabel(bgGrey);
99        labelHint->setObjectName("labelHint");
100        labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
101//      labelHint->setMinimumSize(QSize(190,28));
102        labelHint->setMinimumSize(QSize(0,28));
103        labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX,28));
104        labelHint->setTextFormat(Qt::PlainText);
105//      labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
106        labelHint->setWordWrap(true);
107#ifndef QT_NO_STATUSTIP
108        labelHint->setStatusTip(tr("Hover mouse pointer over dialog elements to get additional help"));
109#endif // QT_NO_STATUSTIP
110
111        lineVertical = new QFrame(this);
112        lineVertical->setObjectName("lineVertical");
113        lineVertical->setFrameShadow(QFrame::Plain);
114        lineVertical->setFrameShape(QFrame::VLine);
115        lineVertical->setLineWidth(2);
116
117        // Top line
118        hbox1 = new QHBoxLayout();
119        hbox1->addWidget(imgIcon);
120        hbox1->addWidget(lineVertical);
121        hbox1->addWidget(bgWhite);
122
123        vbox1 = static_cast<QVBoxLayout *>(tabGeneral->layout());
124        vbox1->insertWidget(vbox1->indexOf(cbUseNativeDialogs) + 1, cbSaveState);
125#ifdef Q_OS_WIN32
126        if (QtWin::isCompositionEnabled())
127                vbox1->insertWidget(vbox1->indexOf(cbUseNativeDialogs) + 1, cbUseTranslucency);
128#endif // Q_OS_WIN32
129
130        // Bottom part (with grey bg)
131        hbox2 = new QHBoxLayout(bgGrey);
132        hbox2->setMargin(6);
133        hbox2->setSpacing(6);
134        hbox2->addWidget(buttonHelp);
135        hbox2->addWidget(labelHint);
136        hbox2->addWidget(buttonBox);
137
138        // Central layout
139        vbox2 = new QVBoxLayout(this);
140        vbox2->setMargin(0);
141        vbox2->setSpacing(0);
142        vbox2->addLayout(hbox1);
143        vbox2->addWidget(lineHorizontal);
144        vbox2->addWidget(bgGrey);
145#endif // Q_OS_WINCE
146
147        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
148        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
149        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
150//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
151        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
152#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
153        // Setting initial text of dialog hint label to own status tip text.
154        labelHint->setText(labelHint->statusTip());
155#endif // Q_OS_WINCE
156
157        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
158
159        cbAutosize->setChecked(settings->value("Autosize", DEF_AUTOSIZE).toBool());
160        cbUseNativeDialogs->setChecked(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool());
161#ifdef Q_OS_WIN32
162        if (QtWin::isCompositionEnabled())
163                cbUseTranslucency->setChecked(settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool());
164#endif // Q_OS_WIN32
165#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
166        cbSaveState->setChecked(settings->value("SavePos", DEF_SAVEPOS).toBool());
167#endif // Q_OS_WINCE
168
169        settings->beginGroup("Task");
170        spinFractionalAccuracy->setValue(settings->value("FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
171        spinRandMin->setMaximum(MAX_RAND_VALUE);
172        spinRandMin->setValue(settings->value("RandMin",DEF_RAND_MIN).toInt());
173        spinRandMax->setMaximum(MAX_RAND_VALUE);
174        spinRandMax->setValue(settings->value("RandMax",DEF_RAND_MAX).toInt());
175        cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool());
176        settings->endGroup();
177
178        settings->beginGroup("Output");
179        cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool());
180        cbCitiesLimit->setEnabled(cbShowMatrix->isChecked());
181        cbCitiesLimit->setChecked(settings->value("UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT && cbShowMatrix->isChecked()).toBool());
182        spinCitiesLimit->setEnabled(cbShowMatrix->isChecked());
183        spinCitiesLimit->setValue(settings->value("ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt());
184        spinCitiesLimit->setMaximum(MAX_NUM_CITIES);
185        cbScrollToEnd->setChecked(settings->value("ScrollToEnd", DEF_SCROLL_TO_END).toBool());
186
187        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
188        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
189        settings->endGroup();
190
191        adjustSize();
192}
193
194/*!
195 * \brief Indicates whether or not the font color has been changed.
196 * \return \c true if font color changed, otherwise \c false.
197 */
198bool SettingsDialog::colorChanged() const
199{
200        return _newColor;
201}
202
203/*!
204 * \brief Indicates whether or not the font properties have been changed.
205 * \return \c true if font properties changed, otherwise \c false.
206 */
207bool SettingsDialog::fontChanged() const
208{
209        return _newFont;
210}
211
212/*!
213 *
214 */
215qint8 SettingsDialog::translucencyChanged() const
216{
217        return _translucency;
218}
219
220/* Privates **********************************************************/
221
222void SettingsDialog::accept()
223{
224#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
225        settings->setValue("SavePos", cbSaveState->isChecked());
226#endif // Q_OS_WINCE
227#ifdef Q_OS_WIN32
228        if (QtWin::isCompositionEnabled()) {
229bool old = settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool();
230                if ((!old && cbUseTranslucency->isChecked()) || (old && !cbUseTranslucency->isChecked())) {
231                        _translucency = old ? -1 : 1;
232                } else
233                        _translucency = 0;
234                settings->setValue("UseTranslucency", cbUseTranslucency->isChecked());
235        }
236#endif // Q_OS_WIN32
237        settings->setValue("UseNativeDialogs", cbUseNativeDialogs->isChecked());
238
239        settings->beginGroup("Task");
240        settings->setValue("FractionalAccuracy", spinFractionalAccuracy->value());
241        settings->setValue("RandMin", spinRandMin->value());
242        settings->setValue("RandMax", spinRandMax->value());
243        settings->setValue("FractionalRandom", cbFractionalRandom->isChecked());
244        settings->endGroup();
245
246        settings->beginGroup("Output");
247        settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
248        settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
249        if (cbCitiesLimit->isChecked())
250                settings->setValue("ShowMatrixLimit", spinCitiesLimit->value());
251        settings->setValue("ScrollToEnd", cbScrollToEnd->isChecked());
252        if (_newFont)
253                settings->setValue("Font", font);
254        if (_newColor)
255                settings->setValue("Color", color);
256        settings->endGroup();
257        QDialog::accept();
258}
259
260void SettingsDialog::buttonColorClicked()
261{
262QColor color = QColorDialog::getColor(this->color,this);
263        if (color.isValid() && (this->color != color)) {
264                this->color = color;
265                _newColor = true;
266        }
267}
268
269void SettingsDialog::buttonFontClicked()
270{
271bool ok;
272QFont font = QFontDialog::getFont(&ok,this->font,this);
273        if (ok && (this->font != font)) {
274                this->font = font;
275                _newFont = true;
276        }
277}
278
279void SettingsDialog::spinRandMinValueChanged(int val) {
280        spinRandMax->setMinimum(val);
281}
282
283#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
284bool SettingsDialog::event(QEvent *ev)
285{
286        // Checking for StatusTip event and if tip text is not empty string
287        // setting it as text of the dialog hint label. Otherwise, setting
288        // dialog hint label text to own status tip text.
289        if (ev->type() == QEvent::StatusTip) {
290QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
291                if (tip.length() != 0)
292                        labelHint->setText(tip);
293                else
294                        labelHint->setText(labelHint->statusTip());
295                return true;
296        } else
297                return QDialog::event(ev);
298}
299#endif // Q_OS_WINCE
Note: See TracBrowser for help on using the repository browser.