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

Last change on this file since 25 was 24, checked in by laleppa, 16 years ago

Fix for color selection dialog code to compile without errors using Qt < 4.5.

  • Property svn:keywords set to Id URL
File size: 4.0 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 24 2009-06-22 07:59:44Z 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 <QMessageBox>
25#include <QStatusTipEvent>
26#include <QFontDialog>
27#include <QColorDialog>
28#include "defines.h"
29#include "settingsdialog.h"
30
31SettingsDialog::SettingsDialog(QWidget *parent)
32        : QDialog(parent)
33{
34        setupUi(this);
35        connect(buttonOK,SIGNAL(clicked()),this,SLOT(accept()));
36        connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));
37        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
38        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
39        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
40//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
41        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
42        layout()->setSizeConstraint(layout()->SetFixedSize);
43#ifndef Q_OS_WINCE
44        // Setting initial text of dialog hint label to own status tip
45        // text.
46        labelHint->setText(labelHint->statusTip());
47        // HACK: Do not resize label hint (and dialog) when text changes
48        // from one-line to two-line and vice versa. Any better solution?
49        labelHint->setMaximumHeight(labelHint->height());
50        labelHint->setMinimumHeight(labelHint->height());
51#endif // Q_OS_WINCE
52        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
53        spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
54        spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
55#ifndef Q_OS_WINCE
56        cbSaveState->setChecked(settings->value("SavePos",false).toBool());
57#endif // Q_OS_WINCE
58        settings->beginGroup("Print");
59        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
60        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
61#ifndef Q_OS_WINCE
62        spinLeftMargin->setValue(settings->value("Offset",DEF_OFFSET).toInt());
63#endif // Q_OS_WINCE
64        settings->endGroup();
65}
66
67#ifndef Q_OS_WINCE
68bool SettingsDialog::event(QEvent *ev)
69{
70        // Checking for StatusTip event and if tip text is not empty string
71        // setting it as text of the dialog hint label. Otherwise, setting
72        // dialog hint label text to own status tip text.
73        if (ev->type() == QEvent::StatusTip) {
74QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
75                if (tip.length() != 0)
76                        labelHint->setText(tip);
77                else
78                        labelHint->setText(labelHint->statusTip());
79                return true;
80        } else
81                return QDialog::event(ev);
82}
83#endif // Q_OS_WINCE
84
85void SettingsDialog::buttonFontClicked()
86{
87bool ok;
88QFont font = QFontDialog::getFont(&ok,this->font,this);
89        if (ok)
90                this->font = font;
91}
92
93void SettingsDialog::buttonColorClicked()
94{
95QColor color = QColorDialog::getColor(this->color,this);
96        if (color.isValid())
97                this->color = color;
98}
99
100void SettingsDialog::accept()
101{
102#ifndef Q_OS_WINCE
103        settings->setValue("SavePos",cbSaveState->isChecked());
104#endif // Q_OS_WINCE
105        settings->setValue("MinCost",spinRandMin->value());
106        settings->setValue("MaxCost",spinRandMax->value());
107        settings->beginGroup("Print");
108        settings->setValue("Font",font);
109        settings->setValue("Color",color);
110#ifndef Q_OS_WINCE
111        settings->setValue("Offset",spinLeftMargin->value());
112#endif // Q_OS_WINCE
113        settings->endGroup();
114        QDialog::accept();
115}
Note: See TracBrowser for help on using the repository browser.