source: tspsg-svn/trunk/src/settingsdialog.cpp @ 91

Last change on this file since 91 was 87, checked in by laleppa, 15 years ago

+ Added Fractional accuracy (in decimail places) to settings.
+ Created defaults.h file. Moved all default defines there.

  • Replaced all double types with qreal.
  • Replaced all calls to trUtf8() with tr() as we use setCodecForTr() to set UTF-8 encoding as default and tr() is enough.
  • Replaced all 2009 with 2010 in copyrights.
  • Fixed an error when loading .zkt file with less than 5 cities.
  • Property svn:keywords set to Id URL
File size: 9.4 KB
RevLine 
[1]1/*
[42]2 *  TSPSG: TSP Solver and Generator
[87]3 *  Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name>
[1]4 *
[6]5 *  $Id: settingsdialog.cpp 87 2010-01-12 14:11:24Z laleppa $
6 *  $URL: https://tspsg.svn.sourceforge.net/svnroot/tspsg/trunk/src/settingsdialog.cpp $
[3]7 *
[6]8 *  This file is part of TSPSG.
[1]9 *
[6]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.
[1]14 *
[6]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.
[1]19 *
[6]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/>.
[1]22 */
23
24#include "settingsdialog.h"
25
[65]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 */
[1]32SettingsDialog::SettingsDialog(QWidget *parent)
[42]33        : QDialog(parent), newFont(false), newColor(false)
[1]34{
35        setupUi(this);
[87]36
[78]37        buttonBox->button(QDialogButtonBox::Save)->setIcon(QIcon(":/images/icons/button_ok.png"));
[87]38        buttonBox->button(QDialogButtonBox::Save)->setStatusTip(tr("Save new preferences"));
[78]39        buttonBox->button(QDialogButtonBox::Save)->setCursor(QCursor(Qt::PointingHandCursor));
40        buttonBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":/images/icons/button_cancel.png"));
[87]41        buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Close without saving preferences"));
[78]42        buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor));
43
[56]44#ifdef Q_OS_WINCE
45        // Layout helper elements
[85]46QVBoxLayout *vbox1;
47QHBoxLayout *hbox1;
[56]48
[85]49        bgWhite->layout()->setMargin(0);
[56]50
51        // Bottom part (with grey bg)
[85]52        hbox1 = new QHBoxLayout(bgGrey);
53        hbox1->setMargin(6);
54        hbox1->setSpacing(6);
55        hbox1->addWidget(buttonHelp);
56        hbox1->addStretch();
57        hbox1->addWidget(buttonBox);
[56]58
59        // Central layout
60        vbox1 = new QVBoxLayout(this);
61        vbox1->setMargin(0);
62        vbox1->setSpacing(0);
63        vbox1->addWidget(bgWhite);
64        vbox1->addWidget(lineHorizontal);
65        vbox1->addWidget(bgGrey);
66#else
67        // Layout helper elements
[85]68QVBoxLayout *vbox1, *vbox2;
69QHBoxLayout *hbox1, *hbox2;
[56]70
71        cbSaveState = new QCheckBox(bgWhite);
72        cbSaveState->setObjectName("cbSaveState");
73#ifndef QT_NO_STATUSTIP
[87]74        cbSaveState->setStatusTip(tr("Restore main window state and position on application restart"));
[56]75#endif // QT_NO_STATUSTIP
[87]76        cbSaveState->setText(tr("Save main window state and position"));
[56]77        cbSaveState->setCursor(QCursor(Qt::PointingHandCursor));
78
79        imgIcon = new QLabel(this);
80        imgIcon->setObjectName("imgIcon");
[58]81        imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
82        imgIcon->setFrameShape(QFrame::Panel);
[56]83        imgIcon->setLineWidth(0);
[78]84        imgIcon->setPixmap(QPixmap(":/images/icons/preferences_system.png"));
[82]85        imgIcon->setStyleSheet("background-color: #0080C0; padding-top: 11px;");
86        imgIcon->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
[78]87        imgIcon->setMinimumWidth(150);
[56]88
89        labelHint = new QLabel(bgGrey);
90        labelHint->setObjectName("labelHint");
91        labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
[58]92//      labelHint->setMinimumSize(QSize(190,28));
93        labelHint->setMinimumSize(QSize(0,28));
94        labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX,28));
[56]95        labelHint->setTextFormat(Qt::PlainText);
96//      labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
97        labelHint->setWordWrap(true);
98#ifndef QT_NO_STATUSTIP
[87]99        labelHint->setStatusTip(tr("Hover mouse pointer over dialog elements to get additional help"));
[56]100#endif // QT_NO_STATUSTIP
101
102        lineVertical = new QFrame(this);
103        lineVertical->setObjectName("lineVertical");
104        lineVertical->setFrameShadow(QFrame::Plain);
105        lineVertical->setFrameShape(QFrame::VLine);
106        lineVertical->setLineWidth(2);
107
108        // Top line
109        hbox1 = new QHBoxLayout();
110        hbox1->addWidget(imgIcon);
111        hbox1->addWidget(lineVertical);
112        hbox1->addWidget(bgWhite);
113
[85]114        vbox1 = static_cast<QVBoxLayout *>(tabGeneral->layout());
[87]115        vbox1->insertWidget(vbox1->indexOf(cbUseNativeDialogs) + 1, cbSaveState);
[56]116
117        // Bottom part (with grey bg)
[85]118        hbox2 = new QHBoxLayout(bgGrey);
119        hbox2->setMargin(6);
120        hbox2->setSpacing(6);
121        hbox2->addWidget(buttonHelp);
122        hbox2->addWidget(labelHint);
123        hbox2->addWidget(buttonBox);
[56]124
125        // Central layout
[85]126        vbox2 = new QVBoxLayout(this);
127        vbox2->setMargin(0);
128        vbox2->setSpacing(0);
129        vbox2->addLayout(hbox1);
130        vbox2->addWidget(lineHorizontal);
131        vbox2->addWidget(bgGrey);
[56]132#endif // Q_OS_WINCE
[85]133
[1]134        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
[17]135        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
[21]136        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
[1]137//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
138        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
[17]139#ifndef Q_OS_WINCE
[78]140        // Setting initial text of dialog hint label to own status tip text.
[9]141        labelHint->setText(labelHint->statusTip());
[17]142#endif // Q_OS_WINCE
[80]143
144        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
145
[82]146        cbAutosize->setChecked(settings->value("Autosize", DEF_AUTOSIZE).toBool());
147        cbUseNativeDialogs->setChecked(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool());
[21]148#ifndef Q_OS_WINCE
[82]149        cbSaveState->setChecked(settings->value("SavePos", DEF_SAVEPOS).toBool());
[21]150#endif // Q_OS_WINCE
[78]151
[87]152        settings->beginGroup("Task");
153        spinFractionalAccuracy->setValue(settings->value("FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
154        spinRandMin->setMaximum(MAX_RAND_VALUE);
155        spinRandMin->setValue(settings->value("RandMin",DEF_RAND_MIN).toInt());
156        spinRandMax->setMaximum(MAX_RAND_VALUE);
157        spinRandMax->setValue(settings->value("RandMax",DEF_RAND_MAX).toInt());
158        cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool());
159        settings->endGroup();
160
[42]161        settings->beginGroup("Output");
[78]162        cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool());
163        cbCitiesLimit->setEnabled(cbShowMatrix->isChecked());
164        cbCitiesLimit->setChecked(settings->value("UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT && cbShowMatrix->isChecked()).toBool());
165        spinCitiesLimit->setEnabled(cbShowMatrix->isChecked());
[82]166        spinCitiesLimit->setValue(settings->value("ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt());
[78]167        spinCitiesLimit->setMaximum(MAX_NUM_CITIES);
[81]168        cbScrollToEnd->setChecked(settings->value("ScrollToEnd", DEF_SCROLL_TO_END).toBool());
[78]169
[21]170        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
171        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
[42]172        settings->endGroup();
[78]173
174        adjustSize();
[42]175}
176
[67]177/*!
178 * \brief Indicates whether or not the font color has been changed.
179 * \return \c true if font color changed, otherwise \c false.
180 */
181bool SettingsDialog::colorChanged() const
182{
183        return newColor;
184}
185
186/*!
187 * \brief Indicates whether or not the font properties have been changed.
188 * \return \c true if font properties changed, otherwise \c false.
189 */
190bool SettingsDialog::fontChanged() const
191{
192        return newFont;
193}
194
195/* Privates **********************************************************/
196
[42]197void SettingsDialog::accept()
198{
[21]199#ifndef Q_OS_WINCE
[78]200        settings->setValue("SavePos", cbSaveState->isChecked());
[21]201#endif // Q_OS_WINCE
[82]202        settings->setValue("UseNativeDialogs", cbUseNativeDialogs->isChecked());
[78]203        settings->setValue("Autosize", cbAutosize->isChecked());
[87]204
205        settings->beginGroup("Task");
206        settings->setValue("FractionalAccuracy", spinFractionalAccuracy->value());
207        settings->setValue("RandMin", spinRandMin->value());
208        settings->setValue("RandMax", spinRandMax->value());
[81]209        settings->setValue("FractionalRandom", cbFractionalRandom->isChecked());
[87]210        settings->endGroup();
[78]211
[42]212        settings->beginGroup("Output");
[78]213        settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
214        settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
215        if (cbCitiesLimit->isChecked())
[82]216                settings->setValue("ShowMatrixLimit", spinCitiesLimit->value());
[81]217        settings->setValue("ScrollToEnd", cbScrollToEnd->isChecked());
[42]218        if (newFont)
[78]219                settings->setValue("Font", font);
[42]220        if (newColor)
[78]221                settings->setValue("Color", color);
[21]222        settings->endGroup();
[42]223        QDialog::accept();
[1]224}
225
[42]226void SettingsDialog::buttonColorClicked()
227{
228QColor color = QColorDialog::getColor(this->color,this);
229        if (color.isValid() && (this->color != color)) {
230                this->color = color;
231                newColor = true;
232        }
233}
234
[67]235void SettingsDialog::buttonFontClicked()
[42]236{
[67]237bool ok;
238QFont font = QFontDialog::getFont(&ok,this->font,this);
239        if (ok && (this->font != font)) {
240                this->font = font;
241                newFont = true;
242        }
[42]243}
244
[65]245void SettingsDialog::spinRandMinValueChanged(int val) {
246        spinRandMax->setMinimum(val);
247}
248
[17]249#ifndef Q_OS_WINCE
[9]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
[10]254        // dialog hint label text to own status tip text.
[9]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);
264}
[17]265#endif // Q_OS_WINCE
Note: See TracBrowser for help on using the repository browser.