[100] | 1 | /* |
---|
| 2 | * TSPSG: TSP Solver and Generator |
---|
| 3 | * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> |
---|
| 4 | * |
---|
| 5 | * $Id: mainwindow.cpp 134 2010-09-06 20:23:38Z laleppa $ |
---|
| 6 | * $URL: https://tspsg.svn.sourceforge.net/svnroot/tspsg/trunk/src/mainwindow.cpp $ |
---|
| 7 | * |
---|
| 8 | * This file is part of TSPSG. |
---|
| 9 | * |
---|
| 10 | * TSPSG is free software: you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 13 | * (at your option) any later version. |
---|
| 14 | * |
---|
| 15 | * TSPSG is distributed in the hope that it will be useful, |
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | * GNU General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with TSPSG. If not, see <http://www.gnu.org/licenses/>. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include "mainwindow.h" |
---|
| 25 | |
---|
[124] | 26 | #ifdef Q_OS_WIN32 |
---|
| 27 | #include "shobjidl.h" |
---|
| 28 | #endif |
---|
| 29 | |
---|
[121] | 30 | #ifdef _T_T_L_ |
---|
| 31 | #include "_.h" |
---|
[122] | 32 | _C_ _R_ _Y_ _P_ _T_ |
---|
[121] | 33 | #endif |
---|
| 34 | |
---|
[100] | 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 | |
---|
[115] | 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 | |
---|
[100] | 55 | loadLanguage(); |
---|
| 56 | setupUi(); |
---|
[105] | 57 | setAcceptDrops(true); |
---|
[100] | 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 |
---|
[114] | 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())); |
---|
[100] | 75 | #ifndef QT_NO_PRINTER |
---|
[114] | 76 | connect(actionFilePrintPreview, SIGNAL(triggered()), SLOT(actionFilePrintPreviewTriggered())); |
---|
| 77 | connect(actionFilePrint, SIGNAL(triggered()), SLOT(actionFilePrintTriggered())); |
---|
[100] | 78 | #endif // QT_NO_PRINTER |
---|
[118] | 79 | #ifndef HANDHELD |
---|
| 80 | connect(actionSettingsToolbarsConfigure, SIGNAL(triggered()), SLOT(actionSettingsToolbarsConfigureTriggered())); |
---|
| 81 | #endif // HANDHELD |
---|
[114] | 82 | connect(actionSettingsPreferences, SIGNAL(triggered()), SLOT(actionSettingsPreferencesTriggered())); |
---|
[100] | 83 | #ifdef Q_OS_WIN32 |
---|
| 84 | connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered())); |
---|
| 85 | #endif // Q_OS_WIN32 |
---|
[114] | 86 | connect(actionSettingsLanguageAutodetect, SIGNAL(triggered(bool)), SLOT(actionSettingsLanguageAutodetectTriggered(bool))); |
---|
| 87 | connect(groupSettingsLanguageList, SIGNAL(triggered(QAction *)), SLOT(groupSettingsLanguageListTriggered(QAction *))); |
---|
[115] | 88 | connect(actionSettingsStyleSystem, SIGNAL(triggered(bool)), SLOT(actionSettingsStyleSystemTriggered(bool))); |
---|
| 89 | connect(groupSettingsStyleList, SIGNAL(triggered(QAction*)), SLOT(groupSettingsStyleListTriggered(QAction*))); |
---|
[114] | 90 | connect(actionHelpAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); |
---|
| 91 | connect(actionHelpAbout, SIGNAL(triggered()), SLOT(actionHelpAboutTriggered())); |
---|
[100] | 92 | |
---|
[114] | 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))); |
---|
[100] | 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); |
---|
[114] | 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())); |
---|
[100] | 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 | |
---|
[128] | 160 | QString file; |
---|
| 161 | if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
[133] | 162 | file = settings->value(OS"/LastUsed/TaskLoadPath").toString(); |
---|
[128] | 163 | else |
---|
| 164 | file = QFileInfo(fileName).path(); |
---|
[100] | 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; |
---|
[128] | 169 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
[133] | 170 | settings->setValue(OS"/LastUsed/TaskLoadPath", QFileInfo(file).path()); |
---|
[128] | 171 | |
---|
[100] | 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 | { |
---|
[128] | 183 | if ((fileName == tr("Untitled") + ".tspt") || !fileName.endsWith(".tspt", Qt::CaseInsensitive)) |
---|
[100] | 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; |
---|
[128] | 201 | if (selectedFile.isEmpty()) { |
---|
| 202 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) { |
---|
[133] | 203 | selectedFile = settings->value(OS"/LastUsed/SolutionSavePath").toString(); |
---|
[128] | 204 | } |
---|
| 205 | } else |
---|
| 206 | selectedFile = QFileInfo(selectedFile).path(); |
---|
[100] | 207 | if (!selectedFile.isEmpty()) |
---|
[128] | 208 | selectedFile.append("/"); |
---|
[100] | 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; |
---|
[128] | 236 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
[133] | 237 | settings->setValue(OS"/LastUsed/SolutionSavePath", QFileInfo(selectedFile).path()); |
---|
[100] | 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 |
---|
[108] | 249 | if (selectedFile.endsWith(".htm", Qt::CaseInsensitive) || selectedFile.endsWith(".html", Qt::CaseInsensitive)) { |
---|
| 250 | QFile file(selectedFile); |
---|
| 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); |
---|
[109] | 257 | QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(); |
---|
[134] | 258 | #if !defined(NOSVG) |
---|
[109] | 259 | if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) { |
---|
[134] | 260 | #else // NOSVG |
---|
[109] | 261 | if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) { |
---|
[134] | 262 | #endif // NOSVG |
---|
[109] | 263 | format = DEF_GRAPH_IMAGE_FORMAT; |
---|
| 264 | settings->remove("Output/GraphImageFormat"); |
---|
| 265 | } |
---|
[108] | 266 | QString html = solutionText->document()->toHtml("UTF-8"), |
---|
[109] | 267 | img = fi.completeBaseName() + "." + format; |
---|
[125] | 268 | html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" alt=\"%2\"").arg(img, tr("Solution Graph"))); |
---|
[109] | 269 | |
---|
[108] | 270 | // Saving solution text as HTML |
---|
| 271 | QTextStream ts(&file); |
---|
| 272 | ts.setCodec(QTextCodec::codecForName("UTF-8")); |
---|
| 273 | ts << html; |
---|
| 274 | file.close(); |
---|
[109] | 275 | |
---|
| 276 | // Saving solution graph as SVG or PNG (depending on settings and SVG support) |
---|
[134] | 277 | #if !defined(NOSVG) |
---|
[109] | 278 | if (format == "svg") { |
---|
[108] | 279 | QSvgGenerator svg; |
---|
[109] | 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())); |
---|
[108] | 285 | QPainter p; |
---|
[109] | 286 | p.begin(&svg); |
---|
| 287 | p.drawPicture(1, 1, graph); |
---|
| 288 | p.end(); |
---|
| 289 | } else { |
---|
[134] | 290 | #endif // NOSVG |
---|
[125] | 291 | QImage i(graph.width(), graph.height(), QImage::Format_ARGB32); |
---|
[109] | 292 | i.fill(0x00FFFFFF); |
---|
| 293 | QPainter p; |
---|
| 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 | } |
---|
[134] | 311 | #if !defined(NOSVG) |
---|
[109] | 312 | } |
---|
[134] | 313 | #endif // NOSVG |
---|
[108] | 314 | } else { |
---|
[100] | 315 | QTextDocumentWriter dw(selectedFile); |
---|
[108] | 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())); |
---|
[100] | 320 | } |
---|
| 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)); |
---|
[117] | 338 | solutionText->print(printer); |
---|
[100] | 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"); |
---|
[115] | 361 | QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on the next %1 start.").arg(QApplication::applicationName())); |
---|
[100] | 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 | |
---|
[115] | 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 | |
---|
[118] | 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 | |
---|
[100] | 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 | { |
---|
[124] | 447 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 448 | |
---|
[100] | 449 | QString title; |
---|
[109] | 450 | title += QString("<b>%1</b><br>").arg(QApplication::applicationName()); |
---|
[100] | 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()); |
---|
[118] | 454 | #endif // HANDHELD |
---|
[126] | 455 | title += QString("<b><a href=\"http://tspsg.info/\">http://tspsg.info/</a></b>"); |
---|
[100] | 456 | |
---|
| 457 | QString about; |
---|
[133] | 458 | about += QString("%1: <b>%2</b><br>").arg(tr("Target OS (ARCH)"), PLATFROM); |
---|
[100] | 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 |
---|
[133] | 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>"; |
---|
[100] | 467 | about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId()); |
---|
| 468 | about += "<br>"; |
---|
[124] | 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>."); |
---|
[100] | 481 | |
---|
[124] | 482 | QString credits; |
---|
[127] | 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" |
---|
[124] | 485 | "see <a href=\"http://qt.nokia.com/\">qt.nokia.com</a><br>\n" |
---|
| 486 | "<br>\n" |
---|
[127] | 487 | "Most icons used in %1 are part of <b>Oxygen Icons</b> project " |
---|
[124] | 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" |
---|
[127] | 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" |
---|
[130] | 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" |
---|
[131] | 497 | "see <a href=\"http://dejavu-fonts.org/\">dejavu-fonts.org</a>") |
---|
| 498 | .arg("TSPSG"); |
---|
[124] | 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 | } |
---|
| 509 | |
---|
[100] | 510 | QDialog *dlg = new QDialog(this); |
---|
| 511 | QLabel *lblIcon = new QLabel(dlg), |
---|
[124] | 512 | *lblTitle = new QLabel(dlg); |
---|
[100] | 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 |
---|
[124] | 516 | QTabWidget *tabs = new QTabWidget(dlg); |
---|
[100] | 517 | QTextBrowser *txtAbout = new QTextBrowser(dlg); |
---|
[124] | 518 | QTextBrowser *txtLicense = new QTextBrowser(dlg); |
---|
| 519 | QTextBrowser *txtCredits = new QTextBrowser(dlg); |
---|
[100] | 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 |
---|
[115] | 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())); |
---|
[100] | 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 |
---|
[115] | 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())); |
---|
[100] | 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); |
---|
[124] | 546 | txtAbout->setFrameShape(QFrame::NoFrame); |
---|
[100] | 547 | |
---|
[124] | 548 | // txtCredits->setWordWrapMode(QTextOption::NoWrap); |
---|
| 549 | txtCredits->setOpenExternalLinks(true); |
---|
| 550 | txtCredits->setHtml(credits); |
---|
| 551 | txtCredits->moveCursor(QTextCursor::Start); |
---|
| 552 | txtCredits->setFrameShape(QFrame::NoFrame); |
---|
[100] | 553 | |
---|
[124] | 554 | txtLicense->setWordWrapMode(QTextOption::NoWrap); |
---|
| 555 | txtLicense->setOpenExternalLinks(true); |
---|
| 556 | txtLicense->setText(f.readAll()); |
---|
| 557 | txtLicense->moveCursor(QTextCursor::Start); |
---|
| 558 | txtLicense->setFrameShape(QFrame::NoFrame); |
---|
[100] | 559 | |
---|
[124] | 560 | bb->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor)); |
---|
[134] | 561 | bb->button(QDialogButtonBox::Ok)->setIcon(GET_ICON("dialog-ok")); |
---|
[121] | 562 | |
---|
[100] | 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 |
---|
[124] | 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); |
---|
[100] | 591 | vb->addLayout(hb2); |
---|
| 592 | |
---|
| 593 | dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
---|
[115] | 594 | dlg->setWindowTitle(tr("About %1").arg(QApplication::applicationName())); |
---|
[134] | 595 | dlg->setWindowIcon(GET_ICON("help-about")); |
---|
[100] | 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); |
---|
[124] | 608 | QApplication::restoreOverrideCursor(); |
---|
[100] | 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); |
---|
[124] | 650 | QPushButton *cancel = new QPushButton(&pd); |
---|
[134] | 651 | cancel->setIcon(GET_ICON("dialog-cancel")); |
---|
[124] | 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); |
---|
[100] | 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 | |
---|
[124] | 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 | |
---|
[100] | 676 | CTSPSolver solver; |
---|
[124] | 677 | solver.setCleanupOnCancel(false); |
---|
[100] | 678 | connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); |
---|
| 679 | connect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); |
---|
[124] | 680 | #ifdef Q_OS_WIN32 |
---|
| 681 | if (tl != NULL) |
---|
| 682 | connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int))); |
---|
| 683 | #endif |
---|
[100] | 684 | SStep *root = solver.solve(n, matrix); |
---|
[124] | 685 | #ifdef Q_OS_WIN32 |
---|
| 686 | if (tl != NULL) |
---|
| 687 | disconnect(&solver, SIGNAL(routePartFound(int)), this, SLOT(solverRoutePartFound(int))); |
---|
| 688 | #endif |
---|
[100] | 689 | disconnect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); |
---|
| 690 | disconnect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); |
---|
| 691 | if (!root) { |
---|
| 692 | pd.reset(); |
---|
[124] | 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); |
---|
[100] | 701 | QMessageBox::warning(this, tr("Solution Result"), tr("Unable to find a solution.\nMaybe, this task has no solution.")); |
---|
[124] | 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 | |
---|
| 713 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
| 714 | while (!f.isFinished()) { |
---|
| 715 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
| 716 | } |
---|
| 717 | pd.reset(); |
---|
| 718 | #ifdef Q_OS_WIN32 |
---|
| 719 | if (tl != NULL) { |
---|
| 720 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
| 721 | tl->Release(); |
---|
| 722 | tl = NULL; |
---|
| 723 | } |
---|
| 724 | #endif |
---|
[100] | 725 | return; |
---|
| 726 | } |
---|
| 727 | pb->setFormat(tr("Generating header")); |
---|
| 728 | pd.setLabelText(tr("Generating solution output...")); |
---|
[107] | 729 | pd.setMaximum(solver.getTotalSteps() + 1); |
---|
[100] | 730 | pd.setValue(0); |
---|
| 731 | |
---|
[124] | 732 | #ifdef Q_OS_WIN32 |
---|
| 733 | if (tl != NULL) |
---|
| 734 | tl->SetProgressValue(winId(), spinCities->value(), spinCities->value() + solver.getTotalSteps() + 1); |
---|
| 735 | #endif |
---|
| 736 | |
---|
[100] | 737 | solutionText->clear(); |
---|
[104] | 738 | solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value())); |
---|
| 739 | |
---|
[106] | 740 | QPainter pic; |
---|
[107] | 741 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
| 742 | pic.begin(&graph); |
---|
[125] | 743 | pic.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); |
---|
[129] | 744 | QFont font = settings->value("Output/Font", QFont(DEF_FONT_FACE, 9)).value<QFont>(); |
---|
[127] | 745 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
| 746 | font.setWeight(QFont::DemiBold); |
---|
| 747 | font.setPointSizeF(font.pointSizeF() * 2); |
---|
| 748 | } |
---|
[125] | 749 | pic.setFont(font); |
---|
[109] | 750 | pic.setBrush(QBrush(QColor(Qt::white))); |
---|
[127] | 751 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
[125] | 752 | QPen pen = pic.pen(); |
---|
[127] | 753 | pen.setWidth(2); |
---|
| 754 | pic.setPen(pen); |
---|
| 755 | } |
---|
[109] | 756 | pic.setBackgroundMode(Qt::OpaqueMode); |
---|
[107] | 757 | } |
---|
[106] | 758 | |
---|
[104] | 759 | QTextDocument *doc = solutionText->document(); |
---|
| 760 | QTextCursor cur(doc); |
---|
| 761 | |
---|
| 762 | cur.beginEditBlock(); |
---|
| 763 | cur.setBlockFormat(fmt_paragraph); |
---|
[106] | 764 | cur.insertText(tr("Variant #%1 Task").arg(spinVariant->value()), fmt_default); |
---|
[104] | 765 | cur.insertBlock(fmt_paragraph); |
---|
| 766 | cur.insertText(tr("Task:")); |
---|
| 767 | outputMatrix(cur, matrix); |
---|
[121] | 768 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
| 769 | #ifdef _T_T_L_ |
---|
[122] | 770 | _b_ _i_ _z_ _a_ _r_ _r_ _e_ |
---|
[121] | 771 | #endif |
---|
[107] | 772 | drawNode(pic, 0); |
---|
[121] | 773 | } |
---|
[104] | 774 | cur.insertHtml("<hr>"); |
---|
| 775 | cur.insertBlock(fmt_paragraph); |
---|
[106] | 776 | int imgpos = cur.position(); |
---|
| 777 | cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default); |
---|
[104] | 778 | cur.endEditBlock(); |
---|
| 779 | |
---|
[100] | 780 | SStep *step = root; |
---|
[107] | 781 | int c = n = 1; |
---|
[100] | 782 | pb->setFormat(tr("Generating step %v")); |
---|
[107] | 783 | while ((step->next != SStep::NoNextStep) && (c < spinCities->value())) { |
---|
[100] | 784 | if (pd.wasCanceled()) { |
---|
[104] | 785 | pd.setLabelText(tr("Cleaning up...")); |
---|
| 786 | pd.setMaximum(0); |
---|
| 787 | pd.setCancelButton(NULL); |
---|
| 788 | pd.show(); |
---|
| 789 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
[124] | 790 | #ifdef Q_OS_WIN32 |
---|
| 791 | if (tl != NULL) |
---|
| 792 | tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
| 793 | #endif |
---|
| 794 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
| 795 | while (!f.isFinished()) { |
---|
| 796 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
| 797 | } |
---|
[100] | 798 | solutionText->clear(); |
---|
[104] | 799 | toggleSolutionActions(false); |
---|
[124] | 800 | #ifdef Q_OS_WIN32 |
---|
| 801 | if (tl != NULL) { |
---|
| 802 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
| 803 | tl->Release(); |
---|
| 804 | tl = NULL; |
---|
| 805 | } |
---|
| 806 | #endif |
---|
[100] | 807 | return; |
---|
| 808 | } |
---|
| 809 | pd.setValue(n); |
---|
[124] | 810 | #ifdef Q_OS_WIN32 |
---|
| 811 | if (tl != NULL) |
---|
| 812 | tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1); |
---|
| 813 | #endif |
---|
[100] | 814 | |
---|
[107] | 815 | cur.beginEditBlock(); |
---|
| 816 | cur.insertBlock(fmt_paragraph); |
---|
| 817 | cur.insertText(tr("Step #%1").arg(n)); |
---|
| 818 | 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())))) { |
---|
| 819 | outputMatrix(cur, *step); |
---|
| 820 | } |
---|
| 821 | cur.insertBlock(fmt_paragraph); |
---|
| 822 | 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); |
---|
| 823 | if (!step->alts.empty()) { |
---|
| 824 | SStep::SCandidate cand; |
---|
| 825 | QString alts; |
---|
| 826 | foreach(cand, step->alts) { |
---|
| 827 | if (!alts.isEmpty()) |
---|
| 828 | alts += ", "; |
---|
| 829 | alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1); |
---|
[100] | 830 | } |
---|
[107] | 831 | cur.insertBlock(fmt_paragraph); |
---|
| 832 | cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist); |
---|
[100] | 833 | } |
---|
[107] | 834 | cur.insertBlock(fmt_paragraph); |
---|
| 835 | cur.insertText(" ", fmt_default); |
---|
| 836 | cur.endEditBlock(); |
---|
| 837 | |
---|
| 838 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
[106] | 839 | if (step->prNode != NULL) |
---|
[107] | 840 | drawNode(pic, n, false, step->prNode); |
---|
[106] | 841 | if (step->plNode != NULL) |
---|
[107] | 842 | drawNode(pic, n, true, step->plNode); |
---|
[106] | 843 | } |
---|
[107] | 844 | n++; |
---|
| 845 | |
---|
| 846 | if (step->next == SStep::RightBranch) { |
---|
| 847 | c++; |
---|
[100] | 848 | step = step->prNode; |
---|
[107] | 849 | } else if (step->next == SStep::LeftBranch) { |
---|
[100] | 850 | step = step->plNode; |
---|
[106] | 851 | } else |
---|
[100] | 852 | break; |
---|
| 853 | } |
---|
| 854 | pb->setFormat(tr("Generating footer")); |
---|
| 855 | pd.setValue(n); |
---|
[124] | 856 | #ifdef Q_OS_WIN32 |
---|
| 857 | if (tl != NULL) |
---|
| 858 | tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1); |
---|
| 859 | #endif |
---|
[100] | 860 | |
---|
[104] | 861 | cur.beginEditBlock(); |
---|
| 862 | cur.insertBlock(fmt_paragraph); |
---|
[100] | 863 | if (solver.isOptimal()) |
---|
[104] | 864 | cur.insertText(tr("Optimal path:")); |
---|
[100] | 865 | else |
---|
[104] | 866 | cur.insertText(tr("Resulting path:")); |
---|
| 867 | |
---|
| 868 | cur.insertBlock(fmt_paragraph); |
---|
[110] | 869 | cur.insertText(" " + solver.getSortedPath(tr("City %1"))); |
---|
[104] | 870 | |
---|
| 871 | cur.insertBlock(fmt_paragraph); |
---|
[100] | 872 | if (isInteger(step->price)) |
---|
[104] | 873 | cur.insertHtml("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>"); |
---|
[100] | 874 | else |
---|
[104] | 875 | 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>"); |
---|
[100] | 876 | if (!solver.isOptimal()) { |
---|
[104] | 877 | cur.insertBlock(fmt_paragraph); |
---|
| 878 | cur.insertText(" "); |
---|
| 879 | cur.insertBlock(fmt_paragraph); |
---|
| 880 | 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>"); |
---|
[100] | 881 | } |
---|
[104] | 882 | cur.endEditBlock(); |
---|
[100] | 883 | |
---|
[107] | 884 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
| 885 | pic.end(); |
---|
| 886 | |
---|
[127] | 887 | QImage i(graph.width() + 1, graph.height() + 1, QImage::Format_RGB32); |
---|
| 888 | i.fill(0xFFFFFF); |
---|
[107] | 889 | pic.begin(&i); |
---|
| 890 | pic.drawPicture(1, 1, graph); |
---|
| 891 | pic.end(); |
---|
| 892 | doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i); |
---|
[106] | 893 | |
---|
| 894 | QTextImageFormat img; |
---|
[107] | 895 | img.setName("tspsg://graph.pic"); |
---|
[127] | 896 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
| 897 | img.setWidth(i.width() / 2); |
---|
| 898 | img.setHeight(i.height() / 2); |
---|
| 899 | } else { |
---|
| 900 | img.setWidth(i.width()); |
---|
| 901 | img.setHeight(i.height()); |
---|
| 902 | } |
---|
[106] | 903 | |
---|
[107] | 904 | cur.setPosition(imgpos); |
---|
| 905 | cur.insertImage(img, QTextFrameFormat::FloatRight); |
---|
| 906 | } |
---|
[106] | 907 | |
---|
[100] | 908 | if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) { |
---|
[104] | 909 | // Scrolling to the end of the text. |
---|
[100] | 910 | solutionText->moveCursor(QTextCursor::End); |
---|
| 911 | } else |
---|
| 912 | solutionText->moveCursor(QTextCursor::Start); |
---|
| 913 | |
---|
| 914 | pd.setLabelText(tr("Cleaning up...")); |
---|
| 915 | pd.setMaximum(0); |
---|
| 916 | pd.setCancelButton(NULL); |
---|
| 917 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
[124] | 918 | #ifdef Q_OS_WIN32 |
---|
| 919 | if (tl != NULL) |
---|
| 920 | tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
| 921 | #endif |
---|
| 922 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
| 923 | while (!f.isFinished()) { |
---|
| 924 | QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
| 925 | } |
---|
[100] | 926 | toggleSolutionActions(); |
---|
| 927 | tabWidget->setCurrentIndex(1); |
---|
[124] | 928 | #ifdef Q_OS_WIN32 |
---|
| 929 | if (tl != NULL) { |
---|
| 930 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
| 931 | tl->Release(); |
---|
| 932 | tl = NULL; |
---|
| 933 | } |
---|
| 934 | #endif |
---|
| 935 | |
---|
| 936 | pd.reset(); |
---|
| 937 | QApplication::alert(this, 3000); |
---|
[100] | 938 | } |
---|
| 939 | |
---|
| 940 | void MainWindow::dataChanged() |
---|
| 941 | { |
---|
| 942 | setWindowModified(true); |
---|
| 943 | } |
---|
| 944 | |
---|
| 945 | void MainWindow::dataChanged(const QModelIndex &tl, const QModelIndex &br) |
---|
| 946 | { |
---|
| 947 | setWindowModified(true); |
---|
| 948 | if (settings->value("Autosize", DEF_AUTOSIZE).toBool()) { |
---|
| 949 | for (int k = tl.row(); k <= br.row(); k++) |
---|
| 950 | taskView->resizeRowToContents(k); |
---|
| 951 | for (int k = tl.column(); k <= br.column(); k++) |
---|
| 952 | taskView->resizeColumnToContents(k); |
---|
| 953 | } |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | #ifdef Q_OS_WINCE_WM |
---|
| 957 | void MainWindow::changeEvent(QEvent *ev) |
---|
| 958 | { |
---|
| 959 | if ((ev->type() == QEvent::ActivationChange) && isActiveWindow()) |
---|
| 960 | desktopResized(0); |
---|
| 961 | |
---|
| 962 | QWidget::changeEvent(ev); |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | void MainWindow::desktopResized(int screen) |
---|
| 966 | { |
---|
| 967 | if ((screen != 0) || !isActiveWindow()) |
---|
| 968 | return; |
---|
| 969 | |
---|
| 970 | QRect availableGeometry = QApplication::desktop()->availableGeometry(0); |
---|
| 971 | if (currentGeometry != availableGeometry) { |
---|
| 972 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 973 | /*! |
---|
| 974 | * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height. |
---|
| 975 | * If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the |
---|
| 976 | * window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile? |
---|
| 977 | */ |
---|
| 978 | if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) { |
---|
| 979 | setWindowState(windowState() | Qt::WindowMaximized); |
---|
| 980 | } else { |
---|
| 981 | if (windowState() & Qt::WindowMaximized) |
---|
| 982 | setWindowState(windowState() ^ Qt::WindowMaximized); |
---|
| 983 | setGeometry(availableGeometry); |
---|
| 984 | } |
---|
| 985 | currentGeometry = availableGeometry; |
---|
| 986 | QApplication::restoreOverrideCursor(); |
---|
| 987 | } |
---|
| 988 | } |
---|
| 989 | #endif // Q_OS_WINCE_WM |
---|
| 990 | |
---|
| 991 | void MainWindow::numCitiesChanged(int nCities) |
---|
| 992 | { |
---|
| 993 | blockSignals(true); |
---|
| 994 | spinCities->setValue(nCities); |
---|
| 995 | blockSignals(false); |
---|
| 996 | } |
---|
| 997 | |
---|
| 998 | #ifndef QT_NO_PRINTER |
---|
| 999 | void MainWindow::printPreview(QPrinter *printer) |
---|
| 1000 | { |
---|
| 1001 | solutionText->print(printer); |
---|
| 1002 | } |
---|
| 1003 | #endif // QT_NO_PRINTER |
---|
| 1004 | |
---|
[124] | 1005 | #ifdef Q_OS_WIN32 |
---|
| 1006 | void MainWindow::solverRoutePartFound(int n) |
---|
| 1007 | { |
---|
| 1008 | #ifdef Q_OS_WIN32 |
---|
| 1009 | tl->SetProgressValue(winId(), n, spinCities->value() * 2); |
---|
| 1010 | #else |
---|
| 1011 | Q_UNUSED(n); |
---|
| 1012 | #endif // Q_OS_WIN32 |
---|
| 1013 | } |
---|
| 1014 | #endif // Q_OS_WIN32 |
---|
| 1015 | |
---|
[100] | 1016 | void MainWindow::spinCitiesValueChanged(int n) |
---|
| 1017 | { |
---|
| 1018 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
| 1019 | int count = tspmodel->numCities(); |
---|
| 1020 | tspmodel->setNumCities(n); |
---|
| 1021 | if ((n > count) && settings->value("Autosize", DEF_AUTOSIZE).toBool()) |
---|
| 1022 | for (int k = count; k < n; k++) { |
---|
| 1023 | taskView->resizeColumnToContents(k); |
---|
| 1024 | taskView->resizeRowToContents(k); |
---|
| 1025 | } |
---|
| 1026 | QApplication::restoreOverrideCursor(); |
---|
| 1027 | } |
---|
| 1028 | |
---|
| 1029 | void MainWindow::closeEvent(QCloseEvent *ev) |
---|
| 1030 | { |
---|
| 1031 | if (!maybeSave()) { |
---|
| 1032 | ev->ignore(); |
---|
| 1033 | return; |
---|
| 1034 | } |
---|
| 1035 | if (!settings->value("SettingsReset", false).toBool()) { |
---|
| 1036 | settings->setValue("NumCities", spinCities->value()); |
---|
| 1037 | |
---|
| 1038 | // Saving Main Window state |
---|
[118] | 1039 | #ifndef HANDHELD |
---|
[100] | 1040 | if (settings->value("SavePos", DEF_SAVEPOS).toBool()) { |
---|
| 1041 | settings->beginGroup("MainWindow"); |
---|
| 1042 | settings->setValue("Geometry", saveGeometry()); |
---|
| 1043 | settings->setValue("State", saveState()); |
---|
[118] | 1044 | settings->setValue("Toolbars", toolBarManager->saveState()); |
---|
[100] | 1045 | settings->endGroup(); |
---|
| 1046 | } |
---|
[118] | 1047 | #endif // HANDHELD |
---|
[100] | 1048 | } else { |
---|
| 1049 | settings->remove("SettingsReset"); |
---|
| 1050 | } |
---|
| 1051 | |
---|
| 1052 | QMainWindow::closeEvent(ev); |
---|
| 1053 | } |
---|
| 1054 | |
---|
[105] | 1055 | void MainWindow::dragEnterEvent(QDragEnterEvent *ev) |
---|
| 1056 | { |
---|
| 1057 | if (ev->mimeData()->hasUrls() && (ev->mimeData()->urls().count() == 1)) { |
---|
| 1058 | QFileInfo fi(ev->mimeData()->urls().first().toLocalFile()); |
---|
| 1059 | if ((fi.suffix() == "tspt") || (fi.suffix() == "zkt")) |
---|
| 1060 | ev->acceptProposedAction(); |
---|
| 1061 | } |
---|
| 1062 | } |
---|
| 1063 | |
---|
[106] | 1064 | void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step) |
---|
| 1065 | { |
---|
[127] | 1066 | int r; |
---|
| 1067 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) |
---|
| 1068 | r = 70; |
---|
| 1069 | else |
---|
| 1070 | r = 35; |
---|
[106] | 1071 | qreal x, y; |
---|
| 1072 | if (step != NULL) |
---|
| 1073 | x = left ? r : r * 3.5; |
---|
| 1074 | else |
---|
| 1075 | x = r * 2.25; |
---|
| 1076 | y = r * (3 * nstep + 1); |
---|
| 1077 | |
---|
[121] | 1078 | #ifdef _T_T_L_ |
---|
| 1079 | if (nstep == -481124) { |
---|
| 1080 | _t_t_l_(pic, r, x); |
---|
| 1081 | return; |
---|
| 1082 | } |
---|
| 1083 | #endif |
---|
| 1084 | |
---|
[106] | 1085 | pic.drawEllipse(QPointF(x, y), r, r); |
---|
| 1086 | |
---|
| 1087 | if (step != NULL) { |
---|
| 1088 | QFont font; |
---|
| 1089 | if (left) { |
---|
| 1090 | font = pic.font(); |
---|
| 1091 | font.setStrikeOut(true); |
---|
| 1092 | pic.setFont(font); |
---|
| 1093 | } |
---|
| 1094 | 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"); |
---|
| 1095 | if (left) { |
---|
| 1096 | font.setStrikeOut(false); |
---|
| 1097 | pic.setFont(font); |
---|
| 1098 | } |
---|
[107] | 1099 | if (step->price != INFINITY) { |
---|
| 1100 | 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())); |
---|
| 1101 | } else { |
---|
| 1102 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, "\n"INFSTR); |
---|
| 1103 | } |
---|
[106] | 1104 | } else { |
---|
| 1105 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root")); |
---|
| 1106 | } |
---|
| 1107 | |
---|
[107] | 1108 | if (nstep == 1) { |
---|
| 1109 | pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r)); |
---|
| 1110 | } else if (nstep > 1) { |
---|
[110] | 1111 | pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == SStep::RightBranch) ? r * 3.5 : r, y - 2 * r)); |
---|
[107] | 1112 | } |
---|
[106] | 1113 | |
---|
| 1114 | } |
---|
| 1115 | |
---|
[105] | 1116 | void MainWindow::dropEvent(QDropEvent *ev) |
---|
| 1117 | { |
---|
| 1118 | if (maybeSave() && tspmodel->loadTask(ev->mimeData()->urls().first().toLocalFile())) { |
---|
| 1119 | setFileName(ev->mimeData()->urls().first().toLocalFile()); |
---|
| 1120 | tabWidget->setCurrentIndex(0); |
---|
| 1121 | setWindowModified(false); |
---|
| 1122 | solutionText->clear(); |
---|
| 1123 | toggleSolutionActions(false); |
---|
| 1124 | |
---|
[107] | 1125 | ev->setDropAction(Qt::CopyAction); |
---|
| 1126 | ev->accept(); |
---|
[105] | 1127 | } |
---|
| 1128 | } |
---|
| 1129 | |
---|
[100] | 1130 | bool MainWindow::hasUpdater() const |
---|
| 1131 | { |
---|
| 1132 | #ifdef Q_OS_WIN32 |
---|
| 1133 | return QFile::exists("updater/Update.exe"); |
---|
| 1134 | #else // Q_OS_WIN32 |
---|
| 1135 | return false; |
---|
| 1136 | #endif // Q_OS_WIN32 |
---|
| 1137 | } |
---|
| 1138 | |
---|
| 1139 | void MainWindow::initDocStyleSheet() |
---|
| 1140 | { |
---|
[129] | 1141 | solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(DEF_FONT_FACE, DEF_FONT_SIZE)).value<QFont>()); |
---|
[104] | 1142 | |
---|
| 1143 | fmt_paragraph.setTopMargin(0); |
---|
| 1144 | fmt_paragraph.setRightMargin(10); |
---|
| 1145 | fmt_paragraph.setBottomMargin(0); |
---|
| 1146 | fmt_paragraph.setLeftMargin(10); |
---|
| 1147 | |
---|
| 1148 | fmt_table.setTopMargin(5); |
---|
| 1149 | fmt_table.setRightMargin(10); |
---|
| 1150 | fmt_table.setBottomMargin(5); |
---|
| 1151 | fmt_table.setLeftMargin(10); |
---|
| 1152 | fmt_table.setBorder(0); |
---|
| 1153 | fmt_table.setBorderStyle(QTextFrameFormat::BorderStyle_None); |
---|
| 1154 | fmt_table.setCellSpacing(5); |
---|
| 1155 | |
---|
[106] | 1156 | fmt_cell.setAlignment(Qt::AlignHCenter); |
---|
[104] | 1157 | |
---|
[119] | 1158 | settings->beginGroup("Output/Colors"); |
---|
| 1159 | |
---|
| 1160 | QColor color = settings->value("Text", DEF_TEXT_COLOR).value<QColor>(); |
---|
[100] | 1161 | QColor hilight; |
---|
| 1162 | if (color.value() < 192) |
---|
[104] | 1163 | hilight.setHsv(color.hue(), color.saturation(), 127 + qRound(color.value() / 2)); |
---|
[100] | 1164 | else |
---|
[104] | 1165 | hilight.setHsv(color.hue(), color.saturation(), color.value() / 2); |
---|
| 1166 | |
---|
| 1167 | solutionText->document()->setDefaultStyleSheet(QString("* {color: %1;}").arg(color.name())); |
---|
| 1168 | fmt_default.setForeground(QBrush(color)); |
---|
| 1169 | |
---|
[119] | 1170 | fmt_selected.setForeground(QBrush(settings->value("Selected", DEF_SELECTED_COLOR).value<QColor>())); |
---|
[104] | 1171 | fmt_selected.setFontWeight(QFont::Bold); |
---|
| 1172 | |
---|
[119] | 1173 | fmt_alternate.setForeground(QBrush(settings->value("Alternate", DEF_ALTERNATE_COLOR).value<QColor>())); |
---|
[104] | 1174 | fmt_alternate.setFontWeight(QFont::Bold); |
---|
| 1175 | fmt_altlist.setForeground(QBrush(hilight)); |
---|
| 1176 | |
---|
[119] | 1177 | settings->endGroup(); |
---|
| 1178 | |
---|
[104] | 1179 | solutionText->setTextColor(color); |
---|
[100] | 1180 | } |
---|
| 1181 | |
---|
| 1182 | void MainWindow::loadLangList() |
---|
| 1183 | { |
---|
[121] | 1184 | QMap<QString, QStringList> langlist; |
---|
| 1185 | QFileInfoList langs; |
---|
| 1186 | QFileInfo lang; |
---|
| 1187 | QString name; |
---|
| 1188 | QStringList language, dirs; |
---|
[100] | 1189 | QTranslator t; |
---|
[121] | 1190 | QDir dir; |
---|
| 1191 | dir.setFilter(QDir::Files); |
---|
| 1192 | dir.setNameFilters(QStringList("tspsg_*.qm")); |
---|
| 1193 | dir.setSorting(QDir::NoSort); |
---|
| 1194 | |
---|
| 1195 | dirs << PATH_L10N << ":/l10n"; |
---|
| 1196 | foreach (QString dirname, dirs) { |
---|
| 1197 | dir.setPath(dirname); |
---|
| 1198 | if (dir.exists()) { |
---|
| 1199 | langs = dir.entryInfoList(); |
---|
| 1200 | for (int k = 0; k < langs.size(); k++) { |
---|
| 1201 | lang = langs.at(k); |
---|
| 1202 | if (lang.completeBaseName().compare("tspsg_en", Qt::CaseInsensitive) && !langlist.contains(lang.completeBaseName().mid(6)) && t.load(lang.completeBaseName(), dirname)) { |
---|
| 1203 | |
---|
| 1204 | language.clear(); |
---|
| 1205 | language.append(lang.completeBaseName().mid(6)); |
---|
| 1206 | language.append(t.translate("--------", "COUNTRY", "Please, provide an ISO 3166-1 alpha-2 country code for this translation language here (eg., UA).").toLower()); |
---|
| 1207 | language.append(t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here.")); |
---|
| 1208 | language.append(t.translate("MainWindow", "Set application language to %1", "").arg(name)); |
---|
| 1209 | |
---|
| 1210 | langlist.insert(language.at(0), language); |
---|
| 1211 | } |
---|
| 1212 | } |
---|
[100] | 1213 | } |
---|
| 1214 | } |
---|
[121] | 1215 | |
---|
| 1216 | QAction *a; |
---|
| 1217 | foreach (language, langlist) { |
---|
| 1218 | a = menuSettingsLanguage->addAction(language.at(2)); |
---|
| 1219 | a->setStatusTip(language.at(3)); |
---|
[134] | 1220 | #if QT_VERSION >= 0x040600 |
---|
[123] | 1221 | a->setIcon(QIcon::fromTheme(QString("flag-%1").arg(language.at(1)), QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1))))); |
---|
[134] | 1222 | #else |
---|
| 1223 | a->setIcon(QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1)))); |
---|
| 1224 | #endif |
---|
[121] | 1225 | a->setData(language.at(0)); |
---|
| 1226 | a->setCheckable(true); |
---|
| 1227 | a->setActionGroup(groupSettingsLanguageList); |
---|
| 1228 | if (settings->value("Language", QLocale::system().name()).toString().startsWith(language.at(0))) |
---|
| 1229 | a->setChecked(true); |
---|
| 1230 | } |
---|
[100] | 1231 | } |
---|
| 1232 | |
---|
| 1233 | bool MainWindow::loadLanguage(const QString &lang) |
---|
| 1234 | { |
---|
| 1235 | // i18n |
---|
| 1236 | bool ad = false; |
---|
| 1237 | QString lng = lang; |
---|
| 1238 | if (lng.isEmpty()) { |
---|
| 1239 | ad = settings->value("Language", "").toString().isEmpty(); |
---|
| 1240 | lng = settings->value("Language", QLocale::system().name()).toString(); |
---|
| 1241 | } |
---|
| 1242 | static QTranslator *qtTranslator; // Qt library translator |
---|
| 1243 | if (qtTranslator) { |
---|
| 1244 | qApp->removeTranslator(qtTranslator); |
---|
| 1245 | delete qtTranslator; |
---|
| 1246 | qtTranslator = NULL; |
---|
| 1247 | } |
---|
| 1248 | static QTranslator *translator; // Application translator |
---|
| 1249 | if (translator) { |
---|
| 1250 | qApp->removeTranslator(translator); |
---|
| 1251 | delete translator; |
---|
| 1252 | translator = NULL; |
---|
| 1253 | } |
---|
| 1254 | |
---|
| 1255 | if (lng == "en") |
---|
| 1256 | return true; |
---|
| 1257 | |
---|
| 1258 | // Trying to load system Qt library translation... |
---|
| 1259 | qtTranslator = new QTranslator(this); |
---|
| 1260 | if (qtTranslator->load("qt_" + lng, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) |
---|
| 1261 | qApp->installTranslator(qtTranslator); |
---|
| 1262 | else { |
---|
| 1263 | // No luck. Let's try to load a bundled one. |
---|
[121] | 1264 | if (qtTranslator->load("qt_" + lng, PATH_L10N)) { |
---|
| 1265 | // We have a translation in the localization direcotry. |
---|
[100] | 1266 | qApp->installTranslator(qtTranslator); |
---|
[121] | 1267 | } else if (qtTranslator->load("qt_" + lng, ":/l10n")) { |
---|
| 1268 | // We have a translation "built-in" into application resources. |
---|
| 1269 | qApp->installTranslator(qtTranslator); |
---|
| 1270 | } else { |
---|
| 1271 | // Qt library translation unavailable for this language. |
---|
[100] | 1272 | delete qtTranslator; |
---|
| 1273 | qtTranslator = NULL; |
---|
| 1274 | } |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | // Now let's load application translation. |
---|
| 1278 | translator = new QTranslator(this); |
---|
[121] | 1279 | if (translator->load("tspsg_" + lng, PATH_L10N)) { |
---|
| 1280 | // We have a translation in the localization directory. |
---|
[100] | 1281 | qApp->installTranslator(translator); |
---|
[121] | 1282 | } else if (translator->load("tspsg_" + lng, ":/l10n")) { |
---|
| 1283 | // We have a translation "built-in" into application resources. |
---|
| 1284 | qApp->installTranslator(translator); |
---|
| 1285 | } else { |
---|
[100] | 1286 | delete translator; |
---|
| 1287 | translator = NULL; |
---|
| 1288 | if (!ad) { |
---|
| 1289 | settings->remove("Language"); |
---|
| 1290 | QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); |
---|
[121] | 1291 | QMessageBox::warning(isVisible() ? this : NULL, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection.")); |
---|
[100] | 1292 | QApplication::restoreOverrideCursor(); |
---|
| 1293 | } |
---|
| 1294 | return false; |
---|
| 1295 | } |
---|
| 1296 | return true; |
---|
| 1297 | } |
---|
| 1298 | |
---|
[115] | 1299 | void MainWindow::loadStyleList() |
---|
| 1300 | { |
---|
| 1301 | menuSettingsStyle->clear(); |
---|
| 1302 | QStringList styles = QStyleFactory::keys(); |
---|
| 1303 | menuSettingsStyle->insertAction(NULL, actionSettingsStyleSystem); |
---|
| 1304 | actionSettingsStyleSystem->setChecked(!settings->contains("Style")); |
---|
| 1305 | menuSettingsStyle->addSeparator(); |
---|
| 1306 | QAction *a; |
---|
| 1307 | foreach (QString style, styles) { |
---|
| 1308 | a = menuSettingsStyle->addAction(style); |
---|
| 1309 | a->setData(false); |
---|
| 1310 | a->setStatusTip(tr("Set application style to %1").arg(style)); |
---|
| 1311 | a->setCheckable(true); |
---|
| 1312 | a->setActionGroup(groupSettingsStyleList); |
---|
| 1313 | if ((style == settings->value("Style").toString()) |
---|
| 1314 | || QString(QApplication::style()->metaObject()->className()).contains(QRegExp(QString("^Q?%1(Style)?$").arg(QRegExp::escape(style)), Qt::CaseInsensitive))) { |
---|
| 1315 | a->setChecked(true); |
---|
| 1316 | } |
---|
| 1317 | } |
---|
| 1318 | } |
---|
| 1319 | |
---|
[118] | 1320 | void MainWindow::loadToolbarList() |
---|
| 1321 | { |
---|
| 1322 | menuSettingsToolbars->clear(); |
---|
| 1323 | #ifndef HANDHELD |
---|
| 1324 | menuSettingsToolbars->insertAction(NULL, actionSettingsToolbarsConfigure); |
---|
| 1325 | menuSettingsToolbars->addSeparator(); |
---|
| 1326 | QList<QToolBar *> list = toolBarManager->toolBars(); |
---|
| 1327 | foreach (QToolBar *t, list) { |
---|
| 1328 | menuSettingsToolbars->insertAction(NULL, t->toggleViewAction()); |
---|
| 1329 | } |
---|
| 1330 | #else // HANDHELD |
---|
| 1331 | menuSettingsToolbars->insertAction(NULL, toolBarMain->toggleViewAction()); |
---|
| 1332 | #endif // HANDHELD |
---|
| 1333 | } |
---|
| 1334 | |
---|
[100] | 1335 | bool MainWindow::maybeSave() |
---|
| 1336 | { |
---|
| 1337 | if (!isWindowModified()) |
---|
| 1338 | return true; |
---|
| 1339 | 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); |
---|
| 1340 | if (res == QMessageBox::Save) |
---|
| 1341 | return actionFileSaveTriggered(); |
---|
| 1342 | else if (res == QMessageBox::Cancel) |
---|
| 1343 | return false; |
---|
| 1344 | else |
---|
| 1345 | return true; |
---|
| 1346 | } |
---|
| 1347 | |
---|
[104] | 1348 | void MainWindow::outputMatrix(QTextCursor &cur, const TMatrix &matrix) |
---|
[100] | 1349 | { |
---|
| 1350 | int n = spinCities->value(); |
---|
[104] | 1351 | QTextTable *table = cur.insertTable(n, n, fmt_table); |
---|
| 1352 | |
---|
[100] | 1353 | for (int r = 0; r < n; r++) { |
---|
| 1354 | for (int c = 0; c < n; c++) { |
---|
[104] | 1355 | cur = table->cellAt(r, c).firstCursorPosition(); |
---|
[106] | 1356 | cur.setBlockFormat(fmt_cell); |
---|
[104] | 1357 | cur.setBlockCharFormat(fmt_default); |
---|
[100] | 1358 | if (matrix.at(r).at(c) == INFINITY) |
---|
[104] | 1359 | cur.insertText(INFSTR); |
---|
[100] | 1360 | else |
---|
[104] | 1361 | 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())); |
---|
[100] | 1362 | } |
---|
[104] | 1363 | QApplication::processEvents(); |
---|
[100] | 1364 | } |
---|
[104] | 1365 | cur.movePosition(QTextCursor::End); |
---|
[100] | 1366 | } |
---|
| 1367 | |
---|
[104] | 1368 | void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step) |
---|
[100] | 1369 | { |
---|
| 1370 | int n = spinCities->value(); |
---|
[104] | 1371 | QTextTable *table = cur.insertTable(n, n, fmt_table); |
---|
| 1372 | |
---|
[100] | 1373 | for (int r = 0; r < n; r++) { |
---|
| 1374 | for (int c = 0; c < n; c++) { |
---|
[104] | 1375 | cur = table->cellAt(r, c).firstCursorPosition(); |
---|
[106] | 1376 | cur.setBlockFormat(fmt_cell); |
---|
[100] | 1377 | if (step.matrix.at(r).at(c) == INFINITY) |
---|
[104] | 1378 | cur.insertText(INFSTR, fmt_default); |
---|
[100] | 1379 | else if ((r == step.candidate.nRow) && (c == step.candidate.nCol)) |
---|
[104] | 1380 | 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); |
---|
[100] | 1381 | else { |
---|
[107] | 1382 | SStep::SCandidate cand; |
---|
[100] | 1383 | cand.nRow = r; |
---|
| 1384 | cand.nCol = c; |
---|
| 1385 | if (step.alts.contains(cand)) |
---|
[104] | 1386 | 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); |
---|
[100] | 1387 | else |
---|
[104] | 1388 | 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); |
---|
[100] | 1389 | } |
---|
| 1390 | } |
---|
[104] | 1391 | QApplication::processEvents(); |
---|
[100] | 1392 | } |
---|
[104] | 1393 | |
---|
| 1394 | cur.movePosition(QTextCursor::End); |
---|
[100] | 1395 | } |
---|
| 1396 | |
---|
| 1397 | void MainWindow::retranslateUi(bool all) |
---|
| 1398 | { |
---|
| 1399 | if (all) |
---|
| 1400 | Ui::MainWindow::retranslateUi(this); |
---|
| 1401 | |
---|
[115] | 1402 | loadStyleList(); |
---|
[118] | 1403 | loadToolbarList(); |
---|
[115] | 1404 | |
---|
[100] | 1405 | #ifndef QT_NO_PRINTER |
---|
[118] | 1406 | actionFilePrintPreview->setText(tr("P&rint Preview...")); |
---|
[100] | 1407 | #ifndef QT_NO_TOOLTIP |
---|
[118] | 1408 | actionFilePrintPreview->setToolTip(tr("Preview solution results")); |
---|
[100] | 1409 | #endif // QT_NO_TOOLTIP |
---|
| 1410 | #ifndef QT_NO_STATUSTIP |
---|
[118] | 1411 | actionFilePrintPreview->setStatusTip(tr("Preview current solution results before printing")); |
---|
[100] | 1412 | #endif // QT_NO_STATUSTIP |
---|
| 1413 | |
---|
[118] | 1414 | actionFilePrint->setText(tr("&Print...")); |
---|
[100] | 1415 | #ifndef QT_NO_TOOLTIP |
---|
[118] | 1416 | actionFilePrint->setToolTip(tr("Print solution")); |
---|
[100] | 1417 | #endif // QT_NO_TOOLTIP |
---|
| 1418 | #ifndef QT_NO_STATUSTIP |
---|
[118] | 1419 | actionFilePrint->setStatusTip(tr("Print current solution results")); |
---|
[100] | 1420 | #endif // QT_NO_STATUSTIP |
---|
[118] | 1421 | actionFilePrint->setShortcut(tr("Ctrl+P")); |
---|
[100] | 1422 | #endif // QT_NO_PRINTER |
---|
[119] | 1423 | |
---|
| 1424 | #ifndef HANDHELD |
---|
| 1425 | actionSettingsToolbarsConfigure->setText(tr("Configure...")); |
---|
| 1426 | #ifndef QT_NO_STATUSTIP |
---|
| 1427 | actionSettingsToolbarsConfigure->setStatusTip(tr("Customize toolbars")); |
---|
| 1428 | #endif // QT_NO_STATUSTIP |
---|
| 1429 | #endif // HANDHELD |
---|
| 1430 | |
---|
[100] | 1431 | #ifdef Q_OS_WIN32 |
---|
| 1432 | actionHelpCheck4Updates->setText(tr("Check for &Updates...")); |
---|
| 1433 | #ifndef QT_NO_STATUSTIP |
---|
| 1434 | actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QApplication::applicationName())); |
---|
| 1435 | #endif // QT_NO_STATUSTIP |
---|
| 1436 | #endif // Q_OS_WIN32 |
---|
| 1437 | } |
---|
| 1438 | |
---|
| 1439 | bool MainWindow::saveTask() { |
---|
| 1440 | QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)"); |
---|
| 1441 | filters.append(tr("All Files") + " (*)"); |
---|
| 1442 | QString file; |
---|
[128] | 1443 | if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) { |
---|
[133] | 1444 | file = settings->value(OS"/LastUsed/TaskSavePath").toString(); |
---|
[128] | 1445 | if (!file.isEmpty()) |
---|
| 1446 | file.append("/"); |
---|
| 1447 | file.append(fileName); |
---|
| 1448 | } else if (fileName.endsWith(".tspt", Qt::CaseInsensitive)) |
---|
[100] | 1449 | file = fileName; |
---|
| 1450 | else |
---|
[128] | 1451 | file = QFileInfo(fileName).path() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"; |
---|
[100] | 1452 | |
---|
| 1453 | QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; |
---|
| 1454 | file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts); |
---|
| 1455 | if (file.isEmpty()) |
---|
| 1456 | return false; |
---|
[128] | 1457 | else if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
[133] | 1458 | settings->setValue(OS"/LastUsed/TaskSavePath", QFileInfo(file).path()); |
---|
[128] | 1459 | |
---|
[100] | 1460 | if (tspmodel->saveTask(file)) { |
---|
| 1461 | setFileName(file); |
---|
| 1462 | setWindowModified(false); |
---|
| 1463 | return true; |
---|
| 1464 | } |
---|
| 1465 | return false; |
---|
| 1466 | } |
---|
| 1467 | |
---|
| 1468 | void MainWindow::setFileName(const QString &fileName) |
---|
| 1469 | { |
---|
| 1470 | this->fileName = fileName; |
---|
[116] | 1471 | setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(QApplication::applicationName())); |
---|
[100] | 1472 | } |
---|
| 1473 | |
---|
| 1474 | void MainWindow::setupUi() |
---|
| 1475 | { |
---|
| 1476 | Ui::MainWindow::setupUi(this); |
---|
| 1477 | |
---|
[121] | 1478 | // File Menu |
---|
[134] | 1479 | actionFileNew->setIcon(GET_ICON("document-new")); |
---|
| 1480 | actionFileOpen->setIcon(GET_ICON("document-open")); |
---|
| 1481 | actionFileSave->setIcon(GET_ICON("document-save")); |
---|
| 1482 | menuFileSaveAs->setIcon(GET_ICON("document-save-as")); |
---|
| 1483 | actionFileExit->setIcon(GET_ICON("application-exit")); |
---|
[121] | 1484 | // Settings Menu |
---|
[134] | 1485 | menuSettingsLanguage->setIcon(GET_ICON("preferences-desktop-locale")); |
---|
| 1486 | actionSettingsLanguageEnglish->setIcon(GET_ICON("flag-gb")); |
---|
| 1487 | menuSettingsStyle->setIcon(GET_ICON("preferences-desktop-theme")); |
---|
| 1488 | actionSettingsPreferences->setIcon(GET_ICON("preferences-system")); |
---|
[121] | 1489 | // Help Menu |
---|
[134] | 1490 | actionHelpContents->setIcon(GET_ICON("help-contents")); |
---|
| 1491 | actionHelpContextual->setIcon(GET_ICON("help-contextual")); |
---|
| 1492 | actionHelpAbout->setIcon(GET_ICON("help-about")); |
---|
[121] | 1493 | // Buttons |
---|
[134] | 1494 | buttonRandom->setIcon(GET_ICON("roll")); |
---|
| 1495 | buttonSolve->setIcon(GET_ICON("dialog-ok")); |
---|
| 1496 | buttonSaveSolution->setIcon(GET_ICON("document-save-as")); |
---|
| 1497 | buttonBackToTask->setIcon(GET_ICON("go-previous")); |
---|
[121] | 1498 | |
---|
[134] | 1499 | // action->setIcon(GET_ICON("")); |
---|
[121] | 1500 | |
---|
[100] | 1501 | #if QT_VERSION >= 0x040600 |
---|
| 1502 | setToolButtonStyle(Qt::ToolButtonFollowStyle); |
---|
| 1503 | #endif |
---|
| 1504 | |
---|
| 1505 | #ifndef HANDHELD |
---|
| 1506 | QStatusBar *statusbar = new QStatusBar(this); |
---|
| 1507 | statusbar->setObjectName("statusbar"); |
---|
| 1508 | setStatusBar(statusbar); |
---|
| 1509 | #endif // HANDHELD |
---|
| 1510 | |
---|
| 1511 | #ifdef Q_OS_WINCE_WM |
---|
| 1512 | menuBar()->setDefaultAction(menuFile->menuAction()); |
---|
| 1513 | |
---|
| 1514 | QScrollArea *scrollArea = new QScrollArea(this); |
---|
| 1515 | scrollArea->setFrameShape(QFrame::NoFrame); |
---|
| 1516 | scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
---|
| 1517 | scrollArea->setWidgetResizable(true); |
---|
| 1518 | scrollArea->setWidget(tabWidget); |
---|
| 1519 | setCentralWidget(scrollArea); |
---|
| 1520 | #else |
---|
| 1521 | setCentralWidget(tabWidget); |
---|
| 1522 | #endif // Q_OS_WINCE_WM |
---|
| 1523 | |
---|
| 1524 | //! \hack HACK: A little hack for toolbar icons to have a sane size. |
---|
[114] | 1525 | #ifdef HANDHELD |
---|
[118] | 1526 | toolBarMain->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4)); |
---|
[114] | 1527 | #endif // HANDHELD |
---|
[118] | 1528 | QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave)); |
---|
| 1529 | if (tb != NULL) { |
---|
| 1530 | tb->setMenu(menuFileSaveAs); |
---|
| 1531 | tb->setPopupMode(QToolButton::MenuButtonPopup); |
---|
| 1532 | } |
---|
[100] | 1533 | |
---|
[119] | 1534 | // solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, DEF_FONT_SIZE)).value<QFont>()); |
---|
[100] | 1535 | solutionText->setWordWrapMode(QTextOption::WordWrap); |
---|
| 1536 | |
---|
| 1537 | #ifndef QT_NO_PRINTER |
---|
| 1538 | actionFilePrintPreview = new QAction(this); |
---|
| 1539 | actionFilePrintPreview->setObjectName("actionFilePrintPreview"); |
---|
| 1540 | actionFilePrintPreview->setEnabled(false); |
---|
[134] | 1541 | actionFilePrintPreview->setIcon(GET_ICON("document-print-preview")); |
---|
[100] | 1542 | |
---|
| 1543 | actionFilePrint = new QAction(this); |
---|
| 1544 | actionFilePrint->setObjectName("actionFilePrint"); |
---|
| 1545 | actionFilePrint->setEnabled(false); |
---|
[134] | 1546 | actionFilePrint->setIcon(GET_ICON("document-print")); |
---|
[100] | 1547 | |
---|
| 1548 | menuFile->insertAction(actionFileExit,actionFilePrintPreview); |
---|
| 1549 | menuFile->insertAction(actionFileExit,actionFilePrint); |
---|
| 1550 | menuFile->insertSeparator(actionFileExit); |
---|
| 1551 | |
---|
[118] | 1552 | toolBarMain->insertAction(actionSettingsPreferences, actionFilePrint); |
---|
[100] | 1553 | #endif // QT_NO_PRINTER |
---|
[114] | 1554 | |
---|
[115] | 1555 | groupSettingsLanguageList = new QActionGroup(this); |
---|
| 1556 | actionSettingsLanguageEnglish->setData("en"); |
---|
| 1557 | actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList); |
---|
| 1558 | loadLangList(); |
---|
| 1559 | actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty()); |
---|
| 1560 | |
---|
| 1561 | actionSettingsStyleSystem->setData(true); |
---|
| 1562 | groupSettingsStyleList = new QActionGroup(this); |
---|
| 1563 | |
---|
[118] | 1564 | #ifndef HANDHELD |
---|
| 1565 | actionSettingsToolbarsConfigure = new QAction(this); |
---|
[134] | 1566 | actionSettingsToolbarsConfigure->setIcon(GET_ICON("configure-toolbars")); |
---|
[118] | 1567 | #endif // HANDHELD |
---|
| 1568 | |
---|
[100] | 1569 | #ifdef Q_OS_WIN32 |
---|
| 1570 | actionHelpCheck4Updates = new QAction(this); |
---|
[134] | 1571 | actionHelpCheck4Updates->setIcon(GET_ICON("system-software-update")); |
---|
[100] | 1572 | actionHelpCheck4Updates->setEnabled(hasUpdater()); |
---|
| 1573 | menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates); |
---|
| 1574 | menuHelp->insertSeparator(actionHelpAboutQt); |
---|
| 1575 | #endif // Q_OS_WIN32 |
---|
| 1576 | |
---|
| 1577 | spinCities->setMaximum(MAX_NUM_CITIES); |
---|
| 1578 | |
---|
[117] | 1579 | #ifndef HANDHELD |
---|
| 1580 | toolBarManager = new QtToolBarManager; |
---|
| 1581 | toolBarManager->setMainWindow(this); |
---|
[118] | 1582 | QString cat = toolBarMain->windowTitle(); |
---|
| 1583 | toolBarManager->addToolBar(toolBarMain, cat); |
---|
[117] | 1584 | #ifndef QT_NO_PRINTER |
---|
| 1585 | toolBarManager->addAction(actionFilePrintPreview, cat); |
---|
| 1586 | #endif // QT_NO_PRINTER |
---|
| 1587 | toolBarManager->addAction(actionHelpContents, cat); |
---|
| 1588 | toolBarManager->addAction(actionHelpContextual, cat); |
---|
| 1589 | // toolBarManager->addAction(action, cat); |
---|
[118] | 1590 | toolBarManager->restoreState(settings->value("MainWindow/Toolbars").toByteArray()); |
---|
[117] | 1591 | #endif // HANDHELD |
---|
[118] | 1592 | |
---|
| 1593 | retranslateUi(false); |
---|
| 1594 | |
---|
| 1595 | #ifdef Q_OS_WIN32 |
---|
| 1596 | // Adding some eyecandy in Vista and 7 :-) |
---|
| 1597 | if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool()) { |
---|
| 1598 | toggleTranclucency(true); |
---|
| 1599 | } |
---|
| 1600 | #endif // Q_OS_WIN32 |
---|
[100] | 1601 | } |
---|
| 1602 | |
---|
| 1603 | void MainWindow::toggleSolutionActions(bool enable) |
---|
| 1604 | { |
---|
| 1605 | buttonSaveSolution->setEnabled(enable); |
---|
| 1606 | actionFileSaveAsSolution->setEnabled(enable); |
---|
| 1607 | solutionText->setEnabled(enable); |
---|
| 1608 | #ifndef QT_NO_PRINTER |
---|
| 1609 | actionFilePrint->setEnabled(enable); |
---|
| 1610 | actionFilePrintPreview->setEnabled(enable); |
---|
| 1611 | #endif // QT_NO_PRINTER |
---|
| 1612 | } |
---|
| 1613 | |
---|
| 1614 | void MainWindow::toggleTranclucency(bool enable) |
---|
| 1615 | { |
---|
| 1616 | #ifdef Q_OS_WIN32 |
---|
| 1617 | toggleStyle(labelVariant, enable); |
---|
| 1618 | toggleStyle(labelCities, enable); |
---|
| 1619 | toggleStyle(statusBar(), enable); |
---|
| 1620 | tabWidget->setDocumentMode(enable); |
---|
| 1621 | QtWin::enableBlurBehindWindow(this, enable); |
---|
| 1622 | #else |
---|
| 1623 | Q_UNUSED(enable); |
---|
| 1624 | #endif // Q_OS_WIN32 |
---|
| 1625 | } |
---|