Changeset 20015b41e7 in tspsg for src/mainwindow.cpp


Ignore:
Timestamp:
Apr 27, 2010, 9:12:55 AM (14 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
5d401f2c50
Parents:
ca3d2a30fa
git-author:
Oleksii Serdiuk <contacts@…> (04/27/10 09:12:55)
git-committer:
Oleksii Serdiuk <contacts@…> (06/29/12 19:41:31)
Message:

+ Added the ability to select in what format to save the graph when saving solution as HTML.

  • Moved all installation and deployment rules to a separate install.pri file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    rca3d2a30fa r20015b41e7  
    226226                }
    227227QFileInfo fi(selectedFile);
     228QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString();
     229#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
     230        if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) {
     231#else // NOSVG && QT_VERSION >= 0x040500
     232        if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) {
     233#endif // NOSVG && QT_VERSION >= 0x040500
     234                format = DEF_GRAPH_IMAGE_FORMAT;
     235                settings->remove("Output/GraphImageFormat");
     236        }
    228237QString html = solutionText->document()->toHtml("UTF-8"),
    229                 img = fi.completeBaseName() + ".svg";
    230                 html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" width=\"%2\" height=\"%3\" alt=\"%4\"").arg(img).arg(graph.width() + 1).arg(graph.height() + 1).arg(tr("Solution Graph")));
     238                img =  fi.completeBaseName() + "." + format;
     239                html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" width=\"%2\" height=\"%3\" alt=\"%4\"").arg(img).arg(graph.width() + 2).arg(graph.height() + 2).arg(tr("Solution Graph")));
     240
    231241                // Saving solution text as HTML
    232242QTextStream ts(&file);
     
    234244                ts << html;
    235245                file.close();
    236                 // Saving solution graph as SVG
     246
     247                // Saving solution graph as SVG or PNG (depending on settings and SVG support)
     248#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
     249                if (format == "svg") {
    237250QSvgGenerator svg;
    238                 svg.setFileName(fi.path() + "/" + img);
    239                 svg.setTitle(tr("Solution Graph"));
     251                        svg.setSize(QSize(graph.width(), graph.height()));
     252                        svg.setResolution(graph.logicalDpiX());
     253                        svg.setFileName(fi.path() + "/" + img);
     254                        svg.setTitle(tr("Solution Graph"));
     255                        svg.setDescription(tr("Generated with %1").arg(QApplication::applicationName()));
    240256QPainter p;
    241                 p.begin(&svg);
    242                 graph.play(&p);
    243                 p.end();
     257                        p.begin(&svg);
     258                        p.drawPicture(1, 1, graph);
     259                        p.end();
     260                } else {
     261#endif // NOSVG && QT_VERSION >= 0x040500
     262QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
     263                        i.fill(0x00FFFFFF);
     264QPainter p;
     265                        p.begin(&i);
     266                        p.drawPicture(1, 1, graph);
     267                        p.end();
     268QImageWriter pic(fi.path() + "/" + img);
     269                        if (pic.supportsOption(QImageIOHandler::Description)) {
     270                                pic.setText("Title", "Solution Graph");
     271                                pic.setText("Software", QApplication::applicationName());
     272                        }
     273                        if (format == "png")
     274                                pic.setQuality(5);
     275                        else if (format == "jpeg")
     276                                pic.setQuality(80);
     277                        if (!pic.write(i)) {
     278                                QApplication::restoreOverrideCursor();
     279                                QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString()));
     280                                return;
     281                        }
     282#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
     283                }
     284#endif // NOSVG && QT_VERSION >= 0x040500
    244285
    245286// Qt < 4.5 has no QTextDocumentWriter class
     
    351392        title += QString("<b>TSPSG<br>TSP Solver and Generator</b><br>");
    352393#else
    353         title += QString("<b>TSPSG: TSP Solver and Generator</b><br>");
     394        title += QString("<b>%1</b><br>").arg(QApplication::applicationName());
    354395#endif // HANDHELD
    355396        title += QString("%1: <b>%2</b><br>").arg(tr("Version"), QApplication::applicationVersion());
     
    536577                pic.begin(&graph);
    537578                pic.setRenderHint(QPainter::Antialiasing);
     579                pic.setFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, 9)).value<QFont>());
     580                pic.setBrush(QBrush(QColor(Qt::white)));
     581                pic.setBackgroundMode(Qt::OpaqueMode);
    538582        }
    539583
     
    805849                        pic.setFont(font);
    806850                }
    807                 pic.setBackgroundMode(Qt::OpaqueMode);
    808851                if (step->price != INFINITY) {
    809852                        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()));
     
    811854                        pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, "\n"INFSTR);
    812855                }
    813                 pic.setBackgroundMode(Qt::TransparentMode);
    814856        } else {
    815857                pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root"));
Note: See TracChangeset for help on using the changeset viewer.