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