[1babbd6ba3] | 1 | /* |
---|
| 2 | * TSPSG: TSP Solver and Generator |
---|
| 3 | * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> |
---|
| 4 | * |
---|
| 5 | * $Id$ |
---|
| 6 | * $URL$ |
---|
| 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 "mainwindow.h" |
---|
| 25 | |
---|
[43c29c04ba] | 26 | #ifdef Q_OS_WIN32 |
---|
| 27 | #include "shobjidl.h" |
---|
| 28 | #endif |
---|
| 29 | |
---|
[3cadf24d00] | 30 | #ifdef _T_T_L_ |
---|
| 31 | #include "_.h" |
---|
[e9db3e216b] | 32 | _C_ _R_ _Y_ _P_ _T_ |
---|
[3cadf24d00] | 33 | #endif |
---|
| 34 | |
---|
[1babbd6ba3] | 35 | /*! |
---|
| 36 | * \brief Class constructor. |
---|
| 37 | * \param parent Main Window parent widget. |
---|
| 38 | * |
---|
| 39 | * Initializes Main Window and creates its layout based on target OS. |
---|
| 40 | * Loads TSPSG settings and opens a task file if it was specified as a commandline parameter. |
---|
| 41 | */ |
---|
| 42 | MainWindow::MainWindow(QWidget *parent) |
---|
| 43 | : QMainWindow(parent) |
---|
| 44 | { |
---|
| 45 | settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this); |
---|
| 46 | |
---|
[e3533af1cf] | 47 | if (settings->contains("Style")) { |
---|
| 48 | QStyle *s = QStyleFactory::create(settings->value("Style").toString()); |
---|
| 49 | if (s != NULL) |
---|
| 50 | QApplication::setStyle(s); |
---|
| 51 | else |
---|
| 52 | settings->remove("Style"); |
---|
| 53 | } |
---|
| 54 | |
---|
[1babbd6ba3] | 55 | loadLanguage(); |
---|
| 56 | setupUi(); |
---|
[b574c383b7] | 57 | setAcceptDrops(true); |
---|
[1babbd6ba3] | 58 | |
---|
| 59 | initDocStyleSheet(); |
---|
| 60 | |
---|
| 61 | #ifndef QT_NO_PRINTER |
---|
| 62 | printer = new QPrinter(QPrinter::HighResolution); |
---|
| 63 | #endif // QT_NO_PRINTER |
---|
| 64 | |
---|
| 65 | #ifdef Q_OS_WINCE_WM |
---|
| 66 | currentGeometry = QApplication::desktop()->availableGeometry(0); |
---|
| 67 | // We need to react to SIP show/hide and resize the window appropriately |
---|
| 68 | connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int))); |
---|
| 69 | #endif // Q_OS_WINCE_WM |
---|
[e51c78af27] | 70 | connect(actionFileNew, SIGNAL(triggered()), SLOT(actionFileNewTriggered())); |
---|
| 71 | connect(actionFileOpen, SIGNAL(triggered()), SLOT(actionFileOpenTriggered())); |
---|
| 72 | connect(actionFileSave, SIGNAL(triggered()), SLOT(actionFileSaveTriggered())); |
---|
| 73 | connect(actionFileSaveAsTask, SIGNAL(triggered()), SLOT(actionFileSaveAsTaskTriggered())); |
---|
| 74 | connect(actionFileSaveAsSolution, SIGNAL(triggered()), SLOT(actionFileSaveAsSolutionTriggered())); |
---|
[1babbd6ba3] | 75 | #ifndef QT_NO_PRINTER |
---|
[e51c78af27] | 76 | connect(actionFilePrintPreview, SIGNAL(triggered()), SLOT(actionFilePrintPreviewTriggered())); |
---|
| 77 | connect(actionFilePrint, SIGNAL(triggered()), SLOT(actionFilePrintTriggered())); |
---|
[1babbd6ba3] | 78 | #endif // QT_NO_PRINTER |
---|
[7bb19df196] | 79 | #ifndef HANDHELD |
---|
| 80 | connect(actionSettingsToolbarsConfigure, SIGNAL(triggered()), SLOT(actionSettingsToolbarsConfigureTriggered())); |
---|
| 81 | #endif // HANDHELD |
---|
[e51c78af27] | 82 | connect(actionSettingsPreferences, SIGNAL(triggered()), SLOT(actionSettingsPreferencesTriggered())); |
---|
[1babbd6ba3] | 83 | #ifdef Q_OS_WIN32 |
---|
| 84 | connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered())); |
---|
| 85 | #endif // Q_OS_WIN32 |
---|
[e51c78af27] | 86 | connect(actionSettingsLanguageAutodetect, SIGNAL(triggered(bool)), SLOT(actionSettingsLanguageAutodetectTriggered(bool))); |
---|
| 87 | connect(groupSettingsLanguageList, SIGNAL(triggered(QAction *)), SLOT(groupSettingsLanguageListTriggered(QAction *))); |
---|
[e3533af1cf] | 88 | connect(actionSettingsStyleSystem, SIGNAL(triggered(bool)), SLOT(actionSettingsStyleSystemTriggered(bool))); |
---|
| 89 | connect(groupSettingsStyleList, SIGNAL(triggered(QAction*)), SLOT(groupSettingsStyleListTriggered(QAction*))); |
---|
[e51c78af27] | 90 | connect(actionHelpAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); |
---|
| 91 | connect(actionHelpAbout, SIGNAL(triggered()), SLOT(actionHelpAboutTriggered())); |
---|
[1babbd6ba3] | 92 | |
---|
[e51c78af27] | 93 | connect(buttonSolve, SIGNAL(clicked()), SLOT(buttonSolveClicked())); |
---|
| 94 | connect(buttonRandom, SIGNAL(clicked()), SLOT(buttonRandomClicked())); |
---|
| 95 | connect(buttonBackToTask, SIGNAL(clicked()), SLOT(buttonBackToTaskClicked())); |
---|
| 96 | connect(spinCities, SIGNAL(valueChanged(int)), SLOT(spinCitiesValueChanged(int))); |
---|
[1babbd6ba3] | 97 | |
---|
| 98 | #ifndef HANDHELD |
---|
| 99 | // Centering main window |
---|
| 100 | QRect rect = geometry(); |
---|
| 101 | rect.moveCenter(QApplication::desktop()->availableGeometry(this).center()); |
---|
| 102 | setGeometry(rect); |
---|
| 103 | if (settings->value("SavePos", DEF_SAVEPOS).toBool()) { |
---|
| 104 | // Loading of saved window state |
---|
| 105 | settings->beginGroup("MainWindow"); |
---|
| 106 | restoreGeometry(settings->value("Geometry").toByteArray()); |
---|
| 107 | restoreState(settings->value("State").toByteArray()); |
---|
| 108 | settings->endGroup(); |
---|
| 109 | } |
---|
| 110 | #endif // HANDHELD |
---|
| 111 | |
---|
| 112 | tspmodel = new CTSPModel(this); |
---|
| 113 | taskView->setModel(tspmodel); |
---|
[e51c78af27] | 114 | connect(tspmodel, SIGNAL(numCitiesChanged(int)), SLOT(numCitiesChanged(int))); |
---|
| 115 | connect(tspmodel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(dataChanged(const QModelIndex &, const QModelIndex &))); |
---|
| 116 | connect(tspmodel, SIGNAL(layoutChanged()), SLOT(dataChanged())); |
---|
[1babbd6ba3] | 117 | if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) |
---|
| 118 | setFileName(QCoreApplication::arguments().at(1)); |
---|
| 119 | else { |
---|
| 120 | setFileName(); |
---|
| 121 | spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt()); |
---|
| 122 | spinCitiesValueChanged(spinCities->value()); |
---|
| 123 | } |
---|
| 124 | setWindowModified(false); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | MainWindow::~MainWindow() |
---|
| 128 | { |
---|
| 129 | #ifndef QT_NO_PRINTER |
---|
| 130 | delete printer; |
---|
| 131 | #endif |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /* Privates **********************************************************/ |
---|
| 135 | |
---|
| 136 | void MainWindow::actionFileNewTriggered() |
---|
| 137 | { |
---|
| 138 | if (!maybeSave()) |
---|
| 139 | return; |
---|
| 140 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 141 | tspmodel->clear(); |
---|
| 142 | setFileName(); |
---|
| 143 | setWindowModified(false); |
---|
| 144 | tabWidget->setCurrentIndex(0); |
---|
| 145 | solutionText->clear(); |
---|
| 146 | toggleSolutionActions(false); |
---|
| 147 | QApplication::restoreOverrideCursor(); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void MainWindow::actionFileOpenTriggered() |
---|
| 151 | { |
---|
| 152 | if (!maybeSave()) |
---|
| 153 | return; |
---|
| 154 | |
---|
| 155 | QStringList filters(tr("All Supported Formats") + " (*.tspt *.zkt)"); |
---|
| 156 | filters.append(tr("%1 Task Files").arg("TSPSG") + " (*.tspt)"); |
---|
| 157 | filters.append(tr("%1 Task Files").arg("ZKomModRd") + " (*.zkt)"); |
---|
| 158 | filters.append(tr("All Files") + " (*)"); |
---|
| 159 | |
---|
[ac76a6a753] | 160 | QString file; |
---|
| 161 | if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
[bbac1ebb13] | 162 | file = settings->value(OS"/LastUsed/TaskLoadPath").toString(); |
---|
[ac76a6a753] | 163 | else |
---|
| 164 | file = QFileInfo(fileName).path(); |
---|
[1babbd6ba3] | 165 | QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; |
---|
| 166 | file = QFileDialog::getOpenFileName(this, tr("Task Load"), file, filters.join(";;"), NULL, opts); |
---|
| 167 | if (file.isEmpty() || !QFileInfo(file).isFile()) |
---|
| 168 | return; |
---|
[ac76a6a753] | 169 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
[bbac1ebb13] | 170 | settings->setValue(OS"/LastUsed/TaskLoadPath", QFileInfo(file).path()); |
---|
[ac76a6a753] | 171 | |
---|
[1babbd6ba3] | 172 | if (!tspmodel->loadTask(file)) |
---|
| 173 | return; |
---|
| 174 | setFileName(file); |
---|
| 175 | tabWidget->setCurrentIndex(0); |
---|
| 176 | setWindowModified(false); |
---|
| 177 | solutionText->clear(); |
---|
| 178 | toggleSolutionActions(false); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | bool MainWindow::actionFileSaveTriggered() |
---|
| 182 | { |
---|
[ac76a6a753] | 183 | if ((fileName == tr("Untitled") + ".tspt") || !fileName.endsWith(".tspt", Qt::CaseInsensitive)) |
---|
[1babbd6ba3] | 184 | return saveTask(); |
---|
| 185 | else |
---|
| 186 | if (tspmodel->saveTask(fileName)) { |
---|
| 187 | setWindowModified(false); |
---|
| 188 | return true; |
---|
| 189 | } else |
---|
| 190 | return false; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | void MainWindow::actionFileSaveAsTaskTriggered() |
---|
| 194 | { |
---|
| 195 | saveTask(); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | void MainWindow::actionFileSaveAsSolutionTriggered() |
---|
| 199 | { |
---|
| 200 | static QString selectedFile; |
---|
[ac76a6a753] | 201 | if (selectedFile.isEmpty()) { |
---|
| 202 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) { |
---|
[bbac1ebb13] | 203 | selectedFile = settings->value(OS"/LastUsed/SolutionSavePath").toString(); |
---|
[ac76a6a753] | 204 | } |
---|
| 205 | } else |
---|
| 206 | selectedFile = QFileInfo(selectedFile).path(); |
---|
[1babbd6ba3] | 207 | if (!selectedFile.isEmpty()) |
---|
[ac76a6a753] | 208 | selectedFile.append("/"); |
---|
[1babbd6ba3] | 209 | if (fileName == tr("Untitled") + ".tspt") { |
---|
| 210 | #ifndef QT_NO_PRINTER |
---|
| 211 | selectedFile += "solution.pdf"; |
---|
| 212 | #else |
---|
| 213 | selectedFile += "solution.html"; |
---|
| 214 | #endif // QT_NO_PRINTER |
---|
| 215 | } else { |
---|
| 216 | #ifndef QT_NO_PRINTER |
---|
| 217 | selectedFile += QFileInfo(fileName).completeBaseName() + ".pdf"; |
---|
| 218 | #else |
---|
| 219 | selectedFile += QFileInfo(fileName).completeBaseName() + ".html"; |
---|
| 220 | #endif // QT_NO_PRINTER |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | QStringList filters; |
---|
| 224 | #ifndef QT_NO_PRINTER |
---|
| 225 | filters.append(tr("PDF Files") + " (*.pdf)"); |
---|
| 226 | #endif |
---|
| 227 | filters.append(tr("HTML Files") + " (*.html *.htm)"); |
---|
| 228 | filters.append(tr("OpenDocument Files") + " (*.odt)"); |
---|
| 229 | filters.append(tr("All Files") + " (*)"); |
---|
| 230 | |
---|
| 231 | QFileDialog::Options opts(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog); |
---|
| 232 | QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, opts); |
---|
| 233 | if (file.isEmpty()) |
---|
| 234 | return; |
---|
| 235 | selectedFile = file; |
---|
[ac76a6a753] | 236 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
[bbac1ebb13] | 237 | settings->setValue(OS"/LastUsed/SolutionSavePath", QFileInfo(selectedFile).path()); |
---|
[1babbd6ba3] | 238 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 239 | #ifndef QT_NO_PRINTER |
---|
| 240 | if (selectedFile.endsWith(".pdf",Qt::CaseInsensitive)) { |
---|
| 241 | QPrinter printer(QPrinter::HighResolution); |
---|
| 242 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
| 243 | printer.setOutputFileName(selectedFile); |
---|
| 244 | solutionText->document()->print(&printer); |
---|
| 245 | QApplication::restoreOverrideCursor(); |
---|
| 246 | return; |
---|
| 247 | } |
---|
| 248 | #endif |
---|
[ca3d2a30fa] | 249 | if (selectedFile.endsWith(".htm", Qt::CaseInsensitive) || selectedFile.endsWith(".html", Qt::CaseInsensitive)) { |
---|
[1babbd6ba3] | 250 | QFile file(selectedFile); |
---|
[ca3d2a30fa] | 251 | if (!file.open(QFile::WriteOnly)) { |
---|
| 252 | QApplication::restoreOverrideCursor(); |
---|
| 253 | QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file.errorString())); |
---|
| 254 | return; |
---|
| 255 | } |
---|
| 256 | QFileInfo fi(selectedFile); |
---|
[20015b41e7] | 257 | QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(); |
---|
[2a436ea693] | 258 | #if !defined(NOSVG) |
---|
[20015b41e7] | 259 | if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) { |
---|
[2a436ea693] | 260 | #else // NOSVG |
---|
[20015b41e7] | 261 | if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) { |
---|
[2a436ea693] | 262 | #endif // NOSVG |
---|
[20015b41e7] | 263 | format = DEF_GRAPH_IMAGE_FORMAT; |
---|
| 264 | settings->remove("Output/GraphImageFormat"); |
---|
| 265 | } |
---|
[ca3d2a30fa] | 266 | QString html = solutionText->document()->toHtml("UTF-8"), |
---|
[20015b41e7] | 267 | img = fi.completeBaseName() + "." + format; |
---|
[7aaa0b0ec7] | 268 | html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" alt=\"%2\"").arg(img, tr("Solution Graph"))); |
---|
[20015b41e7] | 269 | |
---|
[ca3d2a30fa] | 270 | // Saving solution text as HTML |
---|
[1babbd6ba3] | 271 | QTextStream ts(&file); |
---|
[ca3d2a30fa] | 272 | ts.setCodec(QTextCodec::codecForName("UTF-8")); |
---|
| 273 | ts << html; |
---|
| 274 | file.close(); |
---|
[20015b41e7] | 275 | |
---|
| 276 | // Saving solution graph as SVG or PNG (depending on settings and SVG support) |
---|
[2a436ea693] | 277 | #if !defined(NOSVG) |
---|
[20015b41e7] | 278 | if (format == "svg") { |
---|
[ca3d2a30fa] | 279 | QSvgGenerator svg; |
---|
[20015b41e7] | 280 | svg.setSize(QSize(graph.width(), graph.height())); |
---|
| 281 | svg.setResolution(graph.logicalDpiX()); |
---|
| 282 | svg.setFileName(fi.path() + "/" + img); |
---|
| 283 | svg.setTitle(tr("Solution Graph")); |
---|
| 284 | svg.setDescription(tr("Generated with %1").arg(QApplication::applicationName())); |
---|
| 285 | QPainter p; |
---|
| 286 | p.begin(&svg); |
---|
| 287 | p.drawPicture(1, 1, graph); |
---|
| 288 | p.end(); |
---|
| 289 | } else { |
---|
[2a436ea693] | 290 | #endif // NOSVG |
---|
[7aaa0b0ec7] | 291 | QImage i(graph.width(), graph.height(), QImage::Format_ARGB32); |
---|
[20015b41e7] | 292 | i.fill(0x00FFFFFF); |
---|
[ca3d2a30fa] | 293 | QPainter p; |
---|
[20015b41e7] | 294 | p.begin(&i); |
---|
| 295 | p.drawPicture(1, 1, graph); |
---|
| 296 | p.end(); |
---|
| 297 | QImageWriter pic(fi.path() + "/" + img); |
---|
| 298 | if (pic.supportsOption(QImageIOHandler::Description)) { |
---|
| 299 | pic.setText("Title", "Solution Graph"); |
---|
| 300 | pic.setText("Software", QApplication::applicationName()); |
---|
| 301 | } |
---|
| 302 | if (format == "png") |
---|
| 303 | pic.setQuality(5); |
---|
| 304 | else if (format == "jpeg") |
---|
| 305 | pic.setQuality(80); |
---|
| 306 | if (!pic.write(i)) { |
---|
| 307 | QApplication::restoreOverrideCursor(); |
---|
| 308 | QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString())); |
---|
| 309 | return; |
---|
| 310 | } |
---|
[2a436ea693] | 311 | #if !defined(NOSVG) |
---|
[20015b41e7] | 312 | } |
---|
[2a436ea693] | 313 | #endif // NOSVG |
---|
[ca3d2a30fa] | 314 | } else { |
---|
| 315 | QTextDocumentWriter dw(selectedFile); |
---|
| 316 | if (!selectedFile.endsWith(".odt",Qt::CaseInsensitive)) |
---|
| 317 | dw.setFormat("plaintext"); |
---|
| 318 | if (!dw.write(solutionText->document())) |
---|
| 319 | QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString())); |
---|
| 320 | } |
---|
[1babbd6ba3] | 321 | QApplication::restoreOverrideCursor(); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | #ifndef QT_NO_PRINTER |
---|
| 325 | void MainWindow::actionFilePrintPreviewTriggered() |
---|
| 326 | { |
---|
| 327 | QPrintPreviewDialog ppd(printer, this); |
---|
| 328 | connect(&ppd,SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *))); |
---|
| 329 | ppd.exec(); |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | void MainWindow::actionFilePrintTriggered() |
---|
| 333 | { |
---|
| 334 | QPrintDialog pd(printer,this); |
---|
| 335 | if (pd.exec() != QDialog::Accepted) |
---|
| 336 | return; |
---|
| 337 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
[94cd045fad] | 338 | solutionText->print(printer); |
---|
[1babbd6ba3] | 339 | QApplication::restoreOverrideCursor(); |
---|
| 340 | } |
---|
| 341 | #endif // QT_NO_PRINTER |
---|
| 342 | |
---|
| 343 | void MainWindow::actionSettingsPreferencesTriggered() |
---|
| 344 | { |
---|
| 345 | SettingsDialog sd(this); |
---|
| 346 | if (sd.exec() != QDialog::Accepted) |
---|
| 347 | return; |
---|
| 348 | if (sd.colorChanged() || sd.fontChanged()) { |
---|
| 349 | if (!solutionText->document()->isEmpty() && sd.colorChanged()) |
---|
| 350 | QMessageBox::information(this, tr("Settings Changed"), tr("You have changed color settings.\nThey will be applied to the next solution output.")); |
---|
| 351 | initDocStyleSheet(); |
---|
| 352 | } |
---|
| 353 | if (sd.translucencyChanged() != 0) |
---|
| 354 | toggleTranclucency(sd.translucencyChanged() == 1); |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | void MainWindow::actionSettingsLanguageAutodetectTriggered(bool checked) |
---|
| 358 | { |
---|
| 359 | if (checked) { |
---|
| 360 | settings->remove("Language"); |
---|
[e3533af1cf] | 361 | QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on the next %1 start.").arg(QApplication::applicationName())); |
---|
[1babbd6ba3] | 362 | } else |
---|
| 363 | settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString()); |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | void MainWindow::groupSettingsLanguageListTriggered(QAction *action) |
---|
| 367 | { |
---|
| 368 | if (actionSettingsLanguageAutodetect->isChecked()) { |
---|
| 369 | // We have language autodetection. It needs to be disabled to change language. |
---|
| 370 | 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) { |
---|
| 371 | actionSettingsLanguageAutodetect->trigger(); |
---|
| 372 | } else |
---|
| 373 | return; |
---|
| 374 | } |
---|
| 375 | bool untitled = (fileName == tr("Untitled") + ".tspt"); |
---|
| 376 | if (loadLanguage(action->data().toString())) { |
---|
| 377 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 378 | settings->setValue("Language",action->data().toString()); |
---|
| 379 | retranslateUi(); |
---|
| 380 | if (untitled) |
---|
| 381 | setFileName(); |
---|
| 382 | #ifdef Q_OS_WIN32 |
---|
| 383 | if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool()) { |
---|
| 384 | toggleStyle(labelVariant, true); |
---|
| 385 | toggleStyle(labelCities, true); |
---|
| 386 | } |
---|
| 387 | #endif |
---|
| 388 | QApplication::restoreOverrideCursor(); |
---|
| 389 | if (!solutionText->document()->isEmpty()) |
---|
| 390 | 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.")); |
---|
| 391 | } |
---|
| 392 | } |
---|
| 393 | |
---|
[e3533af1cf] | 394 | void MainWindow::actionSettingsStyleSystemTriggered(bool checked) |
---|
| 395 | { |
---|
| 396 | if (checked) { |
---|
| 397 | settings->remove("Style"); |
---|
| 398 | QMessageBox::information(this, tr("Style Change"), tr("To apply the default style you need to restart %1.").arg(QApplication::applicationName())); |
---|
| 399 | } else { |
---|
| 400 | settings->setValue("Style", groupSettingsStyleList->checkedAction()->text()); |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | void MainWindow::groupSettingsStyleListTriggered(QAction *action) |
---|
| 405 | { |
---|
| 406 | QStyle *s = QStyleFactory::create(action->text()); |
---|
| 407 | if (s != NULL) { |
---|
| 408 | QApplication::setStyle(s); |
---|
| 409 | settings->setValue("Style", action->text()); |
---|
| 410 | actionSettingsStyleSystem->setChecked(false); |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | |
---|
[7bb19df196] | 414 | #ifndef HANDHELD |
---|
| 415 | void MainWindow::actionSettingsToolbarsConfigureTriggered() |
---|
| 416 | { |
---|
| 417 | QtToolBarDialog dlg(this); |
---|
| 418 | dlg.setToolBarManager(toolBarManager); |
---|
| 419 | dlg.exec(); |
---|
| 420 | QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave)); |
---|
| 421 | if (tb != NULL) { |
---|
| 422 | tb->setMenu(menuFileSaveAs); |
---|
| 423 | tb->setPopupMode(QToolButton::MenuButtonPopup); |
---|
| 424 | tb->resize(tb->sizeHint()); |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | loadToolbarList(); |
---|
| 428 | } |
---|
| 429 | #endif // HANDHELD |
---|
| 430 | |
---|
[1babbd6ba3] | 431 | #ifdef Q_OS_WIN32 |
---|
| 432 | void MainWindow::actionHelpCheck4UpdatesTriggered() |
---|
| 433 | { |
---|
| 434 | if (!hasUpdater()) { |
---|
| 435 | 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.")); |
---|
| 436 | return; |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 440 | QProcess::execute("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\""); |
---|
| 441 | QApplication::restoreOverrideCursor(); |
---|
| 442 | } |
---|
| 443 | #endif // Q_OS_WIN32 |
---|
| 444 | |
---|
| 445 | void MainWindow::actionHelpAboutTriggered() |
---|
| 446 | { |
---|
[43c29c04ba] | 447 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 448 | |
---|
[1babbd6ba3] | 449 | QString title; |
---|
[20015b41e7] | 450 | title += QString("<b>%1</b><br>").arg(QApplication::applicationName()); |
---|
[1babbd6ba3] | 451 | title += QString("%1: <b>%2</b><br>").arg(tr("Version"), QApplication::applicationVersion()); |
---|
| 452 | #ifndef HANDHELD |
---|
| 453 | title += QString("<b>© 2007-%1 <a href=\"http://%2/\">%3</a></b><br>").arg(QDate::currentDate().toString("yyyy"), QApplication::organizationDomain(), QApplication::organizationName()); |
---|
[7bb19df196] | 454 | #endif // HANDHELD |
---|
[672e522ba2] | 455 | title += QString("<b><a href=\"http://tspsg.info/\">http://tspsg.info/</a></b>"); |
---|
[1babbd6ba3] | 456 | |
---|
| 457 | QString about; |
---|
[bbac1ebb13] | 458 | about += QString("%1: <b>%2</b><br>").arg(tr("Target OS (ARCH)"), PLATFROM); |
---|
[1babbd6ba3] | 459 | #ifndef STATIC_BUILD |
---|
| 460 | about += QString("%1 (%2):<br>").arg(tr("Qt library"), tr("shared")); |
---|
| 461 | about += QString(" %1: <b>%2</b><br>").arg(tr("Build time"), QT_VERSION_STR); |
---|
| 462 | about += QString(" %1: <b>%2</b><br>").arg(tr("Runtime"), qVersion()); |
---|
| 463 | #else |
---|
| 464 | about += QString("%1: <b>%2</b> (%3)<br>").arg(tr("Qt library"), QT_VERSION_STR, tr("static")); |
---|
| 465 | #endif // STATIC_BUILD |
---|
[bbac1ebb13] | 466 | about += tr("Buid <b>%1</b>, built on <b>%2</b> at <b>%3</b> with <b>%4</b> compiler.").arg(BUILD_NUMBER).arg(__DATE__).arg(__TIME__).arg(COMPILER) + "<br>"; |
---|
[1babbd6ba3] | 467 | about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId()); |
---|
| 468 | about += "<br>"; |
---|
[43c29c04ba] | 469 | about += tr("This program is free software: you can redistribute it and/or modify<br>\n" |
---|
| 470 | "it under the terms of the GNU General Public License as published by<br>\n" |
---|
| 471 | "the Free Software Foundation, either version 3 of the License, or<br>\n" |
---|
| 472 | "(at your option) any later version.<br>\n" |
---|
| 473 | "<br>\n" |
---|
| 474 | "This program is distributed in the hope that it will be useful,<br>\n" |
---|
| 475 | "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>\n" |
---|
| 476 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>\n" |
---|
| 477 | "GNU General Public License for more details.<br>\n" |
---|
| 478 | "<br>\n" |
---|
| 479 | "You should have received a copy of the GNU General Public License<br>\n" |
---|
| 480 | "along with TSPSG. If not, see <a href=\"http://www.gnu.org/licenses/\">www.gnu.org/licenses/</a>."); |
---|
| 481 | |
---|
| 482 | QString credits; |
---|
[e26679937d] | 483 | credits += tr("%1 was created using <b>Qt framework</b> licensed " |
---|
| 484 | "under the terms of the GNU Lesser General Public License,<br>\n" |
---|
[43c29c04ba] | 485 | "see <a href=\"http://qt.nokia.com/\">qt.nokia.com</a><br>\n" |
---|
| 486 | "<br>\n" |
---|
[e26679937d] | 487 | "Most icons used in %1 are part of <b>Oxygen Icons</b> project " |
---|
[43c29c04ba] | 488 | "licensed according to the GNU Lesser General Public License,<br>\n" |
---|
| 489 | "see <a href=\"http://www.oxygen-icons.org/\">www.oxygen-icons.org</a><br>\n" |
---|
| 490 | "<br>\n" |
---|
[e26679937d] | 491 | "Country flag icons used in %1 are part of the free " |
---|
| 492 | "<b>Flag Icons</b> collection created by <b>IconDrawer</b>,<br>\n" |
---|
[cb1608daaf] | 493 | "see <a href=\"http://www.icondrawer.com/\">www.icondrawer.com</a><br>\n" |
---|
| 494 | "<br>\n" |
---|
| 495 | "%1 comes with the default \"embedded\" font <b>DejaVu LGC Sans " |
---|
| 496 | "Mono</b> from the <b>DejaVu fonts</b> licensed under a Free license</a>,<br>\n" |
---|
[b81c0a73b7] | 497 | "see <a href=\"http://dejavu-fonts.org/\">dejavu-fonts.org</a>") |
---|
| 498 | .arg("TSPSG"); |
---|
[43c29c04ba] | 499 | |
---|
| 500 | QFile f(":/files/COPYING"); |
---|
| 501 | f.open(QIODevice::ReadOnly); |
---|
| 502 | |
---|
| 503 | QString translation = QApplication::translate("--------", "AUTHORS %1", "Please, provide translator credits here. %1 will be replaced with VERSION"); |
---|
| 504 | if ((translation != "AUTHORS %1") && (translation.contains("%1"))) { |
---|
| 505 | QString about = QApplication::translate("--------", "VERSION", "Please, provide your translation version here."); |
---|
| 506 | if (about != "VERSION") |
---|
| 507 | translation = translation.arg(about); |
---|
| 508 | } |
---|
[1babbd6ba3] | 509 | |
---|
| 510 | QDialog *dlg = new QDialog(this); |
---|
| 511 | QLabel *lblIcon = new QLabel(dlg), |
---|
[43c29c04ba] | 512 | *lblTitle = new QLabel(dlg); |
---|
[1babbd6ba3] | 513 | #ifdef HANDHELD |
---|
| 514 | QLabel *lblSubTitle = new QLabel(QString("<b>© 2007-%1 <a href=\"http://%2/\">%3</a></b>").arg(QDate::currentDate().toString("yyyy"), QApplication::organizationDomain(), QApplication::organizationName()), dlg); |
---|
| 515 | #endif // HANDHELD |
---|
[43c29c04ba] | 516 | QTabWidget *tabs = new QTabWidget(dlg); |
---|
[1babbd6ba3] | 517 | QTextBrowser *txtAbout = new QTextBrowser(dlg); |
---|
[43c29c04ba] | 518 | QTextBrowser *txtLicense = new QTextBrowser(dlg); |
---|
| 519 | QTextBrowser *txtCredits = new QTextBrowser(dlg); |
---|
[1babbd6ba3] | 520 | QVBoxLayout *vb = new QVBoxLayout(); |
---|
| 521 | QHBoxLayout *hb1 = new QHBoxLayout(), |
---|
| 522 | *hb2 = new QHBoxLayout(); |
---|
| 523 | QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg); |
---|
| 524 | |
---|
| 525 | lblTitle->setOpenExternalLinks(true); |
---|
| 526 | lblTitle->setText(title); |
---|
| 527 | lblTitle->setAlignment(Qt::AlignTop); |
---|
| 528 | lblTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
---|
| 529 | #ifndef HANDHELD |
---|
[e3533af1cf] | 530 | lblTitle->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().alternateBase().color().name(), palette().shadow().color().name())); |
---|
[1babbd6ba3] | 531 | #endif // HANDHELD |
---|
| 532 | |
---|
| 533 | lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToHeight(lblTitle->sizeHint().height(), Qt::SmoothTransformation)); |
---|
| 534 | lblIcon->setAlignment(Qt::AlignVCenter); |
---|
| 535 | #ifndef HANDHELD |
---|
[e3533af1cf] | 536 | lblIcon->setStyleSheet(QString("QLabel {background-color: white; border-color: %1; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().windowText().color().name())); |
---|
[1babbd6ba3] | 537 | #endif // HANDHELD |
---|
| 538 | |
---|
| 539 | hb1->addWidget(lblIcon); |
---|
| 540 | hb1->addWidget(lblTitle); |
---|
| 541 | |
---|
| 542 | txtAbout->setWordWrapMode(QTextOption::NoWrap); |
---|
| 543 | txtAbout->setOpenExternalLinks(true); |
---|
| 544 | txtAbout->setHtml(about); |
---|
| 545 | txtAbout->moveCursor(QTextCursor::Start); |
---|
[43c29c04ba] | 546 | txtAbout->setFrameShape(QFrame::NoFrame); |
---|
[1babbd6ba3] | 547 | |
---|
[43c29c04ba] | 548 | // txtCredits->setWordWrapMode(QTextOption::NoWrap); |
---|
| 549 | txtCredits->setOpenExternalLinks(true); |
---|
| 550 | txtCredits->setHtml(credits); |
---|
| 551 | txtCredits->moveCursor(QTextCursor::Start); |
---|
| 552 | txtCredits->setFrameShape(QFrame::NoFrame); |
---|
[1babbd6ba3] | 553 | |
---|
[43c29c04ba] | 554 | txtLicense->setWordWrapMode(QTextOption::NoWrap); |
---|
| 555 | txtLicense->setOpenExternalLinks(true); |
---|
| 556 | txtLicense->setText(f.readAll()); |
---|
| 557 | txtLicense->moveCursor(QTextCursor::Start); |
---|
| 558 | txtLicense->setFrameShape(QFrame::NoFrame); |
---|
[1babbd6ba3] | 559 | |
---|
[43c29c04ba] | 560 | bb->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor)); |
---|
[2a436ea693] | 561 | bb->button(QDialogButtonBox::Ok)->setIcon(GET_ICON("dialog-ok")); |
---|
[3cadf24d00] | 562 | |
---|
[1babbd6ba3] | 563 | hb2->addWidget(bb); |
---|
| 564 | |
---|
| 565 | #ifdef Q_OS_WINCE_WM |
---|
| 566 | vb->setMargin(3); |
---|
| 567 | #endif // Q_OS_WINCE_WM |
---|
| 568 | vb->addLayout(hb1); |
---|
| 569 | #ifdef HANDHELD |
---|
| 570 | vb->addWidget(lblSubTitle); |
---|
| 571 | #endif // HANDHELD |
---|
[43c29c04ba] | 572 | |
---|
| 573 | tabs->addTab(txtAbout, tr("About")); |
---|
| 574 | tabs->addTab(txtLicense, tr("License")); |
---|
| 575 | tabs->addTab(txtCredits, tr("Credits")); |
---|
| 576 | if (translation != "AUTHORS %1") { |
---|
| 577 | QTextBrowser *txtTranslation = new QTextBrowser(dlg); |
---|
| 578 | // txtTranslation->setWordWrapMode(QTextOption::NoWrap); |
---|
| 579 | txtTranslation->setOpenExternalLinks(true); |
---|
| 580 | txtTranslation->setText(translation); |
---|
| 581 | txtTranslation->moveCursor(QTextCursor::Start); |
---|
| 582 | txtTranslation->setFrameShape(QFrame::NoFrame); |
---|
| 583 | |
---|
| 584 | tabs->addTab(txtTranslation, tr("Translation")); |
---|
| 585 | } |
---|
| 586 | #ifndef HANDHELD |
---|
| 587 | tabs->setStyleSheet(QString("QTabWidget::pane {background-color: %1; border-color: %3; border-width: 1px; border-style: solid; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; padding: 1px;} QTabBar::tab {background-color: %2; border-color: %3; border-width: 1px; border-style: solid; border-bottom: none; border-top-left-radius: 4px; border-top-right-radius: 4px; padding: 2px 6px;} QTabBar::tab:selected {background-color: %4;} QTabBar::tab:!selected {margin-top: 1px;}").arg(palette().base().color().name(), palette().button().color().name(), palette().shadow().color().name(), palette().light().color().name())); |
---|
| 588 | #endif // HANDHELD |
---|
| 589 | |
---|
| 590 | vb->addWidget(tabs); |
---|
[1babbd6ba3] | 591 | vb->addLayout(hb2); |
---|
| 592 | |
---|
| 593 | dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
---|
[e3533af1cf] | 594 | dlg->setWindowTitle(tr("About %1").arg(QApplication::applicationName())); |
---|
[2a436ea693] | 595 | dlg->setWindowIcon(GET_ICON("help-about")); |
---|
[1babbd6ba3] | 596 | dlg->setLayout(vb); |
---|
| 597 | |
---|
| 598 | connect(bb, SIGNAL(accepted()), dlg, SLOT(accept())); |
---|
| 599 | |
---|
| 600 | #ifdef Q_OS_WIN32 |
---|
| 601 | // Adding some eyecandy in Vista and 7 :-) |
---|
| 602 | if (QtWin::isCompositionEnabled()) { |
---|
| 603 | QtWin::enableBlurBehindWindow(dlg, true); |
---|
| 604 | } |
---|
| 605 | #endif // Q_OS_WIN32 |
---|
| 606 | |
---|
| 607 | dlg->resize(450, 350); |
---|
[43c29c04ba] | 608 | QApplication::restoreOverrideCursor(); |
---|
[1babbd6ba3] | 609 | |
---|
| 610 | dlg->exec(); |
---|
| 611 | |
---|
| 612 | delete dlg; |
---|
| 613 | } |
---|
| 614 | |
---|
| 615 | void MainWindow::buttonBackToTaskClicked() |
---|
| 616 | { |
---|
| 617 | tabWidget->setCurrentIndex(0); |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | void MainWindow::buttonRandomClicked() |
---|
| 621 | { |
---|
| 622 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 623 | tspmodel->randomize(); |
---|
| 624 | QApplication::restoreOverrideCursor(); |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | void MainWindow::buttonSolveClicked() |
---|
| 628 | { |
---|
| 629 | TMatrix matrix; |
---|
| 630 | QList<double> row; |
---|
| 631 | int n = spinCities->value(); |
---|
| 632 | bool ok; |
---|
| 633 | for (int r = 0; r < n; r++) { |
---|
| 634 | row.clear(); |
---|
| 635 | for (int c = 0; c < n; c++) { |
---|
| 636 | row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok)); |
---|
| 637 | if (!ok) { |
---|
| 638 | QMessageBox::critical(this, tr("Data error"), tr("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1)); |
---|
| 639 | return; |
---|
| 640 | } |
---|
| 641 | } |
---|
| 642 | matrix.append(row); |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | QProgressDialog pd(this); |
---|
| 646 | QProgressBar *pb = new QProgressBar(&pd); |
---|
| 647 | pb->setAlignment(Qt::AlignCenter); |
---|
| 648 | pb->setFormat(tr("%v of %1 parts found").arg(n)); |
---|
| 649 | pd.setBar(pb); |
---|
[43c29c04ba] | 650 | QPushButton *cancel = new QPushButton(&pd); |
---|
[2a436ea693] | 651 | cancel->setIcon(GET_ICON("dialog-cancel")); |
---|
[43c29c04ba] | 652 | cancel->setText(QApplication::translate("QProgressDialog", "Cancel", "No need to translate this. This translation will be taken from Qt translation files.")); |
---|
| 653 | pd.setCancelButton(cancel); |
---|
[1babbd6ba3] | 654 | pd.setMaximum(n); |
---|
| 655 | pd.setAutoReset(false); |
---|
| 656 | pd.setLabelText(tr("Calculating optimal route...")); |
---|
| 657 | pd.setWindowTitle(tr("Solution Progress")); |
---|
| 658 | pd.setWindowModality(Qt::ApplicationModal); |
---|
| 659 | pd.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint); |
---|
| 660 | pd.show(); |
---|
| 661 | |
---|
[43c29c04ba] | 662 | #ifdef Q_OS_WIN32 |
---|
| 663 | HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (LPVOID*)&tl); |
---|
| 664 | if (SUCCEEDED(hr)) { |
---|
| 665 | hr = tl->HrInit(); |
---|
| 666 | if (FAILED(hr)) { |
---|
| 667 | tl->Release(); |
---|
| 668 | tl = NULL; |
---|
| 669 | } else { |
---|
| 670 | // tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
| 671 | tl->SetProgressValue(winId(), 0, n * 2); |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | #endif |
---|
| 675 | |
---|
[1babbd6ba3] | 676 | CTSPSolver solver; |
---|
[43c29c04ba] | 677 | solver.setCleanupOnCancel(false); |
---|
[1babbd6ba3] | 678 | connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); |
---|
| 679 | connect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); |
---|
[43c29c04ba] | 680 | #ifdef Q_OS_WIN32 |
---|
| 681 | if (tl != NULL) |
---|
| 682 | connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int))); |
---|
| 683 | #endif |
---|
[1babbd6ba3] | 684 | SStep *root = solver.solve(n, matrix); |
---|
[43c29c04ba] | 685 | #ifdef Q_OS_WIN32 |
---|
| 686 | if (tl != NULL) |
---|
| 687 | disconnect(&solver, SIGNAL(routePartFound(int)), this, SLOT(solverRoutePartFound(int))); |
---|
| 688 | #endif |
---|
[1babbd6ba3] | 689 | disconnect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); |
---|
| 690 | disconnect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); |
---|
| 691 | if (!root) { |
---|
| 692 | pd.reset(); |
---|
[43c29c04ba] | 693 | if (!solver.wasCanceled()) { |
---|
| 694 | #ifdef Q_OS_WIN32 |
---|
| 695 | if (tl != NULL) { |
---|
| 696 | // tl->SetProgressValue(winId(), n, n * 2); |
---|
| 697 | tl->SetProgressState(winId(), TBPF_ERROR); |
---|
| 698 | } |
---|
| 699 | #endif |
---|
| 700 | QApplication::alert(this); |
---|
[1babbd6ba3] | 701 | QMessageBox::warning(this, tr("Solution Result"), tr("Unable to find a solution.\nMaybe, this task has no solution.")); |
---|
[43c29c04ba] | 702 | } |
---|
| 703 | pd.setLabelText(tr("Cleaning up...")); |
---|
| 704 | pd.setMaximum(0); |
---|
| 705 | pd.setCancelButton(NULL); |
---|
| 706 | pd.show(); |
---|
| 707 | #ifdef Q_OS_WIN32 |
---|
| 708 | if (tl != NULL) |
---|
| 709 | tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
| 710 | #endif |
---|
| 711 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
| 712 | |
---|
[a713b103e8] | 713 | #ifndef QT_NO_CONCURRENT |
---|
[43c29c04ba] | 714 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
| 715 | while (!f.isFinished()) { |
---|
| 716 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
| 717 | } |
---|
[a713b103e8] | 718 | #else |
---|
| 719 | solver.cleanup(true); |
---|
| 720 | #endif |
---|
[43c29c04ba] | 721 | pd.reset(); |
---|
| 722 | #ifdef Q_OS_WIN32 |
---|
| 723 | if (tl != NULL) { |
---|
| 724 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
| 725 | tl->Release(); |
---|
| 726 | tl = NULL; |
---|
| 727 | } |
---|
| 728 | #endif |
---|
[1babbd6ba3] | 729 | return; |
---|
| 730 | } |
---|
| 731 | pb->setFormat(tr("Generating header")); |
---|
| 732 | pd.setLabelText(tr("Generating solution output...")); |
---|
[9cda6e0f5d] | 733 | pd.setMaximum(solver.getTotalSteps() + 1); |
---|
[1babbd6ba3] | 734 | pd.setValue(0); |
---|
| 735 | |
---|
[43c29c04ba] | 736 | #ifdef Q_OS_WIN32 |
---|
| 737 | if (tl != NULL) |
---|
| 738 | tl->SetProgressValue(winId(), spinCities->value(), spinCities->value() + solver.getTotalSteps() + 1); |
---|
| 739 | #endif |
---|
| 740 | |
---|
[1babbd6ba3] | 741 | solutionText->clear(); |
---|
[317ba0432e] | 742 | solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value())); |
---|
| 743 | |
---|
[345e7b6132] | 744 | QPainter pic; |
---|
[9cda6e0f5d] | 745 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
| 746 | pic.begin(&graph); |
---|
[7aaa0b0ec7] | 747 | pic.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); |
---|
[a713b103e8] | 748 | QFont font = qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE, 9))); |
---|
[e26679937d] | 749 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
| 750 | font.setWeight(QFont::DemiBold); |
---|
| 751 | font.setPointSizeF(font.pointSizeF() * 2); |
---|
| 752 | } |
---|
[7aaa0b0ec7] | 753 | pic.setFont(font); |
---|
[20015b41e7] | 754 | pic.setBrush(QBrush(QColor(Qt::white))); |
---|
[e26679937d] | 755 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
[7aaa0b0ec7] | 756 | QPen pen = pic.pen(); |
---|
[e26679937d] | 757 | pen.setWidth(2); |
---|
| 758 | pic.setPen(pen); |
---|
| 759 | } |
---|
[20015b41e7] | 760 | pic.setBackgroundMode(Qt::OpaqueMode); |
---|
[9cda6e0f5d] | 761 | } |
---|
[345e7b6132] | 762 | |
---|
[317ba0432e] | 763 | QTextDocument *doc = solutionText->document(); |
---|
| 764 | QTextCursor cur(doc); |
---|
| 765 | |
---|
| 766 | cur.beginEditBlock(); |
---|
| 767 | cur.setBlockFormat(fmt_paragraph); |
---|
[345e7b6132] | 768 | cur.insertText(tr("Variant #%1 Task").arg(spinVariant->value()), fmt_default); |
---|
[317ba0432e] | 769 | cur.insertBlock(fmt_paragraph); |
---|
| 770 | cur.insertText(tr("Task:")); |
---|
| 771 | outputMatrix(cur, matrix); |
---|
[3cadf24d00] | 772 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
| 773 | #ifdef _T_T_L_ |
---|
[e9db3e216b] | 774 | _b_ _i_ _z_ _a_ _r_ _r_ _e_ |
---|
[3cadf24d00] | 775 | #endif |
---|
[9cda6e0f5d] | 776 | drawNode(pic, 0); |
---|
[3cadf24d00] | 777 | } |
---|
[317ba0432e] | 778 | cur.insertHtml("<hr>"); |
---|
| 779 | cur.insertBlock(fmt_paragraph); |
---|
[345e7b6132] | 780 | int imgpos = cur.position(); |
---|
| 781 | cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default); |
---|
[317ba0432e] | 782 | cur.endEditBlock(); |
---|
| 783 | |
---|
[1babbd6ba3] | 784 | SStep *step = root; |
---|
[9cda6e0f5d] | 785 | int c = n = 1; |
---|
[1babbd6ba3] | 786 | pb->setFormat(tr("Generating step %v")); |
---|
[9cda6e0f5d] | 787 | while ((step->next != SStep::NoNextStep) && (c < spinCities->value())) { |
---|
[1babbd6ba3] | 788 | if (pd.wasCanceled()) { |
---|
[317ba0432e] | 789 | pd.setLabelText(tr("Cleaning up...")); |
---|
| 790 | pd.setMaximum(0); |
---|
| 791 | pd.setCancelButton(NULL); |
---|
| 792 | pd.show(); |
---|
| 793 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
[43c29c04ba] | 794 | #ifdef Q_OS_WIN32 |
---|
| 795 | if (tl != NULL) |
---|
| 796 | tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
| 797 | #endif |
---|
[a713b103e8] | 798 | #ifndef QT_NO_CONCURRENT |
---|
[43c29c04ba] | 799 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
| 800 | while (!f.isFinished()) { |
---|
| 801 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
| 802 | } |
---|
[a713b103e8] | 803 | #else |
---|
| 804 | solver.cleanup(true); |
---|
| 805 | #endif |
---|
[1babbd6ba3] | 806 | solutionText->clear(); |
---|
[317ba0432e] | 807 | toggleSolutionActions(false); |
---|
[43c29c04ba] | 808 | #ifdef Q_OS_WIN32 |
---|
| 809 | if (tl != NULL) { |
---|
| 810 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
| 811 | tl->Release(); |
---|
| 812 | tl = NULL; |
---|
| 813 | } |
---|
| 814 | #endif |
---|
[1babbd6ba3] | 815 | return; |
---|
| 816 | } |
---|
| 817 | pd.setValue(n); |
---|
[43c29c04ba] | 818 | #ifdef Q_OS_WIN32 |
---|
| 819 | if (tl != NULL) |
---|
| 820 | tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1); |
---|
| 821 | #endif |
---|
[1babbd6ba3] | 822 | |
---|
[9cda6e0f5d] | 823 | cur.beginEditBlock(); |
---|
| 824 | cur.insertBlock(fmt_paragraph); |
---|
| 825 | cur.insertText(tr("Step #%1").arg(n)); |
---|
| 826 | 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())))) { |
---|
| 827 | outputMatrix(cur, *step); |
---|
| 828 | } |
---|
| 829 | cur.insertBlock(fmt_paragraph); |
---|
| 830 | cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default); |
---|
| 831 | if (!step->alts.empty()) { |
---|
| 832 | SStep::SCandidate cand; |
---|
| 833 | QString alts; |
---|
| 834 | foreach(cand, step->alts) { |
---|
| 835 | if (!alts.isEmpty()) |
---|
| 836 | alts += ", "; |
---|
| 837 | alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1); |
---|
[1babbd6ba3] | 838 | } |
---|
[9cda6e0f5d] | 839 | cur.insertBlock(fmt_paragraph); |
---|
| 840 | cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist); |
---|
[1babbd6ba3] | 841 | } |
---|
[9cda6e0f5d] | 842 | cur.insertBlock(fmt_paragraph); |
---|
| 843 | cur.insertText(" ", fmt_default); |
---|
| 844 | cur.endEditBlock(); |
---|
| 845 | |
---|
| 846 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
[345e7b6132] | 847 | if (step->prNode != NULL) |
---|
[9cda6e0f5d] | 848 | drawNode(pic, n, false, step->prNode); |
---|
[345e7b6132] | 849 | if (step->plNode != NULL) |
---|
[9cda6e0f5d] | 850 | drawNode(pic, n, true, step->plNode); |
---|
[345e7b6132] | 851 | } |
---|
[9cda6e0f5d] | 852 | n++; |
---|
| 853 | |
---|
| 854 | if (step->next == SStep::RightBranch) { |
---|
| 855 | c++; |
---|
[1babbd6ba3] | 856 | step = step->prNode; |
---|
[9cda6e0f5d] | 857 | } else if (step->next == SStep::LeftBranch) { |
---|
[1babbd6ba3] | 858 | step = step->plNode; |
---|
[345e7b6132] | 859 | } else |
---|
[1babbd6ba3] | 860 | break; |
---|
| 861 | } |
---|
| 862 | pb->setFormat(tr("Generating footer")); |
---|
| 863 | pd.setValue(n); |
---|
[43c29c04ba] | 864 | #ifdef Q_OS_WIN32 |
---|
| 865 | if (tl != NULL) |
---|
| 866 | tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1); |
---|
| 867 | #endif |
---|
[1babbd6ba3] | 868 | |
---|
[317ba0432e] | 869 | cur.beginEditBlock(); |
---|
| 870 | cur.insertBlock(fmt_paragraph); |
---|
[1babbd6ba3] | 871 | if (solver.isOptimal()) |
---|
[317ba0432e] | 872 | cur.insertText(tr("Optimal path:")); |
---|
[1babbd6ba3] | 873 | else |
---|
[317ba0432e] | 874 | cur.insertText(tr("Resulting path:")); |
---|
| 875 | |
---|
| 876 | cur.insertBlock(fmt_paragraph); |
---|
[5d401f2c50] | 877 | cur.insertText(" " + solver.getSortedPath(tr("City %1"))); |
---|
[317ba0432e] | 878 | |
---|
| 879 | cur.insertBlock(fmt_paragraph); |
---|
[1babbd6ba3] | 880 | if (isInteger(step->price)) |
---|
[317ba0432e] | 881 | cur.insertHtml("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>"); |
---|
[1babbd6ba3] | 882 | else |
---|
[317ba0432e] | 883 | cur.insertHtml("<p>" + tr("The price is <b>%1</b> units.").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()) + "</p>"); |
---|
[1babbd6ba3] | 884 | if (!solver.isOptimal()) { |
---|
[317ba0432e] | 885 | cur.insertBlock(fmt_paragraph); |
---|
| 886 | cur.insertText(" "); |
---|
| 887 | cur.insertBlock(fmt_paragraph); |
---|
| 888 | cur.insertHtml("<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>"); |
---|
[1babbd6ba3] | 889 | } |
---|
[317ba0432e] | 890 | cur.endEditBlock(); |
---|
[9cda6e0f5d] | 891 | |
---|
| 892 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
| 893 | pic.end(); |
---|
[345e7b6132] | 894 | |
---|
[e26679937d] | 895 | QImage i(graph.width() + 1, graph.height() + 1, QImage::Format_RGB32); |
---|
| 896 | i.fill(0xFFFFFF); |
---|
[9cda6e0f5d] | 897 | pic.begin(&i); |
---|
| 898 | pic.drawPicture(1, 1, graph); |
---|
| 899 | pic.end(); |
---|
| 900 | doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i); |
---|
[345e7b6132] | 901 | |
---|
| 902 | QTextImageFormat img; |
---|
[9cda6e0f5d] | 903 | img.setName("tspsg://graph.pic"); |
---|
[e26679937d] | 904 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
| 905 | img.setWidth(i.width() / 2); |
---|
| 906 | img.setHeight(i.height() / 2); |
---|
| 907 | } else { |
---|
| 908 | img.setWidth(i.width()); |
---|
| 909 | img.setHeight(i.height()); |
---|
| 910 | } |
---|
[345e7b6132] | 911 | |
---|
[9cda6e0f5d] | 912 | cur.setPosition(imgpos); |
---|
| 913 | cur.insertImage(img, QTextFrameFormat::FloatRight); |
---|
| 914 | } |
---|
[1babbd6ba3] | 915 | |
---|
| 916 | if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) { |
---|
[317ba0432e] | 917 | // Scrolling to the end of the text. |
---|
[1babbd6ba3] | 918 | solutionText->moveCursor(QTextCursor::End); |
---|
| 919 | } else |
---|
| 920 | solutionText->moveCursor(QTextCursor::Start); |
---|
| 921 | |
---|
| 922 | pd.setLabelText(tr("Cleaning up...")); |
---|
| 923 | pd.setMaximum(0); |
---|
| 924 | pd.setCancelButton(NULL); |
---|
| 925 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
[43c29c04ba] | 926 | #ifdef Q_OS_WIN32 |
---|
| 927 | if (tl != NULL) |
---|
| 928 | tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
| 929 | #endif |
---|
[a713b103e8] | 930 | #ifndef QT_NO_CONCURRENT |
---|
[43c29c04ba] | 931 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
| 932 | while (!f.isFinished()) { |
---|
| 933 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
| 934 | } |
---|
[a713b103e8] | 935 | #else |
---|
| 936 | solver.cleanup(true); |
---|
| 937 | #endif |
---|
[1babbd6ba3] | 938 | toggleSolutionActions(); |
---|
| 939 | tabWidget->setCurrentIndex(1); |
---|
[43c29c04ba] | 940 | #ifdef Q_OS_WIN32 |
---|
| 941 | if (tl != NULL) { |
---|
| 942 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
| 943 | tl->Release(); |
---|
| 944 | tl = NULL; |
---|
| 945 | } |
---|
| 946 | #endif |
---|
| 947 | |
---|
| 948 | pd.reset(); |
---|
| 949 | QApplication::alert(this, 3000); |
---|
[1babbd6ba3] | 950 | } |
---|
| 951 | |
---|
| 952 | void MainWindow::dataChanged() |
---|
| 953 | { |
---|
| 954 | setWindowModified(true); |
---|
| 955 | } |
---|
| 956 | |
---|
| 957 | void MainWindow::dataChanged(const QModelIndex &tl, const QModelIndex &br) |
---|
| 958 | { |
---|
| 959 | setWindowModified(true); |
---|
| 960 | if (settings->value("Autosize", DEF_AUTOSIZE).toBool()) { |
---|
| 961 | for (int k = tl.row(); k <= br.row(); k++) |
---|
| 962 | taskView->resizeRowToContents(k); |
---|
| 963 | for (int k = tl.column(); k <= br.column(); k++) |
---|
| 964 | taskView->resizeColumnToContents(k); |
---|
| 965 | } |
---|
| 966 | } |
---|
| 967 | |
---|
| 968 | #ifdef Q_OS_WINCE_WM |
---|
| 969 | void MainWindow::changeEvent(QEvent *ev) |
---|
| 970 | { |
---|
| 971 | if ((ev->type() == QEvent::ActivationChange) && isActiveWindow()) |
---|
| 972 | desktopResized(0); |
---|
| 973 | |
---|
| 974 | QWidget::changeEvent(ev); |
---|
| 975 | } |
---|
| 976 | |
---|
| 977 | void MainWindow::desktopResized(int screen) |
---|
| 978 | { |
---|
| 979 | if ((screen != 0) || !isActiveWindow()) |
---|
| 980 | return; |
---|
| 981 | |
---|
| 982 | QRect availableGeometry = QApplication::desktop()->availableGeometry(0); |
---|
| 983 | if (currentGeometry != availableGeometry) { |
---|
| 984 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 985 | /*! |
---|
| 986 | * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height. |
---|
| 987 | * If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the |
---|
| 988 | * window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile? |
---|
| 989 | */ |
---|
| 990 | if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) { |
---|
| 991 | setWindowState(windowState() | Qt::WindowMaximized); |
---|
| 992 | } else { |
---|
| 993 | if (windowState() & Qt::WindowMaximized) |
---|
| 994 | setWindowState(windowState() ^ Qt::WindowMaximized); |
---|
| 995 | setGeometry(availableGeometry); |
---|
| 996 | } |
---|
| 997 | currentGeometry = availableGeometry; |
---|
| 998 | QApplication::restoreOverrideCursor(); |
---|
| 999 | } |
---|
| 1000 | } |
---|
| 1001 | #endif // Q_OS_WINCE_WM |
---|
| 1002 | |
---|
| 1003 | void MainWindow::numCitiesChanged(int nCities) |
---|
| 1004 | { |
---|
| 1005 | blockSignals(true); |
---|
| 1006 | spinCities->setValue(nCities); |
---|
| 1007 | blockSignals(false); |
---|
| 1008 | } |
---|
| 1009 | |
---|
| 1010 | #ifndef QT_NO_PRINTER |
---|
| 1011 | void MainWindow::printPreview(QPrinter *printer) |
---|
| 1012 | { |
---|
| 1013 | solutionText->print(printer); |
---|
| 1014 | } |
---|
| 1015 | #endif // QT_NO_PRINTER |
---|
| 1016 | |
---|
[43c29c04ba] | 1017 | #ifdef Q_OS_WIN32 |
---|
| 1018 | void MainWindow::solverRoutePartFound(int n) |
---|
| 1019 | { |
---|
| 1020 | #ifdef Q_OS_WIN32 |
---|
| 1021 | tl->SetProgressValue(winId(), n, spinCities->value() * 2); |
---|
| 1022 | #else |
---|
| 1023 | Q_UNUSED(n); |
---|
| 1024 | #endif // Q_OS_WIN32 |
---|
| 1025 | } |
---|
| 1026 | #endif // Q_OS_WIN32 |
---|
| 1027 | |
---|
[1babbd6ba3] | 1028 | void MainWindow::spinCitiesValueChanged(int n) |
---|
| 1029 | { |
---|
| 1030 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 1031 | int count = tspmodel->numCities(); |
---|
| 1032 | tspmodel->setNumCities(n); |
---|
| 1033 | if ((n > count) && settings->value("Autosize", DEF_AUTOSIZE).toBool()) |
---|
| 1034 | for (int k = count; k < n; k++) { |
---|
| 1035 | taskView->resizeColumnToContents(k); |
---|
| 1036 | taskView->resizeRowToContents(k); |
---|
| 1037 | } |
---|
| 1038 | QApplication::restoreOverrideCursor(); |
---|
| 1039 | } |
---|
| 1040 | |
---|
| 1041 | void MainWindow::closeEvent(QCloseEvent *ev) |
---|
| 1042 | { |
---|
| 1043 | if (!maybeSave()) { |
---|
| 1044 | ev->ignore(); |
---|
| 1045 | return; |
---|
| 1046 | } |
---|
| 1047 | if (!settings->value("SettingsReset", false).toBool()) { |
---|
| 1048 | settings->setValue("NumCities", spinCities->value()); |
---|
| 1049 | |
---|
| 1050 | // Saving Main Window state |
---|
[7bb19df196] | 1051 | #ifndef HANDHELD |
---|
[1babbd6ba3] | 1052 | if (settings->value("SavePos", DEF_SAVEPOS).toBool()) { |
---|
| 1053 | settings->beginGroup("MainWindow"); |
---|
| 1054 | settings->setValue("Geometry", saveGeometry()); |
---|
| 1055 | settings->setValue("State", saveState()); |
---|
[7bb19df196] | 1056 | settings->setValue("Toolbars", toolBarManager->saveState()); |
---|
[1babbd6ba3] | 1057 | settings->endGroup(); |
---|
| 1058 | } |
---|
[a713b103e8] | 1059 | #else |
---|
| 1060 | settings->setValue("MainWindow/ToolbarVisible", toolBarMain->isVisible()); |
---|
[7bb19df196] | 1061 | #endif // HANDHELD |
---|
[1babbd6ba3] | 1062 | } else { |
---|
| 1063 | settings->remove("SettingsReset"); |
---|
| 1064 | } |
---|
| 1065 | |
---|
| 1066 | QMainWindow::closeEvent(ev); |
---|
| 1067 | } |
---|
| 1068 | |
---|
[b574c383b7] | 1069 | void MainWindow::dragEnterEvent(QDragEnterEvent *ev) |
---|
| 1070 | { |
---|
| 1071 | if (ev->mimeData()->hasUrls() && (ev->mimeData()->urls().count() == 1)) { |
---|
| 1072 | QFileInfo fi(ev->mimeData()->urls().first().toLocalFile()); |
---|
| 1073 | if ((fi.suffix() == "tspt") || (fi.suffix() == "zkt")) |
---|
| 1074 | ev->acceptProposedAction(); |
---|
| 1075 | } |
---|
| 1076 | } |
---|
| 1077 | |
---|
[345e7b6132] | 1078 | void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step) |
---|
| 1079 | { |
---|
[e26679937d] | 1080 | int r; |
---|
| 1081 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) |
---|
| 1082 | r = 70; |
---|
| 1083 | else |
---|
| 1084 | r = 35; |
---|
[345e7b6132] | 1085 | qreal x, y; |
---|
| 1086 | if (step != NULL) |
---|
| 1087 | x = left ? r : r * 3.5; |
---|
| 1088 | else |
---|
| 1089 | x = r * 2.25; |
---|
| 1090 | y = r * (3 * nstep + 1); |
---|
| 1091 | |
---|
[3cadf24d00] | 1092 | #ifdef _T_T_L_ |
---|
| 1093 | if (nstep == -481124) { |
---|
| 1094 | _t_t_l_(pic, r, x); |
---|
| 1095 | return; |
---|
| 1096 | } |
---|
| 1097 | #endif |
---|
| 1098 | |
---|
[345e7b6132] | 1099 | pic.drawEllipse(QPointF(x, y), r, r); |
---|
| 1100 | |
---|
| 1101 | if (step != NULL) { |
---|
| 1102 | QFont font; |
---|
| 1103 | if (left) { |
---|
| 1104 | font = pic.font(); |
---|
| 1105 | font.setStrikeOut(true); |
---|
| 1106 | pic.setFont(font); |
---|
| 1107 | } |
---|
| 1108 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("(%1;%2)").arg(step->pNode->candidate.nRow + 1).arg(step->pNode->candidate.nCol + 1) + "\n"); |
---|
| 1109 | if (left) { |
---|
| 1110 | font.setStrikeOut(false); |
---|
| 1111 | pic.setFont(font); |
---|
| 1112 | } |
---|
[9cda6e0f5d] | 1113 | if (step->price != INFINITY) { |
---|
| 1114 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, isInteger(step->price) ? QString("\n%1").arg(step->price) : QString("\n%1").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt())); |
---|
| 1115 | } else { |
---|
| 1116 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, "\n"INFSTR); |
---|
| 1117 | } |
---|
[345e7b6132] | 1118 | } else { |
---|
| 1119 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root")); |
---|
| 1120 | } |
---|
| 1121 | |
---|
[9cda6e0f5d] | 1122 | if (nstep == 1) { |
---|
| 1123 | pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r)); |
---|
| 1124 | } else if (nstep > 1) { |
---|
[5d401f2c50] | 1125 | pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == SStep::RightBranch) ? r * 3.5 : r, y - 2 * r)); |
---|
[9cda6e0f5d] | 1126 | } |
---|
[345e7b6132] | 1127 | |
---|
| 1128 | } |
---|
| 1129 | |
---|
[b574c383b7] | 1130 | void MainWindow::dropEvent(QDropEvent *ev) |
---|
| 1131 | { |
---|
| 1132 | if (maybeSave() && tspmodel->loadTask(ev->mimeData()->urls().first().toLocalFile())) { |
---|
| 1133 | setFileName(ev->mimeData()->urls().first().toLocalFile()); |
---|
| 1134 | tabWidget->setCurrentIndex(0); |
---|
| 1135 | setWindowModified(false); |
---|
| 1136 | solutionText->clear(); |
---|
| 1137 | toggleSolutionActions(false); |
---|
| 1138 | |
---|
[9cda6e0f5d] | 1139 | ev->setDropAction(Qt::CopyAction); |
---|
| 1140 | ev->accept(); |
---|
[b574c383b7] | 1141 | } |
---|
| 1142 | } |
---|
| 1143 | |
---|
[1babbd6ba3] | 1144 | bool MainWindow::hasUpdater() const |
---|
| 1145 | { |
---|
| 1146 | #ifdef Q_OS_WIN32 |
---|
| 1147 | return QFile::exists("updater/Update.exe"); |
---|
| 1148 | #else // Q_OS_WIN32 |
---|
| 1149 | return false; |
---|
| 1150 | #endif // Q_OS_WIN32 |
---|
| 1151 | } |
---|
| 1152 | |
---|
| 1153 | void MainWindow::initDocStyleSheet() |
---|
| 1154 | { |
---|
[a713b103e8] | 1155 | solutionText->document()->setDefaultFont(qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE, DEF_FONT_SIZE)))); |
---|
[317ba0432e] | 1156 | |
---|
| 1157 | fmt_paragraph.setTopMargin(0); |
---|
| 1158 | fmt_paragraph.setRightMargin(10); |
---|
| 1159 | fmt_paragraph.setBottomMargin(0); |
---|
| 1160 | fmt_paragraph.setLeftMargin(10); |
---|
| 1161 | |
---|
| 1162 | fmt_table.setTopMargin(5); |
---|
| 1163 | fmt_table.setRightMargin(10); |
---|
| 1164 | fmt_table.setBottomMargin(5); |
---|
| 1165 | fmt_table.setLeftMargin(10); |
---|
| 1166 | fmt_table.setBorder(0); |
---|
| 1167 | fmt_table.setBorderStyle(QTextFrameFormat::BorderStyle_None); |
---|
| 1168 | fmt_table.setCellSpacing(5); |
---|
| 1169 | |
---|
[345e7b6132] | 1170 | fmt_cell.setAlignment(Qt::AlignHCenter); |
---|
[317ba0432e] | 1171 | |
---|
[8b0661d1ee] | 1172 | settings->beginGroup("Output/Colors"); |
---|
| 1173 | |
---|
[a713b103e8] | 1174 | QColor color = qvariant_cast<QColor>(settings->value("Text", DEF_TEXT_COLOR)); |
---|
[1babbd6ba3] | 1175 | QColor hilight; |
---|
| 1176 | if (color.value() < 192) |
---|
[317ba0432e] | 1177 | hilight.setHsv(color.hue(), color.saturation(), 127 + qRound(color.value() / 2)); |
---|
[1babbd6ba3] | 1178 | else |
---|
[317ba0432e] | 1179 | hilight.setHsv(color.hue(), color.saturation(), color.value() / 2); |
---|
| 1180 | |
---|
| 1181 | solutionText->document()->setDefaultStyleSheet(QString("* {color: %1;}").arg(color.name())); |
---|
| 1182 | fmt_default.setForeground(QBrush(color)); |
---|
| 1183 | |
---|
[a713b103e8] | 1184 | fmt_selected.setForeground(QBrush(qvariant_cast<QColor>(settings->value("Selected", DEF_SELECTED_COLOR)))); |
---|
[317ba0432e] | 1185 | fmt_selected.setFontWeight(QFont::Bold); |
---|
| 1186 | |
---|
[a713b103e8] | 1187 | fmt_alternate.setForeground(QBrush(qvariant_cast<QColor>(settings->value("Alternate", DEF_ALTERNATE_COLOR)))); |
---|
[317ba0432e] | 1188 | fmt_alternate.setFontWeight(QFont::Bold); |
---|
| 1189 | fmt_altlist.setForeground(QBrush(hilight)); |
---|
| 1190 | |
---|
[8b0661d1ee] | 1191 | settings->endGroup(); |
---|
| 1192 | |
---|
[317ba0432e] | 1193 | solutionText->setTextColor(color); |
---|
[1babbd6ba3] | 1194 | } |
---|
| 1195 | |
---|
| 1196 | void MainWindow::loadLangList() |
---|
| 1197 | { |
---|
[3cadf24d00] | 1198 | QMap<QString, QStringList> langlist; |
---|
| 1199 | QFileInfoList langs; |
---|
| 1200 | QFileInfo lang; |
---|
[1babbd6ba3] | 1201 | QString name; |
---|
[3cadf24d00] | 1202 | QStringList language, dirs; |
---|
| 1203 | QTranslator t; |
---|
| 1204 | QDir dir; |
---|
| 1205 | dir.setFilter(QDir::Files); |
---|
| 1206 | dir.setNameFilters(QStringList("tspsg_*.qm")); |
---|
| 1207 | dir.setSorting(QDir::NoSort); |
---|
| 1208 | |
---|
| 1209 | dirs << PATH_L10N << ":/l10n"; |
---|
| 1210 | foreach (QString dirname, dirs) { |
---|
| 1211 | dir.setPath(dirname); |
---|
| 1212 | if (dir.exists()) { |
---|
| 1213 | langs = dir.entryInfoList(); |
---|
| 1214 | for (int k = 0; k < langs.size(); k++) { |
---|
| 1215 | lang = langs.at(k); |
---|
| 1216 | if (lang.completeBaseName().compare("tspsg_en", Qt::CaseInsensitive) && !langlist.contains(lang.completeBaseName().mid(6)) && t.load(lang.completeBaseName(), dirname)) { |
---|
| 1217 | |
---|
| 1218 | language.clear(); |
---|
| 1219 | language.append(lang.completeBaseName().mid(6)); |
---|
| 1220 | language.append(t.translate("--------", "COUNTRY", "Please, provide an ISO 3166-1 alpha-2 country code for this translation language here (eg., UA).").toLower()); |
---|
| 1221 | language.append(t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here.")); |
---|
| 1222 | language.append(t.translate("MainWindow", "Set application language to %1", "").arg(name)); |
---|
| 1223 | |
---|
| 1224 | langlist.insert(language.at(0), language); |
---|
| 1225 | } |
---|
| 1226 | } |
---|
[1babbd6ba3] | 1227 | } |
---|
| 1228 | } |
---|
[3cadf24d00] | 1229 | |
---|
| 1230 | QAction *a; |
---|
| 1231 | foreach (language, langlist) { |
---|
| 1232 | a = menuSettingsLanguage->addAction(language.at(2)); |
---|
| 1233 | a->setStatusTip(language.at(3)); |
---|
[2a436ea693] | 1234 | #if QT_VERSION >= 0x040600 |
---|
[d2820c3a1f] | 1235 | a->setIcon(QIcon::fromTheme(QString("flag-%1").arg(language.at(1)), QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1))))); |
---|
[2a436ea693] | 1236 | #else |
---|
| 1237 | a->setIcon(QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1)))); |
---|
| 1238 | #endif |
---|
[3cadf24d00] | 1239 | a->setData(language.at(0)); |
---|
| 1240 | a->setCheckable(true); |
---|
| 1241 | a->setActionGroup(groupSettingsLanguageList); |
---|
| 1242 | if (settings->value("Language", QLocale::system().name()).toString().startsWith(language.at(0))) |
---|
| 1243 | a->setChecked(true); |
---|
| 1244 | } |
---|
[1babbd6ba3] | 1245 | } |
---|
| 1246 | |
---|
| 1247 | bool MainWindow::loadLanguage(const QString &lang) |
---|
| 1248 | { |
---|
| 1249 | // i18n |
---|
| 1250 | bool ad = false; |
---|
| 1251 | QString lng = lang; |
---|
| 1252 | if (lng.isEmpty()) { |
---|
| 1253 | ad = settings->value("Language", "").toString().isEmpty(); |
---|
| 1254 | lng = settings->value("Language", QLocale::system().name()).toString(); |
---|
| 1255 | } |
---|
| 1256 | static QTranslator *qtTranslator; // Qt library translator |
---|
| 1257 | if (qtTranslator) { |
---|
| 1258 | qApp->removeTranslator(qtTranslator); |
---|
| 1259 | delete qtTranslator; |
---|
| 1260 | qtTranslator = NULL; |
---|
| 1261 | } |
---|
| 1262 | static QTranslator *translator; // Application translator |
---|
| 1263 | if (translator) { |
---|
| 1264 | qApp->removeTranslator(translator); |
---|
| 1265 | delete translator; |
---|
| 1266 | translator = NULL; |
---|
| 1267 | } |
---|
| 1268 | |
---|
| 1269 | if (lng == "en") |
---|
| 1270 | return true; |
---|
| 1271 | |
---|
| 1272 | // Trying to load system Qt library translation... |
---|
| 1273 | qtTranslator = new QTranslator(this); |
---|
| 1274 | if (qtTranslator->load("qt_" + lng, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) |
---|
| 1275 | qApp->installTranslator(qtTranslator); |
---|
| 1276 | else { |
---|
| 1277 | // No luck. Let's try to load a bundled one. |
---|
[3cadf24d00] | 1278 | if (qtTranslator->load("qt_" + lng, PATH_L10N)) { |
---|
| 1279 | // We have a translation in the localization direcotry. |
---|
[1babbd6ba3] | 1280 | qApp->installTranslator(qtTranslator); |
---|
[3cadf24d00] | 1281 | } else if (qtTranslator->load("qt_" + lng, ":/l10n")) { |
---|
| 1282 | // We have a translation "built-in" into application resources. |
---|
| 1283 | qApp->installTranslator(qtTranslator); |
---|
| 1284 | } else { |
---|
| 1285 | // Qt library translation unavailable for this language. |
---|
[1babbd6ba3] | 1286 | delete qtTranslator; |
---|
| 1287 | qtTranslator = NULL; |
---|
| 1288 | } |
---|
| 1289 | } |
---|
| 1290 | |
---|
| 1291 | // Now let's load application translation. |
---|
| 1292 | translator = new QTranslator(this); |
---|
[3cadf24d00] | 1293 | if (translator->load("tspsg_" + lng, PATH_L10N)) { |
---|
| 1294 | // We have a translation in the localization directory. |
---|
[1babbd6ba3] | 1295 | qApp->installTranslator(translator); |
---|
[3cadf24d00] | 1296 | } else if (translator->load("tspsg_" + lng, ":/l10n")) { |
---|
| 1297 | // We have a translation "built-in" into application resources. |
---|
| 1298 | qApp->installTranslator(translator); |
---|
| 1299 | } else { |
---|
[1babbd6ba3] | 1300 | delete translator; |
---|
| 1301 | translator = NULL; |
---|
| 1302 | if (!ad) { |
---|
| 1303 | settings->remove("Language"); |
---|
| 1304 | QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); |
---|
[3cadf24d00] | 1305 | QMessageBox::warning(isVisible() ? this : NULL, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection.")); |
---|
[1babbd6ba3] | 1306 | QApplication::restoreOverrideCursor(); |
---|
| 1307 | } |
---|
| 1308 | return false; |
---|
| 1309 | } |
---|
| 1310 | return true; |
---|
| 1311 | } |
---|
| 1312 | |
---|
[e3533af1cf] | 1313 | void MainWindow::loadStyleList() |
---|
| 1314 | { |
---|
| 1315 | menuSettingsStyle->clear(); |
---|
| 1316 | QStringList styles = QStyleFactory::keys(); |
---|
| 1317 | menuSettingsStyle->insertAction(NULL, actionSettingsStyleSystem); |
---|
| 1318 | actionSettingsStyleSystem->setChecked(!settings->contains("Style")); |
---|
| 1319 | menuSettingsStyle->addSeparator(); |
---|
| 1320 | QAction *a; |
---|
| 1321 | foreach (QString style, styles) { |
---|
| 1322 | a = menuSettingsStyle->addAction(style); |
---|
| 1323 | a->setData(false); |
---|
| 1324 | a->setStatusTip(tr("Set application style to %1").arg(style)); |
---|
| 1325 | a->setCheckable(true); |
---|
| 1326 | a->setActionGroup(groupSettingsStyleList); |
---|
| 1327 | if ((style == settings->value("Style").toString()) |
---|
| 1328 | || QString(QApplication::style()->metaObject()->className()).contains(QRegExp(QString("^Q?%1(Style)?$").arg(QRegExp::escape(style)), Qt::CaseInsensitive))) { |
---|
| 1329 | a->setChecked(true); |
---|
| 1330 | } |
---|
| 1331 | } |
---|
| 1332 | } |
---|
| 1333 | |
---|
[7bb19df196] | 1334 | void MainWindow::loadToolbarList() |
---|
| 1335 | { |
---|
| 1336 | menuSettingsToolbars->clear(); |
---|
| 1337 | #ifndef HANDHELD |
---|
| 1338 | menuSettingsToolbars->insertAction(NULL, actionSettingsToolbarsConfigure); |
---|
| 1339 | menuSettingsToolbars->addSeparator(); |
---|
| 1340 | QList<QToolBar *> list = toolBarManager->toolBars(); |
---|
| 1341 | foreach (QToolBar *t, list) { |
---|
| 1342 | menuSettingsToolbars->insertAction(NULL, t->toggleViewAction()); |
---|
| 1343 | } |
---|
| 1344 | #else // HANDHELD |
---|
| 1345 | menuSettingsToolbars->insertAction(NULL, toolBarMain->toggleViewAction()); |
---|
| 1346 | #endif // HANDHELD |
---|
| 1347 | } |
---|
| 1348 | |
---|
[1babbd6ba3] | 1349 | bool MainWindow::maybeSave() |
---|
| 1350 | { |
---|
| 1351 | if (!isWindowModified()) |
---|
| 1352 | return true; |
---|
| 1353 | 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); |
---|
| 1354 | if (res == QMessageBox::Save) |
---|
| 1355 | return actionFileSaveTriggered(); |
---|
| 1356 | else if (res == QMessageBox::Cancel) |
---|
| 1357 | return false; |
---|
| 1358 | else |
---|
| 1359 | return true; |
---|
| 1360 | } |
---|
| 1361 | |
---|
[317ba0432e] | 1362 | void MainWindow::outputMatrix(QTextCursor &cur, const TMatrix &matrix) |
---|
[1babbd6ba3] | 1363 | { |
---|
| 1364 | int n = spinCities->value(); |
---|
[317ba0432e] | 1365 | QTextTable *table = cur.insertTable(n, n, fmt_table); |
---|
| 1366 | |
---|
[1babbd6ba3] | 1367 | for (int r = 0; r < n; r++) { |
---|
| 1368 | for (int c = 0; c < n; c++) { |
---|
[317ba0432e] | 1369 | cur = table->cellAt(r, c).firstCursorPosition(); |
---|
[345e7b6132] | 1370 | cur.setBlockFormat(fmt_cell); |
---|
[317ba0432e] | 1371 | cur.setBlockCharFormat(fmt_default); |
---|
[1babbd6ba3] | 1372 | if (matrix.at(r).at(c) == INFINITY) |
---|
[317ba0432e] | 1373 | cur.insertText(INFSTR); |
---|
[1babbd6ba3] | 1374 | else |
---|
[317ba0432e] | 1375 | cur.insertText(isInteger(matrix.at(r).at(c)) ? QString("%1").arg(matrix.at(r).at(c)) : QString("%1").arg(matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt())); |
---|
[1babbd6ba3] | 1376 | } |
---|
[317ba0432e] | 1377 | QApplication::processEvents(); |
---|
[1babbd6ba3] | 1378 | } |
---|
[317ba0432e] | 1379 | cur.movePosition(QTextCursor::End); |
---|
[1babbd6ba3] | 1380 | } |
---|
| 1381 | |
---|
[317ba0432e] | 1382 | void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step) |
---|
[1babbd6ba3] | 1383 | { |
---|
| 1384 | int n = spinCities->value(); |
---|
[317ba0432e] | 1385 | QTextTable *table = cur.insertTable(n, n, fmt_table); |
---|
| 1386 | |
---|
[1babbd6ba3] | 1387 | for (int r = 0; r < n; r++) { |
---|
| 1388 | for (int c = 0; c < n; c++) { |
---|
[317ba0432e] | 1389 | cur = table->cellAt(r, c).firstCursorPosition(); |
---|
[345e7b6132] | 1390 | cur.setBlockFormat(fmt_cell); |
---|
[1babbd6ba3] | 1391 | if (step.matrix.at(r).at(c) == INFINITY) |
---|
[317ba0432e] | 1392 | cur.insertText(INFSTR, fmt_default); |
---|
[1babbd6ba3] | 1393 | else if ((r == step.candidate.nRow) && (c == step.candidate.nCol)) |
---|
[317ba0432e] | 1394 | cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_selected); |
---|
[1babbd6ba3] | 1395 | else { |
---|
[9cda6e0f5d] | 1396 | SStep::SCandidate cand; |
---|
[1babbd6ba3] | 1397 | cand.nRow = r; |
---|
| 1398 | cand.nCol = c; |
---|
| 1399 | if (step.alts.contains(cand)) |
---|
[317ba0432e] | 1400 | cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_alternate); |
---|
[1babbd6ba3] | 1401 | else |
---|
[317ba0432e] | 1402 | cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_default); |
---|
[1babbd6ba3] | 1403 | } |
---|
| 1404 | } |
---|
[317ba0432e] | 1405 | QApplication::processEvents(); |
---|
[1babbd6ba3] | 1406 | } |
---|
[317ba0432e] | 1407 | |
---|
| 1408 | cur.movePosition(QTextCursor::End); |
---|
[1babbd6ba3] | 1409 | } |
---|
| 1410 | |
---|
| 1411 | void MainWindow::retranslateUi(bool all) |
---|
| 1412 | { |
---|
| 1413 | if (all) |
---|
[a713b103e8] | 1414 | Ui_MainWindow::retranslateUi(this); |
---|
[1babbd6ba3] | 1415 | |
---|
[e3533af1cf] | 1416 | loadStyleList(); |
---|
[7bb19df196] | 1417 | loadToolbarList(); |
---|
[e3533af1cf] | 1418 | |
---|
[1babbd6ba3] | 1419 | #ifndef QT_NO_PRINTER |
---|
[7bb19df196] | 1420 | actionFilePrintPreview->setText(tr("P&rint Preview...")); |
---|
[1babbd6ba3] | 1421 | #ifndef QT_NO_TOOLTIP |
---|
[7bb19df196] | 1422 | actionFilePrintPreview->setToolTip(tr("Preview solution results")); |
---|
[1babbd6ba3] | 1423 | #endif // QT_NO_TOOLTIP |
---|
| 1424 | #ifndef QT_NO_STATUSTIP |
---|
[7bb19df196] | 1425 | actionFilePrintPreview->setStatusTip(tr("Preview current solution results before printing")); |
---|
[1babbd6ba3] | 1426 | #endif // QT_NO_STATUSTIP |
---|
| 1427 | |
---|
[7bb19df196] | 1428 | actionFilePrint->setText(tr("&Print...")); |
---|
[1babbd6ba3] | 1429 | #ifndef QT_NO_TOOLTIP |
---|
[7bb19df196] | 1430 | actionFilePrint->setToolTip(tr("Print solution")); |
---|
[1babbd6ba3] | 1431 | #endif // QT_NO_TOOLTIP |
---|
| 1432 | #ifndef QT_NO_STATUSTIP |
---|
[7bb19df196] | 1433 | actionFilePrint->setStatusTip(tr("Print current solution results")); |
---|
[1babbd6ba3] | 1434 | #endif // QT_NO_STATUSTIP |
---|
[7bb19df196] | 1435 | actionFilePrint->setShortcut(tr("Ctrl+P")); |
---|
[1babbd6ba3] | 1436 | #endif // QT_NO_PRINTER |
---|
[8b0661d1ee] | 1437 | |
---|
| 1438 | #ifndef HANDHELD |
---|
| 1439 | actionSettingsToolbarsConfigure->setText(tr("Configure...")); |
---|
| 1440 | #ifndef QT_NO_STATUSTIP |
---|
| 1441 | actionSettingsToolbarsConfigure->setStatusTip(tr("Customize toolbars")); |
---|
| 1442 | #endif // QT_NO_STATUSTIP |
---|
| 1443 | #endif // HANDHELD |
---|
| 1444 | |
---|
[1babbd6ba3] | 1445 | #ifdef Q_OS_WIN32 |
---|
| 1446 | actionHelpCheck4Updates->setText(tr("Check for &Updates...")); |
---|
| 1447 | #ifndef QT_NO_STATUSTIP |
---|
| 1448 | actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QApplication::applicationName())); |
---|
| 1449 | #endif // QT_NO_STATUSTIP |
---|
| 1450 | #endif // Q_OS_WIN32 |
---|
| 1451 | } |
---|
| 1452 | |
---|
| 1453 | bool MainWindow::saveTask() { |
---|
| 1454 | QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)"); |
---|
| 1455 | filters.append(tr("All Files") + " (*)"); |
---|
| 1456 | QString file; |
---|
[ac76a6a753] | 1457 | if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) { |
---|
[bbac1ebb13] | 1458 | file = settings->value(OS"/LastUsed/TaskSavePath").toString(); |
---|
[ac76a6a753] | 1459 | if (!file.isEmpty()) |
---|
| 1460 | file.append("/"); |
---|
| 1461 | file.append(fileName); |
---|
| 1462 | } else if (fileName.endsWith(".tspt", Qt::CaseInsensitive)) |
---|
[1babbd6ba3] | 1463 | file = fileName; |
---|
| 1464 | else |
---|
[ac76a6a753] | 1465 | file = QFileInfo(fileName).path() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"; |
---|
[1babbd6ba3] | 1466 | |
---|
| 1467 | QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; |
---|
| 1468 | file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts); |
---|
| 1469 | if (file.isEmpty()) |
---|
| 1470 | return false; |
---|
[ac76a6a753] | 1471 | else if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
[bbac1ebb13] | 1472 | settings->setValue(OS"/LastUsed/TaskSavePath", QFileInfo(file).path()); |
---|
[ac76a6a753] | 1473 | |
---|
[1babbd6ba3] | 1474 | if (tspmodel->saveTask(file)) { |
---|
| 1475 | setFileName(file); |
---|
| 1476 | setWindowModified(false); |
---|
| 1477 | return true; |
---|
| 1478 | } |
---|
| 1479 | return false; |
---|
| 1480 | } |
---|
| 1481 | |
---|
| 1482 | void MainWindow::setFileName(const QString &fileName) |
---|
| 1483 | { |
---|
| 1484 | this->fileName = fileName; |
---|
[2bbe924ad8] | 1485 | setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(QApplication::applicationName())); |
---|
[1babbd6ba3] | 1486 | } |
---|
| 1487 | |
---|
| 1488 | void MainWindow::setupUi() |
---|
| 1489 | { |
---|
[a713b103e8] | 1490 | Ui_MainWindow::setupUi(this); |
---|
[1babbd6ba3] | 1491 | |
---|
[3cadf24d00] | 1492 | // File Menu |
---|
[2a436ea693] | 1493 | actionFileNew->setIcon(GET_ICON("document-new")); |
---|
| 1494 | actionFileOpen->setIcon(GET_ICON("document-open")); |
---|
| 1495 | actionFileSave->setIcon(GET_ICON("document-save")); |
---|
[a713b103e8] | 1496 | #ifndef HANDHELD |
---|
[2a436ea693] | 1497 | menuFileSaveAs->setIcon(GET_ICON("document-save-as")); |
---|
[a713b103e8] | 1498 | #endif |
---|
[2a436ea693] | 1499 | actionFileExit->setIcon(GET_ICON("application-exit")); |
---|
[3cadf24d00] | 1500 | // Settings Menu |
---|
[a713b103e8] | 1501 | #ifndef HANDHELD |
---|
[2a436ea693] | 1502 | menuSettingsLanguage->setIcon(GET_ICON("preferences-desktop-locale")); |
---|
[a713b103e8] | 1503 | #if QT_VERSION >= 0x040600 |
---|
| 1504 | actionSettingsLanguageEnglish->setIcon(QIcon::fromTheme("flag-gb", QIcon(":/images/icons/l10n/flag-gb.png"))); |
---|
| 1505 | #else // QT_VERSION >= 0x040600 |
---|
| 1506 | actionSettingsLanguageEnglish->setIcon(QIcon(":/images/icons/l10n/flag-gb.png")); |
---|
| 1507 | #endif // QT_VERSION >= 0x040600 |
---|
[2a436ea693] | 1508 | menuSettingsStyle->setIcon(GET_ICON("preferences-desktop-theme")); |
---|
[a713b103e8] | 1509 | #endif // HANDHELD |
---|
[2a436ea693] | 1510 | actionSettingsPreferences->setIcon(GET_ICON("preferences-system")); |
---|
[3cadf24d00] | 1511 | // Help Menu |
---|
[a713b103e8] | 1512 | #ifndef HANDHELD |
---|
[2a436ea693] | 1513 | actionHelpContents->setIcon(GET_ICON("help-contents")); |
---|
| 1514 | actionHelpContextual->setIcon(GET_ICON("help-contextual")); |
---|
| 1515 | actionHelpAbout->setIcon(GET_ICON("help-about")); |
---|
[a713b103e8] | 1516 | #endif |
---|
[3cadf24d00] | 1517 | // Buttons |
---|
[2a436ea693] | 1518 | buttonRandom->setIcon(GET_ICON("roll")); |
---|
| 1519 | buttonSolve->setIcon(GET_ICON("dialog-ok")); |
---|
| 1520 | buttonSaveSolution->setIcon(GET_ICON("document-save-as")); |
---|
| 1521 | buttonBackToTask->setIcon(GET_ICON("go-previous")); |
---|
[3cadf24d00] | 1522 | |
---|
[2a436ea693] | 1523 | // action->setIcon(GET_ICON("")); |
---|
[3cadf24d00] | 1524 | |
---|
[1babbd6ba3] | 1525 | #if QT_VERSION >= 0x040600 |
---|
| 1526 | setToolButtonStyle(Qt::ToolButtonFollowStyle); |
---|
| 1527 | #endif |
---|
| 1528 | |
---|
| 1529 | #ifndef HANDHELD |
---|
| 1530 | QStatusBar *statusbar = new QStatusBar(this); |
---|
| 1531 | statusbar->setObjectName("statusbar"); |
---|
| 1532 | setStatusBar(statusbar); |
---|
| 1533 | #endif // HANDHELD |
---|
| 1534 | |
---|
| 1535 | #ifdef Q_OS_WINCE_WM |
---|
| 1536 | menuBar()->setDefaultAction(menuFile->menuAction()); |
---|
| 1537 | |
---|
| 1538 | QScrollArea *scrollArea = new QScrollArea(this); |
---|
| 1539 | scrollArea->setFrameShape(QFrame::NoFrame); |
---|
| 1540 | scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
---|
| 1541 | scrollArea->setWidgetResizable(true); |
---|
| 1542 | scrollArea->setWidget(tabWidget); |
---|
| 1543 | setCentralWidget(scrollArea); |
---|
| 1544 | #else |
---|
| 1545 | setCentralWidget(tabWidget); |
---|
| 1546 | #endif // Q_OS_WINCE_WM |
---|
| 1547 | |
---|
| 1548 | //! \hack HACK: A little hack for toolbar icons to have a sane size. |
---|
[e51c78af27] | 1549 | #ifdef HANDHELD |
---|
[7bb19df196] | 1550 | toolBarMain->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4)); |
---|
[e51c78af27] | 1551 | #endif // HANDHELD |
---|
[7bb19df196] | 1552 | QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave)); |
---|
| 1553 | if (tb != NULL) { |
---|
| 1554 | tb->setMenu(menuFileSaveAs); |
---|
| 1555 | tb->setPopupMode(QToolButton::MenuButtonPopup); |
---|
| 1556 | } |
---|
[1babbd6ba3] | 1557 | |
---|
[8b0661d1ee] | 1558 | // solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, DEF_FONT_SIZE)).value<QFont>()); |
---|
[1babbd6ba3] | 1559 | solutionText->setWordWrapMode(QTextOption::WordWrap); |
---|
| 1560 | |
---|
| 1561 | #ifndef QT_NO_PRINTER |
---|
| 1562 | actionFilePrintPreview = new QAction(this); |
---|
| 1563 | actionFilePrintPreview->setObjectName("actionFilePrintPreview"); |
---|
| 1564 | actionFilePrintPreview->setEnabled(false); |
---|
[2a436ea693] | 1565 | actionFilePrintPreview->setIcon(GET_ICON("document-print-preview")); |
---|
[1babbd6ba3] | 1566 | |
---|
| 1567 | actionFilePrint = new QAction(this); |
---|
| 1568 | actionFilePrint->setObjectName("actionFilePrint"); |
---|
| 1569 | actionFilePrint->setEnabled(false); |
---|
[2a436ea693] | 1570 | actionFilePrint->setIcon(GET_ICON("document-print")); |
---|
[1babbd6ba3] | 1571 | |
---|
| 1572 | menuFile->insertAction(actionFileExit,actionFilePrintPreview); |
---|
| 1573 | menuFile->insertAction(actionFileExit,actionFilePrint); |
---|
| 1574 | menuFile->insertSeparator(actionFileExit); |
---|
| 1575 | |
---|
[7bb19df196] | 1576 | toolBarMain->insertAction(actionSettingsPreferences, actionFilePrint); |
---|
[1babbd6ba3] | 1577 | #endif // QT_NO_PRINTER |
---|
[e51c78af27] | 1578 | |
---|
[e3533af1cf] | 1579 | groupSettingsLanguageList = new QActionGroup(this); |
---|
| 1580 | actionSettingsLanguageEnglish->setData("en"); |
---|
| 1581 | actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList); |
---|
| 1582 | loadLangList(); |
---|
| 1583 | actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty()); |
---|
| 1584 | |
---|
| 1585 | actionSettingsStyleSystem->setData(true); |
---|
| 1586 | groupSettingsStyleList = new QActionGroup(this); |
---|
| 1587 | |
---|
[7bb19df196] | 1588 | #ifndef HANDHELD |
---|
| 1589 | actionSettingsToolbarsConfigure = new QAction(this); |
---|
[2a436ea693] | 1590 | actionSettingsToolbarsConfigure->setIcon(GET_ICON("configure-toolbars")); |
---|
[7bb19df196] | 1591 | #endif // HANDHELD |
---|
| 1592 | |
---|
[1babbd6ba3] | 1593 | #ifdef Q_OS_WIN32 |
---|
| 1594 | actionHelpCheck4Updates = new QAction(this); |
---|
[2a436ea693] | 1595 | actionHelpCheck4Updates->setIcon(GET_ICON("system-software-update")); |
---|
[1babbd6ba3] | 1596 | actionHelpCheck4Updates->setEnabled(hasUpdater()); |
---|
| 1597 | menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates); |
---|
| 1598 | menuHelp->insertSeparator(actionHelpAboutQt); |
---|
| 1599 | #endif // Q_OS_WIN32 |
---|
| 1600 | |
---|
| 1601 | spinCities->setMaximum(MAX_NUM_CITIES); |
---|
| 1602 | |
---|
[94cd045fad] | 1603 | #ifndef HANDHELD |
---|
| 1604 | toolBarManager = new QtToolBarManager; |
---|
| 1605 | toolBarManager->setMainWindow(this); |
---|
[7bb19df196] | 1606 | QString cat = toolBarMain->windowTitle(); |
---|
| 1607 | toolBarManager->addToolBar(toolBarMain, cat); |
---|
[94cd045fad] | 1608 | #ifndef QT_NO_PRINTER |
---|
| 1609 | toolBarManager->addAction(actionFilePrintPreview, cat); |
---|
| 1610 | #endif // QT_NO_PRINTER |
---|
| 1611 | toolBarManager->addAction(actionHelpContents, cat); |
---|
| 1612 | toolBarManager->addAction(actionHelpContextual, cat); |
---|
| 1613 | // toolBarManager->addAction(action, cat); |
---|
[7bb19df196] | 1614 | toolBarManager->restoreState(settings->value("MainWindow/Toolbars").toByteArray()); |
---|
[a713b103e8] | 1615 | #else |
---|
| 1616 | toolBarMain->setVisible(settings->value("MainWindow/ToolbarVisible", true).toBool()); |
---|
[94cd045fad] | 1617 | #endif // HANDHELD |
---|
[7bb19df196] | 1618 | |
---|
| 1619 | retranslateUi(false); |
---|
| 1620 | |
---|
| 1621 | #ifdef Q_OS_WIN32 |
---|
| 1622 | // Adding some eyecandy in Vista and 7 :-) |
---|
| 1623 | if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool()) { |
---|
| 1624 | toggleTranclucency(true); |
---|
| 1625 | } |
---|
| 1626 | #endif // Q_OS_WIN32 |
---|
[1babbd6ba3] | 1627 | } |
---|
| 1628 | |
---|
| 1629 | void MainWindow::toggleSolutionActions(bool enable) |
---|
| 1630 | { |
---|
| 1631 | buttonSaveSolution->setEnabled(enable); |
---|
| 1632 | actionFileSaveAsSolution->setEnabled(enable); |
---|
| 1633 | solutionText->setEnabled(enable); |
---|
| 1634 | #ifndef QT_NO_PRINTER |
---|
| 1635 | actionFilePrint->setEnabled(enable); |
---|
| 1636 | actionFilePrintPreview->setEnabled(enable); |
---|
| 1637 | #endif // QT_NO_PRINTER |
---|
| 1638 | } |
---|
| 1639 | |
---|
| 1640 | void MainWindow::toggleTranclucency(bool enable) |
---|
| 1641 | { |
---|
| 1642 | #ifdef Q_OS_WIN32 |
---|
| 1643 | toggleStyle(labelVariant, enable); |
---|
| 1644 | toggleStyle(labelCities, enable); |
---|
| 1645 | toggleStyle(statusBar(), enable); |
---|
| 1646 | tabWidget->setDocumentMode(enable); |
---|
| 1647 | QtWin::enableBlurBehindWindow(this, enable); |
---|
| 1648 | #else |
---|
| 1649 | Q_UNUSED(enable); |
---|
| 1650 | #endif // Q_OS_WIN32 |
---|
| 1651 | } |
---|