source: tspsg/src/settingsdialog.cpp @ a5be8eb2c8

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

Reworked Settings Dialog layout.

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