source: tspsg/src/settingsdialog.cpp @ 243b53b608

appveyorimgbotreadme
Last change on this file since 243b53b608 was 2940c14782, checked in by Oleksii Serdiuk, 11 years ago

Relicensed TSP Solver and Generator under GPLv2 license.

Due to potential conflicts between GPLv3 and app stores.

  • Property mode set to 100644
File size: 24.1 KB
Line 
1/*
2 *  TSPSG: TSP Solver and Generator
3 *  Copyright (C) 2007-2013 Oleksii Serdiuk <contacts[at]oleksii[dot]name>
4 *
5 *  $Id: $Format:%h %ai %an$ $
6 *  $URL: http://tspsg.info/ $
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 2 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#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
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)
52    : QDialog(parent), _fontChanged(false), _colorChanged(false), _translucency(0)
53{
54    setupUi(this);
55
56    setWindowIcon(GET_ICON("preferences-system"));
57
58    buttonBox->button(QDialogButtonBox::Ok)->setIcon(GET_ICON("dialog-ok"));
59#ifndef QT_NO_STATUSTIP
60    buttonBox->button(QDialogButtonBox::Ok)->setStatusTip(tr("Save new preferences"));
61#endif
62    buttonBox->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor));
63    buttonBox->button(QDialogButtonBox::Cancel)->setIcon(GET_ICON("dialog-cancel"));
64#ifndef QT_NO_STATUSTIP
65    buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Close without saving preferences"));
66#endif
67    buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor));
68
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"));
73//    buttonBgColor->setIcon(GET_ICON("format-fill-color"));
74    buttonFont->setIcon(GET_ICON("preferences-desktop-font"));
75    buttonHelp->setIcon(GET_ICON("help-hint"));
76
77QPalette p = bgWhite->palette();
78    p.setColor(QPalette::Window, p.color(QPalette::Base));
79    bgWhite->setPalette(p);
80
81    p = lineHorizontal->palette();
82    p.setColor(QPalette::Window, p.color(QPalette::Text));
83    lineHorizontal->setPalette(p);
84
85// Layout helpers
86QBoxLayout *box;
87QHBoxLayout *hbox;
88#ifndef QT_NO_PRINTER
89    cbHQGraph = new QCheckBox(bgWhite);
90    cbHQGraph->setObjectName("cbHQGraph");
91#ifndef QT_NO_STATUSTIP
92    cbHQGraph->setStatusTip(tr("Higher quality graph looks much better when printing but uglier on the screen"));
93#endif // QT_NO_STATUSTIP
94    cbHQGraph->setText(tr("Draw solution graph in higher quality"));
95    cbHQGraph->setCursor(QCursor(Qt::PointingHandCursor));
96
97    box = static_cast<QBoxLayout *>(tabOutputGeneral->layout());
98    hbox = new QHBoxLayout();
99    hbox->addSpacing(10);
100    hbox->addWidget(cbHQGraph);
101    box->insertLayout(box->indexOf(cbGenerateGraph) + 3, hbox);
102    connect(cbGenerateGraph, SIGNAL(toggled(bool)), cbHQGraph, SLOT(setEnabled(bool)));
103#endif
104
105    if (hasUpdater()) {
106        cbCheck4Updates = new QCheckBox(bgWhite);
107        cbCheck4Updates->setObjectName("cbCheck4Updates");
108#ifndef QT_NO_STATUSTIP
109        cbCheck4Updates->setStatusTip(tr("Automatically check for updates at the given interval"));
110#endif // QT_NO_STATUSTIP
111        cbCheck4Updates->setText(tr("Check for updates every"));
112        cbCheck4Updates->setCursor(QCursor(Qt::PointingHandCursor));
113
114        spinUpdateCheckInterval = new QSpinBox(bgWhite);
115        spinUpdateCheckInterval->setObjectName("spinUpdateCheckInterval");
116#ifndef QT_NO_STATUSTIP
117        spinUpdateCheckInterval->setStatusTip(tr("Minimal interval at which to check for updates"));
118#endif // QT_NO_STATUSTIP
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;
134
135#ifdef HANDHELD
136QVBoxLayout *vbox1; // Layout helper
137
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.
141QScrollArea *scrollArea = new QScrollArea(this);
142    scrollArea->setFrameShape(QFrame::NoFrame);
143    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
144    scrollArea->setWidgetResizable(true);
145    scrollArea->setWidget(bgWhite);
146
147    bgWhite->layout()->setMargin(0);
148
149#ifdef Q_OS_SYMBIAN
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
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);
163#else // HANDHELD
164QVBoxLayout *vbox; // Layout helper
165
166#ifndef HANDHELD
167    if (QtWin::isCompositionEnabled()) {
168        cbUseTranslucency = new QCheckBox(bgWhite);
169        cbUseTranslucency->setObjectName("cbUseTranslucency");
170#ifndef QT_NO_STATUSTIP
171        cbUseTranslucency->setStatusTip(tr("Make Main Window background translucent"));
172#endif // QT_NO_STATUSTIP
173        cbUseTranslucency->setText(tr("Use translucency effects"));
174        cbUseTranslucency->setCursor(QCursor(Qt::PointingHandCursor));
175    }
176#endif // HANDHELD
177
178    cbSaveState = new QCheckBox(bgWhite);
179    cbSaveState->setObjectName("cbSaveState");
180#ifndef QT_NO_STATUSTIP
181    cbSaveState->setStatusTip(tr("Restore main window state and position on application restart"));
182#endif // QT_NO_STATUSTIP
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);
198    labelHint->setMinimumSize(QSize(250, 28));
199    labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX, 28));
200    labelHint->setTextFormat(Qt::PlainText);
201//      labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop);
202    labelHint->setWordWrap(true);
203#ifndef QT_NO_STATUSTIP
204    labelHint->setStatusTip(tr("Hover mouse pointer over dialog elements to get additional help"));
205#endif // QT_NO_STATUSTIP
206
207    lineVertical = new QFrame(this);
208    lineVertical->setObjectName("lineVertical");
209    lineVertical->setFrameShadow(QFrame::Plain);
210    lineVertical->setFrameShape(QFrame::VLine);
211    lineVertical->setLineWidth(2);
212
213    // Top line
214    hbox = new QHBoxLayout();
215    hbox->addWidget(imgIcon);
216    hbox->addWidget(lineVertical);
217    hbox->addWidget(bgWhite);
218
219    box = static_cast<QBoxLayout *>(tabGeneral->layout());
220    box->insertWidget(box->indexOf(cbUseNativeDialogs) + 1, cbSaveState);
221#ifndef HANDHELD
222    if (QtWin::isCompositionEnabled())
223        box->insertWidget(box->indexOf(cbUseNativeDialogs) + 1, cbUseTranslucency);
224#endif // HANDHELD
225
226    // Inserting label for hints to the bottom part (with grey bg)
227    buttons->insertWidget(buttons->indexOf(buttonHelp) + 1, labelHint, 1);
228
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);
236#endif // HANDHELD
237
238#ifdef Q_OS_WINCE_WM
239    // We need to react to SIP show/hide and resize the window appropriately
240    connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int)));
241#endif // Q_OS_WINCE_WM
242    connect(spinRandMin, SIGNAL(valueChanged(int)), SLOT(spinRandMinValueChanged(int)));
243    connect(buttonFont, SIGNAL(clicked()), SLOT(buttonFontClicked()));
244    connect(buttonTextColor, SIGNAL(clicked()), SLOT(buttonTextColorClicked()));
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()));
249    setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
250#if !defined(QT_NO_STATUSTIP) && !defined(HANDHELD)
251    // Setting initial text of dialog hint label to own status tip text.
252    labelHint->setText(labelHint->statusTip());
253#endif // HANDHELD
254
255    settings = initSettings(this);
256    settings->remove("SettingsReset");
257
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());
261#ifndef HANDHELD
262    if (QtWin::isCompositionEnabled())
263        cbUseTranslucency->setChecked(settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool());
264#endif // HANDHELD
265#ifndef HANDHELD
266    cbSaveState->setChecked(settings->value("SavePos", DEF_SAVEPOS).toBool());
267#endif // HANDHELD
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");
287    cbGenerateGraph->setChecked(settings->value("GenerateGraph", DEF_GENERATE_GRAPH).toBool());
288
289    spinGraphWidth->setEnabled(cbGenerateGraph->isChecked());
290    spinGraphWidth->setValue(settings->value("GraphWidth", DEF_GRAPH_WIDTH).toDouble());
291
292#if !defined(NOSVG) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0))
293    comboGraphImageFormat->addItem("svg");
294#endif
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).
298QStringList whitelist;
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));
308    labelGraphImageFormat->setEnabled(cbGenerateGraph->isChecked());
309    comboGraphImageFormat->setEnabled(cbGenerateGraph->isChecked());
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());
317    cbEmbedGraphIntoHTML->setEnabled(cbGenerateGraph->isChecked());
318    cbEmbedGraphIntoHTML->setChecked(settings->value("EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool());
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());
325    settings->endGroup();
326    spinCitiesLimit->setMaximum(settings->value("Tweaks/MaxNumCities", MAX_NUM_CITIES).toInt());
327    settings->beginGroup("Output");
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)));
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());
334    borderColor = QColor(settings->value("Colors/TableBorder", DEF_TABLE_COLOR).toString());
335//    bgColor = QColor(settings->value("Colors/Background", DEF_BACKGROUND_COLOR).toString());
336    settings->endGroup();
337
338    QFont f = font;
339    f.setPointSize(labelFontExample->font().pointSize());
340    labelFontExample->setFont(f);
341    labelFontExample->setText(font.family());
342
343    setBgColor(boxTextColor, textColor);
344    setBgColor(boxSelectedColor, selColor);
345    setBgColor(boxAlternateColor, altColor);
346    setBgColor(boxBorderColor, borderColor);
347//    setBgColor(boxBgColor, bgColor);
348
349#ifdef HANDHELD
350    setWindowState(Qt::WindowMaximized);
351#else
352    adjustSize();
353#endif // Q_OS_WINCE_WM
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{
362    return _colorChanged;
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{
371    return _fontChanged;
372}
373
374/*!
375 * \brief Indicates whether and how the translucency setting was changed
376 * \retval -1 the translucency was \em disabled.
377 * \retval  0 the translucency <em>didn't change</em>.
378 * \retval  1 the translucency was \em enabled.
379 */
380qint8 SettingsDialog::translucencyChanged() const
381{
382    return _translucency;
383}
384
385/* Privates **********************************************************/
386
387void SettingsDialog::accept()
388{
389    if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
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) {
396            _fontChanged = (font != QFont(DEF_FONT_FACE, DEF_FONT_SIZE));
397            _colorChanged = (textColor != DEF_TEXT_COLOR);
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();
405            settings->remove("");
406            settings->setValue("SettingsReset", true);
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            }
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());
423#ifndef HANDHELD
424    if (QtWin::isCompositionEnabled()) {
425bool old = settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool();
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());
433#endif // HANDHELD
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");
451    settings->setValue("GenerateGraph", cbGenerateGraph->isChecked());
452    if (cbGenerateGraph->isChecked()) {
453        settings->setValue("GraphWidth", spinGraphWidth->value());
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        }
460#ifndef QT_NO_PRINTER
461        settings->setValue("HQGraph", cbHQGraph->isChecked());
462#endif
463        settings->setValue("EmbedGraphIntoHTML", cbEmbedGraphIntoHTML->isChecked());
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());
470    if (_fontChanged)
471        settings->setValue("Font", font);
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    }
496    settings->endGroup();
497    QDialog::accept();
498}
499
500void SettingsDialog::pickColor(QColor &where)
501{
502    QColor color = QColorDialog::getColor(where, this);
503    if (color.isValid() && (where != color)) {
504        where = color;
505        _colorChanged = true;
506    }
507}
508
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
546void SettingsDialog::buttonFontClicked()
547{
548bool ok;
549QFont font = QFontDialog::getFont(&ok, this->font, this);
550    if (ok && (this->font != font)) {
551        this->font = font;
552        QFont f = font;
553        f.setPointSize(labelFontExample->font().pointSize());
554        labelFontExample->setFont(f);
555        labelFontExample->setText(font.family());
556        _fontChanged = true;
557    }
558}
559
560#ifdef Q_OS_WINCE_WM
561void SettingsDialog::desktopResized(int screen)
562{
563    if (screen != 0)
564        return;
565
566QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
567    if (currentGeometry != availableGeometry) {
568        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
569        /*!
570         * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
571         *  If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the
572         *  window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile?
573         */
574        if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) {
575            setWindowState(windowState() | Qt::WindowMaximized);
576        } else {
577            if (windowState() & Qt::WindowMaximized)
578                setWindowState(windowState() ^ Qt::WindowMaximized);
579            setGeometry(availableGeometry);
580        }
581        currentGeometry = availableGeometry;
582        QApplication::restoreOverrideCursor();
583    }
584}
585
586void SettingsDialog::showEvent(QShowEvent *ev)
587{
588    desktopResized(0);
589
590    QWidget::showEvent(ev);
591}
592#endif // Q_OS_WINCE_WM
593
594void SettingsDialog::spinRandMinValueChanged(int val) {
595    spinRandMax->setMinimum(val);
596}
597
598#if !defined(QT_NO_STATUSTIP) && !defined(HANDHELD)
599bool SettingsDialog::event(QEvent *ev)
600{
601    // Checking for StatusTip event and if tip text is not empty string
602    // setting it as text of the dialog hint label. Otherwise, setting
603    // dialog hint label text to own status tip text.
604    if (ev->type() == QEvent::StatusTip) {
605QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
606        if (tip.length() != 0)
607            labelHint->setText(tip);
608        else
609            labelHint->setText(labelHint->statusTip());
610        return true;
611    } else
612        return QDialog::event(ev);
613}
614#endif // HANDHELD
Note: See TracBrowser for help on using the repository browser.