- Timestamp:
- Jul 4, 2010, 3:03:13 AM (14 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mainwindow.cpp
r123 r124 23 23 24 24 #include "mainwindow.h" 25 26 #ifdef Q_OS_WIN32 27 #include "shobjidl.h" 28 #endif 25 29 26 30 #ifdef _T_T_L_ … … 436 440 void MainWindow::actionHelpAboutTriggered() 437 441 { 442 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 443 438 444 QString title; 439 445 #ifdef HANDHELD … … 462 468 about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId()); 463 469 about += "<br>"; 464 about += tr("TSPSG is free software: you can redistribute it and/or modify it<br>" 465 "under the terms of the GNU General Public License as published<br>" 466 "by the Free Software Foundation, either version 3 of the License,<br>" 467 "or (at your option) any later version.<br>" 468 "<br>" 469 "TSPSG is distributed in the hope that it will be useful, but<br>" 470 "WITHOUT ANY WARRANTY; without even the implied warranty of<br>" 471 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>" 472 "GNU General Public License for more details.<br>" 473 "<br>" 474 "You should have received a copy of the GNU General Public License<br>" 475 "along with TSPSG. If not, see <a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a>."); 470 about += tr("This program is free software: you can redistribute it and/or modify<br>\n" 471 "it under the terms of the GNU General Public License as published by<br>\n" 472 "the Free Software Foundation, either version 3 of the License, or<br>\n" 473 "(at your option) any later version.<br>\n" 474 "<br>\n" 475 "This program is distributed in the hope that it will be useful,<br>\n" 476 "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>\n" 477 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>\n" 478 "GNU General Public License for more details.<br>\n" 479 "<br>\n" 480 "You should have received a copy of the GNU General Public License<br>\n" 481 "along with TSPSG. If not, see <a href=\"http://www.gnu.org/licenses/\">www.gnu.org/licenses/</a>."); 482 483 QString credits; 484 credits += tr("This software was created using LGPL version of <b>Qt framework</b>,<br>\n" 485 "see <a href=\"http://qt.nokia.com/\">qt.nokia.com</a><br>\n" 486 "<br>\n" 487 "Most icons used in this software are part of <b>Oxygen Icons</b> project " 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" 491 "Country flag icons used in this software are part of the free " 492 "<b>Flag Icons</b> collection created by <b>IconDrawer</b>,<br>\n" 493 "see <a href=\"http://www.icondrawer.com/\">www.icondrawer.com</a>"); 494 495 QFile f(":/files/COPYING"); 496 f.open(QIODevice::ReadOnly); 497 498 QString translation = QApplication::translate("--------", "AUTHORS %1", "Please, provide translator credits here. %1 will be replaced with VERSION"); 499 if ((translation != "AUTHORS %1") && (translation.contains("%1"))) { 500 QString about = QApplication::translate("--------", "VERSION", "Please, provide your translation version here."); 501 if (about != "VERSION") 502 translation = translation.arg(about); 503 } 476 504 477 505 QDialog *dlg = new QDialog(this); 478 506 QLabel *lblIcon = new QLabel(dlg), 479 *lblTitle = new QLabel(dlg), 480 *lblTranslated = new QLabel(dlg); 507 *lblTitle = new QLabel(dlg); 481 508 #ifdef HANDHELD 482 509 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); 483 510 #endif // HANDHELD 511 QTabWidget *tabs = new QTabWidget(dlg); 484 512 QTextBrowser *txtAbout = new QTextBrowser(dlg); 513 QTextBrowser *txtLicense = new QTextBrowser(dlg); 514 QTextBrowser *txtCredits = new QTextBrowser(dlg); 485 515 QVBoxLayout *vb = new QVBoxLayout(); 486 516 QHBoxLayout *hb1 = new QHBoxLayout(), … … 509 539 txtAbout->setHtml(about); 510 540 txtAbout->moveCursor(QTextCursor::Start); 511 #ifndef HANDHELD 512 txtAbout->setStyleSheet(QString("QTextBrowser {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().base().color().name(), palette().shadow().color().name())); 513 #endif // HANDHELD 541 txtAbout->setFrameShape(QFrame::NoFrame); 542 543 // txtCredits->setWordWrapMode(QTextOption::NoWrap); 544 txtCredits->setOpenExternalLinks(true); 545 txtCredits->setHtml(credits); 546 txtCredits->moveCursor(QTextCursor::Start); 547 txtCredits->setFrameShape(QFrame::NoFrame); 548 549 txtLicense->setWordWrapMode(QTextOption::NoWrap); 550 txtLicense->setOpenExternalLinks(true); 551 txtLicense->setText(f.readAll()); 552 txtLicense->moveCursor(QTextCursor::Start); 553 txtLicense->setFrameShape(QFrame::NoFrame); 514 554 515 555 bb->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor)); 516 517 lblTranslated->setText(QApplication::translate("--------", "AUTHORS", "Please, provide translator credits here."));518 if (lblTranslated->text() == "AUTHORS")519 lblTranslated->hide();520 else {521 lblTranslated->setOpenExternalLinks(true);522 #ifndef HANDHELD523 lblTranslated->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px; padding: 1px;}").arg(palette().alternateBase().color().name(), palette().shadow().color().name()));524 #endif // HANDHELD525 hb2->addWidget(lblTranslated);526 }527 528 // This one isn't displayed anywhere, yet. Provided as a placeholder for future use.529 QApplication::translate("--------", "VERSION", "Please, provide your translation version here.");530 556 531 557 hb2->addWidget(bb); … … 538 564 vb->addWidget(lblSubTitle); 539 565 #endif // HANDHELD 540 vb->addWidget(txtAbout); 566 567 tabs->addTab(txtAbout, tr("About")); 568 tabs->addTab(txtLicense, tr("License")); 569 tabs->addTab(txtCredits, tr("Credits")); 570 if (translation != "AUTHORS %1") { 571 QTextBrowser *txtTranslation = new QTextBrowser(dlg); 572 // txtTranslation->setWordWrapMode(QTextOption::NoWrap); 573 txtTranslation->setOpenExternalLinks(true); 574 txtTranslation->setText(translation); 575 txtTranslation->moveCursor(QTextCursor::Start); 576 txtTranslation->setFrameShape(QFrame::NoFrame); 577 578 tabs->addTab(txtTranslation, tr("Translation")); 579 } 580 #ifndef HANDHELD 581 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())); 582 #endif // HANDHELD 583 584 vb->addWidget(tabs); 541 585 vb->addLayout(hb2); 542 586 … … 556 600 557 601 dlg->resize(450, 350); 602 QApplication::restoreOverrideCursor(); 558 603 559 604 dlg->exec(); … … 597 642 pb->setFormat(tr("%v of %1 parts found").arg(n)); 598 643 pd.setBar(pb); 644 QPushButton *cancel = new QPushButton(&pd); 645 cancel->setIcon(QIcon::fromTheme("dialog-cancel", QIcon(":/images/icons/dialog-cancel.png"))); 646 cancel->setText(QApplication::translate("QProgressDialog", "Cancel", "No need to translate this. This translation will be taken from Qt translation files.")); 647 pd.setCancelButton(cancel); 599 648 pd.setMaximum(n); 600 649 pd.setAutoReset(false); … … 605 654 pd.show(); 606 655 656 #ifdef Q_OS_WIN32 657 HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (LPVOID*)&tl); 658 if (SUCCEEDED(hr)) { 659 hr = tl->HrInit(); 660 if (FAILED(hr)) { 661 tl->Release(); 662 tl = NULL; 663 } else { 664 // tl->SetProgressState(winId(), TBPF_INDETERMINATE); 665 tl->SetProgressValue(winId(), 0, n * 2); 666 } 667 } 668 #endif 669 607 670 CTSPSolver solver; 671 solver.setCleanupOnCancel(false); 608 672 connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); 609 673 connect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); 674 #ifdef Q_OS_WIN32 675 if (tl != NULL) 676 connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int))); 677 #endif 610 678 SStep *root = solver.solve(n, matrix); 679 #ifdef Q_OS_WIN32 680 if (tl != NULL) 681 disconnect(&solver, SIGNAL(routePartFound(int)), this, SLOT(solverRoutePartFound(int))); 682 #endif 611 683 disconnect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); 612 684 disconnect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); 613 685 if (!root) { 614 686 pd.reset(); 615 if (!solver.wasCanceled()) 687 if (!solver.wasCanceled()) { 688 #ifdef Q_OS_WIN32 689 if (tl != NULL) { 690 // tl->SetProgressValue(winId(), n, n * 2); 691 tl->SetProgressState(winId(), TBPF_ERROR); 692 } 693 #endif 694 QApplication::alert(this); 616 695 QMessageBox::warning(this, tr("Solution Result"), tr("Unable to find a solution.\nMaybe, this task has no solution.")); 696 } 697 pd.setLabelText(tr("Cleaning up...")); 698 pd.setMaximum(0); 699 pd.setCancelButton(NULL); 700 pd.show(); 701 #ifdef Q_OS_WIN32 702 if (tl != NULL) 703 tl->SetProgressState(winId(), TBPF_INDETERMINATE); 704 #endif 705 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); 706 707 QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); 708 while (!f.isFinished()) { 709 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); 710 } 711 pd.reset(); 712 #ifdef Q_OS_WIN32 713 if (tl != NULL) { 714 tl->SetProgressState(winId(), TBPF_NOPROGRESS); 715 tl->Release(); 716 tl = NULL; 717 } 718 #endif 617 719 return; 618 720 } … … 621 723 pd.setMaximum(solver.getTotalSteps() + 1); 622 724 pd.setValue(0); 725 726 #ifdef Q_OS_WIN32 727 if (tl != NULL) 728 tl->SetProgressValue(winId(), spinCities->value(), spinCities->value() + solver.getTotalSteps() + 1); 729 #endif 623 730 624 731 solutionText->clear(); … … 665 772 pd.show(); 666 773 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); 667 solver.cleanup(true); 774 #ifdef Q_OS_WIN32 775 if (tl != NULL) 776 tl->SetProgressState(winId(), TBPF_INDETERMINATE); 777 #endif 778 QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); 779 while (!f.isFinished()) { 780 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); 781 } 668 782 solutionText->clear(); 669 783 toggleSolutionActions(false); 784 #ifdef Q_OS_WIN32 785 if (tl != NULL) { 786 tl->SetProgressState(winId(), TBPF_NOPROGRESS); 787 tl->Release(); 788 tl = NULL; 789 } 790 #endif 670 791 return; 671 792 } 672 793 pd.setValue(n); 794 #ifdef Q_OS_WIN32 795 if (tl != NULL) 796 tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1); 797 #endif 673 798 674 799 cur.beginEditBlock(); … … 713 838 pb->setFormat(tr("Generating footer")); 714 839 pd.setValue(n); 840 #ifdef Q_OS_WIN32 841 if (tl != NULL) 842 tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1); 843 #endif 715 844 716 845 cur.beginEditBlock(); … … 764 893 pd.setCancelButton(NULL); 765 894 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); 766 solver.cleanup(true); 895 #ifdef Q_OS_WIN32 896 if (tl != NULL) 897 tl->SetProgressState(winId(), TBPF_INDETERMINATE); 898 #endif 899 QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); 900 while (!f.isFinished()) { 901 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); 902 } 767 903 toggleSolutionActions(); 768 904 tabWidget->setCurrentIndex(1); 905 #ifdef Q_OS_WIN32 906 if (tl != NULL) { 907 tl->SetProgressState(winId(), TBPF_NOPROGRESS); 908 tl->Release(); 909 tl = NULL; 910 } 911 #endif 912 913 pd.reset(); 914 QApplication::alert(this, 3000); 769 915 } 770 916 … … 833 979 } 834 980 #endif // QT_NO_PRINTER 981 982 #ifdef Q_OS_WIN32 983 void MainWindow::solverRoutePartFound(int n) 984 { 985 #ifdef Q_OS_WIN32 986 tl->SetProgressValue(winId(), n, spinCities->value() * 2); 987 #else 988 Q_UNUSED(n); 989 #endif // Q_OS_WIN32 990 } 991 #endif // Q_OS_WIN32 835 992 836 993 void MainWindow::spinCitiesValueChanged(int n) -
trunk/src/mainwindow.h
r118 r124 35 35 36 36 #include "tspmodel.h" 37 38 #ifdef Q_OS_WIN32 39 // Forward declaration. A real one is in shobjidl.h 40 struct ITaskbarList3; 41 #endif 37 42 38 43 using namespace TSPSolver; … … 88 93 void printPreview(QPrinter *printer); 89 94 #endif // QT_NO_PRINTER 95 #ifdef Q_OS_WIN32 96 void solverRoutePartFound(int n); 97 #endif // Q_OS_WIN32 90 98 void spinCitiesValueChanged(int nCities); 91 99 … … 111 119 QRect currentGeometry; 112 120 #endif // Q_OS_WINCE_WM 121 122 #ifdef Q_OS_WIN32 123 ITaskbarList3 *tl; 124 #endif // Q_OS_WIN32 113 125 114 126 // The solution graph SVG -
trunk/src/tspsolver.cpp
r116 r124 43 43 */ 44 44 CTSPSolver::CTSPSolver(QObject *parent) 45 : QObject(parent), nCities(0), total(0), root(NULL) {}45 : QObject(parent), cc(true), nCities(0), total(0), root(NULL) {} 46 46 47 47 /*! … … 51 51 * \note It is not required to call this function manually. This function is always called by solve() at the beginning of the solution process. 52 52 * 53 * \sa solve() 53 * \sa solve(), setCleanupOnCancel() 54 54 */ 55 55 void CTSPSolver::cleanup(bool processEvents) 56 56 { 57 #ifdef QAPPLICATION_H58 if (!processEvents)59 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));60 #endif61 57 route.clear(); 62 58 mayNotBeOptimal = false; 63 59 if (root != NULL) 64 60 deleteTree(root, processEvents); 65 #ifdef QAPPLICATION_H66 if (!processEvents)67 QApplication::restoreOverrideCursor();68 #endif69 61 } 70 62 … … 115 107 { 116 108 return !mayNotBeOptimal; 109 } 110 111 /*! 112 * \brief Sets whether or not to call cleanup() on solution cancel. 113 * \param enable Set to \c true to enable clenup (default). 114 * 115 * This may be useful if you want to make cleanup yourself or provide indication of clenup to user. 116 * 117 * \note Please, note that cleanup() is explicitly called at the start of each solution. 118 * Disabling cleanup and forgetting to do it manually may considerably increase the solution time for large tasks (with more than 15 cities). 119 * \sa cleanup() 120 */ 121 void CTSPSolver::setCleanupOnCancel(bool enable) 122 { 123 cc = enable; 117 124 } 118 125 … … 174 181 locker.relock(); 175 182 if ((nRow == -1) || (nCol == -1) || canceled) { 176 cleanup(); 183 if (canceled && cc) 184 cleanup(); 177 185 return NULL; 178 186 } -
trunk/src/tspsolver.h
r116 r124 113 113 CTSPSolver(QObject *parent = NULL); 114 114 void cleanup(bool processEvents = false); 115 QString getSortedPath(const QString &city, const QString &separator = " -> ") const;115 QString getSortedPath(const QString &city, const QString &separator = QString(" -> ")) const; 116 116 int getTotalSteps() const; 117 117 bool isOptimal() const; 118 void setCleanupOnCancel(bool enable = true); 118 119 SStep *solve(int numCities, const TMatrix &task); 119 120 bool wasCanceled() const; … … 131 132 132 133 private: 133 bool mayNotBeOptimal, canceled ;134 bool mayNotBeOptimal, canceled, cc; 134 135 int nCities, total; 135 136 SStep *root;
Note: See TracChangeset
for help on using the changeset viewer.