[5515c2c2a7] | 1 | /* |
---|
[430bd7f7e9] | 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 | |
---|
[caef58b531] | 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 | */ |
---|
[5515c2c2a7] | 32 | SettingsDialog::SettingsDialog(QWidget *parent) |
---|
[430bd7f7e9] | 33 | : QDialog(parent), newFont(false), newColor(false) |
---|
[5515c2c2a7] | 34 | { |
---|
| 35 | setupUi(this); |
---|
[281303f1f7] | 36 | // Laying out elements |
---|
[1fbf016a09] | 37 | layoutCitiesLimit = new QHBoxLayout(); |
---|
| 38 | layoutCitiesLimit->setMargin(0); |
---|
| 39 | layoutCitiesLimit->setSpacing(0); |
---|
| 40 | layoutCitiesLimit->addSpacing(10); |
---|
| 41 | layoutCitiesLimit->addWidget(cbCitiesLimit); |
---|
| 42 | layoutCitiesLimit->addWidget(spinCitiesLimit); |
---|
| 43 | layoutCitiesLimit->addStretch(); |
---|
| 44 | |
---|
| 45 | buttonBox->button(QDialogButtonBox::Save)->setIcon(QIcon(":/images/icons/button_ok.png")); |
---|
| 46 | buttonBox->button(QDialogButtonBox::Save)->setStatusTip(trUtf8("Save new preferences")); |
---|
| 47 | buttonBox->button(QDialogButtonBox::Save)->setCursor(QCursor(Qt::PointingHandCursor)); |
---|
| 48 | buttonBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":/images/icons/button_cancel.png")); |
---|
| 49 | buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(trUtf8("Close without saving preferences")); |
---|
| 50 | buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor)); |
---|
| 51 | |
---|
[281303f1f7] | 52 | #ifdef Q_OS_WINCE |
---|
| 53 | // Layout helper elements |
---|
| 54 | QVBoxLayout *vbox1, *vbox2; |
---|
| 55 | QHBoxLayout *hbox1, *hbox2; |
---|
| 56 | |
---|
| 57 | labelRandMin->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); |
---|
| 58 | labelRandMax->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); |
---|
| 59 | |
---|
| 60 | // Top part (with white bg) |
---|
| 61 | vbox2 = new QVBoxLayout(bgWhite); |
---|
| 62 | vbox2->addWidget(groupRandomSettings); |
---|
| 63 | vbox2->addWidget(groupOutputSettings); |
---|
[1fbf016a09] | 64 | vbox2->addStretch(); |
---|
| 65 | vbox2->addWidget(cbShowMatrix); |
---|
| 66 | vbox2->addLayout(layoutCitiesLimit); |
---|
[2fb523720a] | 67 | vbox2->addWidget(cbAutosize); |
---|
[281303f1f7] | 68 | |
---|
| 69 | // Output settings group |
---|
| 70 | hbox1 = new QHBoxLayout(groupOutputSettings); |
---|
| 71 | hbox1->addWidget(buttonFont); |
---|
| 72 | hbox1->addWidget(buttonColor); |
---|
| 73 | |
---|
| 74 | // Bottom part (with grey bg) |
---|
| 75 | hbox2 = new QHBoxLayout(bgGrey); |
---|
| 76 | hbox2->setMargin(6); |
---|
| 77 | hbox2->setSpacing(6); |
---|
| 78 | hbox2->addWidget(buttonHelp); |
---|
[1fbf016a09] | 79 | hbox2->addStretch(); |
---|
| 80 | hbox2->addWidget(buttonBox); |
---|
[281303f1f7] | 81 | |
---|
| 82 | // Central layout |
---|
| 83 | vbox1 = new QVBoxLayout(this); |
---|
| 84 | vbox1->setMargin(0); |
---|
| 85 | vbox1->setSpacing(0); |
---|
| 86 | vbox1->addWidget(bgWhite); |
---|
| 87 | vbox1->addWidget(lineHorizontal); |
---|
| 88 | vbox1->addWidget(bgGrey); |
---|
| 89 | #else |
---|
| 90 | // Layout helper elements |
---|
| 91 | QVBoxLayout *vbox1, *vbox2, *vbox3; |
---|
| 92 | QHBoxLayout *hbox1, *hbox2, *hbox3; |
---|
| 93 | |
---|
| 94 | cbSaveState = new QCheckBox(bgWhite); |
---|
| 95 | cbSaveState->setObjectName("cbSaveState"); |
---|
| 96 | #ifndef QT_NO_STATUSTIP |
---|
| 97 | cbSaveState->setStatusTip(trUtf8("Restore main window state and position on application restart")); |
---|
| 98 | #endif // QT_NO_STATUSTIP |
---|
| 99 | cbSaveState->setText(trUtf8("Save main window state and position")); |
---|
| 100 | cbSaveState->setCursor(QCursor(Qt::PointingHandCursor)); |
---|
| 101 | |
---|
| 102 | imgIcon = new QLabel(this); |
---|
| 103 | imgIcon->setObjectName("imgIcon"); |
---|
[5a81a64d74] | 104 | imgIcon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding); |
---|
| 105 | imgIcon->setFrameShape(QFrame::Panel); |
---|
[281303f1f7] | 106 | imgIcon->setLineWidth(0); |
---|
[1fbf016a09] | 107 | imgIcon->setPixmap(QPixmap(":/images/icons/preferences_system.png")); |
---|
[281303f1f7] | 108 | imgIcon->setStyleSheet("background-color: #0080C0;"); |
---|
| 109 | imgIcon->setAlignment(Qt::AlignCenter); |
---|
[1fbf016a09] | 110 | imgIcon->setMinimumWidth(150); |
---|
[281303f1f7] | 111 | |
---|
| 112 | labelHint = new QLabel(bgGrey); |
---|
| 113 | labelHint->setObjectName("labelHint"); |
---|
| 114 | labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); |
---|
[5a81a64d74] | 115 | // labelHint->setMinimumSize(QSize(190,28)); |
---|
| 116 | labelHint->setMinimumSize(QSize(0,28)); |
---|
| 117 | labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX,28)); |
---|
[281303f1f7] | 118 | labelHint->setTextFormat(Qt::PlainText); |
---|
| 119 | // labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
---|
| 120 | labelHint->setWordWrap(true); |
---|
| 121 | #ifndef QT_NO_STATUSTIP |
---|
| 122 | labelHint->setStatusTip(trUtf8("Hover mouse pointer over dialog elements to get additional help")); |
---|
| 123 | #endif // QT_NO_STATUSTIP |
---|
| 124 | |
---|
| 125 | lineVertical = new QFrame(this); |
---|
| 126 | lineVertical->setObjectName("lineVertical"); |
---|
| 127 | lineVertical->setFrameShadow(QFrame::Plain); |
---|
| 128 | lineVertical->setFrameShape(QFrame::VLine); |
---|
| 129 | lineVertical->setLineWidth(2); |
---|
| 130 | |
---|
| 131 | // Top line |
---|
| 132 | hbox1 = new QHBoxLayout(); |
---|
| 133 | hbox1->addWidget(imgIcon); |
---|
| 134 | hbox1->addWidget(lineVertical); |
---|
| 135 | hbox1->addWidget(bgWhite); |
---|
| 136 | |
---|
| 137 | // Output settings group |
---|
| 138 | vbox3 = new QVBoxLayout(groupOutputSettings); |
---|
| 139 | vbox3->addWidget(buttonFont); |
---|
| 140 | vbox3->addWidget(buttonColor); |
---|
| 141 | |
---|
| 142 | // Random and Output settings groups |
---|
| 143 | hbox2 = new QHBoxLayout(); |
---|
| 144 | hbox2->addWidget(groupRandomSettings); |
---|
| 145 | hbox2->addWidget(groupOutputSettings); |
---|
[1fbf016a09] | 146 | hbox2->addStretch(); |
---|
[281303f1f7] | 147 | |
---|
| 148 | // Top right part (with white bg) |
---|
| 149 | vbox2 = new QVBoxLayout(bgWhite); |
---|
[1fbf016a09] | 150 | vbox2->addStretch(); |
---|
[281303f1f7] | 151 | vbox2->addLayout(hbox2); |
---|
[1fbf016a09] | 152 | vbox2->addWidget(cbShowMatrix); |
---|
| 153 | vbox2->addLayout(layoutCitiesLimit); |
---|
[2fb523720a] | 154 | vbox2->addWidget(cbAutosize); |
---|
[281303f1f7] | 155 | vbox2->addWidget(cbSaveState); |
---|
[1fbf016a09] | 156 | vbox2->addStretch(); |
---|
[281303f1f7] | 157 | |
---|
| 158 | // Bottom part (with grey bg) |
---|
| 159 | hbox3 = new QHBoxLayout(bgGrey); |
---|
| 160 | hbox3->setMargin(6); |
---|
| 161 | hbox3->setSpacing(6); |
---|
| 162 | hbox3->addWidget(buttonHelp); |
---|
| 163 | hbox3->addWidget(labelHint); |
---|
[1fbf016a09] | 164 | hbox3->addWidget(buttonBox); |
---|
[281303f1f7] | 165 | |
---|
| 166 | // Central layout |
---|
| 167 | vbox1 = new QVBoxLayout(this); |
---|
| 168 | vbox1->setMargin(0); |
---|
| 169 | vbox1->setSpacing(0); |
---|
| 170 | vbox1->addLayout(hbox1); |
---|
| 171 | vbox1->addWidget(lineHorizontal); |
---|
| 172 | vbox1->addWidget(bgGrey); |
---|
| 173 | #endif // Q_OS_WINCE |
---|
[5515c2c2a7] | 174 | connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int))); |
---|
[5354a01311] | 175 | connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked())); |
---|
[aecdf994f9] | 176 | connect(buttonColor,SIGNAL(clicked()),this,SLOT(buttonColorClicked())); |
---|
[5515c2c2a7] | 177 | // setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint); |
---|
| 178 | setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint); |
---|
[5354a01311] | 179 | #ifndef Q_OS_WINCE |
---|
[1fbf016a09] | 180 | // Setting initial text of dialog hint label to own status tip text. |
---|
[7836f136eb] | 181 | labelHint->setText(labelHint->statusTip()); |
---|
[5354a01311] | 182 | #endif // Q_OS_WINCE |
---|
[665d32434f] | 183 | settings = new QSettings(QSettings::IniFormat,QSettings::UserScope,"TSPSG","tspsg"); |
---|
[2fb523720a] | 184 | spinRandMin->setMaximum(MAX_RAND_VALUE); |
---|
[aecdf994f9] | 185 | spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt()); |
---|
[2fb523720a] | 186 | spinRandMax->setMaximum(MAX_RAND_VALUE); |
---|
[aecdf994f9] | 187 | spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt()); |
---|
[2fb523720a] | 188 | cbAutosize->setChecked(settings->value("Autosize",true).toBool()); |
---|
[aecdf994f9] | 189 | #ifndef Q_OS_WINCE |
---|
| 190 | cbSaveState->setChecked(settings->value("SavePos",false).toBool()); |
---|
| 191 | #endif // Q_OS_WINCE |
---|
[1fbf016a09] | 192 | |
---|
[430bd7f7e9] | 193 | settings->beginGroup("Output"); |
---|
[1fbf016a09] | 194 | cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool()); |
---|
| 195 | cbCitiesLimit->setEnabled(cbShowMatrix->isChecked()); |
---|
| 196 | cbCitiesLimit->setChecked(settings->value("UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT && cbShowMatrix->isChecked()).toBool()); |
---|
| 197 | spinCitiesLimit->setEnabled(cbShowMatrix->isChecked()); |
---|
| 198 | spinCitiesLimit->setValue(settings->value("ShowMatrixCitiesLimit", DEF_SHOW_MATRIX_CITY_LIMIT).toInt()); |
---|
| 199 | spinCitiesLimit->setMaximum(MAX_NUM_CITIES); |
---|
| 200 | |
---|
[aecdf994f9] | 201 | font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>(); |
---|
| 202 | color = settings->value("Color",DEF_FONT_COLOR).value<QColor>(); |
---|
| 203 | settings->endGroup(); |
---|
[1fbf016a09] | 204 | |
---|
| 205 | adjustSize(); |
---|
[7836f136eb] | 206 | } |
---|
| 207 | |
---|
[e0fcac5f2c] | 208 | /*! |
---|
| 209 | * \brief Indicates whether or not the font color has been changed. |
---|
| 210 | * \return \c true if font color changed, otherwise \c false. |
---|
| 211 | */ |
---|
| 212 | bool SettingsDialog::colorChanged() const |
---|
| 213 | { |
---|
| 214 | return newColor; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | /*! |
---|
| 218 | * \brief Indicates whether or not the font properties have been changed. |
---|
| 219 | * \return \c true if font properties changed, otherwise \c false. |
---|
| 220 | */ |
---|
| 221 | bool SettingsDialog::fontChanged() const |
---|
| 222 | { |
---|
| 223 | return newFont; |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | /* Privates **********************************************************/ |
---|
| 227 | |
---|
[430bd7f7e9] | 228 | void SettingsDialog::accept() |
---|
[7836f136eb] | 229 | { |
---|
[430bd7f7e9] | 230 | #ifndef Q_OS_WINCE |
---|
[1fbf016a09] | 231 | settings->setValue("SavePos", cbSaveState->isChecked()); |
---|
[5354a01311] | 232 | #endif // Q_OS_WINCE |
---|
[1fbf016a09] | 233 | settings->setValue("Autosize", cbAutosize->isChecked()); |
---|
| 234 | settings->setValue("MinCost", spinRandMin->value()); |
---|
| 235 | settings->setValue("MaxCost", spinRandMax->value()); |
---|
| 236 | |
---|
[430bd7f7e9] | 237 | settings->beginGroup("Output"); |
---|
[1fbf016a09] | 238 | settings->setValue("ShowMatrix", cbShowMatrix->isChecked()); |
---|
| 239 | settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked()); |
---|
| 240 | if (cbCitiesLimit->isChecked()) |
---|
| 241 | settings->setValue("ShowMatrixCitiesLimit", spinCitiesLimit->value()); |
---|
[430bd7f7e9] | 242 | if (newFont) |
---|
[1fbf016a09] | 243 | settings->setValue("Font", font); |
---|
[430bd7f7e9] | 244 | if (newColor) |
---|
[1fbf016a09] | 245 | settings->setValue("Color", color); |
---|
[430bd7f7e9] | 246 | settings->endGroup(); |
---|
| 247 | QDialog::accept(); |
---|
| 248 | } |
---|
[5515c2c2a7] | 249 | |
---|
[aecdf994f9] | 250 | void SettingsDialog::buttonColorClicked() |
---|
| 251 | { |
---|
[e7f7d3854d] | 252 | QColor color = QColorDialog::getColor(this->color,this); |
---|
[430bd7f7e9] | 253 | if (color.isValid() && (this->color != color)) { |
---|
[e7f7d3854d] | 254 | this->color = color; |
---|
[430bd7f7e9] | 255 | newColor = true; |
---|
| 256 | } |
---|
[aecdf994f9] | 257 | } |
---|
| 258 | |
---|
[e0fcac5f2c] | 259 | void SettingsDialog::buttonFontClicked() |
---|
[430bd7f7e9] | 260 | { |
---|
[e0fcac5f2c] | 261 | bool ok; |
---|
| 262 | QFont font = QFontDialog::getFont(&ok,this->font,this); |
---|
| 263 | if (ok && (this->font != font)) { |
---|
| 264 | this->font = font; |
---|
| 265 | newFont = true; |
---|
| 266 | } |
---|
[430bd7f7e9] | 267 | } |
---|
| 268 | |
---|
[caef58b531] | 269 | void SettingsDialog::spinRandMinValueChanged(int val) { |
---|
| 270 | spinRandMax->setMinimum(val); |
---|
| 271 | } |
---|
| 272 | |
---|
[aecdf994f9] | 273 | #ifndef Q_OS_WINCE |
---|
[430bd7f7e9] | 274 | bool SettingsDialog::event(QEvent *ev) |
---|
| 275 | { |
---|
| 276 | // Checking for StatusTip event and if tip text is not empty string |
---|
| 277 | // setting it as text of the dialog hint label. Otherwise, setting |
---|
| 278 | // dialog hint label text to own status tip text. |
---|
| 279 | if (ev->type() == QEvent::StatusTip) { |
---|
| 280 | QString tip = static_cast<QStatusTipEvent *>(ev)->tip(); |
---|
| 281 | if (tip.length() != 0) |
---|
| 282 | labelHint->setText(tip); |
---|
| 283 | else |
---|
| 284 | labelHint->setText(labelHint->statusTip()); |
---|
| 285 | return true; |
---|
| 286 | } else |
---|
| 287 | return QDialog::event(ev); |
---|
[5354a01311] | 288 | } |
---|
[430bd7f7e9] | 289 | #endif // Q_OS_WINCE |
---|