source: tspsg/src/settingsdialog.cpp @ 0e473fbe88

appveyorimgbotreadme
Last change on this file since 0e473fbe88 was 89e5214692, checked in by Oleksii Serdiuk, 12 years ago

Replaced all Q_WS_xxx with Q_OS_xxx ifdefs where possible.

This is needed for compatibility with Qt 5.

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