[5515c2c2a7] | 1 | /* |
---|
[bb994a7ff8] | 2 | * TSPSG - TSP Solver and Generator |
---|
[5354a01311] | 3 | * Copyright (C) 2007-2009 Lёppa <contacts[at]oleksii[dot]name> |
---|
[5515c2c2a7] | 4 | * |
---|
[bb994a7ff8] | 5 | * $Id$ |
---|
| 6 | * $URL$ |
---|
[f99964aa0b] | 7 | * |
---|
[bb994a7ff8] | 8 | * This file is part of TSPSG. |
---|
[5515c2c2a7] | 9 | * |
---|
[bb994a7ff8] | 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. |
---|
[5515c2c2a7] | 14 | * |
---|
[bb994a7ff8] | 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. |
---|
[5515c2c2a7] | 19 | * |
---|
[bb994a7ff8] | 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/>. |
---|
[5515c2c2a7] | 22 | */ |
---|
| 23 | |
---|
[7836f136eb] | 24 | #include "settingsdialog.h" |
---|
[5515c2c2a7] | 25 | |
---|
| 26 | SettingsDialog::SettingsDialog(QWidget *parent) |
---|
| 27 | : QDialog(parent) |
---|
| 28 | { |
---|
| 29 | setupUi(this); |
---|
| 30 | connect(buttonOK,SIGNAL(clicked()),this,SLOT(accept())); |
---|
| 31 | connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject())); |
---|
| 32 | connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int))); |
---|
[5354a01311] | 33 | connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked())); |
---|
[aecdf994f9] | 34 | connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked())); |
---|
[5515c2c2a7] | 35 | // setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint); |
---|
| 36 | setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint); |
---|
| 37 | layout()->setSizeConstraint(layout()->SetFixedSize); |
---|
[5354a01311] | 38 | #ifndef Q_OS_WINCE |
---|
[95eca626aa] | 39 | // Setting initial text of dialog hint label to own status tip |
---|
| 40 | // text. |
---|
[7836f136eb] | 41 | labelHint->setText(labelHint->statusTip()); |
---|
[95eca626aa] | 42 | // HACK: Do not resize label hint (and dialog) when text changes |
---|
| 43 | // from one-line to two-line and vice versa. Any better solution? |
---|
| 44 | labelHint->setMaximumHeight(labelHint->height()); |
---|
| 45 | labelHint->setMinimumHeight(labelHint->height()); |
---|
[5354a01311] | 46 | #endif // Q_OS_WINCE |
---|
[665d32434f] | 47 | settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg"); |
---|
[aecdf994f9] | 48 | spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt()); |
---|
| 49 | spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt()); |
---|
| 50 | #ifndef Q_OS_WINCE |
---|
| 51 | cbSaveState->setChecked(settings->value("SavePos",false).toBool()); |
---|
| 52 | #endif // Q_OS_WINCE |
---|
| 53 | settings->beginGroup("Print"); |
---|
| 54 | font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>(); |
---|
| 55 | color = settings->value("Color",DEF_FONT_COLOR).value<QColor>(); |
---|
| 56 | #ifndef Q_OS_WINCE |
---|
| 57 | spinLeftMargin->setValue(settings->value("Offset",DEF_OFFSET).toInt()); |
---|
| 58 | #endif // Q_OS_WINCE |
---|
| 59 | settings->endGroup(); |
---|
[7836f136eb] | 60 | } |
---|
| 61 | |
---|
[5354a01311] | 62 | #ifndef Q_OS_WINCE |
---|
[7836f136eb] | 63 | bool SettingsDialog::event(QEvent *ev) |
---|
| 64 | { |
---|
| 65 | // Checking for StatusTip event and if tip text is not empty string |
---|
| 66 | // setting it as text of the dialog hint label. Otherwise, setting |
---|
[95eca626aa] | 67 | // dialog hint label text to own status tip text. |
---|
[7836f136eb] | 68 | if (ev->type() == QEvent::StatusTip) { |
---|
| 69 | QString tip = static_cast<QStatusTipEvent *>(ev)->tip(); |
---|
| 70 | if (tip.length() != 0) |
---|
| 71 | labelHint->setText(tip); |
---|
| 72 | else |
---|
| 73 | labelHint->setText(labelHint->statusTip()); |
---|
| 74 | return true; |
---|
| 75 | } else |
---|
| 76 | return QDialog::event(ev); |
---|
[5515c2c2a7] | 77 | } |
---|
[5354a01311] | 78 | #endif // Q_OS_WINCE |
---|
[5515c2c2a7] | 79 | |
---|
[5354a01311] | 80 | void SettingsDialog::buttonFontClicked() |
---|
| 81 | { |
---|
[aecdf994f9] | 82 | bool ok; |
---|
| 83 | QFont font = QFontDialog::getFont(&ok,this->font,this); |
---|
| 84 | if (ok) |
---|
| 85 | this->font = font; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | void SettingsDialog::buttonColorClicked() |
---|
| 89 | { |
---|
[e7f7d3854d] | 90 | QColor color = QColorDialog::getColor(this->color,this); |
---|
| 91 | if (color.isValid()) |
---|
| 92 | this->color = color; |
---|
[aecdf994f9] | 93 | } |
---|
| 94 | |
---|
| 95 | void SettingsDialog::accept() |
---|
| 96 | { |
---|
| 97 | #ifndef Q_OS_WINCE |
---|
| 98 | settings->setValue("SavePos",cbSaveState->isChecked()); |
---|
| 99 | #endif // Q_OS_WINCE |
---|
| 100 | settings->setValue("MinCost",spinRandMin->value()); |
---|
| 101 | settings->setValue("MaxCost",spinRandMax->value()); |
---|
| 102 | settings->beginGroup("Print"); |
---|
| 103 | settings->setValue("Font",font); |
---|
| 104 | settings->setValue("Color",color); |
---|
| 105 | #ifndef Q_OS_WINCE |
---|
| 106 | settings->setValue("Offset",spinLeftMargin->value()); |
---|
| 107 | #endif // Q_OS_WINCE |
---|
| 108 | settings->endGroup(); |
---|
| 109 | QDialog::accept(); |
---|
[5354a01311] | 110 | } |
---|