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

Last change on this file since 53 was 42, checked in by laleppa, 15 years ago

+ Finished solving algorithm (needs thorough testing).
+ Solution can be saved to HTML or OpenDocument? format.
+ Added VERSIONINFO resource for windows builds.

  • Updated translations to have unified terminology everywhere.

NB: This will be the first public alpha build.

  • Property svn:keywords set to Id URL
File size: 3.7 KB
Line 
1/*
2 *  TSPSG: TSP Solver and Generator
3 *  Copyright (C) 2007-2009 Lёppa <contacts[at]oleksii[dot]name>
4 *
5 *  $Id: settingsdialog.cpp 42 2009-07-31 18:23:07Z laleppa $
6 *  $URL: https://tspsg.svn.sourceforge.net/svnroot/tspsg/trunk/src/settingsdialog.cpp $
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
26SettingsDialog::SettingsDialog(QWidget *parent)
27        : QDialog(parent), newFont(false), newColor(false)
28{
29        setupUi(this);
30        connect(buttonOK,SIGNAL(clicked()),this,SLOT(accept()));
31        connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));
32        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
33        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
34        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
35//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
36        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
37#ifndef Q_OS_WINCE
38        // Setting initial text of dialog hint label to own status tip
39        // text.
40        labelHint->setText(labelHint->statusTip());
41#endif // Q_OS_WINCE
42        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
43        spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
44        spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
45#ifndef Q_OS_WINCE
46        cbSaveState->setChecked(settings->value("SavePos",false).toBool());
47#endif // Q_OS_WINCE
48        settings->beginGroup("Output");
49        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
50        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
51        settings->endGroup();
52}
53
54void SettingsDialog::accept()
55{
56#ifndef Q_OS_WINCE
57        settings->setValue("SavePos",cbSaveState->isChecked());
58#endif // Q_OS_WINCE
59        settings->setValue("MinCost",spinRandMin->value());
60        settings->setValue("MaxCost",spinRandMax->value());
61        settings->beginGroup("Output");
62        if (newFont)
63                settings->setValue("Font",font);
64        if (newColor)
65                settings->setValue("Color",color);
66        settings->endGroup();
67        QDialog::accept();
68}
69
70void SettingsDialog::buttonFontClicked()
71{
72bool ok;
73QFont font = QFontDialog::getFont(&ok,this->font,this);
74        if (ok && (this->font != font)) {
75                this->font = font;
76                newFont = true;
77        }
78}
79
80void SettingsDialog::buttonColorClicked()
81{
82QColor color = QColorDialog::getColor(this->color,this);
83        if (color.isValid() && (this->color != color)) {
84                this->color = color;
85                newColor = true;
86        }
87}
88
89bool SettingsDialog::colorChanged() const
90{
91        return newColor;
92}
93
94bool SettingsDialog::fontChanged() const
95{
96        return newFont;
97}
98
99#ifndef Q_OS_WINCE
100bool SettingsDialog::event(QEvent *ev)
101{
102        // Checking for StatusTip event and if tip text is not empty string
103        // setting it as text of the dialog hint label. Otherwise, setting
104        // dialog hint label text to own status tip text.
105        if (ev->type() == QEvent::StatusTip) {
106QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
107                if (tip.length() != 0)
108                        labelHint->setText(tip);
109                else
110                        labelHint->setText(labelHint->statusTip());
111                return true;
112        } else
113                return QDialog::event(ev);
114}
115#endif // Q_OS_WINCE
Note: See TracBrowser for help on using the repository browser.