Changeset ca3d2a30fa in tspsg for src/mainwindow.cpp


Ignore:
Timestamp:
Apr 25, 2010, 10:09:26 PM (15 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
20015b41e7
Parents:
9cda6e0f5d
git-author:
Oleksii Serdiuk <contacts@…> (04/25/10 22:09:26)
git-committer:
Oleksii Serdiuk <contacts@…> (06/29/12 19:41:31)
Message:

+ Implemented saving the solution graph when saving solution as HTML (in SVG format).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    r9cda6e0f5d rca3d2a30fa  
    218218        }
    219219#endif
     220        if (selectedFile.endsWith(".htm", Qt::CaseInsensitive) || selectedFile.endsWith(".html", Qt::CaseInsensitive)) {
     221QFile file(selectedFile);
     222                if (!file.open(QFile::WriteOnly)) {
     223                        QApplication::restoreOverrideCursor();
     224                        QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file.errorString()));
     225                        return;
     226                }
     227QFileInfo fi(selectedFile);
     228QString 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")));
     231                // Saving solution text as HTML
     232QTextStream ts(&file);
     233                ts.setCodec(QTextCodec::codecForName("UTF-8"));
     234                ts << html;
     235                file.close();
     236                // Saving solution graph as SVG
     237QSvgGenerator svg;
     238                svg.setFileName(fi.path() + "/" + img);
     239                svg.setTitle(tr("Solution Graph"));
     240QPainter p;
     241                p.begin(&svg);
     242                graph.play(&p);
     243                p.end();
     244
     245// Qt < 4.5 has no QTextDocumentWriter class
    220246#if QT_VERSION >= 0x040500
     247        } else {
    221248QTextDocumentWriter dw(selectedFile);
    222         if (!(selectedFile.endsWith(".htm",Qt::CaseInsensitive) || selectedFile.endsWith(".html",Qt::CaseInsensitive) || selectedFile.endsWith(".odt",Qt::CaseInsensitive) || selectedFile.endsWith(".txt",Qt::CaseInsensitive)))
    223                 dw.setFormat("plaintext");
    224         if (!dw.write(solutionText->document()))
    225                 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString()));
    226 #else // QT_VERSION >= 0x040500
    227         // Qt < 4.5 has no QTextDocumentWriter class
    228 QFile file(selectedFile);
    229         if (!file.open(QFile::WriteOnly)) {
    230                 QApplication::restoreOverrideCursor();
    231                 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file->errorString()));
    232                 return;
    233         }
    234 QTextStream ts(&file);
    235         ts.setCodec(QTextCodec::codecForName("UTF-8"));
    236         ts << solutionText->document()->toHtml("UTF-8");
    237         file.close();
     249                if (!selectedFile.endsWith(".odt",Qt::CaseInsensitive))
     250                        dw.setFormat("plaintext");
     251                if (!dw.write(solutionText->document()))
     252                        QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString()));
    238253#endif // QT_VERSION >= 0x040500
     254        }
    239255        QApplication::restoreOverrideCursor();
    240256}
Note: See TracChangeset for help on using the changeset viewer.