summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Eftevaag <oliver.eftevaag@qt.io>2023-02-22 23:36:55 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-28 15:40:01 +0000
commite5205ca7a02c9a6c8961f8edb3bf15db6cbdfa62 (patch)
treeb863371e77c08ca0eece4ee9e400155517e6c5cd
parent51e4a625d537f034e708b9adac2ddf40488780ce (diff)
downloadqtdoc-e5205ca7a02c9a6c8961f8edb3bf15db6cbdfa62.tar.gz
Minor tweeks to the photosurface demo
The commit 0391a2fb98f703c43a8aaaba5d817e2c34cf5a7b makes a lot of improvements to the demo, but it also makes it no longer search your system's photos directory by default. This commit also updates the project files. The CMakeLists.txt file will use qt_add_qml_module() among other things that our guildelines recommend. The .qrc file will have the /qt/qml/photosurface prefix, in order to make qmake compatible with the AUTO_RESOURCE_PREFIX module. Task-number: QTBUG-108924 Change-Id: I19291ead744f8eebcd4151f02b44f746b2040319 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 8b3600e0163e83b3478fef2f1a1a19322c4cc504) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/demos/photosurface/CMakeLists.txt31
-rw-r--r--examples/demos/photosurface/main.cpp2
-rw-r--r--examples/demos/photosurface/photosurface.qml15
-rw-r--r--examples/demos/photosurface/photosurface.qrc2
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>