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