Commit f20bebf4 authored by Michael Winkelmann's avatar Michael Winkelmann

Commandline executable

parent e81ecccc
INCLUDEPATH += $$PWD
SOURCES += $$PWD/qmlprinter.cpp \
$$PWD/styledtext.cpp
SOURCES += $$PWD/qmlprinter.cpp
HEADERS += $$PWD/qmlprinter.h \
$$PWD/styledtext.h
HEADERS += $$PWD/qmlprinter.h
OTHER_FILES += \
$$PWD/LICENSE
......
QT += qml quick gui printsupport
include($$PWD/QmlPrinter.pri)
SOURCES += main.cpp
#include <QGuiApplication>
#include <QQuickView>
#include <QQmlEngine>
#include <QQmlContext>
#include <QDir>
#include <QCommandLineParser>
#include "qmlprinter.h"
int main(int ac, char* av[]) {
QGuiApplication app(ac,av);
QCommandLineParser parser;
parser.setApplicationDescription("QML PDF generator");
parser.addHelpOption();
parser.addVersionOption();
parser.addOptions({
{
{ "input", "i" }, "Input QML file", "input"
},
{
{ "output", "o" }, "Output PDF file", "output", "output.pdf"
}
});
QCommandLineOption showOption({ "show", "s"},"Show PDF file", "show");
parser.addOption(showOption);
QCommandLineOption showPresentation({ "presentation", "p"},"Show Presentation", "presentation");
parser.addOption(showPresentation);
parser.process(app);
auto* view = new QQuickView;
auto inputQml = parser.value("input");
auto outputPdf = parser.value("output");
auto showPdf = parser.isSet(showOption);
auto showPres = parser.isSet(showPresentation);
QDir outputPdfDir;
if (QDir::isRelativePath(outputPdf)) {
outputPdfDir = QDir(qApp->applicationDirPath() + QDir::separator() + outputPdf);
} else {
outputPdfDir = QDir(outputPdfDir);
}
view->setSource(QUrl::fromLocalFile(inputQml));
QmlPrinter printer;
printer.printPdf( outputPdfDir.absolutePath(), view->rootObject());
qInfo() << app.tr("Writing PDF to %1").arg(outputPdfDir.absolutePath());
if (showPres) {
view->rootObject()->setProperty("currentSlide",0);
view->show();
}
if (showPdf)
QDesktopServices::openUrl(QUrl::fromLocalFile(outputPdfDir.absolutePath()));
return showPres ? app.exec() : EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment