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

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

+ Created installation (INSTALLS and DEPLOYMENT) entries for *nix, windows and wince platforms in tspsg.pro file. Now qmake generates install rules in Makefile.
+ Automatic resize of columns after their content changes can be turned on/off in settings now.

  • Different search path for translations on different platforms.
  • Updated translations.
  • Property svn:keywords set to Id URL
File size: 7.9 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 57 2009-08-22 23:26:42Z 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");
86        imgIcon->setFrameShape(QFrame::StyledPanel);
87        imgIcon->setLineWidth(0);
88        imgIcon->setPixmap(QPixmap(QString::fromUtf8(":/images/icons/preferences_system.png")));
89        imgIcon->setStyleSheet("background-color: #0080C0;");
90        imgIcon->setAlignment(Qt::AlignCenter);
91
92        labelHint = new QLabel(bgGrey);
93        labelHint->setObjectName("labelHint");
94        labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
[57]95        labelHint->setMinimumSize(QSize(190,28));
[56]96        labelHint->setMaximumSize(QSize(0xFFFFFF,28));
97        labelHint->setTextFormat(Qt::PlainText);
98//      labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
99        labelHint->setWordWrap(true);
100#ifndef QT_NO_STATUSTIP
101        labelHint->setStatusTip(trUtf8("Hover mouse pointer over dialog elements to get additional help"));
102#endif // QT_NO_STATUSTIP
103
104        lineVertical = new QFrame(this);
105        lineVertical->setObjectName("lineVertical");
106        lineVertical->setFrameShadow(QFrame::Plain);
107        lineVertical->setFrameShape(QFrame::VLine);
108        lineVertical->setLineWidth(2);
109
110        // Top line
111        hbox1 = new QHBoxLayout();
112        hbox1->addWidget(imgIcon);
113        hbox1->addWidget(lineVertical);
114        hbox1->addWidget(bgWhite);
115
116        // Output settings group
117        vbox3 = new QVBoxLayout(groupOutputSettings);
118        vbox3->addWidget(buttonFont);
119        vbox3->addWidget(buttonColor);
120
121        // Random and Output settings groups
122        hbox2 = new QHBoxLayout();
123        hbox2->addWidget(groupRandomSettings);
124        hbox2->addWidget(groupOutputSettings);
125        spacer = new QSpacerItem(0,0,QSizePolicy::Expanding);
126        hbox2->addItem(spacer);
127
128        // Top right part (with white bg)
129        vbox2 = new QVBoxLayout(bgWhite);
130        spacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding);
131        vbox2->addItem(spacer);
132        vbox2->addLayout(hbox2);
[57]133        vbox2->addWidget(cbAutosize);
[56]134        vbox2->addWidget(cbSaveState);
135        spacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding);
136        vbox2->addItem(spacer);
137
138        // Bottom part (with grey bg)
139        hbox3 = new QHBoxLayout(bgGrey);
140        hbox3->setMargin(6);
141        hbox3->setSpacing(6);
142        hbox3->addWidget(buttonHelp);
143        hbox3->addWidget(labelHint);
144        hbox3->addWidget(buttonOK);
145        hbox3->addWidget(buttonCancel);
146
147        // Central layout
148        vbox1 = new QVBoxLayout(this);
149        vbox1->setMargin(0);
150        vbox1->setSpacing(0);
151        vbox1->addLayout(hbox1);
152        vbox1->addWidget(lineHorizontal);
153        vbox1->addWidget(bgGrey);
154#endif // Q_OS_WINCE
[1]155        connect(buttonOK,SIGNAL(clicked()),this,SLOT(accept()));
156        connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));
157        connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int)));
[17]158        connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked()));
[21]159        connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked()));
[1]160//      setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
161        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
[17]162#ifndef Q_OS_WINCE
[10]163        // Setting initial text of dialog hint label to own status tip
164        // text.
[9]165        labelHint->setText(labelHint->statusTip());
[17]166#endif // Q_OS_WINCE
[23]167        settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg");
[57]168        spinRandMin->setMaximum(MAX_RAND_VALUE);
[21]169        spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());
[57]170        spinRandMax->setMaximum(MAX_RAND_VALUE);
[21]171        spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
[57]172        cbAutosize->setChecked(settings->value("Autosize",true).toBool());
[21]173#ifndef Q_OS_WINCE
174        cbSaveState->setChecked(settings->value("SavePos",false).toBool());
175#endif // Q_OS_WINCE
[42]176        settings->beginGroup("Output");
[21]177        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
178        color = settings->value("Color",DEF_FONT_COLOR).value<QColor>();
[42]179        settings->endGroup();
180}
181
182void SettingsDialog::accept()
183{
[21]184#ifndef Q_OS_WINCE
[42]185        settings->setValue("SavePos",cbSaveState->isChecked());
[21]186#endif // Q_OS_WINCE
[57]187        settings->setValue("Autosize",cbAutosize->isChecked());
[42]188        settings->setValue("MinCost",spinRandMin->value());
189        settings->setValue("MaxCost",spinRandMax->value());
190        settings->beginGroup("Output");
191        if (newFont)
192                settings->setValue("Font",font);
193        if (newColor)
194                settings->setValue("Color",color);
[21]195        settings->endGroup();
[42]196        QDialog::accept();
[1]197}
198
[42]199void SettingsDialog::buttonFontClicked()
200{
201bool ok;
202QFont font = QFontDialog::getFont(&ok,this->font,this);
203        if (ok && (this->font != font)) {
204                this->font = font;
205                newFont = true;
206        }
207}
208
209void SettingsDialog::buttonColorClicked()
210{
211QColor color = QColorDialog::getColor(this->color,this);
212        if (color.isValid() && (this->color != color)) {
213                this->color = color;
214                newColor = true;
215        }
216}
217
218bool SettingsDialog::colorChanged() const
219{
220        return newColor;
221}
222
223bool SettingsDialog::fontChanged() const
224{
225        return newFont;
226}
227
[17]228#ifndef Q_OS_WINCE
[9]229bool SettingsDialog::event(QEvent *ev)
230{
231        // Checking for StatusTip event and if tip text is not empty string
232        // setting it as text of the dialog hint label. Otherwise, setting
[10]233        // dialog hint label text to own status tip text.
[9]234        if (ev->type() == QEvent::StatusTip) {
235QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
236                if (tip.length() != 0)
237                        labelHint->setText(tip);
238                else
239                        labelHint->setText(labelHint->statusTip());
240                return true;
241        } else
242                return QDialog::event(ev);
243}
[17]244#endif // Q_OS_WINCE
Note: See TracBrowser for help on using the repository browser.