source: tspsg/src/settingsdialog.cpp @ 354e06314f

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

A little temorary fix for better Settings Dialog display under WinCE.

  • Property mode set to 100644
File size: 10.8 KB
RevLine 
[5515c2c2a7]1/*
[430bd7f7e9]2 *  TSPSG: TSP Solver and Generator
[5354a01311]3 *  Copyright (C) 2007-2009 Lёppa <contacts[at]oleksii[dot]name>
[5515c2c2a7]4 *
[bb994a7ff8]5 *  $Id$
6 *  $URL$
[f99964aa0b]7 *
[bb994a7ff8]8 *  This file is part of TSPSG.
[5515c2c2a7]9 *
[bb994a7ff8]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.
[5515c2c2a7]14 *
[bb994a7ff8]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.
[5515c2c2a7]19 *
[bb994a7ff8]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/>.
[5515c2c2a7]22 */
23
[7836f136eb]24#include "settingsdialog.h"
[5515c2c2a7]25
[caef58b531]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 */
[5515c2c2a7]32SettingsDialog::SettingsDialog(QWidget *parent)
[430bd7f7e9]33        : QDialog(parent), newFont(false), newColor(false)
[5515c2c2a7]34{
35        setupUi(this);
[281303f1f7]36        // Laying out elements
[1fbf016a09]37        layoutCitiesLimit = new QHBoxLayout();
38        layoutCitiesLimit->setMargin(0);
39        layoutCitiesLimit->setSpacing(0);
40        layoutCitiesLimit->addSpacing(10);
41        layoutCitiesLimit->addWidget(cbCitiesLimit);
42        layoutCitiesLimit->addWidget(spinCitiesLimit);
43        layoutCitiesLimit->addStretch();
44
45        buttonBox->button(QDialogButtonBox::Save)->setIcon(QIcon(":/images/icons/button_ok.png"));
46        buttonBox->button(QDialogButtonBox::Save)->setStatusTip(trUtf8("Save new preferences"));
47        buttonBox->button(QDialogButtonBox::Save)->setCursor(QCursor(Qt::PointingHandCursor));
48        buttonBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":/images/icons/button_cancel.png"));
49        buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(trUtf8("Close without saving preferences"));
50        buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor));
51
[281303f1f7]52#ifdef Q_OS_WINCE
53        // Layout helper elements
54QVBoxLayout *vbox1, *vbox2;
55QHBoxLayout *hbox1, *hbox2;
56
57        labelRandMin->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
58        labelRandMax->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
59
[354e06314f]60        groupRandomSettings->layout()->addWidget(cbFractionalRandom);
61        groupRandomSettings->layout()->setSpacing(2);
62
[281303f1f7]63        // Top part (with white bg)
64        vbox2 = new QVBoxLayout(bgWhite);
[354e06314f]65        vbox2->setSpacing(2);
[281303f1f7]66        vbox2->addWidget(groupRandomSettings);
67        vbox2->addWidget(groupOutputSettings);
[1fbf016a09]68        vbox2->addStretch();
[354e06314f]69//      vbox2->addWidget(cbFractionalRandom);
[1fbf016a09]70        vbox2->addWidget(cbShowMatrix);
71        vbox2->addLayout(layoutCitiesLimit);
[f1fb54b9f7]72        vbox2->addWidget(cbScrollToEnd);
[2fb523720a]73        vbox2->addWidget(cbAutosize);
[946f442ab0]74        vbox2->addWidget(cbUseNativeDialogs);
[281303f1f7]75
76        // Output settings group
77        hbox1 = new QHBoxLayout(groupOutputSettings);
78        hbox1->addWidget(buttonFont);
79        hbox1->addWidget(buttonColor);
80
81        // Bottom part (with grey bg)
82        hbox2 = new QHBoxLayout(bgGrey);
83        hbox2->setMargin(6);
84        hbox2->setSpacing(6);
85        hbox2->addWidget(buttonHelp);
[1fbf016a09]86        hbox2->addStretch();
87        hbox2->addWidget(buttonBox);
[281303f1f7]88
89        // Central layout
90        vbox1 = new QVBoxLayout(this);
91        vbox1->setMargin(0);
92        vbox1->setSpacing(0);
93        vbox1->addWidget(bgWhite);
94        vbox1->addWidget(lineHorizontal);
95        vbox1->addWidget(bgGrey);
96#else
97        // Layout helper elements
98QVBoxLayout *vbox1, *vbox2, *vbox3;
99QHBoxLayout *hbox1, *hbox2, *hbox3;
100
101        cbSaveState = new QCheckBox(bgWhite);
102        cbSaveState->setObjectName("cbSaveState");
103#ifndef QT_NO_STATUSTIP
104        cbSaveState->setStatusTip(trUtf8("Restore main window state and position on application restart"));
105#endif // QT_NO_STATUSTIP
106        cbSaveState->setText(trUtf8("Save main window state and position"));
107        cbSaveState->setCursor(QCursor(Qt::PointingHandCursor));
108
109        imgIcon = new QLabel(this);
110        imgIcon->setObjectName("imgIcon");
[5a81a64d74]111        imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
112        imgIcon->setFrameShape(QFrame::Panel);
[281303f1f7]113        imgIcon->setLineWidth(0);
[1fbf016a09]114        imgIcon->setPixmap(QPixmap(":/images/icons/preferences_system.png"));
[946f442ab0]115        imgIcon->setStyleSheet("background-color: #0080C0; padding-top: 11px;");
116        imgIcon->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
[1fbf016a09]117        imgIcon->setMinimumWidth(150);
[281303f1f7]118
119        labelHint = new QLabel(bgGrey);
120        labelHint->setObjectName("labelHint");
121        labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
[5a81a64d74]122//      labelHint->setMinimumSize(QSize(190,28));
123        labelHint->setMinimumSize(QSize(0,28));
124        labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX,28));
[281303f1f7]125        labelHint->setTextFormat(Qt::PlainText);
126//      labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
127        labelHint->setWordWrap(true);
128#ifndef QT_NO_STATUSTIP
129        labelHint->setStatusTip(trUtf8("Hover mouse pointer over dialog elements to get additional help"));
130#endif // QT_NO_STATUSTIP
131
132        lineVertical = new QFrame(this);
133        lineVertical->setObjectName("lineVertical");
134        lineVertical->setFrameShadow(QFrame::Plain);
135        lineVertical->setFrameShape(QFrame::VLine);
136        lineVertical->setLineWidth(2);
137
138        // Top line
139        hbox1 = new QHBoxLayout();
140        hbox1->addWidget(imgIcon);
141        hbox1->addWidget(lineVertical);
142        hbox1->addWidget(bgWhite);
143
144        // Output settings group
145        vbox3 = new QVBoxLayout(groupOutputSettings);
146        vbox3->addWidget(buttonFont);
147        vbox3->addWidget(buttonColor);
148
149        // Random and Output settings groups
150        hbox2 = new QHBoxLayout();
151        hbox2->addWidget(groupRandomSettings);
152        hbox2->addWidget(groupOutputSettings);
[1fbf016a09]153        hbox2->addStretch();
[281303f1f7]154
155        // Top right part (with white bg)
156        vbox2 = new QVBoxLayout(bgWhite);
[946f442ab0]157//      vbox2->addStretch();
[281303f1f7]158        vbox2->addLayout(hbox2);
[f1fb54b9f7]159        vbox2->addWidget(cbFractionalRandom);
[1fbf016a09]160        vbox2->addWidget(cbShowMatrix);
161        vbox2->addLayout(layoutCitiesLimit);
[f1fb54b9f7]162        vbox2->addWidget(cbScrollToEnd);
[2fb523720a]163        vbox2->addWidget(cbAutosize);
[946f442ab0]164        vbox2->addWidget(cbUseNativeDialogs);
[281303f1f7]165        vbox2->addWidget(cbSaveState);
[1fbf016a09]166        vbox2->addStretch();
[281303f1f7]167
168        // Bottom part (with grey bg)
169        hbox3 = new QHBoxLayout(bgGrey);
170        hbox3->setMargin(6);
171        hbox3->setSpacing(6);
172        hbox3->addWidget(buttonHelp);
173        hbox3->addWidget(labelHint);
[1fbf016a09]174        hbox3->addWidget(buttonBox);
[281303f1f7]175
176        // Central layout
177        vbox1 = new QVBoxLayout(this);
178        vbox1->setMargin(0);
179        vbox1->setSpacing(0);
180        vbox1->addLayout(hbox1);
181        vbox1->addWidget(lineHorizontal);
182        vbox1->addWidget(bgGrey);
183#endif // Q_OS_WINCE
[5515c2c2a7]184        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
[5354a01311]185        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
[aecdf994f9]186        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
[5515c2c2a7]187//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
188        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
[5354a01311]189#ifndef Q_OS_WINCE
[1fbf016a09]190        // Setting initial text of dialog hint label to own status tip text.
[7836f136eb]191        labelHint->setText(labelHint->statusTip());
[5354a01311]192#endif // Q_OS_WINCE
[4ccf855df8]193
194        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
195
[2fb523720a]196        spinRandMin->setMaximum(MAX_RAND_VALUE);
[aecdf994f9]197        spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
[2fb523720a]198        spinRandMax->setMaximum(MAX_RAND_VALUE);
[aecdf994f9]199        spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
[f1fb54b9f7]200        cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool());
[946f442ab0]201        cbAutosize->setChecked(settings->value("Autosize", DEF_AUTOSIZE).toBool());
202        cbUseNativeDialogs->setChecked(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool());
[aecdf994f9]203#ifndef Q_OS_WINCE
[946f442ab0]204        cbSaveState->setChecked(settings->value("SavePos", DEF_SAVEPOS).toBool());
[aecdf994f9]205#endif // Q_OS_WINCE
[1fbf016a09]206
[430bd7f7e9]207        settings->beginGroup("Output");
[1fbf016a09]208        cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool());
209        cbCitiesLimit->setEnabled(cbShowMatrix->isChecked());
210        cbCitiesLimit->setChecked(settings->value("UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT && cbShowMatrix->isChecked()).toBool());
211        spinCitiesLimit->setEnabled(cbShowMatrix->isChecked());
[946f442ab0]212        spinCitiesLimit->setValue(settings->value("ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt());
[1fbf016a09]213        spinCitiesLimit->setMaximum(MAX_NUM_CITIES);
[f1fb54b9f7]214        cbScrollToEnd->setChecked(settings->value("ScrollToEnd", DEF_SCROLL_TO_END).toBool());
[1fbf016a09]215
[aecdf994f9]216        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
217        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
218        settings->endGroup();
[1fbf016a09]219
220        adjustSize();
[7836f136eb]221}
222
[e0fcac5f2c]223/*!
224 * \brief Indicates whether or not the font color has been changed.
225 * \return \c true if font color changed, otherwise \c false.
226 */
227bool SettingsDialog::colorChanged() const
228{
229        return newColor;
230}
231
232/*!
233 * \brief Indicates whether or not the font properties have been changed.
234 * \return \c true if font properties changed, otherwise \c false.
235 */
236bool SettingsDialog::fontChanged() const
237{
238        return newFont;
239}
240
241/* Privates **********************************************************/
242
[430bd7f7e9]243void SettingsDialog::accept()
[7836f136eb]244{
[430bd7f7e9]245#ifndef Q_OS_WINCE
[1fbf016a09]246        settings->setValue("SavePos", cbSaveState->isChecked());
[5354a01311]247#endif // Q_OS_WINCE
[946f442ab0]248        settings->setValue("UseNativeDialogs", cbUseNativeDialogs->isChecked());
[1fbf016a09]249        settings->setValue("Autosize", cbAutosize->isChecked());
250        settings->setValue("MinCost", spinRandMin->value());
251        settings->setValue("MaxCost", spinRandMax->value());
[f1fb54b9f7]252        settings->setValue("FractionalRandom", cbFractionalRandom->isChecked());
[1fbf016a09]253
[430bd7f7e9]254        settings->beginGroup("Output");
[1fbf016a09]255        settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
256        settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
257        if (cbCitiesLimit->isChecked())
[946f442ab0]258                settings->setValue("ShowMatrixLimit", spinCitiesLimit->value());
[f1fb54b9f7]259        settings->setValue("ScrollToEnd", cbScrollToEnd->isChecked());
[430bd7f7e9]260        if (newFont)
[1fbf016a09]261                settings->setValue("Font", font);
[430bd7f7e9]262        if (newColor)
[1fbf016a09]263                settings->setValue("Color", color);
[430bd7f7e9]264        settings->endGroup();
265        QDialog::accept();
266}
[5515c2c2a7]267
[aecdf994f9]268void SettingsDialog::buttonColorClicked()
269{
[e7f7d3854d]270QColor color = QColorDialog::getColor(this->color,this);
[430bd7f7e9]271        if (color.isValid() && (this->color != color)) {
[e7f7d3854d]272                this->color = color;
[430bd7f7e9]273                newColor = true;
274        }
[aecdf994f9]275}
276
[e0fcac5f2c]277void SettingsDialog::buttonFontClicked()
[430bd7f7e9]278{
[e0fcac5f2c]279bool ok;
280QFont font = QFontDialog::getFont(&ok,this->font,this);
281        if (ok && (this->font != font)) {
282                this->font = font;
283                newFont = true;
284        }
[430bd7f7e9]285}
286
[caef58b531]287void SettingsDialog::spinRandMinValueChanged(int val) {
288        spinRandMax->setMinimum(val);
289}
290
[aecdf994f9]291#ifndef Q_OS_WINCE
[430bd7f7e9]292bool SettingsDialog::event(QEvent *ev)
293{
294        // Checking for StatusTip event and if tip text is not empty string
295        // setting it as text of the dialog hint label. Otherwise, setting
296        // dialog hint label text to own status tip text.
297        if (ev->type() == QEvent::StatusTip) {
298QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
299                if (tip.length() != 0)
300                        labelHint->setText(tip);
301                else
302                        labelHint->setText(labelHint->statusTip());
303                return true;
304        } else
305                return QDialog::event(ev);
[5354a01311]306}
[430bd7f7e9]307#endif // Q_OS_WINCE
Note: See TracBrowser for help on using the repository browser.