diff options
-rw-r--r-- | examples/demos/photosurface/CMakeLists.txt | 31 | ||||
-rw-r--r-- | examples/demos/photosurface/main.cpp | 2 | ||||
-rw-r--r-- | examples/demos/photosurface/photosurface.qml | 15 | ||||
-rw-r--r-- | examples/demos/photosurface/photosurface.qrc | 2 |
4 files changed, 28 insertions, 22 deletions
diff --git a/examples/demos/photosurface/CMakeLists.txt b/examples/demos/photosurface/CMakeLists.txt index 3f38649b..d696882f 100644 --- a/examples/demos/photosurface/CMakeLists.txt +++ b/examples/demos/photosurface/CMakeLists.txt @@ -14,10 +14,12 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/demos/photosurface") find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick) +qt_standard_project_setup(REQUIRES 6.5) + if (WIN32) #! [appicon_windows] set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources/photosurface.rc") - qt_add_executable(photosurface main.cpp ${app_icon_resource_windows}) + qt_add_executable(photosurfaceexample main.cpp ${app_icon_resource_windows}) #! [appicon_windows] elseif (APPLE) #! [appicon_macOS] @@ -31,34 +33,29 @@ elseif (APPLE) set_source_files_properties(${app_icon_macos} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") - qt_add_executable(photosurface MACOSX_BUNDLE main.cpp ${app_icon_macos}) + qt_add_executable(photosurfaceexample MACOSX_BUNDLE main.cpp ${app_icon_macos}) #! [appicon_macOS] else() - qt_add_executable(photosurface main.cpp) + qt_add_executable(photosurfaceexample main.cpp) endif() -target_link_libraries(photosurface PUBLIC +target_link_libraries(photosurfaceexample PRIVATE Qt::Core Qt::Gui Qt::Qml Qt::Quick ) -# Resources: -set(photosurface_resource_files - "photosurface.qml" - "resources/folder.png" - "resources/MomentumAnimation.qml" -) - -qt6_add_resources(photosurface "photosurface" - PREFIX - "/" - FILES - ${photosurface_resource_files} +qt_add_qml_module(photosurfaceexample + URI photosurface + QML_FILES + "photosurface.qml" + "resources/MomentumAnimation.qml" + RESOURCES + "resources/folder.png" ) -install(TARGETS photosurface +install(TARGETS photosurfaceexample RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/demos/photosurface/main.cpp b/examples/demos/photosurface/main.cpp index f4d135d9..67a5d1fa 100644 --- a/examples/demos/photosurface/main.cpp +++ b/examples/demos/photosurface/main.cpp @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) parser.process(app); QQmlApplicationEngine engine; - engine.load(QUrl("qrc:///photosurface.qml")); + engine.load(QUrl("qrc:/qt/qml/photosurface/photosurface.qml")); if (engine.rootObjects().isEmpty()) return -1; diff --git a/examples/demos/photosurface/photosurface.qml b/examples/demos/photosurface/photosurface.qml index 606b9148..7b4fd1d0 100644 --- a/examples/demos/photosurface/photosurface.qml +++ b/examples/demos/photosurface/photosurface.qml @@ -1,5 +1,6 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtCore import QtQuick import QtQuick.Controls import QtQuick.Dialogs @@ -160,9 +161,17 @@ Window { Shortcut { sequence: StandardKey.Quit; onActivated: Qt.quit() } Component.onCompleted: { - let lastArg = Application.arguments.slice(-1)[0] - if (/.*hotosurface.*|--+/.test(lastArg)) - folderDialog.open() + const lastArg = Application.arguments.slice(-1)[0] + const standardPicturesLocations = StandardPaths.standardLocations(StandardPaths.PicturesLocation) + const hasValidPicturesLocation = standardPicturesLocations.length > 0 + if (hasValidPicturesLocation) + folderDialog.currentFolder = standardPicturesLocations[0] + if (/.*hotosurface.*|--+/.test(lastArg)) { + if (hasValidPicturesLocation) + folderModel.folder = standardPicturesLocations[0] + else + folderDialog.open() + } else folderModel.folder = Qt.resolvedUrl("file:" + lastArg) } diff --git a/examples/demos/photosurface/photosurface.qrc b/examples/demos/photosurface/photosurface.qrc index 217c214f..9834eecb 100644 --- a/examples/demos/photosurface/photosurface.qrc +++ b/examples/demos/photosurface/photosurface.qrc @@ -1,5 +1,5 @@ <RCC> - <qresource prefix="/"> + <qresource prefix="/qt/qml/photosurface"> <file>photosurface.qml</file> <file>resources/folder.png</file> <file>resources/MomentumAnimation.qml</file> |