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

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