Changeset f0464480db in tspsg for src/mainwindow.cpp
- Timestamp:
- Dec 16, 2009, 11:22:05 PM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 0bd0e1aca7
- Parents:
- 53f11f0e6c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mainwindow.cpp
r53f11f0e6c rf0464480db 302 302 { 303 303 //! \todo TODO: Normal about window :-) 304 QString about = QString::fromUtf8("TSPSG: TSP Solver and Generator\n"); 305 about += QString::fromUtf8(" Version: "BUILD_VERSION"\n"); 306 about += QString::fromUtf8(" Copyright (C) 2007-%1 Lёppa <contacts[at]oleksii[dot]name>\n").arg(QDate::currentDate().toString("yyyy")); 307 about += QString::fromUtf8("Target OS: %1\n").arg(OS); 308 about += "Qt library:\n"; 309 about += QString::fromUtf8(" Compile time: %1\n").arg(QT_VERSION_STR); 310 about += QString::fromUtf8(" Runtime: %1\n").arg(qVersion()); 311 about += QString::fromUtf8("Built on %1 at %2\n").arg(__DATE__).arg(__TIME__); 312 about += QString::fromUtf8(VERSIONID"\n\n"); 313 about += QString::fromUtf8("Algorithm: %1\n").arg(CTSPSolver::getVersionId()); 314 about += "\n"; 315 about += "TSPSG is licensed under the terms of the GNU General Public License. You should have received a copy of the GNU General Public License along with TSPSG."; 316 QMessageBox(QMessageBox::Information,"About",about,QMessageBox::Ok,this).exec(); 304 QString about = QString::fromUtf8("<b>TSPSG: TSP Solver and Generator</b><br>"); 305 about += QString::fromUtf8(" Version: <b>"BUILD_VERSION"</b><br>"); 306 about += QString::fromUtf8(" Copyright: <b>© 2007-%1 Lёppa</b><br>").arg(QDate::currentDate().toString("yyyy")); 307 about += QString::fromUtf8(" <b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sourceforge.net/</a></b><br>"); 308 about += "<br>"; 309 about += QString::fromUtf8("Target OS: <b>%1</b><br>").arg(OS); 310 about += "Qt library:<br>"; 311 about += QString::fromUtf8(" Build time: <b>%1</b><br>").arg(QT_VERSION_STR); 312 about += QString::fromUtf8(" Runtime: <b>%1</b><br>").arg(qVersion()); 313 about += QString::fromUtf8("Built on <b>%1</b> at <b>%2</b><br>").arg(__DATE__).arg(__TIME__); 314 about += QString::fromUtf8("Id: <b>"VERSIONID"</b><br>"); 315 about += QString::fromUtf8("Algorithm: <b>%1</b><br>").arg(CTSPSolver::getVersionId()); 316 about += "<br>"; 317 about += "TSPSG is free software: you can redistribute it and/or modify it<br>" 318 "under the terms of the GNU General Public License as published<br>" 319 "by the Free Software Foundation, either version 3 of the License,<br>" 320 "or (at your option) any later version.<br>" 321 "<br>" 322 "TSPSG is distributed in the hope that it will be useful, but<br>" 323 "WITHOUT ANY WARRANTY; without even the implied warranty of<br>" 324 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>" 325 "GNU General Public License for more details.<br>" 326 "<br>" 327 "You should have received a copy of the GNU General Public License<br>" 328 "along with TSPSG. If not, see <a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a>."; 329 330 QDialog *dlg = new QDialog(this); 331 QLabel *lblIcon = new QLabel(dlg); 332 QTextBrowser *txtAbout = new QTextBrowser(dlg); 333 QVBoxLayout *vb1 = new QVBoxLayout(), 334 *vb2 = new QVBoxLayout(); 335 QHBoxLayout *hb = new QHBoxLayout(); 336 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg); 337 338 lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(64, Qt::SmoothTransformation)); 339 340 vb1->addWidget(lblIcon); 341 vb1->addStretch(); 342 343 // txtAbout->setTextInteractionFlags(txtAbout->textInteractionFlags() ^ Qt::TextEditable); 344 txtAbout->setWordWrapMode(QTextOption::NoWrap); 345 txtAbout->setOpenExternalLinks(true); 346 txtAbout->setHtml(about); 347 txtAbout->moveCursor(QTextCursor::Start); 348 349 hb->addLayout(vb1); 350 hb->addWidget(txtAbout); 351 352 vb2->addLayout(hb); 353 vb2->addWidget(bb); 354 355 dlg->setWindowTitle(trUtf8("About TSPSG")); 356 dlg->setLayout(vb2); 357 358 connect(bb, SIGNAL(accepted()), dlg, SLOT(accept())); 359 360 dlg->resize(475, 350); 361 dlg->exec(); 362 363 delete dlg; 317 364 } 318 365 … … 331 378 void MainWindow::buttonSolveClicked() 332 379 { 333 tMatrix matrix;380 TMatrix matrix; 334 381 QList<double> row; 335 382 int n = spinCities->value(); … … 347 394 } 348 395 CTSPSolver solver; 349 sStep *root = solver.solve(n,matrix,this);396 SStep *root = solver.solve(n,matrix,this); 350 397 if (!root) 351 398 return; … … 358 405 output.append("<hr>"); 359 406 output.append("<p>" + trUtf8("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>"); 360 sStep *step = root;407 SStep *step = root; 361 408 n = 1; 362 409 while (n <= spinCities->value()) { 363 if (step->prNode->prNode != NULL || ( step->prNode->prNode == NULL && step->plNode->prNode == NULL)) {410 if (step->prNode->prNode != NULL || ((step->prNode->prNode == NULL) && (step->plNode->prNode == NULL))) { 364 411 if (n != spinCities->value()) { 365 412 output.append("<p>" + trUtf8("Step #%1").arg(n++) + "</p>"); 366 outputMatrix(step->matrix,output,step->candidate.nRow,step->candidate.nCol); 367 if (step->alts) 368 output.append("<p class=\"hasalts\">" + trUtf8("This step has alternate candidates for branching.") + "</p>"); 413 outputMatrix(*step, output); 414 output.append("<p>" + trUtf8("Selected candidate for branching: %1.").arg(trUtf8("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)) + "</p>"); 415 if (!step->alts.empty()) { 416 TCandidate cand; 417 QString alts; 418 foreach(cand, step->alts) { 419 if (!alts.isEmpty()) 420 alts += ", "; 421 alts += trUtf8("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1); 422 } 423 output.append("<p class=\"hasalts\">" + trUtf8("%n alternate candidate(s) for branching: %1.","",step->alts.count()).arg(alts) + "</p>"); 424 } 369 425 output.append("<p> </p>"); 370 426 } … … 392 448 393 449 // Scrolling to the end of text. 394 QTextCursor cursor(solutionText->textCursor()); 395 cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); 396 solutionText->setTextCursor(cursor); 450 solutionText->moveCursor(QTextCursor::End); 397 451 398 452 enableSolutionActions(); … … 536 590 qtTranslator = NULL; 537 591 } 538 qtTranslator = new QTranslator();539 592 static QTranslator *translator; // Application translator 540 593 if (translator) { … … 543 596 } 544 597 translator = new QTranslator(); 545 if ( lng.compare("en") && !lng.startsWith("en_")) {598 if ((lng.compare("en") != 0) && !lng.startsWith("en_")) { 546 599 // Trying to load system Qt library translation... 600 qtTranslator = new QTranslator(); 547 601 if (qtTranslator->load("qt_" + lng,QLibraryInfo::location(QLibraryInfo::TranslationsPath))) 548 602 qApp->installTranslator(qtTranslator); 549 else 550 // No luck. Let's try to load bundled one.603 else { 604 // No luck. Let's try to load a bundled one. 551 605 if (qtTranslator->load("qt_" + lng,PATH_I18N)) 552 606 qApp->installTranslator(qtTranslator); … … 556 610 qtTranslator = NULL; 557 611 } 558 // Now let's load application translation. 559 if (translator->load(lng,PATH_I18N)) 560 qApp->installTranslator(translator); 561 else { 612 } 613 } 614 // Now let's load application translation. 615 if (translator->load(lng,PATH_I18N)) 616 qApp->installTranslator(translator); 617 else { 618 delete translator; 619 translator = NULL; 620 if ((lng.compare("en") != 0) && !lng.startsWith("en_")) { 562 621 if (!ad) 563 622 QMessageBox(QMessageBox::Warning,trUtf8("Language Change"),trUtf8("Unable to load translation language."),QMessageBox::Ok,this).exec(); 564 delete translator;565 translator = NULL;566 623 return false; 567 624 } … … 583 640 } 584 641 585 void MainWindow::outputMatrix(const tMatrix &matrix, QStringList &output, int nRow, int nCol)642 void MainWindow::outputMatrix(const TMatrix &matrix, QStringList &output) 586 643 { 587 644 int n = spinCities->value(); … … 593 650 if (matrix.at(r).at(c) == INFINITY) 594 651 line += "<td align=\"center\">"INFSTR"</td>"; 595 else if ((r == nRow) && (c == nCol))596 line += "<td align=\"center\" class=\"selected\">" + QVariant(matrix.at(r).at(c)).toString() + "</td>";597 652 else 598 653 line += "<td align=\"center\">" + QVariant(matrix.at(r).at(c)).toString() + "</td>"; 654 } 655 line += "</tr>"; 656 output.append(line); 657 } 658 output.append("</table>"); 659 } 660 661 void MainWindow::outputMatrix(const SStep &step, QStringList &output) 662 { 663 int n = spinCities->value(); 664 QString line=""; 665 output.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"); 666 for (int r = 0; r < n; r++) { 667 line = "<tr>"; 668 for (int c = 0; c < n; c++) { 669 if (step.matrix.at(r).at(c) == INFINITY) 670 line += "<td align=\"center\">"INFSTR"</td>"; 671 else if ((r == step.candidate.nRow) && (c == step.candidate.nCol)) 672 line += "<td align=\"center\" class=\"selected\">" + QVariant(step.matrix.at(r).at(c)).toString() + "</td>"; 673 else { 674 TCandidate cand; 675 cand.nRow = r; 676 cand.nCol = c; 677 if (step.alts.contains(cand)) 678 line += "<td align=\"center\" class=\"alternate\">" + QVariant(step.matrix.at(r).at(c)).toString() + "</td>"; 679 else 680 line += "<td align=\"center\">" + QVariant(step.matrix.at(r).at(c)).toString() + "</td>"; 681 } 599 682 } 600 683 line += "</tr>";
Note: See TracChangeset
for help on using the changeset viewer.