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

Last change on this file since 21 was 21, checked in by laleppa, 16 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 svn:keywords set to Id URL
File size: 4.0 KB
RevLine 
[1]1/*
[6]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 21 2009-06-21 23:37:12Z 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
[9]24#include <QMessageBox>
25#include <QStatusTipEvent>
[17]26#include <QFontDialog>
[21]27#include <QColorDialog>
28#include "defines.h"
[1]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)));
[17]38        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
[21]39        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
[1]40//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
41        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
42        layout()->setSizeConstraint(layout()->SetFixedSize);
[17]43#ifndef Q_OS_WINCE
[10]44        // Setting initial text of dialog hint label to own status tip
45        // text.
[9]46        labelHint->setText(labelHint->statusTip());
[10]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());
[17]51#endif // Q_OS_WINCE
[21]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();
[1]65}
66
[17]67#ifndef Q_OS_WINCE
[9]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
[10]72        // dialog hint label text to own status tip text.
[9]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}
[17]83#endif // Q_OS_WINCE
[9]84
[17]85void SettingsDialog::buttonFontClicked()
86{
[21]87bool ok;
88QFont font = QFontDialog::getFont(&ok,this->font,this);
89        if (ok)
90                this->font = font;
[17]91}
[21]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.