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

Last change on this file since 58 was 58, checked in by laleppa, 15 years ago

Some UI tweaks...

  • Property svn:keywords set to Id URL
File size: 8.2 KB
RevLine 
[1]1/*
[42]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 58 2009-08-23 18:58:46Z 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
24#include "settingsdialog.h"
25
26SettingsDialog::SettingsDialog(QWidget *parent)
[42]27        : QDialog(parent), newFont(false), newColor(false)
[1]28{
29        setupUi(this);
[56]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);
[57]46        vbox2->addWidget(cbAutosize);
[56]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");
[58]86        imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
87        imgIcon->setFrameShape(QFrame::Panel);
[56]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);
[58]96//      labelHint->setMinimumSize(QSize(190,28));
97        labelHint->setMinimumSize(QSize(0,28));
98        labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX,28));
[56]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);
[57]135        vbox2->addWidget(cbAutosize);
[56]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
[1]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)));
[17]160        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
[21]161        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
[1]162//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
163        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
[17]164#ifndef Q_OS_WINCE
[10]165        // Setting initial text of dialog hint label to own status tip
166        // text.
[9]167        labelHint->setText(labelHint->statusTip());
[17]168#endif // Q_OS_WINCE
[23]169        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
[57]170        spinRandMin->setMaximum(MAX_RAND_VALUE);
[21]171        spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
[57]172        spinRandMax->setMaximum(MAX_RAND_VALUE);
[21]173        spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
[57]174        cbAutosize->setChecked(settings->value("Autosize",true).toBool());
[21]175#ifndef Q_OS_WINCE
176        cbSaveState->setChecked(settings->value("SavePos",false).toBool());
177#endif // Q_OS_WINCE
[42]178        settings->beginGroup("Output");
[21]179        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
180        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
[42]181        settings->endGroup();
182}
183
184void SettingsDialog::accept()
185{
[21]186#ifndef Q_OS_WINCE
[42]187        settings->setValue("SavePos",cbSaveState->isChecked());
[21]188#endif // Q_OS_WINCE
[57]189        settings->setValue("Autosize",cbAutosize->isChecked());
[42]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);
[21]197        settings->endGroup();
[42]198        QDialog::accept();
[1]199}
200
[42]201void SettingsDialog::buttonFontClicked()
202{
203bool ok;
204QFont font = QFontDialog::getFont(&ok,this->font,this);
205        if (ok && (this->font != font)) {
206                this->font = font;
207                newFont = true;
208        }
209}
210
211void SettingsDialog::buttonColorClicked()
212{
213QColor color = QColorDialog::getColor(this->color,this);
214        if (color.isValid() && (this->color != color)) {
215                this->color = color;
216                newColor = true;
217        }
218}
219
220bool SettingsDialog::colorChanged() const
221{
222        return newColor;
223}
224
225bool SettingsDialog::fontChanged() const
226{
227        return newFont;
228}
229
[17]230#ifndef Q_OS_WINCE
[9]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
[10]235        // dialog hint label text to own status tip text.
[9]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;
[58]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;
[9]249        } else
250                return QDialog::event(ev);
251}
[17]252#endif // Q_OS_WINCE
Note: See TracBrowser for help on using the repository browser.