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