Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Winkelmann
QmlSlidePrinter
Commits
f20bebf4
Commit
f20bebf4
authored
Aug 15, 2018
by
Michael Winkelmann
Browse files
Commandline executable
parent
e81ecccc
Changes
3
Hide whitespace changes
Inline
Side-by-side
QmlPrinter.pri
View file @
f20bebf4
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
...
...
QmlPrinter.pro
0 → 100644
View file @
f20bebf4
QT
+=
qml
quick
gui
printsupport
include
(
$$
PWD
/
QmlPrinter
.
pri
)
SOURCES
+=
main
.
cpp
main.cpp
0 → 100644
View file @
f20bebf4
#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
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment