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