source: tspsg/src/settingsdialog.cpp @ d5384ee64e

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

+ Settings are now saved and restored.
+ Font color selection in settings.
+ Primitive about dialog.
+ Automatic resizing of cells to its contents in wince.

  • No "Save window position" checkbox in wince.
  • Property mode set to 100644
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$
6 *  $URL$
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(INI_FILE,QSettings::IniFormat);
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{
95QColorDialog cd(color,this);
96        if (cd.exec() == QDialog::Accepted)
97                color = cd.selectedColor();
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.