[ec54b4490b] | 1 | /* |
---|
[430bd7f7e9] | 2 | * TSPSG: TSP Solver and Generator |
---|
[1757eb594b] | 3 | * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> |
---|
[003e4193be] | 4 | * |
---|
[bb994a7ff8] | 5 | * $Id$ |
---|
| 6 | * $URL$ |
---|
[5515c2c2a7] | 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 | |
---|
| 24 | #include "mainwindow.h" |
---|
| 25 | |
---|
[caef58b531] | 26 | /*! |
---|
| 27 | * \brief Class constructor. |
---|
| 28 | * \param parent Main Window parent widget. |
---|
| 29 | * |
---|
| 30 | * Initializes Main Window and creates its layout based on target OS. |
---|
| 31 | * Loads TSPSG settings and opens a task file if it was specified as a commandline parameter. |
---|
| 32 | */ |
---|
[5515c2c2a7] | 33 | MainWindow::MainWindow(QWidget *parent) |
---|
[aecdf994f9] | 34 | : QMainWindow(parent) |
---|
[5515c2c2a7] | 35 | { |
---|
[4ccf855df8] | 36 | settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this); |
---|
[b2bf8e3b6b] | 37 | |
---|
[899d1b8e15] | 38 | loadLanguage(); |
---|
[4ccf855df8] | 39 | setupUi(); |
---|
| 40 | |
---|
[430bd7f7e9] | 41 | initDocStyleSheet(); |
---|
[4ccf855df8] | 42 | |
---|
[c10297cf73] | 43 | #ifndef QT_NO_PRINTER |
---|
[56dca709c9] | 44 | printer = new QPrinter(QPrinter::HighResolution); |
---|
[c10297cf73] | 45 | #endif // QT_NO_PRINTER |
---|
[4ccf855df8] | 46 | |
---|
[b2bf8e3b6b] | 47 | #ifdef Q_OS_WINCE |
---|
| 48 | currentGeometry = QApplication::desktop()->availableGeometry(0); |
---|
| 49 | // We need to react to SIP show/hide and resize the window appropriately |
---|
| 50 | connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int))); |
---|
| 51 | #endif // Q_OS_WINCE |
---|
[899d1b8e15] | 52 | connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered())); |
---|
[993d5af6f6] | 53 | connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered())); |
---|
[aaf2113307] | 54 | connect(actionFileSave,SIGNAL(triggered()),this,SLOT(actionFileSaveTriggered())); |
---|
[430bd7f7e9] | 55 | connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered())); |
---|
| 56 | connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered())); |
---|
[4ccf855df8] | 57 | #ifndef QT_NO_PRINTER |
---|
| 58 | connect(actionFilePrintPreview,SIGNAL(triggered()),this,SLOT(actionFilePrintPreviewTriggered())); |
---|
| 59 | connect(actionFilePrint,SIGNAL(triggered()),this,SLOT(actionFilePrintTriggered())); |
---|
| 60 | #endif // QT_NO_PRINTER |
---|
[899d1b8e15] | 61 | connect(actionSettingsPreferences,SIGNAL(triggered()),this,SLOT(actionSettingsPreferencesTriggered())); |
---|
[394216e468] | 62 | #ifdef Q_OS_WIN32 |
---|
| 63 | connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered())); |
---|
| 64 | #endif // Q_OS_WIN32 |
---|
[899d1b8e15] | 65 | connect(actionSettingsLanguageAutodetect,SIGNAL(triggered(bool)),this,SLOT(actionSettingsLanguageAutodetectTriggered(bool))); |
---|
| 66 | connect(groupSettingsLanguageList,SIGNAL(triggered(QAction *)),this,SLOT(groupSettingsLanguageListTriggered(QAction *))); |
---|
[690f6939a7] | 67 | connect(actionHelpAboutQt,SIGNAL(triggered()),qApp,SLOT(aboutQt())); |
---|
[899d1b8e15] | 68 | connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(actionHelpAboutTriggered())); |
---|
[4ccf855df8] | 69 | |
---|
[899d1b8e15] | 70 | connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked())); |
---|
| 71 | connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked())); |
---|
[aaf2113307] | 72 | connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked())); |
---|
[899d1b8e15] | 73 | connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int))); |
---|
[0ac9690913] | 74 | |
---|
[6beb157497] | 75 | #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
---|
[278bc7818f] | 76 | // Centering main window |
---|
| 77 | QRect rect = geometry(); |
---|
| 78 | rect.moveCenter(QApplication::desktop()->availableGeometry(this).center()); |
---|
| 79 | setGeometry(rect); |
---|
[946f442ab0] | 80 | if (settings->value("SavePos", DEF_SAVEPOS).toBool()) { |
---|
[aecdf994f9] | 81 | // Loading of saved window state |
---|
[665d32434f] | 82 | settings->beginGroup("MainWindow"); |
---|
[0ac9690913] | 83 | restoreGeometry(settings->value("Geometry").toByteArray()); |
---|
| 84 | restoreState(settings->value("State").toByteArray()); |
---|
[665d32434f] | 85 | settings->endGroup(); |
---|
[0ac9690913] | 86 | } |
---|
[6beb157497] | 87 | #else |
---|
[b2bf8e3b6b] | 88 | setWindowState(Qt::WindowMaximized); |
---|
[6beb157497] | 89 | #endif // Q_OS_WINCE |
---|
[0ac9690913] | 90 | |
---|
| 91 | tspmodel = new CTSPModel(this); |
---|
[56dca709c9] | 92 | taskView->setModel(tspmodel); |
---|
[993d5af6f6] | 93 | connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int))); |
---|
[2fb523720a] | 94 | connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged(const QModelIndex &, const QModelIndex &))); |
---|
[690f6939a7] | 95 | connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged())); |
---|
[aaf2113307] | 96 | if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) |
---|
[b424a7e320] | 97 | setFileName(QCoreApplication::arguments().at(1)); |
---|
[aaf2113307] | 98 | else { |
---|
[b424a7e320] | 99 | setFileName(); |
---|
[aaf2113307] | 100 | spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt()); |
---|
[56dca709c9] | 101 | spinCitiesValueChanged(spinCities->value()); |
---|
[aaf2113307] | 102 | } |
---|
| 103 | setWindowModified(false); |
---|
[003e4193be] | 104 | } |
---|
[052d1b9331] | 105 | |
---|
[4ccf855df8] | 106 | MainWindow::~MainWindow() |
---|
| 107 | { |
---|
| 108 | #ifndef QT_NO_PRINTER |
---|
| 109 | delete printer; |
---|
| 110 | #endif |
---|
| 111 | } |
---|
| 112 | |
---|
[e0fcac5f2c] | 113 | /* Privates **********************************************************/ |
---|
[899d1b8e15] | 114 | |
---|
| 115 | void MainWindow::actionFileNewTriggered() |
---|
| 116 | { |
---|
[b424a7e320] | 117 | if (!maybeSave()) |
---|
| 118 | return; |
---|
[c10297cf73] | 119 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
[899d1b8e15] | 120 | tspmodel->clear(); |
---|
[b424a7e320] | 121 | setFileName(); |
---|
[690f6939a7] | 122 | setWindowModified(false); |
---|
[430bd7f7e9] | 123 | tabWidget->setCurrentIndex(0); |
---|
| 124 | solutionText->clear(); |
---|
[1fbf016a09] | 125 | toggleSolutionActions(false); |
---|
[c10297cf73] | 126 | QApplication::restoreOverrideCursor(); |
---|
[899d1b8e15] | 127 | } |
---|
| 128 | |
---|
[993d5af6f6] | 129 | void MainWindow::actionFileOpenTriggered() |
---|
| 130 | { |
---|
[b424a7e320] | 131 | if (!maybeSave()) |
---|
| 132 | return; |
---|
[1fbf016a09] | 133 | |
---|
[1757eb594b] | 134 | QStringList filters(tr("All Supported Formats") + " (*.tspt *.zkt)"); |
---|
| 135 | filters.append(tr("%1 Task Files").arg("TSPSG") + " (*.tspt)"); |
---|
| 136 | filters.append(tr("%1 Task Files").arg("ZKomModRd") + " (*.zkt)"); |
---|
| 137 | filters.append(tr("All Files") + " (*)"); |
---|
[1fbf016a09] | 138 | |
---|
[394216e468] | 139 | QString file = QFileInfo(fileName).canonicalPath(); |
---|
[946f442ab0] | 140 | QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; |
---|
[394216e468] | 141 | file = QFileDialog::getOpenFileName(this, tr("Task Load"), file, filters.join(";;"), NULL, opts); |
---|
[1fbf016a09] | 142 | if (file.isEmpty() || !QFileInfo(file).isFile()) |
---|
[b424a7e320] | 143 | return; |
---|
[1fbf016a09] | 144 | if (!tspmodel->loadTask(file)) |
---|
[993d5af6f6] | 145 | return; |
---|
[1fbf016a09] | 146 | setFileName(file); |
---|
[b424a7e320] | 147 | tabWidget->setCurrentIndex(0); |
---|
[690f6939a7] | 148 | setWindowModified(false); |
---|
[430bd7f7e9] | 149 | solutionText->clear(); |
---|
[1fbf016a09] | 150 | toggleSolutionActions(false); |
---|
[993d5af6f6] | 151 | } |
---|
| 152 | |
---|
[394216e468] | 153 | bool MainWindow::actionFileSaveTriggered() |
---|
[aaf2113307] | 154 | { |
---|
[162d5c5f94] | 155 | if ((fileName == tr("Untitled") + ".tspt") || (!fileName.endsWith(".tspt", Qt::CaseInsensitive))) |
---|
[394216e468] | 156 | return saveTask(); |
---|
[244c614c6b] | 157 | else |
---|
[394216e468] | 158 | if (tspmodel->saveTask(fileName)) { |
---|
[aaf2113307] | 159 | setWindowModified(false); |
---|
[394216e468] | 160 | return true; |
---|
| 161 | } else |
---|
| 162 | return false; |
---|
[aaf2113307] | 163 | } |
---|
| 164 | |
---|
[430bd7f7e9] | 165 | void MainWindow::actionFileSaveAsTaskTriggered() |
---|
[993d5af6f6] | 166 | { |
---|
[690f6939a7] | 167 | saveTask(); |
---|
| 168 | } |
---|
| 169 | |
---|
[430bd7f7e9] | 170 | void MainWindow::actionFileSaveAsSolutionTriggered() |
---|
| 171 | { |
---|
| 172 | static QString selectedFile; |
---|
[394216e468] | 173 | if (selectedFile.isEmpty()) |
---|
| 174 | selectedFile = QFileInfo(fileName).canonicalPath(); |
---|
| 175 | else |
---|
| 176 | selectedFile = QFileInfo(selectedFile).canonicalPath(); |
---|
| 177 | if (!selectedFile.isEmpty()) |
---|
| 178 | selectedFile += "/"; |
---|
| 179 | if (fileName == tr("Untitled") + ".tspt") { |
---|
[1fbf016a09] | 180 | #ifndef QT_NO_PRINTER |
---|
[394216e468] | 181 | selectedFile += "solution.pdf"; |
---|
[1fbf016a09] | 182 | #else |
---|
[394216e468] | 183 | selectedFile += "solution.html"; |
---|
[1fbf016a09] | 184 | #endif // QT_NO_PRINTER |
---|
[394216e468] | 185 | } else { |
---|
[6dfdef0c3e] | 186 | #ifndef QT_NO_PRINTER |
---|
[394216e468] | 187 | selectedFile += QFileInfo(fileName).completeBaseName() + ".pdf"; |
---|
[6dfdef0c3e] | 188 | #else |
---|
[394216e468] | 189 | selectedFile += QFileInfo(fileName).completeBaseName() + ".html"; |
---|
[6dfdef0c3e] | 190 | #endif // QT_NO_PRINTER |
---|
[1fbf016a09] | 191 | } |
---|
| 192 | |
---|
[6dfdef0c3e] | 193 | QStringList filters; |
---|
| 194 | #ifndef QT_NO_PRINTER |
---|
[1757eb594b] | 195 | filters.append(tr("PDF Files") + " (*.pdf)"); |
---|
[6dfdef0c3e] | 196 | #endif |
---|
[1757eb594b] | 197 | filters.append(tr("HTML Files") + " (*.html *.htm)"); |
---|
[ec54b4490b] | 198 | #if QT_VERSION >= 0x040500 |
---|
[1757eb594b] | 199 | filters.append(tr("OpenDocument Files") + " (*.odt)"); |
---|
[ec54b4490b] | 200 | #endif // QT_VERSION >= 0x040500 |
---|
[1757eb594b] | 201 | filters.append(tr("All Files") + " (*)"); |
---|
[1fbf016a09] | 202 | |
---|
[394216e468] | 203 | QFileDialog::Options opts(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog); |
---|
[946f442ab0] | 204 | QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, opts); |
---|
[1fbf016a09] | 205 | if (file.isEmpty()) |
---|
[430bd7f7e9] | 206 | return; |
---|
[1fbf016a09] | 207 | selectedFile = file; |
---|
[f44855d99e] | 208 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
[6dfdef0c3e] | 209 | #ifndef QT_NO_PRINTER |
---|
| 210 | if (selectedFile.endsWith(".pdf",Qt::CaseInsensitive)) { |
---|
| 211 | QPrinter printer(QPrinter::HighResolution); |
---|
| 212 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
| 213 | printer.setOutputFileName(selectedFile); |
---|
| 214 | solutionText->document()->print(&printer); |
---|
| 215 | QApplication::restoreOverrideCursor(); |
---|
| 216 | return; |
---|
| 217 | } |
---|
| 218 | #endif |
---|
[ec54b4490b] | 219 | #if QT_VERSION >= 0x040500 |
---|
[430bd7f7e9] | 220 | QTextDocumentWriter dw(selectedFile); |
---|
| 221 | if (!(selectedFile.endsWith(".htm",Qt::CaseInsensitive) || selectedFile.endsWith(".html",Qt::CaseInsensitive) || selectedFile.endsWith(".odt",Qt::CaseInsensitive) || selectedFile.endsWith(".txt",Qt::CaseInsensitive))) |
---|
| 222 | dw.setFormat("plaintext"); |
---|
[394216e468] | 223 | if (!dw.write(solutionText->document())) |
---|
| 224 | QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString())); |
---|
| 225 | #else // QT_VERSION >= 0x040500 |
---|
[ec54b4490b] | 226 | // Qt < 4.5 has no QTextDocumentWriter class |
---|
| 227 | QFile file(selectedFile); |
---|
[f44855d99e] | 228 | if (!file.open(QFile::WriteOnly)) { |
---|
| 229 | QApplication::restoreOverrideCursor(); |
---|
[394216e468] | 230 | QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file->errorString())); |
---|
[ec54b4490b] | 231 | return; |
---|
[f44855d99e] | 232 | } |
---|
[ec54b4490b] | 233 | QTextStream ts(&file); |
---|
| 234 | ts.setCodec(QTextCodec::codecForName("UTF-8")); |
---|
| 235 | ts << solutionText->document()->toHtml("UTF-8"); |
---|
[f44855d99e] | 236 | file.close(); |
---|
[ec54b4490b] | 237 | #endif // QT_VERSION >= 0x040500 |
---|
[f44855d99e] | 238 | QApplication::restoreOverrideCursor(); |
---|
[430bd7f7e9] | 239 | } |
---|
| 240 | |
---|
[c10297cf73] | 241 | #ifndef QT_NO_PRINTER |
---|
[56dca709c9] | 242 | void MainWindow::actionFilePrintPreviewTriggered() |
---|
| 243 | { |
---|
| 244 | QPrintPreviewDialog ppd(printer, this); |
---|
[11086c2def] | 245 | connect(&ppd,SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *))); |
---|
| 246 | ppd.exec(); |
---|
[56dca709c9] | 247 | } |
---|
| 248 | |
---|
| 249 | void MainWindow::actionFilePrintTriggered() |
---|
[5354a01311] | 250 | { |
---|
[899d1b8e15] | 251 | QPrintDialog pd(printer,this); |
---|
[140912822f] | 252 | #if QT_VERSION >= 0x040500 |
---|
| 253 | // No such methods in Qt < 4.5 |
---|
[899d1b8e15] | 254 | pd.setOption(QAbstractPrintDialog::PrintSelection,false); |
---|
| 255 | pd.setOption(QAbstractPrintDialog::PrintPageRange,false); |
---|
[140912822f] | 256 | #endif |
---|
[56dca709c9] | 257 | if (pd.exec() != QDialog::Accepted) |
---|
| 258 | return; |
---|
[c10297cf73] | 259 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
[56dca709c9] | 260 | solutionText->document()->print(printer); |
---|
[c10297cf73] | 261 | QApplication::restoreOverrideCursor(); |
---|
[5354a01311] | 262 | } |
---|
[c10297cf73] | 263 | #endif // QT_NO_PRINTER |
---|
[5354a01311] | 264 | |
---|
[e0fcac5f2c] | 265 | void MainWindow::actionSettingsPreferencesTriggered() |
---|
[bb994a7ff8] | 266 | { |
---|
[e0fcac5f2c] | 267 | SettingsDialog sd(this); |
---|
| 268 | if (sd.exec() != QDialog::Accepted) |
---|
| 269 | return; |
---|
| 270 | if (sd.colorChanged() || sd.fontChanged()) { |
---|
| 271 | initDocStyleSheet(); |
---|
[394216e468] | 272 | if (!solutionText->document()->isEmpty() && sd.colorChanged()) |
---|
| 273 | QMessageBox::information(this, tr("Settings Changed"), tr("You have changed color settings.\nThey will be applied to the next solution output.")); |
---|
[e0fcac5f2c] | 274 | } |
---|
[394216e468] | 275 | if (sd.translucencyChanged() != 0) |
---|
[11086c2def] | 276 | toggleTranclucency(sd.translucencyChanged() == 1); |
---|
[e0fcac5f2c] | 277 | } |
---|
| 278 | |
---|
| 279 | void MainWindow::actionSettingsLanguageAutodetectTriggered(bool checked) |
---|
| 280 | { |
---|
| 281 | if (checked) { |
---|
| 282 | settings->remove("Language"); |
---|
[b2bf8e3b6b] | 283 | QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on next application start.")); |
---|
[e0fcac5f2c] | 284 | } else |
---|
[b2bf8e3b6b] | 285 | settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString()); |
---|
[e0fcac5f2c] | 286 | } |
---|
| 287 | |
---|
| 288 | void MainWindow::groupSettingsLanguageListTriggered(QAction *action) |
---|
| 289 | { |
---|
| 290 | if (actionSettingsLanguageAutodetect->isChecked()) { |
---|
| 291 | // We have language autodetection. It needs to be disabled to change language. |
---|
[394216e468] | 292 | if (QMessageBox::question(this, tr("Language change"), tr("You have language autodetection turned on.\nIt needs to be off.\nDo you wish to turn it off?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { |
---|
[e0fcac5f2c] | 293 | actionSettingsLanguageAutodetect->trigger(); |
---|
| 294 | } else |
---|
| 295 | return; |
---|
| 296 | } |
---|
[1757eb594b] | 297 | bool untitled = (fileName == tr("Untitled") + ".tspt"); |
---|
[e0fcac5f2c] | 298 | if (loadLanguage(action->data().toString())) { |
---|
[4ccf855df8] | 299 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
[e0fcac5f2c] | 300 | settings->setValue("Language",action->data().toString()); |
---|
[4ccf855df8] | 301 | retranslateUi(); |
---|
[e0fcac5f2c] | 302 | if (untitled) |
---|
| 303 | setFileName(); |
---|
[e2abfd326f] | 304 | #ifdef Q_OS_WIN32 |
---|
| 305 | if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool()) { |
---|
| 306 | toggleStyle(labelVariant, true); |
---|
| 307 | toggleStyle(labelCities, true); |
---|
| 308 | } |
---|
| 309 | #endif |
---|
[4ccf855df8] | 310 | QApplication::restoreOverrideCursor(); |
---|
[394216e468] | 311 | QMessageBox::information(this, tr("Settings Changed"), tr("You have changed the application language.\nTo get current solution output in the new language\nyou need to re-run the solution process.")); |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | #ifdef Q_OS_WIN32 |
---|
| 316 | void MainWindow::actionHelpCheck4UpdatesTriggered() |
---|
| 317 | { |
---|
| 318 | if (!hasUpdater()) { |
---|
| 319 | QMessageBox::warning(this, tr("Unsupported Feature"), tr("Sorry, but this feature is not supported on your platform\nor support for this feature was not installed.")); |
---|
| 320 | return; |
---|
[e0fcac5f2c] | 321 | } |
---|
[394216e468] | 322 | |
---|
| 323 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 324 | QProcess::execute("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\""); |
---|
| 325 | QApplication::restoreOverrideCursor(); |
---|
[e0fcac5f2c] | 326 | } |
---|
[394216e468] | 327 | #endif // Q_OS_WIN32 |
---|
[e0fcac5f2c] | 328 | |
---|
| 329 | void MainWindow::actionHelpAboutTriggered() |
---|
| 330 | { |
---|
[1fbf016a09] | 331 | QString title; |
---|
[6beb157497] | 332 | #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
---|
[e2abfd326f] | 333 | title += QString("<b>TSPSG<br>TSP Solver and Generator</b><br>"); |
---|
[1fbf016a09] | 334 | #else |
---|
[e2abfd326f] | 335 | title += QString("<b>TSPSG: TSP Solver and Generator</b><br>"); |
---|
| 336 | #endif // Q_OS_WINCE || Q_OS_SYMBIAN |
---|
[394216e468] | 337 | title += QString("%1: <b>%2</b><br>").arg(tr("Version"), QApplication::applicationVersion()); |
---|
[e2abfd326f] | 338 | #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
---|
[394216e468] | 339 | title += QString("<b>© 2007-%1 <a href=\"http://%2/\">%3</a></b><br>").arg(QDate::currentDate().toString("yyyy"), QApplication::organizationDomain(), QApplication::organizationName()); |
---|
[e2abfd326f] | 340 | title += QString("<b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sourceforge.net/</a></b>"); |
---|
| 341 | #else |
---|
| 342 | title += QString("<b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sf.net/</a></b>"); |
---|
| 343 | #endif // Q_OS_WINCE && Q_OS_SYMBIAN |
---|
| 344 | |
---|
[1fbf016a09] | 345 | QString about; |
---|
[e2abfd326f] | 346 | about += QString("%1: <b>%2</b><br>").arg(tr("Target OS (ARCH)"), OS); |
---|
[1fbf016a09] | 347 | #ifndef STATIC_BUILD |
---|
[e2abfd326f] | 348 | about += QString("%1 (%2):<br>").arg(tr("Qt library"), tr("shared")); |
---|
| 349 | about += QString(" %1: <b>%2</b><br>").arg(tr("Build time"), QT_VERSION_STR); |
---|
| 350 | about += QString(" %1: <b>%2</b><br>").arg(tr("Runtime"), qVersion()); |
---|
[1fbf016a09] | 351 | #else |
---|
[e2abfd326f] | 352 | about += QString("%1: <b>%2</b> (%3)<br>").arg(tr("Qt library"), QT_VERSION_STR, tr("static")); |
---|
[1fbf016a09] | 353 | #endif // STATIC_BUILD |
---|
[e2abfd326f] | 354 | about += tr("Buid <b>%1</b>, built on <b>%2</b> at <b>%3</b>").arg(BUILD_NUMBER).arg(__DATE__).arg(__TIME__) + "<br>"; |
---|
| 355 | about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId()); |
---|
[f0464480db] | 356 | about += "<br>"; |
---|
[e2abfd326f] | 357 | about += tr("TSPSG is free software: you can redistribute it and/or modify it<br>" |
---|
[f0464480db] | 358 | "under the terms of the GNU General Public License as published<br>" |
---|
| 359 | "by the Free Software Foundation, either version 3 of the License,<br>" |
---|
| 360 | "or (at your option) any later version.<br>" |
---|
| 361 | "<br>" |
---|
| 362 | "TSPSG is distributed in the hope that it will be useful, but<br>" |
---|
| 363 | "WITHOUT ANY WARRANTY; without even the implied warranty of<br>" |
---|
| 364 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>" |
---|
| 365 | "GNU General Public License for more details.<br>" |
---|
| 366 | "<br>" |
---|
| 367 | "You should have received a copy of the GNU General Public License<br>" |
---|
[e2abfd326f] | 368 | "along with TSPSG. If not, see <a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a>."); |
---|
[f0464480db] | 369 | |
---|
| 370 | QDialog *dlg = new QDialog(this); |
---|
[1fbf016a09] | 371 | QLabel *lblIcon = new QLabel(dlg), |
---|
[e2abfd326f] | 372 | *lblTitle = new QLabel(dlg), |
---|
| 373 | *lblTranslated = new QLabel(dlg); |
---|
| 374 | #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
---|
| 375 | QLabel *lblSubTitle = new QLabel(QString("<b>© 2007-%1 Oleksii \"Lёppa\" Serdiuk</b>").arg(QDate::currentDate().toString("yyyy")), dlg); |
---|
| 376 | #endif // Q_OS_WINCE || Q_OS_SYMBIAN |
---|
[f0464480db] | 377 | QTextBrowser *txtAbout = new QTextBrowser(dlg); |
---|
[1fbf016a09] | 378 | QVBoxLayout *vb = new QVBoxLayout(); |
---|
[e2abfd326f] | 379 | QHBoxLayout *hb1 = new QHBoxLayout(), |
---|
| 380 | *hb2 = new QHBoxLayout(); |
---|
[f0464480db] | 381 | QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg); |
---|
| 382 | |
---|
[1fbf016a09] | 383 | lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(logicalDpiX() * 2 / 3, Qt::SmoothTransformation)); |
---|
| 384 | lblIcon->setAlignment(Qt::AlignTop); |
---|
[e2abfd326f] | 385 | #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
---|
| 386 | lblIcon->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().windowText().color().name())); |
---|
| 387 | #endif |
---|
| 388 | |
---|
[4ccf855df8] | 389 | lblTitle->setOpenExternalLinks(true); |
---|
[1fbf016a09] | 390 | lblTitle->setText(title); |
---|
[e2abfd326f] | 391 | lblTitle->setAlignment(Qt::AlignTop); |
---|
| 392 | lblTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
---|
| 393 | #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
---|
| 394 | lblTitle->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().shadow().color().name())); |
---|
| 395 | #endif |
---|
[f0464480db] | 396 | |
---|
[e2abfd326f] | 397 | hb1->addWidget(lblIcon); |
---|
| 398 | hb1->addWidget(lblTitle); |
---|
[f0464480db] | 399 | |
---|
| 400 | txtAbout->setWordWrapMode(QTextOption::NoWrap); |
---|
| 401 | txtAbout->setOpenExternalLinks(true); |
---|
| 402 | txtAbout->setHtml(about); |
---|
| 403 | txtAbout->moveCursor(QTextCursor::Start); |
---|
[e2abfd326f] | 404 | #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
---|
| 405 | txtAbout->setStyleSheet(QString("QTextBrowser {border-color: %1; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().shadow().color().name())); |
---|
| 406 | #endif |
---|
[f0464480db] | 407 | |
---|
[11086c2def] | 408 | bb->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor)); |
---|
| 409 | |
---|
[e2abfd326f] | 410 | lblTranslated->setText(QApplication::translate("--------", "TRANSLATION", "Please, provide translator credits here.")); |
---|
| 411 | if (lblTranslated->text() == "TRANSLATION") |
---|
| 412 | lblTranslated->hide(); |
---|
| 413 | else { |
---|
| 414 | lblTranslated->setOpenExternalLinks(true); |
---|
| 415 | #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
---|
| 416 | lblTranslated->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().shadow().color().name())); |
---|
| 417 | #endif |
---|
| 418 | hb2->addWidget(lblTranslated); |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | hb2->addWidget(bb); |
---|
| 422 | |
---|
| 423 | #if defined(Q_OS_WINCE) |
---|
| 424 | vb->setMargin(3); |
---|
| 425 | #endif |
---|
| 426 | vb->addLayout(hb1); |
---|
| 427 | #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
---|
| 428 | vb->addWidget(lblSubTitle); |
---|
| 429 | #endif // Q_OS_WINCE || Q_OS_SYMBIAN |
---|
[1fbf016a09] | 430 | vb->addWidget(txtAbout); |
---|
[e2abfd326f] | 431 | vb->addLayout(hb2); |
---|
[f0464480db] | 432 | |
---|
[394216e468] | 433 | dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
---|
[1757eb594b] | 434 | dlg->setWindowTitle(tr("About TSPSG")); |
---|
[1fbf016a09] | 435 | dlg->setLayout(vb); |
---|
[f0464480db] | 436 | |
---|
| 437 | connect(bb, SIGNAL(accepted()), dlg, SLOT(accept())); |
---|
| 438 | |
---|
[162d5c5f94] | 439 | #ifdef Q_OS_WIN32 |
---|
[11086c2def] | 440 | // Adding some eyecandy in Vista and 7 :-) |
---|
| 441 | if (QtWin::isCompositionEnabled()) { |
---|
| 442 | QtWin::enableBlurBehindWindow(dlg, true); |
---|
| 443 | } |
---|
[162d5c5f94] | 444 | #endif // Q_OS_WIN32 |
---|
[11086c2def] | 445 | |
---|
[e2abfd326f] | 446 | dlg->resize(450, 350); |
---|
| 447 | |
---|
[f0464480db] | 448 | dlg->exec(); |
---|
| 449 | |
---|
| 450 | delete dlg; |
---|
[aaf2113307] | 451 | } |
---|
| 452 | |
---|
| 453 | void MainWindow::buttonBackToTaskClicked() |
---|
| 454 | { |
---|
| 455 | tabWidget->setCurrentIndex(0); |
---|
[bb994a7ff8] | 456 | } |
---|
| 457 | |
---|
[e0fcac5f2c] | 458 | void MainWindow::buttonRandomClicked() |
---|
[430bd7f7e9] | 459 | { |
---|
[e0fcac5f2c] | 460 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 461 | tspmodel->randomize(); |
---|
| 462 | QApplication::restoreOverrideCursor(); |
---|
[430bd7f7e9] | 463 | } |
---|
| 464 | |
---|
[899d1b8e15] | 465 | void MainWindow::buttonSolveClicked() |
---|
[bb994a7ff8] | 466 | { |
---|
[f0464480db] | 467 | TMatrix matrix; |
---|
[e4ae9e95f7] | 468 | QList<double> row; |
---|
[2bc8e278b7] | 469 | int n = spinCities->value(); |
---|
[e664262f7d] | 470 | bool ok; |
---|
[2bc8e278b7] | 471 | for (int r = 0; r < n; r++) { |
---|
[430bd7f7e9] | 472 | row.clear(); |
---|
[2bc8e278b7] | 473 | for (int c = 0; c < n; c++) { |
---|
[e4ae9e95f7] | 474 | row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok)); |
---|
[2bc8e278b7] | 475 | if (!ok) { |
---|
[394216e468] | 476 | QMessageBox::critical(this, tr("Data error"), tr("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1)); |
---|
[2bc8e278b7] | 477 | return; |
---|
[e664262f7d] | 478 | } |
---|
| 479 | } |
---|
| 480 | matrix.append(row); |
---|
| 481 | } |
---|
[394216e468] | 482 | |
---|
| 483 | QProgressDialog pd(this); |
---|
| 484 | QProgressBar *pb = new QProgressBar(&pd); |
---|
| 485 | pb->setAlignment(Qt::AlignCenter); |
---|
| 486 | pb->setFormat(tr("%v of %1 parts found").arg(n)); |
---|
| 487 | pd.setBar(pb); |
---|
| 488 | pd.setMaximum(n * 2 + 3); |
---|
| 489 | pd.setMinimumDuration(1000); |
---|
| 490 | pd.setLabelText(tr("Calculating optimal route...")); |
---|
| 491 | pd.setWindowTitle(tr("Solution Progress")); |
---|
| 492 | pd.setWindowModality(Qt::ApplicationModal); |
---|
| 493 | pd.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint); |
---|
| 494 | pd.setValue(0); |
---|
| 495 | |
---|
[e664262f7d] | 496 | CTSPSolver solver; |
---|
[394216e468] | 497 | connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); |
---|
| 498 | connect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); |
---|
| 499 | SStep *root = solver.solve(n, matrix); |
---|
| 500 | disconnect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); |
---|
| 501 | disconnect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); |
---|
| 502 | if (!root) { |
---|
| 503 | pd.reset(); |
---|
| 504 | if (!solver.wasCanceled()) |
---|
| 505 | QMessageBox::warning(this, tr("Solution Result"), tr("Unable to find a solution.\nMaybe, this task has no solution.")); |
---|
[430bd7f7e9] | 506 | return; |
---|
[394216e468] | 507 | } |
---|
| 508 | pb->setFormat("%p%"); |
---|
| 509 | pd.setLabelText(tr("Generating solution output...")); |
---|
| 510 | pd.setValue(n + 1); |
---|
| 511 | |
---|
| 512 | solutionText->clear(); |
---|
| 513 | pd.setValue(n + 2); |
---|
| 514 | |
---|
| 515 | solutionText->setDocumentTitle(tr("Solution of Variant #%1 task").arg(spinVariant->value())); |
---|
| 516 | solutionText->append("<p>" + tr("Variant #%1").arg(spinVariant->value()) + "</p>"); |
---|
| 517 | solutionText->append("<p>" + tr("Task:") + "</p>"); |
---|
| 518 | solutionText->append(outputMatrix(matrix)); |
---|
| 519 | solutionText->append("<hr><p>" + tr("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>"); |
---|
[f0464480db] | 520 | SStep *step = root; |
---|
[430bd7f7e9] | 521 | n = 1; |
---|
| 522 | while (n <= spinCities->value()) { |
---|
[394216e468] | 523 | if (pd.wasCanceled()) { |
---|
| 524 | solutionText->clear(); |
---|
| 525 | return; |
---|
| 526 | } |
---|
| 527 | pd.setValue(spinCities->value() + 2 + n); |
---|
| 528 | |
---|
[f0464480db] | 529 | if (step->prNode->prNode != NULL || ((step->prNode->prNode == NULL) && (step->plNode->prNode == NULL))) { |
---|
[430bd7f7e9] | 530 | if (n != spinCities->value()) { |
---|
[394216e468] | 531 | solutionText->append("<p>" + tr("Step #%1").arg(n++) + "</p>"); |
---|
[8203c075d5] | 532 | if (settings->value("Output/ShowMatrix", DEF_SHOW_MATRIX).toBool() && (!settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() || (settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() && (spinCities->value() <= settings->value("Output/ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt())))) { |
---|
[394216e468] | 533 | solutionText->append(outputMatrix(*step)); |
---|
[1fbf016a09] | 534 | } |
---|
[394216e468] | 535 | solutionText->append("<p>" + tr("Selected candidate for branching: %1.").arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)) + "</p>"); |
---|
[f0464480db] | 536 | if (!step->alts.empty()) { |
---|
[fcaa74f7d7] | 537 | SCandidate cand; |
---|
[f0464480db] | 538 | QString alts; |
---|
| 539 | foreach(cand, step->alts) { |
---|
| 540 | if (!alts.isEmpty()) |
---|
| 541 | alts += ", "; |
---|
[1757eb594b] | 542 | alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1); |
---|
[f0464480db] | 543 | } |
---|
[394216e468] | 544 | solutionText->append("<p class=\"hasalts\">" + tr("%n alternate candidate(s) for branching: %1.","",step->alts.count()).arg(alts) + "</p>"); |
---|
[f0464480db] | 545 | } |
---|
[394216e468] | 546 | solutionText->append("<p> </p>"); |
---|
[430bd7f7e9] | 547 | } |
---|
| 548 | } |
---|
| 549 | if (step->prNode->prNode != NULL) |
---|
| 550 | step = step->prNode; |
---|
| 551 | else if (step->plNode->prNode != NULL) |
---|
| 552 | step = step->plNode; |
---|
| 553 | else |
---|
| 554 | break; |
---|
| 555 | } |
---|
[394216e468] | 556 | pd.setValue(spinCities->value() + 2 + n); |
---|
| 557 | |
---|
[9cf98b9bd6] | 558 | if (solver.isOptimal()) |
---|
[394216e468] | 559 | solutionText->append("<p>" + tr("Optimal path:") + "</p>"); |
---|
[9cf98b9bd6] | 560 | else |
---|
[394216e468] | 561 | solutionText->append("<p>" + tr("Resulting path:") + "</p>"); |
---|
| 562 | solutionText->append("<p> " + solver.getSortedPath() + "</p>"); |
---|
[f1fb54b9f7] | 563 | if (isInteger(step->price)) |
---|
[394216e468] | 564 | solutionText->append("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>"); |
---|
[f1fb54b9f7] | 565 | else |
---|
[394216e468] | 566 | solutionText->append("<p>" + tr("The price is <b>%1</b> units.").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()) + "</p>"); |
---|
[9cf98b9bd6] | 567 | if (!solver.isOptimal()) { |
---|
[394216e468] | 568 | solutionText->append("<p> </p>"); |
---|
| 569 | solutionText->append("<p>" + tr("<b>WARNING!!!</b><br>This result is a record, but it may not be optimal.<br>Iterations need to be continued to check whether this result is optimal or get an optimal one.") + "</p>"); |
---|
[9cf98b9bd6] | 570 | } |
---|
[caef58b531] | 571 | |
---|
[f1fb54b9f7] | 572 | if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) { |
---|
| 573 | // Scrolling to the end of text. |
---|
| 574 | solutionText->moveCursor(QTextCursor::End); |
---|
[394216e468] | 575 | } else |
---|
| 576 | solutionText->moveCursor(QTextCursor::Start); |
---|
| 577 | |
---|
| 578 | pd.setLabelText(tr("Cleaning up...")); |
---|
| 579 | pd.setMaximum(0); |
---|
| 580 | pd.setCancelButton(NULL); |
---|
| 581 | pd.adjustSize(); |
---|
| 582 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
| 583 | solver.cleanup(true); |
---|
[1fbf016a09] | 584 | toggleSolutionActions(); |
---|
[430bd7f7e9] | 585 | tabWidget->setCurrentIndex(1); |
---|
[bb994a7ff8] | 586 | } |
---|
[aecdf994f9] | 587 | |
---|
[e0fcac5f2c] | 588 | void MainWindow::dataChanged() |
---|
[aecdf994f9] | 589 | { |
---|
[e0fcac5f2c] | 590 | setWindowModified(true); |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | void MainWindow::dataChanged(const QModelIndex &tl, const QModelIndex &br) |
---|
| 594 | { |
---|
| 595 | setWindowModified(true); |
---|
[946f442ab0] | 596 | if (settings->value("Autosize", DEF_AUTOSIZE).toBool()) { |
---|
[e0fcac5f2c] | 597 | for (int k = tl.row(); k <= br.row(); k++) |
---|
| 598 | taskView->resizeRowToContents(k); |
---|
| 599 | for (int k = tl.column(); k <= br.column(); k++) |
---|
| 600 | taskView->resizeColumnToContents(k); |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | |
---|
[b2bf8e3b6b] | 604 | #ifdef Q_OS_WINCE |
---|
[278bc7818f] | 605 | void MainWindow::changeEvent(QEvent *ev) |
---|
| 606 | { |
---|
| 607 | if ((ev->type() == QEvent::ActivationChange) && isActiveWindow()) |
---|
| 608 | desktopResized(0); |
---|
| 609 | |
---|
| 610 | QWidget::changeEvent(ev); |
---|
| 611 | } |
---|
| 612 | |
---|
[b2bf8e3b6b] | 613 | void MainWindow::desktopResized(int screen) |
---|
| 614 | { |
---|
[278bc7818f] | 615 | if ((screen != 0) || !isActiveWindow()) |
---|
[b2bf8e3b6b] | 616 | return; |
---|
| 617 | |
---|
| 618 | QRect availableGeometry = QApplication::desktop()->availableGeometry(0); |
---|
| 619 | if (currentGeometry != availableGeometry) { |
---|
[278bc7818f] | 620 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
[b2bf8e3b6b] | 621 | /*! |
---|
| 622 | * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height. |
---|
| 623 | * If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the |
---|
| 624 | * window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile? |
---|
| 625 | */ |
---|
| 626 | if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) { |
---|
| 627 | setWindowState(windowState() | Qt::WindowMaximized); |
---|
| 628 | } else { |
---|
| 629 | if (windowState() & Qt::WindowMaximized) |
---|
| 630 | setWindowState(windowState() ^ Qt::WindowMaximized); |
---|
| 631 | setGeometry(availableGeometry); |
---|
| 632 | } |
---|
[278bc7818f] | 633 | currentGeometry = availableGeometry; |
---|
| 634 | QApplication::restoreOverrideCursor(); |
---|
[b2bf8e3b6b] | 635 | } |
---|
| 636 | } |
---|
| 637 | #endif // Q_OS_WINCE |
---|
| 638 | |
---|
[e0fcac5f2c] | 639 | void MainWindow::numCitiesChanged(int nCities) |
---|
| 640 | { |
---|
| 641 | blockSignals(true); |
---|
| 642 | spinCities->setValue(nCities); |
---|
| 643 | blockSignals(false); |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | #ifndef QT_NO_PRINTER |
---|
| 647 | void MainWindow::printPreview(QPrinter *printer) |
---|
| 648 | { |
---|
| 649 | solutionText->print(printer); |
---|
| 650 | } |
---|
| 651 | #endif // QT_NO_PRINTER |
---|
| 652 | |
---|
| 653 | void MainWindow::spinCitiesValueChanged(int n) |
---|
| 654 | { |
---|
[4ccf855df8] | 655 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
[e0fcac5f2c] | 656 | int count = tspmodel->numCities(); |
---|
| 657 | tspmodel->setNumCities(n); |
---|
[946f442ab0] | 658 | if ((n > count) && settings->value("Autosize", DEF_AUTOSIZE).toBool()) |
---|
[e0fcac5f2c] | 659 | for (int k = count; k < n; k++) { |
---|
| 660 | taskView->resizeColumnToContents(k); |
---|
| 661 | taskView->resizeRowToContents(k); |
---|
| 662 | } |
---|
[4ccf855df8] | 663 | QApplication::restoreOverrideCursor(); |
---|
[e0fcac5f2c] | 664 | } |
---|
| 665 | |
---|
[0ac9690913] | 666 | void MainWindow::closeEvent(QCloseEvent *ev) |
---|
[f383cb181c] | 667 | { |
---|
| 668 | if (!maybeSave()) { |
---|
[0ac9690913] | 669 | ev->ignore(); |
---|
[f383cb181c] | 670 | return; |
---|
| 671 | } |
---|
[278bc7818f] | 672 | if (!settings->value("SettingsReset", false).toBool()) { |
---|
| 673 | settings->setValue("NumCities", spinCities->value()); |
---|
[0ac9690913] | 674 | |
---|
[278bc7818f] | 675 | // Saving Main Window state |
---|
| 676 | if (settings->value("SavePos", DEF_SAVEPOS).toBool()) { |
---|
| 677 | settings->beginGroup("MainWindow"); |
---|
[6beb157497] | 678 | #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
---|
[278bc7818f] | 679 | settings->setValue("Geometry", saveGeometry()); |
---|
[0ac9690913] | 680 | #endif // Q_OS_WINCE |
---|
[278bc7818f] | 681 | settings->setValue("State", saveState()); |
---|
| 682 | settings->endGroup(); |
---|
| 683 | } |
---|
| 684 | } else { |
---|
| 685 | settings->remove("SettingsReset"); |
---|
[f383cb181c] | 686 | } |
---|
[0ac9690913] | 687 | |
---|
| 688 | QMainWindow::closeEvent(ev); |
---|
[f383cb181c] | 689 | } |
---|
| 690 | |
---|
[394216e468] | 691 | bool MainWindow::hasUpdater() const |
---|
| 692 | { |
---|
| 693 | #ifdef Q_OS_WIN32 |
---|
| 694 | return QFile::exists("updater/Update.exe"); |
---|
| 695 | #else // Q_OS_WIN32 |
---|
| 696 | return false; |
---|
| 697 | #endif // Q_OS_WIN32 |
---|
| 698 | } |
---|
| 699 | |
---|
[e0fcac5f2c] | 700 | void MainWindow::initDocStyleSheet() |
---|
| 701 | { |
---|
| 702 | QColor color = settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>(); |
---|
| 703 | QColor hilight; |
---|
| 704 | if (color.value() < 192) |
---|
| 705 | hilight.setHsv(color.hue(),color.saturation(),127 + qRound(color.value() / 2)); |
---|
| 706 | else |
---|
| 707 | hilight.setHsv(color.hue(),color.saturation(),color.value() / 2); |
---|
| 708 | solutionText->document()->setDefaultStyleSheet("* {color: " + color.name() +";} p {margin: 0px 10px;} table {margin: 5px;} td {padding: 1px 5px;} .hasalts {color: " + hilight.name() + ";} .selected {color: #A00000; font-weight: bold;} .alternate {color: #008000; font-weight: bold;}"); |
---|
| 709 | solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>()); |
---|
[aecdf994f9] | 710 | } |
---|
| 711 | |
---|
[899d1b8e15] | 712 | void MainWindow::loadLangList() |
---|
| 713 | { |
---|
[162d5c5f94] | 714 | QDir dir(PATH_L10N, "tspsg_*.qm", QDir::Name | QDir::IgnoreCase, QDir::Files); |
---|
[899d1b8e15] | 715 | if (!dir.exists()) |
---|
| 716 | return; |
---|
| 717 | QFileInfoList langs = dir.entryInfoList(); |
---|
| 718 | if (langs.size() <= 0) |
---|
| 719 | return; |
---|
| 720 | QAction *a; |
---|
[b2bf8e3b6b] | 721 | QTranslator t; |
---|
| 722 | QString name; |
---|
[899d1b8e15] | 723 | for (int k = 0; k < langs.size(); k++) { |
---|
| 724 | QFileInfo lang = langs.at(k); |
---|
[162d5c5f94] | 725 | if (lang.completeBaseName().compare("tspsg_en", Qt::CaseInsensitive) && t.load(lang.completeBaseName(), PATH_L10N)) { |
---|
[b2bf8e3b6b] | 726 | name = t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here."); |
---|
| 727 | a = menuSettingsLanguage->addAction(name); |
---|
| 728 | a->setStatusTip(QString("Set application language to %1").arg(name)); |
---|
| 729 | a->setData(lang.completeBaseName().mid(6)); |
---|
[899d1b8e15] | 730 | a->setCheckable(true); |
---|
| 731 | a->setActionGroup(groupSettingsLanguageList); |
---|
[b2bf8e3b6b] | 732 | if (settings->value("Language", QLocale::system().name()).toString().startsWith(lang.completeBaseName().mid(6))) |
---|
[899d1b8e15] | 733 | a->setChecked(true); |
---|
| 734 | } |
---|
| 735 | } |
---|
| 736 | } |
---|
| 737 | |
---|
[0ac9690913] | 738 | bool MainWindow::loadLanguage(const QString &lang) |
---|
[899d1b8e15] | 739 | { |
---|
[e0fcac5f2c] | 740 | // i18n |
---|
| 741 | bool ad = false; |
---|
[0ac9690913] | 742 | QString lng = lang; |
---|
| 743 | if (lng.isEmpty()) { |
---|
[6beb157497] | 744 | ad = settings->value("Language", "").toString().isEmpty(); |
---|
| 745 | lng = settings->value("Language", QLocale::system().name()).toString(); |
---|
[899d1b8e15] | 746 | } |
---|
[e0fcac5f2c] | 747 | static QTranslator *qtTranslator; // Qt library translator |
---|
| 748 | if (qtTranslator) { |
---|
| 749 | qApp->removeTranslator(qtTranslator); |
---|
| 750 | delete qtTranslator; |
---|
| 751 | qtTranslator = NULL; |
---|
[899d1b8e15] | 752 | } |
---|
[e0fcac5f2c] | 753 | static QTranslator *translator; // Application translator |
---|
| 754 | if (translator) { |
---|
| 755 | qApp->removeTranslator(translator); |
---|
| 756 | delete translator; |
---|
[4ccf855df8] | 757 | translator = NULL; |
---|
[690f6939a7] | 758 | } |
---|
[4ccf855df8] | 759 | |
---|
| 760 | if (lng == "en") |
---|
| 761 | return true; |
---|
| 762 | |
---|
| 763 | // Trying to load system Qt library translation... |
---|
| 764 | qtTranslator = new QTranslator(this); |
---|
[6beb157497] | 765 | if (qtTranslator->load("qt_" + lng, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) |
---|
[4ccf855df8] | 766 | qApp->installTranslator(qtTranslator); |
---|
| 767 | else { |
---|
| 768 | // No luck. Let's try to load a bundled one. |
---|
[162d5c5f94] | 769 | if (qtTranslator->load("qt_" + lng, PATH_L10N)) |
---|
[e0fcac5f2c] | 770 | qApp->installTranslator(qtTranslator); |
---|
[f0464480db] | 771 | else { |
---|
[4ccf855df8] | 772 | // Qt library translation unavailable |
---|
| 773 | delete qtTranslator; |
---|
| 774 | qtTranslator = NULL; |
---|
[f0464480db] | 775 | } |
---|
| 776 | } |
---|
[4ccf855df8] | 777 | |
---|
[f0464480db] | 778 | // Now let's load application translation. |
---|
[4ccf855df8] | 779 | translator = new QTranslator(this); |
---|
[162d5c5f94] | 780 | if (translator->load("tspsg_" + lng, PATH_L10N)) |
---|
[f0464480db] | 781 | qApp->installTranslator(translator); |
---|
| 782 | else { |
---|
| 783 | delete translator; |
---|
| 784 | translator = NULL; |
---|
[b2bf8e3b6b] | 785 | if (!ad) { |
---|
| 786 | settings->remove("Language"); |
---|
[394216e468] | 787 | QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); |
---|
[b2bf8e3b6b] | 788 | if (isVisible()) |
---|
| 789 | QMessageBox::warning(this, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection.")); |
---|
| 790 | else |
---|
| 791 | QMessageBox::warning(NULL, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection.")); |
---|
[394216e468] | 792 | QApplication::restoreOverrideCursor(); |
---|
[b2bf8e3b6b] | 793 | } |
---|
[4ccf855df8] | 794 | return false; |
---|
[aecdf994f9] | 795 | } |
---|
[e0fcac5f2c] | 796 | return true; |
---|
[aecdf994f9] | 797 | } |
---|
[993d5af6f6] | 798 | |
---|
[e0fcac5f2c] | 799 | bool MainWindow::maybeSave() |
---|
[690f6939a7] | 800 | { |
---|
[e0fcac5f2c] | 801 | if (!isWindowModified()) |
---|
| 802 | return true; |
---|
[394216e468] | 803 | int res = QMessageBox::warning(this, tr("Unsaved Changes"), tr("Would you like to save changes in the current task?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); |
---|
[e0fcac5f2c] | 804 | if (res == QMessageBox::Save) |
---|
[394216e468] | 805 | return actionFileSaveTriggered(); |
---|
[e0fcac5f2c] | 806 | else if (res == QMessageBox::Cancel) |
---|
| 807 | return false; |
---|
| 808 | else |
---|
| 809 | return true; |
---|
[690f6939a7] | 810 | } |
---|
| 811 | |
---|
[394216e468] | 812 | QString MainWindow::outputMatrix(const TMatrix &matrix) const |
---|
[2fb523720a] | 813 | { |
---|
[e0fcac5f2c] | 814 | int n = spinCities->value(); |
---|
[394216e468] | 815 | QString output(""), line; |
---|
[e0fcac5f2c] | 816 | output.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"); |
---|
| 817 | for (int r = 0; r < n; r++) { |
---|
| 818 | line = "<tr>"; |
---|
| 819 | for (int c = 0; c < n; c++) { |
---|
[0ac9690913] | 820 | if (matrix.at(r).at(c) == INFINITY) |
---|
[e0fcac5f2c] | 821 | line += "<td align=\"center\">"INFSTR"</td>"; |
---|
| 822 | else |
---|
[1757eb594b] | 823 | line += isInteger(matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); |
---|
[e0fcac5f2c] | 824 | } |
---|
| 825 | line += "</tr>"; |
---|
| 826 | output.append(line); |
---|
[f0464480db] | 827 | } |
---|
| 828 | output.append("</table>"); |
---|
[394216e468] | 829 | return output; |
---|
[f0464480db] | 830 | } |
---|
| 831 | |
---|
[394216e468] | 832 | QString MainWindow::outputMatrix(const SStep &step) const |
---|
[f0464480db] | 833 | { |
---|
| 834 | int n = spinCities->value(); |
---|
[394216e468] | 835 | QString output(""), line; |
---|
[f0464480db] | 836 | output.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"); |
---|
| 837 | for (int r = 0; r < n; r++) { |
---|
| 838 | line = "<tr>"; |
---|
| 839 | for (int c = 0; c < n; c++) { |
---|
| 840 | if (step.matrix.at(r).at(c) == INFINITY) |
---|
| 841 | line += "<td align=\"center\">"INFSTR"</td>"; |
---|
| 842 | else if ((r == step.candidate.nRow) && (c == step.candidate.nCol)) |
---|
[1757eb594b] | 843 | line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); |
---|
[f0464480db] | 844 | else { |
---|
[fcaa74f7d7] | 845 | SCandidate cand; |
---|
[f0464480db] | 846 | cand.nRow = r; |
---|
| 847 | cand.nCol = c; |
---|
| 848 | if (step.alts.contains(cand)) |
---|
[1757eb594b] | 849 | line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); |
---|
[f0464480db] | 850 | else |
---|
[1757eb594b] | 851 | line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); |
---|
[f0464480db] | 852 | } |
---|
| 853 | } |
---|
| 854 | line += "</tr>"; |
---|
| 855 | output.append(line); |
---|
[2fb523720a] | 856 | } |
---|
[e0fcac5f2c] | 857 | output.append("</table>"); |
---|
[394216e468] | 858 | return output; |
---|
[2fb523720a] | 859 | } |
---|
| 860 | |
---|
[4ccf855df8] | 861 | void MainWindow::retranslateUi(bool all) |
---|
| 862 | { |
---|
| 863 | if (all) |
---|
| 864 | Ui::MainWindow::retranslateUi(this); |
---|
| 865 | |
---|
[b2bf8e3b6b] | 866 | actionSettingsLanguageEnglish->setStatusTip(tr("Set application language to %1").arg("English")); |
---|
| 867 | |
---|
[4ccf855df8] | 868 | #ifndef QT_NO_PRINTER |
---|
| 869 | actionFilePrintPreview->setText(QApplication::translate("MainWindow", "P&rint Preview...", 0, QApplication::UnicodeUTF8)); |
---|
| 870 | #ifndef QT_NO_TOOLTIP |
---|
| 871 | actionFilePrintPreview->setToolTip(QApplication::translate("MainWindow", "Preview solution results", 0, QApplication::UnicodeUTF8)); |
---|
| 872 | #endif // QT_NO_TOOLTIP |
---|
| 873 | #ifndef QT_NO_STATUSTIP |
---|
| 874 | actionFilePrintPreview->setStatusTip(QApplication::translate("MainWindow", "Preview current solution results before printing", 0, QApplication::UnicodeUTF8)); |
---|
| 875 | #endif // QT_NO_STATUSTIP |
---|
| 876 | |
---|
| 877 | actionFilePrint->setText(QApplication::translate("MainWindow", "&Print...", 0, QApplication::UnicodeUTF8)); |
---|
| 878 | #ifndef QT_NO_TOOLTIP |
---|
| 879 | actionFilePrint->setToolTip(QApplication::translate("MainWindow", "Print solution", 0, QApplication::UnicodeUTF8)); |
---|
| 880 | #endif // QT_NO_TOOLTIP |
---|
| 881 | #ifndef QT_NO_STATUSTIP |
---|
| 882 | actionFilePrint->setStatusTip(QApplication::translate("MainWindow", "Print current solution results", 0, QApplication::UnicodeUTF8)); |
---|
| 883 | #endif // QT_NO_STATUSTIP |
---|
| 884 | actionFilePrint->setShortcut(QApplication::translate("MainWindow", "Ctrl+P", 0, QApplication::UnicodeUTF8)); |
---|
| 885 | #endif // QT_NO_PRINTER |
---|
[394216e468] | 886 | #ifdef Q_OS_WIN32 |
---|
| 887 | actionHelpCheck4Updates->setText(tr("Check for &Updates...")); |
---|
| 888 | #ifndef QT_NO_TOOLTIP |
---|
| 889 | actionHelpCheck4Updates->setToolTip(tr("Check for %1 updates").arg(QApplication::applicationName())); |
---|
| 890 | #endif // QT_NO_TOOLTIP |
---|
| 891 | #ifndef QT_NO_STATUSTIP |
---|
| 892 | actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QApplication::applicationName())); |
---|
| 893 | #endif // QT_NO_STATUSTIP |
---|
| 894 | #endif // Q_OS_WIN32 |
---|
[4ccf855df8] | 895 | } |
---|
| 896 | |
---|
[e0fcac5f2c] | 897 | bool MainWindow::saveTask() { |
---|
[1757eb594b] | 898 | QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)"); |
---|
| 899 | filters.append(tr("All Files") + " (*)"); |
---|
[1fbf016a09] | 900 | QString file; |
---|
| 901 | if (fileName.endsWith(".tspt", Qt::CaseInsensitive)) |
---|
| 902 | file = fileName; |
---|
[e0fcac5f2c] | 903 | else |
---|
[1fbf016a09] | 904 | file = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"; |
---|
| 905 | |
---|
[946f442ab0] | 906 | QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; |
---|
[1757eb594b] | 907 | file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts); |
---|
[4ccf855df8] | 908 | |
---|
[1fbf016a09] | 909 | if (file.isEmpty()) |
---|
[e0fcac5f2c] | 910 | return false; |
---|
[1fbf016a09] | 911 | if (tspmodel->saveTask(file)) { |
---|
| 912 | setFileName(file); |
---|
[e0fcac5f2c] | 913 | setWindowModified(false); |
---|
| 914 | return true; |
---|
| 915 | } |
---|
| 916 | return false; |
---|
| 917 | } |
---|
| 918 | |
---|
[0ac9690913] | 919 | void MainWindow::setFileName(const QString &fileName) |
---|
[993d5af6f6] | 920 | { |
---|
[e0fcac5f2c] | 921 | this->fileName = fileName; |
---|
[1757eb594b] | 922 | setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(tr("Travelling Salesman Problem"))); |
---|
[993d5af6f6] | 923 | } |
---|
[1fbf016a09] | 924 | |
---|
[4ccf855df8] | 925 | void MainWindow::setupUi() |
---|
| 926 | { |
---|
| 927 | Ui::MainWindow::setupUi(this); |
---|
| 928 | |
---|
| 929 | #if QT_VERSION >= 0x040600 |
---|
| 930 | setToolButtonStyle(Qt::ToolButtonFollowStyle); |
---|
| 931 | #endif |
---|
| 932 | |
---|
[6beb157497] | 933 | #if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
---|
[4ccf855df8] | 934 | QStatusBar *statusbar = new QStatusBar(this); |
---|
| 935 | statusbar->setObjectName("statusbar"); |
---|
| 936 | setStatusBar(statusbar); |
---|
| 937 | #endif // Q_OS_WINCE |
---|
| 938 | |
---|
| 939 | #ifdef Q_OS_WINCE |
---|
[11086c2def] | 940 | menuBar()->setDefaultAction(menuFile->menuAction()); |
---|
[b2bf8e3b6b] | 941 | |
---|
| 942 | QScrollArea *scrollArea = new QScrollArea(this); |
---|
| 943 | scrollArea->setFrameShape(QFrame::NoFrame); |
---|
| 944 | scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
---|
| 945 | scrollArea->setWidgetResizable(true); |
---|
| 946 | scrollArea->setWidget(tabWidget); |
---|
| 947 | setCentralWidget(scrollArea); |
---|
[e2abfd326f] | 948 | #else |
---|
| 949 | setCentralWidget(tabWidget); |
---|
[11086c2def] | 950 | #endif // Q_OS_WINCE |
---|
| 951 | |
---|
[4ccf855df8] | 952 | //! \hack HACK: A little hack for toolbar icons to have a sane size. |
---|
[6beb157497] | 953 | #ifdef Q_OS_WINCE |
---|
[4ccf855df8] | 954 | toolBar->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4)); |
---|
[6beb157497] | 955 | #elif defined(Q_OS_SYMBIAN) |
---|
| 956 | toolBar->setIconSize(QSize(logicalDpiX() / 5, logicalDpiY() / 5)); |
---|
[11086c2def] | 957 | #endif // Q_OS_WINCE |
---|
[4ccf855df8] | 958 | |
---|
| 959 | solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>()); |
---|
| 960 | solutionText->setTextColor(settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>()); |
---|
| 961 | solutionText->setWordWrapMode(QTextOption::WordWrap); |
---|
| 962 | |
---|
| 963 | #ifndef QT_NO_PRINTER |
---|
| 964 | actionFilePrintPreview = new QAction(this); |
---|
| 965 | actionFilePrintPreview->setObjectName("actionFilePrintPreview"); |
---|
| 966 | actionFilePrintPreview->setEnabled(false); |
---|
| 967 | actionFilePrintPreview->setIcon(QIcon(":/images/icons/document_preview.png")); |
---|
| 968 | |
---|
| 969 | actionFilePrint = new QAction(this); |
---|
| 970 | actionFilePrint->setObjectName("actionFilePrint"); |
---|
| 971 | actionFilePrint->setEnabled(false); |
---|
| 972 | actionFilePrint->setIcon(QIcon(":/images/icons/fileprint.png")); |
---|
| 973 | |
---|
| 974 | menuFile->insertAction(actionFileExit,actionFilePrintPreview); |
---|
| 975 | menuFile->insertAction(actionFileExit,actionFilePrint); |
---|
| 976 | menuFile->insertSeparator(actionFileExit); |
---|
| 977 | |
---|
| 978 | toolBar->insertAction(actionSettingsPreferences,actionFilePrint); |
---|
| 979 | #endif // QT_NO_PRINTER |
---|
[394216e468] | 980 | #ifdef Q_OS_WIN32 |
---|
| 981 | actionHelpCheck4Updates = new QAction(this); |
---|
| 982 | actionHelpCheck4Updates->setEnabled(hasUpdater()); |
---|
| 983 | menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates); |
---|
| 984 | menuHelp->insertSeparator(actionHelpAboutQt); |
---|
| 985 | #endif // Q_OS_WIN32 |
---|
[4ccf855df8] | 986 | |
---|
| 987 | groupSettingsLanguageList = new QActionGroup(this); |
---|
| 988 | actionSettingsLanguageEnglish->setData("en"); |
---|
| 989 | actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList); |
---|
| 990 | loadLangList(); |
---|
[b2bf8e3b6b] | 991 | actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty()); |
---|
[4ccf855df8] | 992 | |
---|
| 993 | spinCities->setMaximum(MAX_NUM_CITIES); |
---|
| 994 | |
---|
| 995 | retranslateUi(false); |
---|
| 996 | |
---|
[162d5c5f94] | 997 | #ifdef Q_OS_WIN32 |
---|
[11086c2def] | 998 | // Adding some eyecandy in Vista and 7 :-) |
---|
| 999 | if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool()) { |
---|
| 1000 | toggleTranclucency(true); |
---|
| 1001 | } |
---|
[162d5c5f94] | 1002 | #endif // Q_OS_WIN32 |
---|
[4ccf855df8] | 1003 | } |
---|
| 1004 | |
---|
[1fbf016a09] | 1005 | void MainWindow::toggleSolutionActions(bool enable) |
---|
| 1006 | { |
---|
| 1007 | buttonSaveSolution->setEnabled(enable); |
---|
| 1008 | actionFileSaveAsSolution->setEnabled(enable); |
---|
| 1009 | solutionText->setEnabled(enable); |
---|
| 1010 | #ifndef QT_NO_PRINTER |
---|
| 1011 | actionFilePrint->setEnabled(enable); |
---|
| 1012 | actionFilePrintPreview->setEnabled(enable); |
---|
| 1013 | #endif // QT_NO_PRINTER |
---|
| 1014 | } |
---|
[11086c2def] | 1015 | |
---|
| 1016 | void MainWindow::toggleTranclucency(bool enable) |
---|
| 1017 | { |
---|
[162d5c5f94] | 1018 | #ifdef Q_OS_WIN32 |
---|
[e2abfd326f] | 1019 | toggleStyle(labelVariant, enable); |
---|
| 1020 | toggleStyle(labelCities, enable); |
---|
| 1021 | toggleStyle(statusBar(), enable); |
---|
[f19df0a3e5] | 1022 | tabWidget->setDocumentMode(enable); |
---|
[11086c2def] | 1023 | QtWin::enableBlurBehindWindow(this, enable); |
---|
[162d5c5f94] | 1024 | #else |
---|
| 1025 | Q_UNUSED(enable); |
---|
| 1026 | #endif // Q_OS_WIN32 |
---|
[11086c2def] | 1027 | } |
---|