source: tspsg/src/settingsdialog.cpp @ f0097d1bf3

appveyorimgbot
Last change on this file since f0097d1bf3 was b4b4f8d479, checked in by Oleksii Serdiuk, 10 years ago

Updated copyright endyear from 2013 to 2014

  • Property mode set to 100644
File size: 24.3 KB
RevLine 
[1babbd6ba3]1/*
2 *  TSPSG: TSP Solver and Generator
[b4b4f8d479]3 *  Copyright (C) 2007-2014 Oleksii Serdiuk <contacts[at]oleksii[dot]name>
[1babbd6ba3]4 *
[7ba743d983]5 *  $Id: $Format:%h %ai %an$ $
6 *  $URL: http://tspsg.info/ $
[1babbd6ba3]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
[2940c14782]12 *  the Free Software Foundation, either version 2 of the License, or
[1babbd6ba3]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
[07e43cf61a]26#include <QColorDialog>
27#include <QFontDialog>
28#include <QImageWriter>
29#include <QMessageBox>
30#include <QSettings>
31
32#ifdef HANDHELD
33#   include <QScrollArea>
34#endif
35
36#if !defined(QT_NO_STATUSTIP)
37#   include <QStatusTipEvent>
38#endif
39
40#ifndef HANDHELD
41    // Eyecandy
42#   include "qtwin.h"
43#endif // HANDHELD
44
[1babbd6ba3]45/*!
46 * \brief Class constructor.
47 * \param parent Settings Dialog parent widget.
48 *
49 * Initializes Settings Dialog and creates its layout based on target OS.
50 */
51SettingsDialog::SettingsDialog(QWidget *parent)
[a09f31733a]52    : QDialog(parent), _fontChanged(false), _colorChanged(false), _translucency(0)
[1babbd6ba3]53{
[9eb63a1598]54    setupUi(this);
[1babbd6ba3]55
[9eb63a1598]56    setWindowIcon(GET_ICON("preferences-system"));
[3cadf24d00]57
[9eb63a1598]58    buttonBox->button(QDialogButtonBox::Ok)->setIcon(GET_ICON("dialog-ok"));
[9adbc413c7]59#ifndef QT_NO_STATUSTIP
[9eb63a1598]60    buttonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Save new preferences"));
[9adbc413c7]61#endif
[9eb63a1598]62    buttonBox->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor));
63    buttonBox->button(QDialogButtonBox::Cancel)->setIcon(GET_ICON("dialog-cancel"));
[9adbc413c7]64#ifndef QT_NO_STATUSTIP
[9eb63a1598]65    buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Close without saving preferences"));
[9adbc413c7]66#endif
[9eb63a1598]67    buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor));
[1babbd6ba3]68
[a09f31733a]69    buttonTextColor->setIcon(GET_ICON("format-text-color"));
70    buttonSelectedColor->setIcon(GET_ICON("format-text-color"));
71    buttonAlternateColor->setIcon(GET_ICON("format-text-color"));
72    buttonBorderColor->setIcon(GET_ICON("format-stroke-color"));
[c8ed26ddf1]73//    buttonBgColor->setIcon(GET_ICON("format-fill-color"));
[9eb63a1598]74    buttonFont->setIcon(GET_ICON("preferences-desktop-font"));
75    buttonHelp->setIcon(GET_ICON("help-hint"));
[3cadf24d00]76
[317ba0432e]77QPalette p = bgWhite->palette();
[9eb63a1598]78    p.setColor(QPalette::Window, p.color(QPalette::Base));
79    bgWhite->setPalette(p);
[317ba0432e]80
[9eb63a1598]81    p = lineHorizontal->palette();
82    p.setColor(QPalette::Window, p.color(QPalette::Text));
83    lineHorizontal->setPalette(p);
[317ba0432e]84
[0007f69c46]85// Layout helpers
86QBoxLayout *box;
87QHBoxLayout *hbox;
[e26679937d]88#ifndef QT_NO_PRINTER
[9eb63a1598]89    cbHQGraph = new QCheckBox(bgWhite);
90    cbHQGraph->setObjectName("cbHQGraph");
[e26679937d]91#ifndef QT_NO_STATUSTIP
[9eb63a1598]92    cbHQGraph->setStatusTip(tr("Higher quality graph looks much better when printing but uglier on the screen"));
[e26679937d]93#endif // QT_NO_STATUSTIP
[9eb63a1598]94    cbHQGraph->setText(tr("Draw solution graph in higher quality"));
95    cbHQGraph->setCursor(QCursor(Qt::PointingHandCursor));
96
[ff8d0488a0]97    box = static_cast<QBoxLayout *>(tabOutputGeneral->layout());
[9eb63a1598]98    hbox = new QHBoxLayout();
99    hbox->addSpacing(10);
100    hbox->addWidget(cbHQGraph);
[6652ac66a4]101    box->insertLayout(box->indexOf(cbGenerateGraph) + 3, hbox);
[8f2427aaf0]102    connect(cbGenerateGraph, SIGNAL(toggled(bool)), cbHQGraph, SLOT(setEnabled(bool)));
[e26679937d]103#endif
104
[9eb63a1598]105    if (hasUpdater()) {
106        cbCheck4Updates = new QCheckBox(bgWhite);
107        cbCheck4Updates->setObjectName("cbCheck4Updates");
[f5c945d7ac]108#ifndef QT_NO_STATUSTIP
[9eb63a1598]109        cbCheck4Updates->setStatusTip(tr("Automatically check for updates at the given interval"));
[f5c945d7ac]110#endif // QT_NO_STATUSTIP
[9eb63a1598]111        cbCheck4Updates->setText(tr("Check for updates every"));
112        cbCheck4Updates->setCursor(QCursor(Qt::PointingHandCursor));
[f5c945d7ac]113
[9eb63a1598]114        spinUpdateCheckInterval = new QSpinBox(bgWhite);
115        spinUpdateCheckInterval->setObjectName("spinUpdateCheckInterval");
[f5c945d7ac]116#ifndef QT_NO_STATUSTIP
[9eb63a1598]117        spinUpdateCheckInterval->setStatusTip(tr("Minimal interval at which to check for updates"));
[f5c945d7ac]118#endif // QT_NO_STATUSTIP
[9eb63a1598]119        spinUpdateCheckInterval->setSuffix(tr(" days", "Don't forget a space at the beginning!"));
120        spinUpdateCheckInterval->setRange(1, 365);
121        spinUpdateCheckInterval->setCursor(QCursor(Qt::PointingHandCursor));
122
123        connect(cbCheck4Updates, SIGNAL(toggled(bool)), spinUpdateCheckInterval, SLOT(setEnabled(bool)));
124
125        box = static_cast<QBoxLayout *>(tabGeneral->layout());
126        hbox = new QHBoxLayout();
127        hbox->setSpacing(0);
128        hbox->addWidget(cbCheck4Updates);
129        hbox->addWidget(spinUpdateCheckInterval);
130        hbox->addStretch();
131        box->insertLayout(box->indexOf(cbUseNativeDialogs) + 1, hbox);
132    } else
133        cbCheck4Updates = NULL;
[f5c945d7ac]134
[1babbd6ba3]135#ifdef HANDHELD
136QVBoxLayout *vbox1; // Layout helper
137
[9eb63a1598]138    // On screens with small height when SIP is shown and the window is resized
139    // there is not enought space for all elements.
140    // So we show the scrollbars to be able to access them.
[1babbd6ba3]141QScrollArea *scrollArea = new QScrollArea(this);
[9eb63a1598]142    scrollArea->setFrameShape(QFrame::NoFrame);
143    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
144    scrollArea->setWidgetResizable(true);
145    scrollArea->setWidget(bgWhite);
[1babbd6ba3]146
[9eb63a1598]147    bgWhite->layout()->setMargin(0);
[1babbd6ba3]148
[89e5214692]149#ifdef Q_OS_SYMBIAN
[bf92f16303]150    // On Symbian buttons are moved to a native bar so Help button is
151    // left alone. This causes it to be more to the middle instead of
152    // to the left. Adding a stretch fixes this issue.
153    buttons->insertStretch(buttons->indexOf(buttonHelp) + 1);
154#endif
155
[9eb63a1598]156    // Central layout
157    vbox1 = new QVBoxLayout(this);
158    vbox1->setMargin(0);
159    vbox1->setSpacing(0);
160    vbox1->addWidget(scrollArea);
161    vbox1->addWidget(bgGrey);
162    setLayout(vbox1);
[1babbd6ba3]163#else // HANDHELD
[0007f69c46]164QVBoxLayout *vbox; // Layout helper
[1babbd6ba3]165
[b8a2a118c4]166#ifndef HANDHELD
[9eb63a1598]167    if (QtWin::isCompositionEnabled()) {
168        cbUseTranslucency = new QCheckBox(bgWhite);
169        cbUseTranslucency->setObjectName("cbUseTranslucency");
[1babbd6ba3]170#ifndef QT_NO_STATUSTIP
[8f2427aaf0]171        cbUseTranslucency->setStatusTip(tr("Make Main Window background translucent"));
[1babbd6ba3]172#endif // QT_NO_STATUSTIP
[9eb63a1598]173        cbUseTranslucency->setText(tr("Use translucency effects"));
174        cbUseTranslucency->setCursor(QCursor(Qt::PointingHandCursor));
175    }
[b8a2a118c4]176#endif // HANDHELD
[1babbd6ba3]177
[9eb63a1598]178    cbSaveState = new QCheckBox(bgWhite);
179    cbSaveState->setObjectName("cbSaveState");
[1babbd6ba3]180#ifndef QT_NO_STATUSTIP
[9eb63a1598]181    cbSaveState->setStatusTip(tr("Restore main window state and position on application restart"));
[1babbd6ba3]182#endif // QT_NO_STATUSTIP
[9eb63a1598]183    cbSaveState->setText(tr("Save main window state and position"));
184    cbSaveState->setCursor(QCursor(Qt::PointingHandCursor));
185
186    imgIcon = new QLabel(this);
187    imgIcon->setObjectName("imgIcon");
188    imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
189    imgIcon->setFrameShape(QFrame::NoFrame);
190    imgIcon->setPixmap(GET_ICON("preferences-system").pixmap(128, 128));
191    imgIcon->setStyleSheet("background-color: #0080C0; padding-top: 11px;");
192    imgIcon->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
193    imgIcon->setMinimumWidth(150);
194
195    labelHint = new QLabel(bgGrey);
196    labelHint->setObjectName("labelHint");
197    labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
[8f2427aaf0]198    labelHint->setMinimumSize(QSize(250, 28));
199    labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX, 28));
[9eb63a1598]200    labelHint->setTextFormat(Qt::PlainText);
[1babbd6ba3]201//      labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
[9eb63a1598]202    labelHint->setWordWrap(true);
[1babbd6ba3]203#ifndef QT_NO_STATUSTIP
[9eb63a1598]204    labelHint->setStatusTip(tr("Hover mouse pointer over dialog elements to get additional help"));
[1babbd6ba3]205#endif // QT_NO_STATUSTIP
206
[9eb63a1598]207    lineVertical = new QFrame(this);
208    lineVertical->setObjectName("lineVertical");
209    lineVertical->setFrameShadow(QFrame::Plain);
210    lineVertical->setFrameShape(QFrame::VLine);
211    lineVertical->setLineWidth(2);
[1babbd6ba3]212
[9eb63a1598]213    // Top line
214    hbox = new QHBoxLayout();
215    hbox->addWidget(imgIcon);
216    hbox->addWidget(lineVertical);
217    hbox->addWidget(bgWhite);
[e26679937d]218
[9eb63a1598]219    box = static_cast<QBoxLayout *>(tabGeneral->layout());
220    box->insertWidget(box->indexOf(cbUseNativeDialogs) + 1, cbSaveState);
[b8a2a118c4]221#ifndef HANDHELD
[9eb63a1598]222    if (QtWin::isCompositionEnabled())
223        box->insertWidget(box->indexOf(cbUseNativeDialogs) + 1, cbUseTranslucency);
[b8a2a118c4]224#endif // HANDHELD
[1babbd6ba3]225
[9eb63a1598]226    // Inserting label for hints to the bottom part (with grey bg)
227    buttons->insertWidget(buttons->indexOf(buttonHelp) + 1, labelHint, 1);
[1babbd6ba3]228
[9eb63a1598]229    // Central layout
230    vbox = new QVBoxLayout(this);
231    vbox->setMargin(0);
232    vbox->setSpacing(0);
233    vbox->addLayout(hbox);
234    vbox->addWidget(bgGrey);
235    setLayout(vbox);
[1babbd6ba3]236#endif // HANDHELD
237
[89e5214692]238#ifdef Q_OS_WINCE_WM
[9eb63a1598]239    // We need to react to SIP show/hide and resize the window appropriately
240    connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int)));
[89e5214692]241#endif // Q_OS_WINCE_WM
[9eb63a1598]242    connect(spinRandMin, SIGNAL(valueChanged(int)), SLOT(spinRandMinValueChanged(int)));
243    connect(buttonFont, SIGNAL(clicked()), SLOT(buttonFontClicked()));
[a09f31733a]244    connect(buttonTextColor, SIGNAL(clicked()), SLOT(buttonTextColorClicked()));
[c8ed26ddf1]245    connect(buttonSelectedColor, SIGNAL(clicked()), SLOT(buttonSelectedColorClicked()));
246    connect(buttonAlternateColor, SIGNAL(clicked()), SLOT(buttonAlternateColorClicked()));
247    connect(buttonBorderColor, SIGNAL(clicked()), SLOT(buttonBorderColorClicked()));
248//    connect(buttonBgColor, SIGNAL(clicked()), SLOT(buttonBgColorClicked()));
[9eb63a1598]249    setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
[9adbc413c7]250#if !defined(QT_NO_STATUSTIP) && !defined(HANDHELD)
[9eb63a1598]251    // Setting initial text of dialog hint label to own status tip text.
252    labelHint->setText(labelHint->statusTip());
[1babbd6ba3]253#endif // HANDHELD
254
[31694c8b58]255    settings = initSettings(this);
[9eb63a1598]256    settings->remove("SettingsReset");
[1babbd6ba3]257
[9eb63a1598]258    cbAutosize->setChecked(settings->value("Autosize", DEF_AUTOSIZE).toBool());
259    cbSaveLastUsed->setChecked(settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool());
260    cbUseNativeDialogs->setChecked(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool());
[b8a2a118c4]261#ifndef HANDHELD
[9eb63a1598]262    if (QtWin::isCompositionEnabled())
263        cbUseTranslucency->setChecked(settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool());
[b8a2a118c4]264#endif // HANDHELD
[1babbd6ba3]265#ifndef HANDHELD
[9eb63a1598]266    cbSaveState->setChecked(settings->value("SavePos", DEF_SAVEPOS).toBool());
[1babbd6ba3]267#endif // HANDHELD
[9eb63a1598]268    if (cbCheck4Updates != NULL) {
269        settings->beginGroup("Check4Updates");
270        cbCheck4Updates->setChecked(settings->value("Enabled", DEF_CHECK_FOR_UPDATES).toBool());
271        spinUpdateCheckInterval->setValue(settings->value("Interval", DEF_UPDATE_CHECK_INTERVAL).toInt());
272        settings->endGroup();
273        spinUpdateCheckInterval->setEnabled(cbCheck4Updates->isChecked());
274    }
275
276    settings->beginGroup("Task");
277    cbSymmetricMode->setChecked(settings->value("SymmetricMode", DEF_SYMMETRIC_MODE).toBool());
278    spinFractionalAccuracy->setValue(settings->value("FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
279    spinRandMin->setMaximum(MAX_RAND_VALUE);
280    spinRandMin->setValue(settings->value("RandMin",DEF_RAND_MIN).toInt());
281    spinRandMax->setMaximum(MAX_RAND_VALUE);
282    spinRandMax->setValue(settings->value("RandMax",DEF_RAND_MAX).toInt());
283    cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool());
284    settings->endGroup();
285
286    settings->beginGroup("Output");
[8f2427aaf0]287    cbGenerateGraph->setChecked(settings->value("GenerateGraph", DEF_GENERATE_GRAPH).toBool());
[20015b41e7]288
[6652ac66a4]289    spinGraphWidth->setEnabled(cbGenerateGraph->isChecked());
290    spinGraphWidth->setValue(settings->value("GraphWidth", DEF_GRAPH_WIDTH).toDouble());
[e26679937d]291
[356169a3d3]292#if !defined(NOSVG) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0))
[9eb63a1598]293    comboGraphImageFormat->addItem("svg");
[356169a3d3]294#endif
[9eb63a1598]295    // We create whitelist of formats, supported by the most popular web browsers according to
296    //  http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support
297    //  + TIFF format (there are plugins to support it).
[20015b41e7]298QStringList whitelist;
[9eb63a1598]299    whitelist << "bmp" << "jpeg" << "png" << "tiff" << "xbm";
300    foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
301        if (whitelist.contains(format))
302            comboGraphImageFormat->addItem(format);
303    }
304    comboGraphImageFormat->model()->sort(0);
305    comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(settings->value("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(), Qt::MatchFixedString));
306    if (comboGraphImageFormat->currentIndex() < 0)
307        comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(DEF_GRAPH_IMAGE_FORMAT, Qt::MatchFixedString));
[8f2427aaf0]308    labelGraphImageFormat->setEnabled(cbGenerateGraph->isChecked());
309    comboGraphImageFormat->setEnabled(cbGenerateGraph->isChecked());
[6652ac66a4]310
311#ifndef QT_NO_PRINTER
312    cbHQGraph->setEnabled(cbGenerateGraph->isChecked());
313    cbHQGraph->setChecked(settings->value("HQGraph", DEF_HQ_GRAPH).toBool());
314#endif
315
316    labelGraphWidth->setEnabled(cbGenerateGraph->isChecked());
[8f2427aaf0]317    cbEmbedGraphIntoHTML->setEnabled(cbGenerateGraph->isChecked());
[6652ac66a4]318    cbEmbedGraphIntoHTML->setChecked(settings->value("EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool());
[9eb63a1598]319
320    cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool());
321    cbCitiesLimit->setEnabled(cbShowMatrix->isChecked());
322    cbCitiesLimit->setChecked(settings->value("UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT && cbShowMatrix->isChecked()).toBool());
323    spinCitiesLimit->setEnabled(cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
324    spinCitiesLimit->setValue(settings->value("ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt());
[47c811cc09]325    settings->endGroup();
326    spinCitiesLimit->setMaximum(settings->value("Tweaks/MaxNumCities", MAX_NUM_CITIES).toInt());
327    settings->beginGroup("Output");
[9eb63a1598]328    cbScrollToEnd->setChecked(settings->value("ScrollToEnd", DEF_SCROLL_TO_END).toBool());
329
330    font = qvariant_cast<QFont>(settings->value("Font", QFont(DEF_FONT_FACE, DEF_FONT_SIZE)));
[a09f31733a]331    textColor = QColor(settings->value("Colors/Text", DEF_TEXT_COLOR).toString());
332    selColor = QColor(settings->value("Colors/Selected", DEF_SELECTED_COLOR).toString());
333    altColor = QColor(settings->value("Colors/Alternate", DEF_ALTERNATE_COLOR).toString());
[c8ed26ddf1]334    borderColor = QColor(settings->value("Colors/TableBorder", DEF_TABLE_COLOR).toString());
335//    bgColor = QColor(settings->value("Colors/Background", DEF_BACKGROUND_COLOR).toString());
[9eb63a1598]336    settings->endGroup();
[1babbd6ba3]337
[a09f31733a]338    QFont f = font;
339    f.setPointSize(labelFontExample->font().pointSize());
340    labelFontExample->setFont(f);
341    labelFontExample->setText(font.family());
342
[c8ed26ddf1]343    setBgColor(boxTextColor, textColor);
344    setBgColor(boxSelectedColor, selColor);
345    setBgColor(boxAlternateColor, altColor);
346    setBgColor(boxBorderColor, borderColor);
347//    setBgColor(boxBgColor, bgColor);
[a09f31733a]348
[e51c78af27]349#ifdef HANDHELD
[9eb63a1598]350    setWindowState(Qt::WindowMaximized);
[e51c78af27]351#else
[9eb63a1598]352    adjustSize();
[89e5214692]353#endif // Q_OS_WINCE_WM
[1babbd6ba3]354}
355
356/*!
357 * \brief Indicates whether or not the font color has been changed.
358 * \return \c true if font color changed, otherwise \c false.
359 */
360bool SettingsDialog::colorChanged() const
361{
[a09f31733a]362    return _colorChanged;
[1babbd6ba3]363}
364
365/*!
366 * \brief Indicates whether or not the font properties have been changed.
367 * \return \c true if font properties changed, otherwise \c false.
368 */
369bool SettingsDialog::fontChanged() const
370{
[a09f31733a]371    return _fontChanged;
[1babbd6ba3]372}
373
374/*!
375 * \brief Indicates whether and how the translucency setting was changed
376 * \retval -1 the translucency was \em disabled.
[8f2427aaf0]377 * \retval  0 the translucency <em>didn't change</em>.
[1babbd6ba3]378 * \retval  1 the translucency was \em enabled.
379 */
380qint8 SettingsDialog::translucencyChanged() const
381{
[9eb63a1598]382    return _translucency;
[1babbd6ba3]383}
384
385/* Privates **********************************************************/
386
387void SettingsDialog::accept()
388{
[9eb63a1598]389    if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
[47c811cc09]390        if (QMessageBox::question(this, tr("Settings Reset"),
391                                  tr("Do you really want to <b>reset all application settings"
392                                     " to their defaults</b>?<br>"
393                                     "Please, note that \"Tweaks\" section won't be reset."),
394                                  QMessageBox::RestoreDefaults | QMessageBox::Cancel)
395                == QMessageBox::RestoreDefaults) {
[a09f31733a]396            _fontChanged = (font != QFont(DEF_FONT_FACE, DEF_FONT_SIZE));
397            _colorChanged = (textColor != DEF_TEXT_COLOR);
[47c811cc09]398            // Saving Tweaks section as we don't reset it
399            settings->beginGroup("Tweaks");
400            QHash<QString, QVariant> values;
401            foreach (const QString &key, settings->childKeys()) {
402                values.insert(key, settings->value(key));
403            }
404            settings->endGroup();
[9eb63a1598]405            settings->remove("");
406            settings->setValue("SettingsReset", true);
[47c811cc09]407            if (!values.empty()) {
408                settings->beginGroup("Tweaks");
409                foreach (const QString &key, values.keys()) {
410                    settings->setValue(key, values.value(key));
411                }
412                settings->endGroup();
413            }
[9eb63a1598]414            QDialog::accept();
415            QMessageBox::information(this->parentWidget(), tr("Settings Reset"), tr("All settings where successfully reset to their defaults.\nIt is recommended to restart the application now."));
416            return;
417        } else
418            return;
419    }
420    settings->setValue("Autosize", cbAutosize->isChecked());
421    settings->setValue("SaveLastUsed", cbSaveLastUsed->isChecked());
422    settings->setValue("UseNativeDialogs", cbUseNativeDialogs->isChecked());
[b8a2a118c4]423#ifndef HANDHELD
[9eb63a1598]424    if (QtWin::isCompositionEnabled()) {
[1babbd6ba3]425bool old = settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool();
[9eb63a1598]426        if ((!old && cbUseTranslucency->isChecked()) || (old && !cbUseTranslucency->isChecked())) {
427            _translucency = old ? -1 : 1;
428        } else
429            _translucency = 0;
430        settings->setValue("UseTranslucency", cbUseTranslucency->isChecked());
431    }
432    settings->setValue("SavePos", cbSaveState->isChecked());
[ac76a6a753]433#endif // HANDHELD
[9eb63a1598]434    if (cbCheck4Updates != NULL) {
435        settings->beginGroup("Check4Updates");
436        settings->setValue("Enabled", cbCheck4Updates->isChecked());
437        if (cbCheck4Updates->isChecked())
438            settings->setValue("Interval", spinUpdateCheckInterval->value());
439        settings->endGroup();
440    }
441
442    settings->beginGroup("Task");
443    settings->setValue("SymmetricMode", cbSymmetricMode->isChecked());
444    settings->setValue("FractionalAccuracy", spinFractionalAccuracy->value());
445    settings->setValue("RandMin", spinRandMin->value());
446    settings->setValue("RandMax", spinRandMax->value());
447    settings->setValue("FractionalRandom", cbFractionalRandom->isChecked());
448    settings->endGroup();
449
450    settings->beginGroup("Output");
[8f2427aaf0]451    settings->setValue("GenerateGraph", cbGenerateGraph->isChecked());
452    if (cbGenerateGraph->isChecked()) {
[6652ac66a4]453        settings->setValue("GraphWidth", spinGraphWidth->value());
[8f2427aaf0]454        if (cbGenerateGraph->isChecked()) {
455            if (comboGraphImageFormat->currentIndex() >= 0)
456                settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText());
457            else
458                settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT);
459        }
[6652ac66a4]460#ifndef QT_NO_PRINTER
461        settings->setValue("HQGraph", cbHQGraph->isChecked());
462#endif
[8f2427aaf0]463        settings->setValue("EmbedGraphIntoHTML", cbEmbedGraphIntoHTML->isChecked());
[9eb63a1598]464    }
465    settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
466    settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
467    if (cbCitiesLimit->isChecked())
468        settings->setValue("ShowMatrixLimit", spinCitiesLimit->value());
469    settings->setValue("ScrollToEnd", cbScrollToEnd->isChecked());
[a09f31733a]470    if (_fontChanged)
[9eb63a1598]471        settings->setValue("Font", font);
[c8ed26ddf1]472    if (_colorChanged) {
473        settings->beginGroup("Colors");
474        if (textColor != DEF_TEXT_COLOR)
475            settings->setValue("Text", textColor.name());
476        else
477            settings->remove("Text");
478        if (selColor != QColor(DEF_SELECTED_COLOR))
479            settings->setValue("Selected", selColor.name());
480        else
481            settings->remove("Selected");
482        if (altColor != DEF_ALTERNATE_COLOR)
483            settings->setValue("Alternate",altColor.name());
484        else
485            settings->remove("Alternate");
486        if (borderColor != DEF_TABLE_COLOR)
487            settings->setValue("TableBorder", borderColor.name());
488        else
489            settings->remove("TableColor");
490//        if (bgColor != DEF_BACKGROUND_COLOR)
491//            settings->setValue("Background", bgColor.name());
492//        else
493//            settings->remove("Background");
494        settings->endGroup();
495    }
[9eb63a1598]496    settings->endGroup();
497    QDialog::accept();
[1babbd6ba3]498}
499
[c8ed26ddf1]500void SettingsDialog::pickColor(QColor &where)
[1babbd6ba3]501{
[c8ed26ddf1]502    QColor color = QColorDialog::getColor(where, this);
503    if (color.isValid() && (where != color)) {
504        where = color;
[a09f31733a]505        _colorChanged = true;
[9eb63a1598]506    }
[1babbd6ba3]507}
508
[c8ed26ddf1]509void SettingsDialog::setBgColor(QWidget *widget, const QColor &color)
510{
511    QPalette p = widget->palette();
512    p.setColor(QPalette::Window, color);
513    widget->setPalette(p);
514}
515
516void SettingsDialog::buttonTextColorClicked()
517{
518    pickColor(textColor);
519    setBgColor(boxTextColor, textColor);
520}
521
522void SettingsDialog::buttonSelectedColorClicked()
523{
524    pickColor(selColor);
525    setBgColor(boxSelectedColor, selColor);
526}
527
528void SettingsDialog::buttonAlternateColorClicked()
529{
530    pickColor(altColor);
531    setBgColor(boxAlternateColor, altColor);
532}
533
534void SettingsDialog::buttonBorderColorClicked()
535{
536    pickColor(borderColor);
537    setBgColor(boxBorderColor, borderColor);
538}
539
540//void SettingsDialog::buttonBgColorClicked()
541//{
542//    pickColor(bgColor);
543//    setBgColor(boxBgColor, bgColor);
544//}
545
[1babbd6ba3]546void SettingsDialog::buttonFontClicked()
547{
[7ed8b57eea]548    QFont newFont;
549#ifdef Q_OS_BLACKBERRY
550    QFontDialog fd(font, this);
551    fd.setWindowState(Qt::WindowMaximized);
552    if ((fd.exec() != QDialog::Accepted) || (fd.selectedFont() == font))
553        return;
554    newFont = fd.selectedFont();
555#else
556    bool ok;
557    newFont = QFontDialog::getFont(&ok, font, this);
558    if (!ok || (font == newFont))
559        return;
560#endif
561    font = newFont;
562    QFont f = font;
563    f.setPointSize(labelFontExample->font().pointSize());
564    labelFontExample->setFont(f);
565    labelFontExample->setText(font.family());
566    _fontChanged = true;
[1babbd6ba3]567}
568
[89e5214692]569#ifdef Q_OS_WINCE_WM
[1babbd6ba3]570void SettingsDialog::desktopResized(int screen)
571{
[9eb63a1598]572    if (screen != 0)
573        return;
[1babbd6ba3]574
575QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
[9eb63a1598]576    if (currentGeometry != availableGeometry) {
577        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
578        /*!
579         * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
580         *  If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the
581         *  window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile?
582         */
583        if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) {
584            setWindowState(windowState() | Qt::WindowMaximized);
585        } else {
586            if (windowState() & Qt::WindowMaximized)
587                setWindowState(windowState() ^ Qt::WindowMaximized);
588            setGeometry(availableGeometry);
589        }
590        currentGeometry = availableGeometry;
591        QApplication::restoreOverrideCursor();
592    }
[1babbd6ba3]593}
594
595void SettingsDialog::showEvent(QShowEvent *ev)
596{
[9eb63a1598]597    desktopResized(0);
[1babbd6ba3]598
[9eb63a1598]599    QWidget::showEvent(ev);
[1babbd6ba3]600}
[89e5214692]601#endif // Q_OS_WINCE_WM
[1babbd6ba3]602
603void SettingsDialog::spinRandMinValueChanged(int val) {
[9eb63a1598]604    spinRandMax->setMinimum(val);
[1babbd6ba3]605}
606
[9adbc413c7]607#if !defined(QT_NO_STATUSTIP) && !defined(HANDHELD)
[1babbd6ba3]608bool SettingsDialog::event(QEvent *ev)
609{
[9eb63a1598]610    // Checking for StatusTip event and if tip text is not empty string
611    // setting it as text of the dialog hint label. Otherwise, setting
612    // dialog hint label text to own status tip text.
613    if (ev->type() == QEvent::StatusTip) {
[1babbd6ba3]614QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
[9eb63a1598]615        if (tip.length() != 0)
616            labelHint->setText(tip);
617        else
618            labelHint->setText(labelHint->statusTip());
619        return true;
620    } else
621        return QDialog::event(ev);
[1babbd6ba3]622}
623#endif // HANDHELD
Note: See TracBrowser for help on using the repository browser.