source: tspsg/src/settingsdialog.cpp @ 07e43cf61a

appveyorimgbotreadme
Last change on this file since 07e43cf61a was 07e43cf61a, checked in by Oleksii Serdiuk, 12 years ago

Improved compilation time by about 30%.

By reducing number of includes to only required minimum.

NOTE: Compilation time comparison was done by measuring compilation time
while using only one thread (i.e., "make -j1").

  • Property mode set to 100644
File size: 23.2 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#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    spinCitiesLimit->setMaximum(MAX_NUM_CITIES);
326    cbScrollToEnd->setChecked(settings->value("ScrollToEnd", DEF_SCROLL_TO_END).toBool());
327
328    font = qvariant_cast<QFont>(settings->value("Font", QFont(DEF_FONT_FACE, DEF_FONT_SIZE)));
329    textColor = QColor(settings->value("Colors/Text", DEF_TEXT_COLOR).toString());
330    selColor = QColor(settings->value("Colors/Selected", DEF_SELECTED_COLOR).toString());
331    altColor = QColor(settings->value("Colors/Alternate", DEF_ALTERNATE_COLOR).toString());
332    borderColor = QColor(settings->value("Colors/TableBorder", DEF_TABLE_COLOR).toString());
333//    bgColor = QColor(settings->value("Colors/Background", DEF_BACKGROUND_COLOR).toString());
334    settings->endGroup();
335
336    QFont f = font;
337    f.setPointSize(labelFontExample->font().pointSize());
338    labelFontExample->setFont(f);
339    labelFontExample->setText(font.family());
340
341    setBgColor(boxTextColor, textColor);
342    setBgColor(boxSelectedColor, selColor);
343    setBgColor(boxAlternateColor, altColor);
344    setBgColor(boxBorderColor, borderColor);
345//    setBgColor(boxBgColor, bgColor);
346
347#ifdef HANDHELD
348    setWindowState(Qt::WindowMaximized);
349#else
350    adjustSize();
351#endif // Q_OS_WINCE_WM
352}
353
354/*!
355 * \brief Indicates whether or not the font color has been changed.
356 * \return \c true if font color changed, otherwise \c false.
357 */
358bool SettingsDialog::colorChanged() const
359{
360    return _colorChanged;
361}
362
363/*!
364 * \brief Indicates whether or not the font properties have been changed.
365 * \return \c true if font properties changed, otherwise \c false.
366 */
367bool SettingsDialog::fontChanged() const
368{
369    return _fontChanged;
370}
371
372/*!
373 * \brief Indicates whether and how the translucency setting was changed
374 * \retval -1 the translucency was \em disabled.
375 * \retval  0 the translucency <em>didn't change</em>.
376 * \retval  1 the translucency was \em enabled.
377 */
378qint8 SettingsDialog::translucencyChanged() const
379{
380    return _translucency;
381}
382
383/* Privates **********************************************************/
384
385void SettingsDialog::accept()
386{
387    if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
388        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) {
389            _fontChanged = (font != QFont(DEF_FONT_FACE, DEF_FONT_SIZE));
390            _colorChanged = (textColor != DEF_TEXT_COLOR);
391            settings->remove("");
392            settings->setValue("SettingsReset", true);
393            QDialog::accept();
394            QMessageBox::information(this->parentWidget(), tr("Settings Reset"), tr("All settings where successfully reset to their defaults.\nIt is recommended to restart the application now."));
395            return;
396        } else
397            return;
398    }
399    settings->setValue("Autosize", cbAutosize->isChecked());
400    settings->setValue("SaveLastUsed", cbSaveLastUsed->isChecked());
401    settings->setValue("UseNativeDialogs", cbUseNativeDialogs->isChecked());
402#ifndef HANDHELD
403    if (QtWin::isCompositionEnabled()) {
404bool old = settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool();
405        if ((!old && cbUseTranslucency->isChecked()) || (old && !cbUseTranslucency->isChecked())) {
406            _translucency = old ? -1 : 1;
407        } else
408            _translucency = 0;
409        settings->setValue("UseTranslucency", cbUseTranslucency->isChecked());
410    }
411    settings->setValue("SavePos", cbSaveState->isChecked());
412#endif // HANDHELD
413    if (cbCheck4Updates != NULL) {
414        settings->beginGroup("Check4Updates");
415        settings->setValue("Enabled", cbCheck4Updates->isChecked());
416        if (cbCheck4Updates->isChecked())
417            settings->setValue("Interval", spinUpdateCheckInterval->value());
418        settings->endGroup();
419    }
420
421    settings->beginGroup("Task");
422    settings->setValue("SymmetricMode", cbSymmetricMode->isChecked());
423    settings->setValue("FractionalAccuracy", spinFractionalAccuracy->value());
424    settings->setValue("RandMin", spinRandMin->value());
425    settings->setValue("RandMax", spinRandMax->value());
426    settings->setValue("FractionalRandom", cbFractionalRandom->isChecked());
427    settings->endGroup();
428
429    settings->beginGroup("Output");
430    settings->setValue("GenerateGraph", cbGenerateGraph->isChecked());
431    if (cbGenerateGraph->isChecked()) {
432        settings->setValue("GraphWidth", spinGraphWidth->value());
433        if (cbGenerateGraph->isChecked()) {
434            if (comboGraphImageFormat->currentIndex() >= 0)
435                settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText());
436            else
437                settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT);
438        }
439#ifndef QT_NO_PRINTER
440        settings->setValue("HQGraph", cbHQGraph->isChecked());
441#endif
442        settings->setValue("EmbedGraphIntoHTML", cbEmbedGraphIntoHTML->isChecked());
443    }
444    settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
445    settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
446    if (cbCitiesLimit->isChecked())
447        settings->setValue("ShowMatrixLimit", spinCitiesLimit->value());
448    settings->setValue("ScrollToEnd", cbScrollToEnd->isChecked());
449    if (_fontChanged)
450        settings->setValue("Font", font);
451    if (_colorChanged) {
452        settings->beginGroup("Colors");
453        if (textColor != DEF_TEXT_COLOR)
454            settings->setValue("Text", textColor.name());
455        else
456            settings->remove("Text");
457        if (selColor != QColor(DEF_SELECTED_COLOR))
458            settings->setValue("Selected", selColor.name());
459        else
460            settings->remove("Selected");
461        if (altColor != DEF_ALTERNATE_COLOR)
462            settings->setValue("Alternate",altColor.name());
463        else
464            settings->remove("Alternate");
465        if (borderColor != DEF_TABLE_COLOR)
466            settings->setValue("TableBorder", borderColor.name());
467        else
468            settings->remove("TableColor");
469//        if (bgColor != DEF_BACKGROUND_COLOR)
470//            settings->setValue("Background", bgColor.name());
471//        else
472//            settings->remove("Background");
473        settings->endGroup();
474    }
475    settings->endGroup();
476    QDialog::accept();
477}
478
479void SettingsDialog::pickColor(QColor &where)
480{
481    QColor color = QColorDialog::getColor(where, this);
482    if (color.isValid() && (where != color)) {
483        where = color;
484        _colorChanged = true;
485    }
486}
487
488void SettingsDialog::setBgColor(QWidget *widget, const QColor &color)
489{
490    QPalette p = widget->palette();
491    p.setColor(QPalette::Window, color);
492    widget->setPalette(p);
493}
494
495void SettingsDialog::buttonTextColorClicked()
496{
497    pickColor(textColor);
498    setBgColor(boxTextColor, textColor);
499}
500
501void SettingsDialog::buttonSelectedColorClicked()
502{
503    pickColor(selColor);
504    setBgColor(boxSelectedColor, selColor);
505}
506
507void SettingsDialog::buttonAlternateColorClicked()
508{
509    pickColor(altColor);
510    setBgColor(boxAlternateColor, altColor);
511}
512
513void SettingsDialog::buttonBorderColorClicked()
514{
515    pickColor(borderColor);
516    setBgColor(boxBorderColor, borderColor);
517}
518
519//void SettingsDialog::buttonBgColorClicked()
520//{
521//    pickColor(bgColor);
522//    setBgColor(boxBgColor, bgColor);
523//}
524
525void SettingsDialog::buttonFontClicked()
526{
527bool ok;
528QFont font = QFontDialog::getFont(&ok, this->font, this);
529    if (ok && (this->font != font)) {
530        this->font = font;
531        QFont f = font;
532        f.setPointSize(labelFontExample->font().pointSize());
533        labelFontExample->setFont(f);
534        labelFontExample->setText(font.family());
535        _fontChanged = true;
536    }
537}
538
539#ifdef Q_OS_WINCE_WM
540void SettingsDialog::desktopResized(int screen)
541{
542    if (screen != 0)
543        return;
544
545QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
546    if (currentGeometry != availableGeometry) {
547        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
548        /*!
549         * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height.
550         *  If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the
551         *  window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile?
552         */
553        if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) {
554            setWindowState(windowState() | Qt::WindowMaximized);
555        } else {
556            if (windowState() & Qt::WindowMaximized)
557                setWindowState(windowState() ^ Qt::WindowMaximized);
558            setGeometry(availableGeometry);
559        }
560        currentGeometry = availableGeometry;
561        QApplication::restoreOverrideCursor();
562    }
563}
564
565void SettingsDialog::showEvent(QShowEvent *ev)
566{
567    desktopResized(0);
568
569    QWidget::showEvent(ev);
570}
571#endif // Q_OS_WINCE_WM
572
573void SettingsDialog::spinRandMinValueChanged(int val) {
574    spinRandMax->setMinimum(val);
575}
576
577#if !defined(QT_NO_STATUSTIP) && !defined(HANDHELD)
578bool SettingsDialog::event(QEvent *ev)
579{
580    // Checking for StatusTip event and if tip text is not empty string
581    // setting it as text of the dialog hint label. Otherwise, setting
582    // dialog hint label text to own status tip text.
583    if (ev->type() == QEvent::StatusTip) {
584QString tip = static_cast<QStatusTipEvent *>(ev)->tip();
585        if (tip.length() != 0)
586            labelHint->setText(tip);
587        else
588            labelHint->setText(labelHint->statusTip());
589        return true;
590    } else
591        return QDialog::event(ev);
592}
593#endif // HANDHELD
Note: See TracBrowser for help on using the repository browser.