Changeset 20015b41e7 in tspsg for src


Ignore:
Timestamp:
Apr 27, 2010, 9:12:55 AM (15 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.
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/defaults.h

    rca3d2a30fa r20015b41e7  
    6767//! Default for "Show solution graph"
    6868#define DEF_SHOW_GRAPH true
     69/*!
     70 * \def DEF_GRAPH_IMAGE_FORMAT
     71 * \brief Default for "Save solution graph as"
     72 */
     73#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
     74        #define DEF_GRAPH_IMAGE_FORMAT "svg"
     75#else
     76        #define DEF_GRAPH_IMAGE_FORMAT "png"
     77#endif // NOSVG && QT_VERSION >= 0x040500
    6978//! Default for "Show solution steps' matrices for every solution step"
    7079#define DEF_SHOW_MATRIX true
  • src/globals.h

    rca3d2a30fa r20015b41e7  
    3232#include <QtCore>
    3333#include <QtGui>
    34 #include <QtSvg>
     34#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
     35        #include <QtSvg>
     36#endif // NOSVG && QT_VERSION >= 0x040500
    3537
    3638// Version info
  • src/main.cpp

    rca3d2a30fa r20015b41e7  
    3333#endif
    3434
    35 #ifdef STATIC_BUILD
    36         Q_IMPORT_PLUGIN(qjpeg)
    37         Q_IMPORT_PLUGIN(qsvg)
    38 #endif
     35//#ifdef STATIC_BUILD
     36//      Q_IMPORT_PLUGIN(qjpeg)
     37//      Q_IMPORT_PLUGIN(qtiff)
     38//#endif
    3939
    4040int main(int argc, char *argv[])
     
    4747        app.setOrganizationName("Oleksii \"Lёppa\" Serdiuk");
    4848        app.setOrganizationDomain("oleksii.name");
    49         app.setApplicationName("TSPSG");
     49        app.setApplicationName("TSPSG: TSP Solver and Generator");
    5050        app.setApplicationVersion(BUILD_VERSION);
    5151
  • 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"));
  • src/settingsdialog.cpp

    rca3d2a30fa r20015b41e7  
    195195        settings->beginGroup("Output");
    196196        cbShowGraph->setChecked(settings->value("ShowGraph", DEF_SHOW_GRAPH).toBool());
     197
     198#if !defined(NOSVG) && (QT_VERSION >= 0x040500)
     199        comboGraphImageFormat->addItem("svg");
     200#endif // NOSVG && QT_VERSION >= 0x040500
     201// We create a whitelist of formats, supported by the most popular web browsers according to
     202//  http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support
     203//  + TIFF format (there are plugins to support it).
     204QStringList whitelist;
     205        whitelist << "bmp" << "jpeg" << "png" << "tiff" << "xbm";
     206        foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
     207                if (whitelist.contains(format))
     208                        comboGraphImageFormat->addItem(format);
     209        }
     210        comboGraphImageFormat->model()->sort(0);
     211        comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(settings->value("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(), Qt::MatchFixedString));
     212        if (comboGraphImageFormat->currentIndex() < 0)
     213                comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(DEF_GRAPH_IMAGE_FORMAT, Qt::MatchFixedString));
     214        labelGraphImageFormat->setEnabled(cbShowGraph->isChecked());
     215        comboGraphImageFormat->setEnabled(cbShowGraph->isChecked());
     216
    197217        cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool());
    198218        cbCitiesLimit->setEnabled(cbShowMatrix->isChecked());
     
    252272                        settings->setValue("SettingsReset", true);
    253273                        QDialog::accept();
    254                         QMessageBox::information(this, tr("Settings Reset"), tr("All settings where successfully reset to their defaults.\nIt is recommended to restart the application now."));
     274                        QMessageBox::information(this->parentWidget(), tr("Settings Reset"), tr("All settings where successfully reset to their defaults.\nIt is recommended to restart the application now."));
    255275                        return;
    256276                } else
     
    282302        settings->beginGroup("Output");
    283303        settings->setValue("ShowGraph", cbShowGraph->isChecked());
     304        if (cbShowGraph->isChecked()) {
     305                if (comboGraphImageFormat->currentIndex() >= 0)
     306                        settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText());
     307                else
     308                        settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT);
     309        }
    284310        settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
    285311        settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
Note: See TracChangeset for help on using the changeset viewer.