Changeset 1fbf016a09 in tspsg for src/mainwindow.cpp
- Timestamp:
- Dec 18, 2009, 1:57:39 PM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 3bcb7e8910
- Parents:
- 140109febb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mainwindow.cpp
r140109febb r1fbf016a09 47 47 solutionText->setWordWrapMode(QTextOption::WordWrap); 48 48 #ifdef Q_OS_WINCE 49 // A little hack for toolbar icons to have sane size. 50 int s = qMin(QApplication::desktop()->screenGeometry().width(),QApplication::desktop()->screenGeometry().height()); 51 toolBar->setIconSize(QSize(s / 10,s / 10)); 49 // A little hack for toolbar icons to have a sane size. 50 toolBar->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4)); 52 51 #endif 53 52 #ifndef QT_NO_PRINTER … … 129 128 tabWidget->setCurrentIndex(0); 130 129 solutionText->clear(); 131 enableSolutionActions(false);130 toggleSolutionActions(false); 132 131 QApplication::restoreOverrideCursor(); 133 132 } … … 137 136 if (!maybeSave()) 138 137 return; 139 QFileDialog od(this); 140 od.setAcceptMode(QFileDialog::AcceptOpen); 141 od.setFileMode(QFileDialog::ExistingFile); 138 142 139 QStringList filters(trUtf8("All Supported Formats") + " (*.tspt *.zkt)"); 143 140 filters.append(trUtf8("%1 Task Files").arg("TSPSG") + " (*.tspt)"); 144 141 filters.append(trUtf8("%1 Task Files").arg("ZKomModRd") + " (*.zkt)"); 145 142 filters.append(trUtf8("All Files") + " (*)"); 146 od.setNameFilters(filters); 147 if (od.exec() != QDialog::Accepted) 148 return; 149 QStringList files = od.selectedFiles(); 150 if (files.empty()) 151 return; 152 if (!tspmodel->loadTask(files.first())) 153 return; 154 setFileName(files.first()); 143 144 QString file = QFileDialog::getOpenFileName(this, trUtf8("Task Load"), QString(), filters.join(";;")); 145 if (file.isEmpty() || !QFileInfo(file).isFile()) 146 return; 147 if (!tspmodel->loadTask(file)) 148 return; 149 setFileName(file); 155 150 tabWidget->setCurrentIndex(0); 156 151 setWindowModified(false); 157 152 solutionText->clear(); 158 enableSolutionActions(false);153 toggleSolutionActions(false); 159 154 } 160 155 … … 176 171 { 177 172 static QString selectedFile; 178 if (selectedFile.isEmpty()) 179 #ifndef QT_NO_PRINTER 180 selectedFile = "solution.pdf"; 173 if (selectedFile.isEmpty()) { 174 if (fileName == trUtf8("Untitled") + ".tspt") { 175 #ifndef QT_NO_PRINTER 176 selectedFile = "solution.pdf"; 181 177 #else 182 selectedFile = "solution.html";178 selectedFile = "solution.html"; 183 179 #endif // QT_NO_PRINTER 184 QFileDialog sd(this); 185 sd.setAcceptMode(QFileDialog::AcceptSave); 180 } else { 181 #ifndef QT_NO_PRINTER 182 selectedFile = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".pdf"; 183 #else 184 selectedFile = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".html"; 185 #endif // QT_NO_PRINTER 186 } 187 } 188 186 189 QStringList filters; 187 190 #ifndef QT_NO_PRINTER 188 filters.append(trUtf8("PDF Files") + " (*.pdf)");191 filters.append(trUtf8("PDF Files") + " (*.pdf)"); 189 192 #endif 190 193 filters.append(trUtf8("HTML Files") + " (*.html *.htm)"); … … 193 196 #endif // QT_VERSION >= 0x040500 194 197 filters.append(trUtf8("All Files") + " (*)"); 195 sd.setNameFilters(filters); 196 sd.selectFile(selectedFile); 197 if (sd.exec() != QDialog::Accepted) 198 return; 199 QStringList files = sd.selectedFiles(); 200 if (files.empty()) 201 return; 202 selectedFile = files.first(); 198 199 QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;")); 200 if (file.isEmpty()) 201 return; 202 selectedFile = file; 203 203 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 204 204 #ifndef QT_NO_PRINTER … … 302 302 { 303 303 //! \todo TODO: Normal about window :-) 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>"; 304 QString title; 305 #ifdef Q_OS_WINCE 306 title += QString::fromUtf8("<b>TSPSG<br>TSP Solver and Generator</b><br>"); 307 #else 308 title += QString::fromUtf8("<b>TSPSG: TSP Solver and Generator</b><br>"); 309 #endif // Q_OS_WINCE 310 title += QString::fromUtf8("Version: <b>"BUILD_VERSION"</b><br>"); 311 title += QString::fromUtf8("<b>© 2007-%1 Lёppa</b><br>").arg(QDate::currentDate().toString("yyyy")); 312 title += QString::fromUtf8("<b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sf.net/</a></b><br>"); 313 QString about; 309 314 about += QString::fromUtf8("Target OS: <b>%1</b><br>").arg(OS); 310 about += "Qt library:<br>"; 315 #ifndef STATIC_BUILD 316 about += "Qt library (shared):<br>"; 311 317 about += QString::fromUtf8(" Build time: <b>%1</b><br>").arg(QT_VERSION_STR); 312 318 about += QString::fromUtf8(" Runtime: <b>%1</b><br>").arg(qVersion()); 319 #else 320 about += QString::fromUtf8("Qt library: <b>%1</b> (static)<br>").arg(QT_VERSION_STR); 321 #endif // STATIC_BUILD 313 322 about += QString::fromUtf8("Built on <b>%1</b> at <b>%2</b><br>").arg(__DATE__).arg(__TIME__); 323 about += "<br>"; 314 324 about += QString::fromUtf8("Id: <b>"VERSIONID"</b><br>"); 315 325 about += QString::fromUtf8("Algorithm: <b>%1</b><br>").arg(CTSPSolver::getVersionId()); … … 329 339 330 340 QDialog *dlg = new QDialog(this); 331 QLabel *lblIcon = new QLabel(dlg); 341 QLabel *lblIcon = new QLabel(dlg), 342 *lblTitle = new QLabel(dlg); 332 343 QTextBrowser *txtAbout = new QTextBrowser(dlg); 333 QVBoxLayout *vb1 = new QVBoxLayout(), 334 *vb2 = new QVBoxLayout(); 344 QVBoxLayout *vb = new QVBoxLayout(); 335 345 QHBoxLayout *hb = new QHBoxLayout(); 336 346 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg); 337 347 338 lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(64, Qt::SmoothTransformation)); 339 340 vb1->addWidget(lblIcon); 341 vb1->addStretch(); 348 lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(logicalDpiX() * 2 / 3, Qt::SmoothTransformation)); 349 lblIcon->setAlignment(Qt::AlignTop); 350 lblTitle->setText(title); 351 352 hb->addWidget(lblIcon); 353 hb->addWidget(lblTitle); 354 hb->addStretch(); 342 355 343 356 // txtAbout->setTextInteractionFlags(txtAbout->textInteractionFlags() ^ Qt::TextEditable); … … 347 360 txtAbout->moveCursor(QTextCursor::Start); 348 361 349 hb->addLayout(vb1); 350 hb->addWidget(txtAbout); 351 352 vb2->addLayout(hb); 353 vb2->addWidget(bb); 354 362 vb->addLayout(hb); 363 vb->addWidget(txtAbout); 364 vb->addWidget(bb); 365 366 dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); 355 367 dlg->setWindowTitle(trUtf8("About TSPSG")); 356 dlg->setLayout(vb 2);368 dlg->setLayout(vb); 357 369 358 370 connect(bb, SIGNAL(accepted()), dlg, SLOT(accept())); 359 371 360 dlg->resize(4 75, 350);372 dlg->resize(410, 300); 361 373 dlg->exec(); 362 374 … … 402 414 output.append("<p>" + trUtf8("Variant #%1").arg(spinVariant->value()) + "</p>"); 403 415 output.append("<p>" + trUtf8("Task:") + "</p>"); 404 outputMatrix(matrix, output);416 outputMatrix(matrix, output); 405 417 output.append("<hr>"); 406 418 output.append("<p>" + trUtf8("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>"); … … 411 423 if (n != spinCities->value()) { 412 424 output.append("<p>" + trUtf8("Step #%1").arg(n++) + "</p>"); 413 outputMatrix(*step, output); 425 if (settings->value("Output/ShowMatrix", DEF_SHOW_MATRIX).toBool() && settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() && (spinCities->value() <= settings->value("Output/ShowMatrixCitiesLimit", DEF_SHOW_MATRIX_CITY_LIMIT).toInt())) { 426 outputMatrix(*step, output); 427 } 414 428 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 429 if (!step->alts.empty()) { … … 444 458 } 445 459 output.append("<p></p>"); 460 446 461 solutionText->setHtml(output.join("")); 447 462 solutionText->setDocumentTitle(trUtf8("Solution of Variant #%1 task").arg(spinVariant->value())); … … 450 465 solutionText->moveCursor(QTextCursor::End); 451 466 452 enableSolutionActions();467 toggleSolutionActions(); 453 468 tabWidget->setCurrentIndex(1); 454 469 QApplication::restoreOverrideCursor(); … … 515 530 516 531 QMainWindow::closeEvent(ev); 517 }518 519 void MainWindow::enableSolutionActions(bool enable)520 {521 buttonSaveSolution->setEnabled(enable);522 actionFileSaveAsSolution->setEnabled(enable);523 solutionText->setEnabled(enable);524 if (!enable)525 output.clear();526 #ifndef QT_NO_PRINTER527 actionFilePrint->setEnabled(enable);528 actionFilePrintPreview->setEnabled(enable);529 #endif // QT_NO_PRINTER530 532 } 531 533 … … 688 690 689 691 bool MainWindow::saveTask() { 690 QFileDialog sd(this);691 sd.setAcceptMode(QFileDialog::AcceptSave);692 692 QStringList filters(trUtf8("%1 Task File").arg("TSPSG") + " (*.tspt)"); 693 693 filters.append(trUtf8("All Files") + " (*)"); 694 sd.setNameFilters(filters); 695 sd.setDefaultSuffix("tspt"); 696 if (fileName.endsWith(".tspt",Qt::CaseInsensitive)) 697 sd.selectFile(fileName); 694 QString file; 695 if (fileName.endsWith(".tspt", Qt::CaseInsensitive)) 696 file = fileName; 698 697 else 699 sd.selectFile(QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"); 700 if (sd.exec() != QDialog::Accepted) 698 file = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"; 699 700 file = QFileDialog::getSaveFileName(this, trUtf8("Task Save"), file, filters.join(";;")); 701 if (file.isEmpty()) 701 702 return false; 702 QStringList files = sd.selectedFiles(); 703 if (files.empty()) 704 return false; 705 if (tspmodel->saveTask(files.first())) { 706 setFileName(files.first()); 703 if (tspmodel->saveTask(file)) { 704 setFileName(file); 707 705 setWindowModified(false); 708 706 return true; … … 716 714 setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(trUtf8("Travelling Salesman Problem"))); 717 715 } 716 717 void MainWindow::toggleSolutionActions(bool enable) 718 { 719 buttonSaveSolution->setEnabled(enable); 720 actionFileSaveAsSolution->setEnabled(enable); 721 solutionText->setEnabled(enable); 722 if (!enable) 723 output.clear(); 724 #ifndef QT_NO_PRINTER 725 actionFilePrint->setEnabled(enable); 726 actionFilePrintPreview->setEnabled(enable); 727 #endif // QT_NO_PRINTER 728 }
Note: See TracChangeset
for help on using the changeset viewer.