source: tspsg/src/settingsdialog.cpp @ 2b9257627c

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

+ Opening task file
+ Saving task file

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