- Timestamp:
- Apr 20, 2010, 11:18:18 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mainwindow.cpp
r105 r106 513 513 pd.setValue(0); 514 514 515 #ifdef DEBUG516 QTime t;517 t.start();518 #endif519 515 solutionText->clear(); 520 #ifdef DEBUG521 qDebug() << "Clear:" << t.elapsed();522 t.restart();523 #endif524 516 solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value())); 517 518 QPainter pic; 519 pic.begin(&graph); 520 pic.setRenderHint(QPainter::Antialiasing); 525 521 526 522 QTextDocument *doc = solutionText->document(); … … 529 525 cur.beginEditBlock(); 530 526 cur.setBlockFormat(fmt_paragraph); 531 cur.insertText(tr("Variant #%1 ").arg(spinVariant->value()), fmt_default);527 cur.insertText(tr("Variant #%1 Task").arg(spinVariant->value()), fmt_default); 532 528 cur.insertBlock(fmt_paragraph); 533 529 cur.insertText(tr("Task:")); 534 530 outputMatrix(cur, matrix); 531 drawNode(pic, 0); 535 532 cur.insertHtml("<hr>"); 536 533 cur.insertBlock(fmt_paragraph); 537 cur.insertText(tr("Solution of Variant #%1 Task").arg(spinVariant->value()), fmt_default); 534 int imgpos = cur.position(); 535 cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default); 538 536 cur.endEditBlock(); 539 537 … … 581 579 } 582 580 } 583 if (step->prNode->prNode != NULL) 581 if (n < spinCities->value()) { 582 if (step->prNode != NULL) 583 drawNode(pic, n - 1, false, step->prNode); 584 if (step->plNode != NULL) 585 drawNode(pic, n - 1, true, step->plNode); 586 } 587 if (step->prNode->prNode != NULL) { 584 588 step = step->prNode; 585 else if (step->plNode->prNode != NULL)589 } else if (step->plNode->prNode != NULL) { 586 590 step = step->plNode; 587 else591 } else 588 592 break; 589 593 } … … 613 617 } 614 618 cur.endEditBlock(); 615 #ifdef DEBUG 616 qDebug() << "Generate:" << t.elapsed(); 617 #endif 619 pic.end(); 620 621 QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32); 622 i.fill(0); 623 pic.begin(&i); 624 pic.drawPicture(1, 1, graph); 625 pic.end(); 626 doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i); 627 628 QTextImageFormat img; 629 img.setName("tspsg://graph.pic"); 630 631 cur.setPosition(imgpos); 632 cur.insertImage(img, QTextFrameFormat::FloatRight); 618 633 619 634 if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) { … … 744 759 } 745 760 761 void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step) 762 { 763 const int r = 35; 764 qreal x, y; 765 if (step != NULL) 766 x = left ? r : r * 3.5; 767 else 768 x = r * 2.25; 769 y = r * (3 * nstep + 1); 770 771 pic.drawEllipse(QPointF(x, y), r, r); 772 773 if (step != NULL) { 774 QFont font; 775 if (left) { 776 font = pic.font(); 777 font.setStrikeOut(true); 778 pic.setFont(font); 779 } 780 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"); 781 if (left) { 782 font.setStrikeOut(false); 783 pic.setFont(font); 784 } 785 pic.setBackgroundMode(Qt::OpaqueMode); 786 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())); 787 pic.setBackgroundMode(Qt::TransparentMode); 788 } else { 789 pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root")); 790 } 791 792 if (nstep == 1) 793 pic.drawLine(QPointF(r * 2.25, r * (3 * (nstep - 1) + 2)), QPointF(x, y - r)); 794 else 795 pic.drawLine(QPointF(r * 3.5, r * (3 * (nstep - 1) + 2)), QPointF(x, y - r)); 796 797 } 798 746 799 void MainWindow::dropEvent(QDropEvent *ev) 747 800 { … … 783 836 fmt_table.setCellSpacing(5); 784 837 785 fmt_ce nter.setAlignment(Qt::AlignHCenter);838 fmt_cell.setAlignment(Qt::AlignHCenter); 786 839 787 840 QColor color = settings->value("Output/Colors/Text", DEF_TEXT_COLOR).value<QColor>(); … … 913 966 for (int c = 0; c < n; c++) { 914 967 cur = table->cellAt(r, c).firstCursorPosition(); 915 cur.setBlockFormat(fmt_ce nter);968 cur.setBlockFormat(fmt_cell); 916 969 cur.setBlockCharFormat(fmt_default); 917 970 if (matrix.at(r).at(c) == INFINITY) … … 933 986 for (int c = 0; c < n; c++) { 934 987 cur = table->cellAt(r, c).firstCursorPosition(); 935 cur.setBlockFormat(fmt_ce nter);988 cur.setBlockFormat(fmt_cell); 936 989 if (step.matrix.at(r).at(c) == INFINITY) 937 990 cur.insertText(INFSTR, fmt_default); -
trunk/src/mainwindow.h
r105 r106 101 101 #endif // Q_OS_WINCE_WM 102 102 103 // The solution graph SVG 104 QPicture graph; 105 103 106 // Formats 104 107 QTextTableFormat fmt_table; 105 108 QTextBlockFormat fmt_paragraph, 106 fmt_ce nter;109 fmt_cell; 107 110 QTextCharFormat fmt_default, 108 111 fmt_selected, … … 112 115 void closeEvent(QCloseEvent *ev); 113 116 void dragEnterEvent(QDragEnterEvent *ev); 117 void drawNode(QPainter &pic, int nstep, bool left = false, SStep *step = NULL); 114 118 void dropEvent(QDropEvent *ev); 115 119 bool hasUpdater() const;
Note: See TracChangeset
for help on using the changeset viewer.