source: tspsg/src/settingsdialog.cpp @ 332a9399dd

appveyorimgbotreadme
Last change on this file since 332a9399dd was 0a4e16b182, checked in by Oleksii Serdiuk, 13 years ago

Added a border to tables in the solution output. Looks more readable
with long numbers, now. The border color can be controlled through
Output/Colors/TableBorder? setting in tspsg.ini. It is in #RRGGBB format.

  • Property mode set to 100644
File size: 19.2 KB
RevLine 
[1babbd6ba3]1/*
2 *  TSPSG: TSP Solver and Generator
[bfe1e5e2ea]3 *  Copyright (C) 2007-2011 Lёppa <contacts[at]oleksii[dot]name>
[1babbd6ba3]4 *
5 *  $Id$
6 *  $URL$
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
12 *  the Free Software Foundation, either version 3 of the License, or
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
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 */
32SettingsDialog::SettingsDialog(QWidget *parent)
[9eb63a1598]33    : QDialog(parent), _newFont(false), _newColor(false), _translucency(0)
[1babbd6ba3]34{
[9eb63a1598]35    setupUi(this);
[1babbd6ba3]36
[9eb63a1598]37    setWindowIcon(GET_ICON("preferences-system"));
[3cadf24d00]38
[9eb63a1598]39    buttonBox->button(QDialogButtonBox::Ok)->setIcon(GET_ICON("dialog-ok"));
[9adbc413c7]40#ifndef QT_NO_STATUSTIP
[9eb63a1598]41    buttonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Save new preferences"));
[9adbc413c7]42#endif
[9eb63a1598]43    buttonBox->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor));
44    buttonBox->button(QDialogButtonBox::Cancel)->setIcon(GET_ICON("dialog-cancel"));
[9adbc413c7]45#ifndef QT_NO_STATUSTIP
[9eb63a1598]46    buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Close without saving preferences"));
[9adbc413c7]47#endif
[9eb63a1598]48    buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor));
[1babbd6ba3]49
[9eb63a1598]50    buttonColor->setIcon(GET_ICON("format-text-color"));
51    buttonFont->setIcon(GET_ICON("preferences-desktop-font"));
52    buttonHelp->setIcon(GET_ICON("help-hint"));
[3cadf24d00]53
[317ba0432e]54QPalette p = bgWhite->palette();
[9eb63a1598]55    p.setColor(QPalette::Window, p.color(QPalette::Base));
56    bgWhite->setPalette(p);
[317ba0432e]57
[9eb63a1598]58    p = lineHorizontal->palette();
59    p.setColor(QPalette::Window, p.color(QPalette::Text));
60    lineHorizontal->setPalette(p);
[317ba0432e]61
[0007f69c46]62// Layout helpers
63QBoxLayout *box;
64QHBoxLayout *hbox;
[e26679937d]65#ifndef QT_NO_PRINTER
[9eb63a1598]66    cbHQGraph = new QCheckBox(bgWhite);
67    cbHQGraph->setObjectName("cbHQGraph");
[e26679937d]68#ifndef QT_NO_STATUSTIP
[9eb63a1598]69    cbHQGraph->setStatusTip(tr("Higher quality graph looks much better when printing but uglier on the screen"));
[e26679937d]70#endif // QT_NO_STATUSTIP
[9eb63a1598]71    cbHQGraph->setText(tr("Draw solution graph in higher quality"));
72    cbHQGraph->setCursor(QCursor(Qt::PointingHandCursor));
73
74    box = static_cast<QBoxLayout *>(tabOutput->layout());
75    hbox = new QHBoxLayout();
76    hbox->addSpacing(10);
77    hbox->addWidget(cbHQGraph);
[8f2427aaf0]78    box->insertLayout(box->indexOf(cbGenerateGraph) + 2, hbox);
79    connect(cbGenerateGraph, SIGNAL(toggled(bool)), cbHQGraph, SLOT(setEnabled(bool)));
[e26679937d]80#endif
81
[9eb63a1598]82    if (hasUpdater()) {
83        cbCheck4Updates = new QCheckBox(bgWhite);
84        cbCheck4Updates->setObjectName("cbCheck4Updates");
[f5c945d7ac]85#ifndef QT_NO_STATUSTIP
[9eb63a1598]86        cbCheck4Updates->setStatusTip(tr("Automatically check for updates at the given interval"));
[f5c945d7ac]87#endif // QT_NO_STATUSTIP
[9eb63a1598]88        cbCheck4Updates->setText(tr("Check for updates every"));
89        cbCheck4Updates->setCursor(QCursor(Qt::PointingHandCursor));
[f5c945d7ac]90
[9eb63a1598]91        spinUpdateCheckInterval = new QSpinBox(bgWhite);
92        spinUpdateCheckInterval->setObjectName("spinUpdateCheckInterval");
[f5c945d7ac]93#ifndef QT_NO_STATUSTIP
[9eb63a1598]94        spinUpdateCheckInterval->setStatusTip(tr("Minimal interval at which to check for updates"));
[f5c945d7ac]95#endif // QT_NO_STATUSTIP
[9eb63a1598]96        spinUpdateCheckInterval->setSuffix(tr(" days", "Don't forget a space at the beginning!"));
97        spinUpdateCheckInterval->setRange(1, 365);
98        spinUpdateCheckInterval->setCursor(QCursor(Qt::PointingHandCursor));
99
100        connect(cbCheck4Updates, SIGNAL(toggled(bool)), spinUpdateCheckInterval, SLOT(setEnabled(bool)));
101
102        box = static_cast<QBoxLayout *>(tabGeneral->layout());
103        hbox = new QHBoxLayout();
104        hbox->setSpacing(0);
105        hbox->addWidget(cbCheck4Updates);
106        hbox->addWidget(spinUpdateCheckInterval);
107        hbox->addStretch();
108        box->insertLayout(box->indexOf(cbUseNativeDialogs) + 1, hbox);
109    } else
110        cbCheck4Updates = NULL;
[f5c945d7ac]111
[1babbd6ba3]112#ifdef HANDHELD
113QVBoxLayout *vbox1; // Layout helper
114
[9eb63a1598]115    // On screens with small height when SIP is shown and the window is resized
116    // there is not enought space for all elements.
117    // So we show the scrollbars to be able to access them.
[1babbd6ba3]118QScrollArea *scrollArea = new QScrollArea(this);
[9eb63a1598]119    scrollArea->setFrameShape(QFrame::NoFrame);
120    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
121    scrollArea->setWidgetResizable(true);
122    scrollArea->setWidget(bgWhite);
[1babbd6ba3]123
[9eb63a1598]124    bgWhite->layout()->setMargin(0);
[1babbd6ba3]125
[9eb63a1598]126    // Central layout
127    vbox1 = new QVBoxLayout(this);
128    vbox1->setMargin(0);
129    vbox1->setSpacing(0);
130    vbox1->addWidget(scrollArea);
131    vbox1->addWidget(bgGrey);
132    setLayout(vbox1);
[1babbd6ba3]133#else // HANDHELD
[0007f69c46]134QVBoxLayout *vbox; // Layout helper
[1babbd6ba3]135
[b8a2a118c4]136#ifndef HANDHELD
[9eb63a1598]137    if (QtWin::isCompositionEnabled()) {
138        cbUseTranslucency = new QCheckBox(bgWhite);
139        cbUseTranslucency->setObjectName("cbUseTranslucency");
[1babbd6ba3]140#ifndef QT_NO_STATUSTIP
[8f2427aaf0]141        cbUseTranslucency->setStatusTip(tr("Make Main Window background translucent"));
[1babbd6ba3]142#endif // QT_NO_STATUSTIP
[9eb63a1598]143        cbUseTranslucency->setText(tr("Use translucency effects"));
144        cbUseTranslucency->setCursor(QCursor(Qt::PointingHandCursor));
145    }
[b8a2a118c4]146#endif // HANDHELD
[1babbd6ba3]147
[9eb63a1598]148    cbSaveState = new QCheckBox(bgWhite);
149    cbSaveState->setObjectName("cbSaveState");
[1babbd6ba3]150#ifndef QT_NO_STATUSTIP
[9eb63a1598]151    cbSaveState->setStatusTip(tr("Restore main window state and position on application restart"));
[1babbd6ba3]152#endif // QT_NO_STATUSTIP
[9eb63a1598]153    cbSaveState->setText(tr("Save main window state and position"));
154    cbSaveState->setCursor(QCursor(Qt::PointingHandCursor));
155
156    imgIcon = new QLabel(this);
157    imgIcon->setObjectName("imgIcon");
158    imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
159    imgIcon->setFrameShape(QFrame::NoFrame);
160    imgIcon->setPixmap(GET_ICON("preferences-system").pixmap(128, 128));
161    imgIcon->setStyleSheet("background-color: #0080C0; padding-top: 11px;");
162    imgIcon->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
163    imgIcon->setMinimumWidth(150);
164
165    labelHint = new QLabel(bgGrey);
166    labelHint->setObjectName("labelHint");
167    labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
[8f2427aaf0]168    labelHint->setMinimumSize(QSize(250, 28));
169    labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX, 28));
[9eb63a1598]170    labelHint->setTextFormat(Qt::PlainText);
[1babbd6ba3]171//      labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
[9eb63a1598]172    labelHint->setWordWrap(true);
[1babbd6ba3]173#ifndef QT_NO_STATUSTIP
[9eb63a1598]174    labelHint->setStatusTip(tr("Hover mouse pointer over dialog elements to get additional help"));
[1babbd6ba3]175#endif // QT_NO_STATUSTIP
176
[9eb63a1598]177    lineVertical = new QFrame(this);
178    lineVertical->setObjectName("lineVertical");
179    lineVertical->setFrameShadow(QFrame::Plain);
180    lineVertical->setFrameShape(QFrame::VLine);
181    lineVertical->setLineWidth(2);
[1babbd6ba3]182
[9eb63a1598]183    // Top line
184    hbox = new QHBoxLayout();
185    hbox->addWidget(imgIcon);
186    hbox->addWidget(lineVertical);
187    hbox->addWidget(bgWhite);
[e26679937d]188
[9eb63a1598]189    box = static_cast<QBoxLayout *>(tabGeneral->layout());
190    box->insertWidget(box->indexOf(cbUseNativeDialogs) + 1, cbSaveState);
[b8a2a118c4]191#ifndef HANDHELD
[9eb63a1598]192    if (QtWin::isCompositionEnabled())
193        box->insertWidget(box->indexOf(cbUseNativeDialogs) + 1, cbUseTranslucency);
[b8a2a118c4]194#endif // HANDHELD
[1babbd6ba3]195
[9eb63a1598]196    // Inserting label for hints to the bottom part (with grey bg)
197    buttons->insertWidget(buttons->indexOf(buttonHelp) + 1, labelHint, 1);
[1babbd6ba3]198
[9eb63a1598]199    // Central layout
200    vbox = new QVBoxLayout(this);
201    vbox->setMargin(0);
202    vbox->setSpacing(0);
203    vbox->addLayout(hbox);
204    vbox->addWidget(bgGrey);
205    setLayout(vbox);
[1babbd6ba3]206#endif // HANDHELD
207
[97e90f9be6]208#ifdef Q_WS_WINCE_WM
[9eb63a1598]209    // We need to react to SIP show/hide and resize the window appropriately
210    connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int)));
[97e90f9be6]211#endif // Q_WS_WINCE_WM
[9eb63a1598]212    connect(spinRandMin, SIGNAL(valueChanged(int)), SLOT(spinRandMinValueChanged(int)));
213    connect(buttonFont, SIGNAL(clicked()), SLOT(buttonFontClicked()));
214    connect(buttonColor, SIGNAL(clicked()), SLOT(buttonColorClicked()));
215    setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
[9adbc413c7]216#if !defined(QT_NO_STATUSTIP) && !defined(HANDHELD)
[9eb63a1598]217    // Setting initial text of dialog hint label to own status tip text.
218    labelHint->setText(labelHint->statusTip());
[1babbd6ba3]219#endif // HANDHELD
220
[9eb63a1598]221    settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
222    settings->remove("SettingsReset");
[1babbd6ba3]223
[9eb63a1598]224    cbAutosize->setChecked(settings->value("Autosize", DEF_AUTOSIZE).toBool());
225    cbSaveLastUsed->setChecked(settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool());
226    cbUseNativeDialogs->setChecked(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool());
[b8a2a118c4]227#ifndef HANDHELD
[9eb63a1598]228    if (QtWin::isCompositionEnabled())
229        cbUseTranslucency->setChecked(settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool());
[b8a2a118c4]230#endif // HANDHELD
[1babbd6ba3]231#ifndef HANDHELD
[9eb63a1598]232    cbSaveState->setChecked(settings->value("SavePos", DEF_SAVEPOS).toBool());
[1babbd6ba3]233#endif // HANDHELD
[9eb63a1598]234    if (cbCheck4Updates != NULL) {
235        settings->beginGroup("Check4Updates");
236        cbCheck4Updates->setChecked(settings->value("Enabled", DEF_CHECK_FOR_UPDATES).toBool());
237        spinUpdateCheckInterval->setValue(settings->value("Interval", DEF_UPDATE_CHECK_INTERVAL).toInt());
238        settings->endGroup();
239        spinUpdateCheckInterval->setEnabled(cbCheck4Updates->isChecked());
240    }
241
242    settings->beginGroup("Task");
243    cbSymmetricMode->setChecked(settings->value("SymmetricMode", DEF_SYMMETRIC_MODE).toBool());
244    spinFractionalAccuracy->setValue(settings->value("FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
245    spinRandMin->setMaximum(MAX_RAND_VALUE);
246    spinRandMin->setValue(settings->value("RandMin",DEF_RAND_MIN).toInt());
247    spinRandMax->setMaximum(MAX_RAND_VALUE);
248    spinRandMax->setValue(settings->value("RandMax",DEF_RAND_MAX).toInt());
249    cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool());
250    settings->endGroup();
251
252    settings->beginGroup("Output");
[8f2427aaf0]253    cbGenerateGraph->setChecked(settings->value("GenerateGraph", DEF_GENERATE_GRAPH).toBool());
[20015b41e7]254
[e26679937d]255#ifndef QT_NO_PRINTER
[8f2427aaf0]256    cbHQGraph->setEnabled(cbGenerateGraph->isChecked());
257    cbHQGraph->setChecked(settings->value("HQGraph", DEF_HQ_GRAPH).toBool());
[e26679937d]258#endif
259
[20015b41e7]260#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
[9eb63a1598]261    comboGraphImageFormat->addItem("svg");
[20015b41e7]262#endif // NOSVG && QT_VERSION >= 0x040500
[9eb63a1598]263    // We create whitelist of formats, supported by the most popular web browsers according to
264    //  http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support
265    //  + TIFF format (there are plugins to support it).
[20015b41e7]266QStringList whitelist;
[9eb63a1598]267    whitelist << "bmp" << "jpeg" << "png" << "tiff" << "xbm";
268    foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
269        if (whitelist.contains(format))
270            comboGraphImageFormat->addItem(format);
271    }
272    comboGraphImageFormat->model()->sort(0);
273    comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(settings->value("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(), Qt::MatchFixedString));
274    if (comboGraphImageFormat->currentIndex() < 0)
275        comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(DEF_GRAPH_IMAGE_FORMAT, Qt::MatchFixedString));
[8f2427aaf0]276    labelGraphImageFormat->setEnabled(cbGenerateGraph->isChecked());
277    comboGraphImageFormat->setEnabled(cbGenerateGraph->isChecked());
278    cbEmbedGraphIntoHTML->setChecked(settings->value("EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool());
279    cbEmbedGraphIntoHTML->setEnabled(cbGenerateGraph->isChecked());
[9eb63a1598]280
281    cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool());
282    cbCitiesLimit->setEnabled(cbShowMatrix->isChecked());
283    cbCitiesLimit->setChecked(settings->value("UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT && cbShowMatrix->isChecked()).toBool());
284    spinCitiesLimit->setEnabled(cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
285    spinCitiesLimit->setValue(settings->value("ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt());
286    spinCitiesLimit->setMaximum(MAX_NUM_CITIES);
287    cbScrollToEnd->setChecked(settings->value("ScrollToEnd", DEF_SCROLL_TO_END).toBool());
288
289    font = qvariant_cast<QFont>(settings->value("Font", QFont(DEF_FONT_FACE, DEF_FONT_SIZE)));
[0a4e16b182]290    color = QColor(settings->value("Colors/Text", DEF_TEXT_COLOR).toString());
[9eb63a1598]291    settings->endGroup();
[1babbd6ba3]292
[e51c78af27]293#ifdef HANDHELD
[9eb63a1598]294    setWindowState(Qt::WindowMaximized);
[e51c78af27]295#else
[9eb63a1598]296    adjustSize();
[97e90f9be6]297#endif // Q_WS_WINCE_WM
[1babbd6ba3]298}
299
300/*!
301 * \brief Indicates whether or not the font color has been changed.
302 * \return \c true if font color changed, otherwise \c false.
303 */
304bool SettingsDialog::colorChanged() const
305{
[9eb63a1598]306    return _newColor;
[1babbd6ba3]307}
308
309/*!
310 * \brief Indicates whether or not the font properties have been changed.
311 * \return \c true if font properties changed, otherwise \c false.
312 */
313bool SettingsDialog::fontChanged() const
314{
[9eb63a1598]315    return _newFont;
[1babbd6ba3]316}
317
318/*!
319 * \brief Indicates whether and how the translucency setting was changed
320 * \retval -1 the translucency was \em disabled.
[8f2427aaf0]321 * \retval  0 the translucency <em>didn't change</em>.
[1babbd6ba3]322 * \retval  1 the translucency was \em enabled.
323 */
324qint8 SettingsDialog::translucencyChanged() const
325{
[9eb63a1598]326    return _translucency;
[1babbd6ba3]327}
328
329/* Privates **********************************************************/
330
331void SettingsDialog::accept()
332{
[9eb63a1598]333    if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
334        if (QMessageBox::question(this, tr("Settings Reset"), tr("Do you really want to <b>reset all application settings to their defaults</b>?"), QMessageBox::RestoreDefaults | QMessageBox::Cancel) == QMessageBox::RestoreDefaults) {
335            _newFont = (font != QFont(DEF_FONT_FACE, DEF_FONT_SIZE));
336            _newColor = (color != DEF_TEXT_COLOR);
337            settings->remove("");
338            settings->setValue("SettingsReset", true);
339            QDialog::accept();
340            QMessageBox::information(this->parentWidget(), tr("Settings Reset"), tr("All settings where successfully reset to their defaults.\nIt is recommended to restart the application now."));
341            return;
342        } else
343            return;
344    }
345    settings->setValue("Autosize", cbAutosize->isChecked());
346    settings->setValue("SaveLastUsed", cbSaveLastUsed->isChecked());
347    settings->setValue("UseNativeDialogs", cbUseNativeDialogs->isChecked());
[b8a2a118c4]348#ifndef HANDHELD
[9eb63a1598]349    if (QtWin::isCompositionEnabled()) {
[1babbd6ba3]350bool old = settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool();
[9eb63a1598]351        if ((!old && cbUseTranslucency->isChecked()) || (old && !cbUseTranslucency->isChecked())) {
352            _translucency = old ? -1 : 1;
353        } else
354            _translucency = 0;
355        settings->setValue("UseTranslucency", cbUseTranslucency->isChecked());
356    }
357    settings->setValue("SavePos", cbSaveState->isChecked());
[ac76a6a753]358#endif // HANDHELD
[9eb63a1598]359    if (cbCheck4Updates != NULL) {
360        settings->beginGroup("Check4Updates");
361        settings->setValue("Enabled", cbCheck4Updates->isChecked());
362        if (cbCheck4Updates->isChecked())
363            settings->setValue("Interval", spinUpdateCheckInterval->value());
364        settings->endGroup();
365    }
366
367    settings->beginGroup("Task");
368    settings->setValue("SymmetricMode", cbSymmetricMode->isChecked());
369    settings->setValue("FractionalAccuracy", spinFractionalAccuracy->value());
370    settings->setValue("RandMin", spinRandMin->value());
371    settings->setValue("RandMax", spinRandMax->value());
372    settings->setValue("FractionalRandom", cbFractionalRandom->isChecked());
373    settings->endGroup();
374
375    settings->beginGroup("Output");
[8f2427aaf0]376    settings->setValue("GenerateGraph", cbGenerateGraph->isChecked());
377    if (cbGenerateGraph->isChecked()) {
[e26679937d]378#ifndef QT_NO_PRINTER
[8f2427aaf0]379        settings->setValue("HQGraph", cbHQGraph->isChecked());
[e26679937d]380#endif
[8f2427aaf0]381        if (cbGenerateGraph->isChecked()) {
382            if (comboGraphImageFormat->currentIndex() >= 0)
383                settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText());
384            else
385                settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT);
386        }
387        settings->setValue("EmbedGraphIntoHTML", cbEmbedGraphIntoHTML->isChecked());
[9eb63a1598]388    }
389    settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
390    settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
391    if (cbCitiesLimit->isChecked())
392        settings->setValue("ShowMatrixLimit", spinCitiesLimit->value());
393    settings->setValue("ScrollToEnd", cbScrollToEnd->isChecked());
394    if (_newFont)
395        settings->setValue("Font", font);
396    if (_newColor)
[0a4e16b182]397        settings->setValue("Colors/Text", color.name());
[9eb63a1598]398    settings->endGroup();
399    QDialog::accept();
[1babbd6ba3]400}
401
402void SettingsDialog::buttonColorClicked()
403{
404QColor color = QColorDialog::getColor(this->color,this);
[9eb63a1598]405    if (color.isValid() && (this->color != color)) {
406        this->color = color;
407        _newColor = true;
408    }
[1babbd6ba3]409}
410
411void SettingsDialog::buttonFontClicked()
412{
413bool ok;
414QFont font = QFontDialog::getFont(&ok,this->font,this);
[9eb63a1598]415    if (ok && (this->font != font)) {
416        this->font = font;
417        _newFont = true;
418    }
[1babbd6ba3]419}
420
[97e90f9be6]421#ifdef Q_WS_WINCE_WM
[1babbd6ba3]422void SettingsDialog::desktopResized(int screen)
423{
[9eb63a1598]424    if (screen != 0)
425        return;
[1babbd6ba3]426
427QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
[9eb63a1598]428    if (currentGeometry != availableGeometry) {
429        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
430        /*!
431         * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
432         *  If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the
433         *  window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile?
434         */
435        if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) {
436            setWindowState(windowState() | Qt::WindowMaximized);
437        } else {
438            if (windowState() & Qt::WindowMaximized)
439                setWindowState(windowState() ^ Qt::WindowMaximized);
440            setGeometry(availableGeometry);
441        }
442        currentGeometry = availableGeometry;
443        QApplication::restoreOverrideCursor();
444    }
[1babbd6ba3]445}
446
447void SettingsDialog::showEvent(QShowEvent *ev)
448{
[9eb63a1598]449    desktopResized(0);
[1babbd6ba3]450
[9eb63a1598]451    QWidget::showEvent(ev);
[1babbd6ba3]452}
[97e90f9be6]453#endif // Q_WS_WINCE_WM
[1babbd6ba3]454
455void SettingsDialog::spinRandMinValueChanged(int val) {
[9eb63a1598]456    spinRandMax->setMinimum(val);
[1babbd6ba3]457}
458
[9adbc413c7]459#if !defined(QT_NO_STATUSTIP) && !defined(HANDHELD)
[1babbd6ba3]460bool SettingsDialog::event(QEvent *ev)
461{
[9eb63a1598]462    // Checking for StatusTip event and if tip text is not empty string
463    // setting it as text of the dialog hint label. Otherwise, setting
464    // dialog hint label text to own status tip text.
465    if (ev->type() == QEvent::StatusTip) {
[1babbd6ba3]466QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
[9eb63a1598]467        if (tip.length() != 0)
468            labelHint->setText(tip);
469        else
470            labelHint->setText(labelHint->statusTip());
471        return true;
472    } else
473        return QDialog::event(ev);
[1babbd6ba3]474}
475#endif // HANDHELD
Note: See TracBrowser for help on using the repository browser.