source: tspsg/src/settingsdialog.cpp @ bc1b8837b6

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

Some UI tweaks...

  • Property mode set to 100644
File size: 8.2 KB
RevLine 
[5515c2c2a7]1/*
[430bd7f7e9]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
[7836f136eb]24#include "settingsdialog.h"
[5515c2c2a7]25
26SettingsDialog::SettingsDialog(QWidget *parent)
[430bd7f7e9]27        : QDialog(parent), newFont(false), newColor(false)
[5515c2c2a7]28{
29        setupUi(this);
[281303f1f7]30        // Laying out elements
31#ifdef Q_OS_WINCE
32        // Layout helper elements
33QVBoxLayout *vbox1, *vbox2;
34QHBoxLayout *hbox1, *hbox2;
35QSpacerItem *spacer;
36
37        labelRandMin->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
38        labelRandMax->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
39
40        // Top part (with white bg)
41        vbox2 = new QVBoxLayout(bgWhite);
42        vbox2->addWidget(groupRandomSettings);
43        vbox2->addWidget(groupOutputSettings);
44        spacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding);
45        vbox2->addItem(spacer);
[2fb523720a]46        vbox2->addWidget(cbAutosize);
[281303f1f7]47
48        // Output settings group
49        hbox1 = new QHBoxLayout(groupOutputSettings);
50        hbox1->addWidget(buttonFont);
51        hbox1->addWidget(buttonColor);
52
53        // Bottom part (with grey bg)
54        hbox2 = new QHBoxLayout(bgGrey);
55        hbox2->setMargin(6);
56        hbox2->setSpacing(6);
57        hbox2->addWidget(buttonHelp);
58        spacer = new QSpacerItem(0,0,QSizePolicy::Expanding);
59        hbox2->addItem(spacer);
60        hbox2->addWidget(buttonOK);
61        hbox2->addWidget(buttonCancel);
62
63        // Central layout
64        vbox1 = new QVBoxLayout(this);
65        vbox1->setMargin(0);
66        vbox1->setSpacing(0);
67        vbox1->addWidget(bgWhite);
68        vbox1->addWidget(lineHorizontal);
69        vbox1->addWidget(bgGrey);
70#else
71        // Layout helper elements
72QVBoxLayout *vbox1, *vbox2, *vbox3;
73QHBoxLayout *hbox1, *hbox2, *hbox3;
74QSpacerItem *spacer;
75
76        cbSaveState = new QCheckBox(bgWhite);
77        cbSaveState->setObjectName("cbSaveState");
78#ifndef QT_NO_STATUSTIP
79        cbSaveState->setStatusTip(trUtf8("Restore main window state and position on application restart"));
80#endif // QT_NO_STATUSTIP
81        cbSaveState->setText(trUtf8("Save main window state and position"));
82        cbSaveState->setCursor(QCursor(Qt::PointingHandCursor));
83
84        imgIcon = new QLabel(this);
85        imgIcon->setObjectName("imgIcon");
[5a81a64d74]86        imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
87        imgIcon->setFrameShape(QFrame::Panel);
[281303f1f7]88        imgIcon->setLineWidth(0);
89        imgIcon->setPixmap(QPixmap(QString::fromUtf8(":/images/icons/preferences_system.png")));
90        imgIcon->setStyleSheet("background-color: #0080C0;");
91        imgIcon->setAlignment(Qt::AlignCenter);
92
93        labelHint = new QLabel(bgGrey);
94        labelHint->setObjectName("labelHint");
95        labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
[5a81a64d74]96//      labelHint->setMinimumSize(QSize(190,28));
97        labelHint->setMinimumSize(QSize(0,28));
98        labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX,28));
[281303f1f7]99        labelHint->setTextFormat(Qt::PlainText);
100//      labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
101        labelHint->setWordWrap(true);
102#ifndef QT_NO_STATUSTIP
103        labelHint->setStatusTip(trUtf8("Hover mouse pointer over dialog elements to get additional help"));
104#endif // QT_NO_STATUSTIP
105
106        lineVertical = new QFrame(this);
107        lineVertical->setObjectName("lineVertical");
108        lineVertical->setFrameShadow(QFrame::Plain);
109        lineVertical->setFrameShape(QFrame::VLine);
110        lineVertical->setLineWidth(2);
111
112        // Top line
113        hbox1 = new QHBoxLayout();
114        hbox1->addWidget(imgIcon);
115        hbox1->addWidget(lineVertical);
116        hbox1->addWidget(bgWhite);
117
118        // Output settings group
119        vbox3 = new QVBoxLayout(groupOutputSettings);
120        vbox3->addWidget(buttonFont);
121        vbox3->addWidget(buttonColor);
122
123        // Random and Output settings groups
124        hbox2 = new QHBoxLayout();
125        hbox2->addWidget(groupRandomSettings);
126        hbox2->addWidget(groupOutputSettings);
127        spacer = new QSpacerItem(0,0,QSizePolicy::Expanding);
128        hbox2->addItem(spacer);
129
130        // Top right part (with white bg)
131        vbox2 = new QVBoxLayout(bgWhite);
132        spacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding);
133        vbox2->addItem(spacer);
134        vbox2->addLayout(hbox2);
[2fb523720a]135        vbox2->addWidget(cbAutosize);
[281303f1f7]136        vbox2->addWidget(cbSaveState);
137        spacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding);
138        vbox2->addItem(spacer);
139
140        // Bottom part (with grey bg)
141        hbox3 = new QHBoxLayout(bgGrey);
142        hbox3->setMargin(6);
143        hbox3->setSpacing(6);
144        hbox3->addWidget(buttonHelp);
145        hbox3->addWidget(labelHint);
146        hbox3->addWidget(buttonOK);
147        hbox3->addWidget(buttonCancel);
148
149        // Central layout
150        vbox1 = new QVBoxLayout(this);
151        vbox1->setMargin(0);
152        vbox1->setSpacing(0);
153        vbox1->addLayout(hbox1);
154        vbox1->addWidget(lineHorizontal);
155        vbox1->addWidget(bgGrey);
156#endif // Q_OS_WINCE
[5515c2c2a7]157        connect(buttonOK,SIGNAL(clicked()),this,SLOT(accept()));
158        connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));
159        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
[5354a01311]160        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
[aecdf994f9]161        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
[5515c2c2a7]162//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
163        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
[5354a01311]164#ifndef Q_OS_WINCE
[95eca626aa]165        // Setting initial text of dialog hint label to own status tip
166        // text.
[7836f136eb]167        labelHint->setText(labelHint->statusTip());
[5354a01311]168#endif // Q_OS_WINCE
[665d32434f]169        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
[2fb523720a]170        spinRandMin->setMaximum(MAX_RAND_VALUE);
[aecdf994f9]171        spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
[2fb523720a]172        spinRandMax->setMaximum(MAX_RAND_VALUE);
[aecdf994f9]173        spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
[2fb523720a]174        cbAutosize->setChecked(settings->value("Autosize",true).toBool());
[aecdf994f9]175#ifndef Q_OS_WINCE
176        cbSaveState->setChecked(settings->value("SavePos",false).toBool());
177#endif // Q_OS_WINCE
[430bd7f7e9]178        settings->beginGroup("Output");
[aecdf994f9]179        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
180        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
181        settings->endGroup();
[7836f136eb]182}
183
[430bd7f7e9]184void SettingsDialog::accept()
[7836f136eb]185{
[430bd7f7e9]186#ifndef Q_OS_WINCE
187        settings->setValue("SavePos",cbSaveState->isChecked());
[5354a01311]188#endif // Q_OS_WINCE
[2fb523720a]189        settings->setValue("Autosize",cbAutosize->isChecked());
[430bd7f7e9]190        settings->setValue("MinCost",spinRandMin->value());
191        settings->setValue("MaxCost",spinRandMax->value());
192        settings->beginGroup("Output");
193        if (newFont)
194                settings->setValue("Font",font);
195        if (newColor)
196                settings->setValue("Color",color);
197        settings->endGroup();
198        QDialog::accept();
199}
[5515c2c2a7]200
[5354a01311]201void SettingsDialog::buttonFontClicked()
202{
[aecdf994f9]203bool ok;
204QFont font = QFontDialog::getFont(&ok,this->font,this);
[430bd7f7e9]205        if (ok && (this->font != font)) {
[aecdf994f9]206                this->font = font;
[430bd7f7e9]207                newFont = true;
208        }
[aecdf994f9]209}
210
211void SettingsDialog::buttonColorClicked()
212{
[e7f7d3854d]213QColor color = QColorDialog::getColor(this->color,this);
[430bd7f7e9]214        if (color.isValid() && (this->color != color)) {
[e7f7d3854d]215                this->color = color;
[430bd7f7e9]216                newColor = true;
217        }
[aecdf994f9]218}
219
[430bd7f7e9]220bool SettingsDialog::colorChanged() const
[aecdf994f9]221{
[430bd7f7e9]222        return newColor;
223}
224
225bool SettingsDialog::fontChanged() const
226{
227        return newFont;
228}
229
[aecdf994f9]230#ifndef Q_OS_WINCE
[430bd7f7e9]231bool SettingsDialog::event(QEvent *ev)
232{
233        // Checking for StatusTip event and if tip text is not empty string
234        // setting it as text of the dialog hint label. Otherwise, setting
235        // dialog hint label text to own status tip text.
236        if (ev->type() == QEvent::StatusTip) {
237QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
238                if (tip.length() != 0)
239                        labelHint->setText(tip);
240                else
241                        labelHint->setText(labelHint->statusTip());
242                return true;
[5a81a64d74]243        // Making imgIcon square.
244        } else if (ev->type() == QEvent::Show) {
245bool result = QDialog::event(ev);
246                if (result)
247                        imgIcon->setMinimumWidth(imgIcon->height());
248                return result;
[430bd7f7e9]249        } else
250                return QDialog::event(ev);
[5354a01311]251}
[430bd7f7e9]252#endif // Q_OS_WINCE
Note: See TracBrowser for help on using the repository browser.