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

Last change on this file since 47 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
RevLine 
[1]1/*
[42]2 *  TSPSG: TSP Solver and Generator
[17]3 *  Copyright (C) 2007-2009 Lёppa <contacts[at]oleksii[dot]name>
[1]4 *
[6]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 $
[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
26SettingsDialog::SettingsDialog(QWidget *parent)
[42]27        : QDialog(parent), newFont(false), newColor(false)
[1]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)));
[17]33        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
[21]34        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
[1]35//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
36        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
[17]37#ifndef Q_OS_WINCE
[10]38        // Setting initial text of dialog hint label to own status tip
39        // text.
[9]40        labelHint->setText(labelHint->statusTip());
[17]41#endif // Q_OS_WINCE
[23]42        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
[21]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
[42]48        settings->beginGroup("Output");
[21]49        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
50        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
[42]51        settings->endGroup();
52}
53
54void SettingsDialog::accept()
55{
[21]56#ifndef Q_OS_WINCE
[42]57        settings->setValue("SavePos",cbSaveState->isChecked());
[21]58#endif // Q_OS_WINCE
[42]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);
[21]66        settings->endGroup();
[42]67        QDialog::accept();
[1]68}
69
[42]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
[17]99#ifndef Q_OS_WINCE
[9]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
[10]104        // dialog hint label text to own status tip text.
[9]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}
[17]115#endif // Q_OS_WINCE
Note: See TracBrowser for help on using the repository browser.