diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-09-09 12:39:05 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-09-22 13:58:20 +0200 |
commit | 803e11fd787fc854e1e091f257ef97894e5729d0 (patch) | |
tree | 63e8e4ebf051e9fb8574c62482360df6f4ce9930 | |
parent | 84ebd698597cf7a45b5e0967221547c21b1d67e8 (diff) | |
download | qtwebengine-803e11fd787fc854e1e091f257ef97894e5729d0.tar.gz |
QtPdf multipage example: add macOS icon; support QFileOpenEvent
The icon uses some parts from
https://openclipart.org/detail/171857/icon-pdf-a%C2%8Dcone
Pick-to: 6.4
Task-number: QTBUG-106460
Change-Id: I94ecc81d83f96fdced3dce630b94b9037d3e90f9
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | examples/pdf/multipage/CMakeLists.txt | 11 | ||||
-rw-r--r-- | examples/pdf/multipage/main.cpp | 10 | ||||
-rw-r--r-- | examples/pdf/multipage/multipage.pro | 4 | ||||
-rw-r--r-- | examples/pdf/multipage/pdfapplication.cpp | 16 | ||||
-rw-r--r-- | examples/pdf/multipage/pdfapplication.h | 24 | ||||
-rw-r--r-- | examples/pdf/multipage/resources/macos/Info.plist | 29 | ||||
-rw-r--r-- | examples/pdf/multipage/resources/multipage.icns | bin | 0 -> 117648 bytes |
7 files changed, 88 insertions, 6 deletions
diff --git a/examples/pdf/multipage/CMakeLists.txt b/examples/pdf/multipage/CMakeLists.txt index 96effd384..25cc726ed 100644 --- a/examples/pdf/multipage/CMakeLists.txt +++ b/examples/pdf/multipage/CMakeLists.txt @@ -16,8 +16,19 @@ find_package(Qt6 REQUIRED COMPONENTS Gui Qml) qt_add_executable(multipage main.cpp + pdfapplication.h + pdfapplication.cpp ) +if (APPLE AND NOT IOS) + set(MACOSX_BUNDLE_ICON_FILE multipage.icns) + set(app_icon_macos "${CMAKE_CURRENT_SOURCE_DIR}/resources/multipage.icns") + set_source_files_properties(${app_icon_macos} PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources") + target_sources(multipage PRIVATE ${app_icon_macos}) + set(MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/resources/macos/Info.plist") +endif() + set_target_properties(multipage PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE diff --git a/examples/pdf/multipage/main.cpp b/examples/pdf/multipage/main.cpp index f5b246ac4..9f9272d69 100644 --- a/examples/pdf/multipage/main.cpp +++ b/examples/pdf/multipage/main.cpp @@ -1,7 +1,7 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QGuiApplication> +#include "pdfapplication.h" #include <QQmlApplicationEngine> int main(int argc, char* argv[]) @@ -9,17 +9,17 @@ int main(int argc, char* argv[]) QCoreApplication::setApplicationName("Qt Quick Multi-page PDF Viewer Example"); QCoreApplication::setOrganizationName("QtProject"); QCoreApplication::setApplicationVersion(QT_VERSION_STR); - QGuiApplication app(argc, argv); + PdfApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:///pdfviewer/viewer.qml"))); + app.setFileOpener(engine.rootObjects().constFirst()); if (app.arguments().count() > 1) { QUrl toLoad = QUrl::fromUserInput(app.arguments().at(1)); - engine.rootObjects().first()->setProperty("source", toLoad); + engine.rootObjects().constFirst()->setProperty("source", toLoad); } else { - engine.rootObjects().first()->setProperty("source", QStringLiteral("resources/test.pdf")); + engine.rootObjects().constFirst()->setProperty("source", QStringLiteral("resources/test.pdf")); } - return app.exec(); } diff --git a/examples/pdf/multipage/multipage.pro b/examples/pdf/multipage/multipage.pro index bd08ba0de..c12651335 100644 --- a/examples/pdf/multipage/multipage.pro +++ b/examples/pdf/multipage/multipage.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += qml quick pdf svg -SOURCES += main.cpp +SOURCES += main.cpp pdfapplication.cpp RESOURCES += \ viewer.qrc @@ -12,3 +12,5 @@ EXAMPLE_FILES = \ target.path = $$[QT_INSTALL_EXAMPLES]/pdf/multipage INSTALLS += target +macos:QMAKE_INFO_PLIST = resources/macos/Info.plist +macos:ICON = resources/multipage.icns diff --git a/examples/pdf/multipage/pdfapplication.cpp b/examples/pdf/multipage/pdfapplication.cpp new file mode 100644 index 000000000..d8e7c6486 --- /dev/null +++ b/examples/pdf/multipage/pdfapplication.cpp @@ -0,0 +1,16 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "pdfapplication.h" +#include <QFileOpenEvent> + +PdfApplication::PdfApplication(int &argc, char **argv) + : QGuiApplication(argc, argv) { } + +bool PdfApplication::event(QEvent *e) { + if (e->type() == QEvent::FileOpen) { + QFileOpenEvent *foEvent = static_cast<QFileOpenEvent *>(e); + m_fileOpener->setProperty("source", foEvent->url()); + } + return QGuiApplication::event(e); +} diff --git a/examples/pdf/multipage/pdfapplication.h b/examples/pdf/multipage/pdfapplication.h new file mode 100644 index 000000000..06c998e1c --- /dev/null +++ b/examples/pdf/multipage/pdfapplication.h @@ -0,0 +1,24 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef PDFAPPLICATION_H +#define PDFAPPLICATION_H + +#include <QGuiApplication> +#include <QObject> + +class PdfApplication : public QGuiApplication +{ +public: + PdfApplication(int &argc, char **argv); + void setFileOpener(QObject *opener) { + m_fileOpener = opener; + } + +protected: + bool event(QEvent *e) override; + + QObject *m_fileOpener; +}; + +#endif // PDFAPPLICATION_H diff --git a/examples/pdf/multipage/resources/macos/Info.plist b/examples/pdf/multipage/resources/macos/Info.plist new file mode 100644 index 000000000..512becda0 --- /dev/null +++ b/examples/pdf/multipage/resources/macos/Info.plist @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> +<plist version="0.1"> +<dict> + <key>CFBundleIconFile</key> + <string>multipage</string> + <key>CFBundleIdentifier</key> + <string>org.qt-project.multipage</string> + <key>CFBundleDisplayName</key> + <string>Multi-page PDF Viewer</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleExecutable</key> + <string>multipage</string> + <key>CFBundleDocumentTypes</key> + <array> + <dict> + <key>CFBundleTypeRole</key> + <string>Viewer</string> + <key>CFBundleTypeName</key> + <string>pdf</string> + <key>LSItemContentTypes</key> + <array> + <string>com.adobe.pdf</string> + </array> + </dict> + </array> +</dict> +</plist> diff --git a/examples/pdf/multipage/resources/multipage.icns b/examples/pdf/multipage/resources/multipage.icns Binary files differnew file mode 100644 index 000000000..2e3756903 --- /dev/null +++ b/examples/pdf/multipage/resources/multipage.icns |