source: tspsg/src/settingsdialog.cpp @ 78282ec778

0.1.3.145-beta1-symbian0.1.4.170-beta2-bb10appveyorimgbotreadme
Last change on this file since 78282ec778 was e7f7d3854d, checked in by Oleksii Serdiuk, 15 years ago

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

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[5515c2c2a7]1/*
[bb994a7ff8]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
24#include <QMessageBox>
[7836f136eb]25#include <QStatusTipEvent>
[5354a01311]26#include <QFontDialog>
[aecdf994f9]27#include <QColorDialog>
28#include "defines.h"
[7836f136eb]29#include "settingsdialog.h"
[5515c2c2a7]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)));
[5354a01311]38        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
[aecdf994f9]39        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
[5515c2c2a7]40//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
41        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
42        layout()->setSizeConstraint(layout()->SetFixedSize);
[5354a01311]43#ifndef Q_OS_WINCE
[95eca626aa]44        // Setting initial text of dialog hint label to own status tip
45        // text.
[7836f136eb]46        labelHint->setText(labelHint->statusTip());
[95eca626aa]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());
[5354a01311]51#endif // Q_OS_WINCE
[665d32434f]52        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
[aecdf994f9]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();
[7836f136eb]65}
66
[5354a01311]67#ifndef Q_OS_WINCE
[7836f136eb]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
[95eca626aa]72        // dialog hint label text to own status tip text.
[7836f136eb]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);
[5515c2c2a7]82}
[5354a01311]83#endif // Q_OS_WINCE
[5515c2c2a7]84
[5354a01311]85void SettingsDialog::buttonFontClicked()
86{
[aecdf994f9]87bool ok;
88QFont font = QFontDialog::getFont(&ok,this->font,this);
89        if (ok)
90                this->font = font;
91}
92
93void SettingsDialog::buttonColorClicked()
94{
[e7f7d3854d]95QColor color = QColorDialog::getColor(this->color,this);
96        if (color.isValid())
97                this->color = color;
[aecdf994f9]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();
[5354a01311]115}
Note: See TracBrowser for help on using the repository browser.