Minor tweeks to the photosurface demo

The commit 0391a2fb98
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
Pick-to: 6.5
Change-Id: I19291ead744f8eebcd4151f02b44f746b2040319
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Oliver Eftevaag 2023-02-22 23:36:55 +01:00 committed by Shawn Rutledge
parent 1a5419646a
commit 8b3600e016
4 changed files with 28 additions and 22 deletions

View File

@ -14,10 +14,12 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/demos/photosurface")
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick) find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
qt_standard_project_setup(REQUIRES 6.5)
if (WIN32) if (WIN32)
#! [appicon_windows] #! [appicon_windows]
set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources/photosurface.rc") 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] #! [appicon_windows]
elseif (APPLE) elseif (APPLE)
#! [appicon_macOS] #! [appicon_macOS]
@ -31,34 +33,29 @@ elseif (APPLE)
set_source_files_properties(${app_icon_macos} PROPERTIES set_source_files_properties(${app_icon_macos} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources") 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] #! [appicon_macOS]
else() else()
qt_add_executable(photosurface main.cpp) qt_add_executable(photosurfaceexample main.cpp)
endif() endif()
target_link_libraries(photosurface PUBLIC target_link_libraries(photosurfaceexample PRIVATE
Qt::Core Qt::Core
Qt::Gui Qt::Gui
Qt::Qml Qt::Qml
Qt::Quick Qt::Quick
) )
# Resources: qt_add_qml_module(photosurfaceexample
set(photosurface_resource_files URI photosurface
"photosurface.qml" QML_FILES
"resources/folder.png" "photosurface.qml"
"resources/MomentumAnimation.qml" "resources/MomentumAnimation.qml"
RESOURCES
"resources/folder.png"
) )
qt6_add_resources(photosurface "photosurface" install(TARGETS photosurfaceexample
PREFIX
"/"
FILES
${photosurface_resource_files}
)
install(TARGETS photosurface
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"

View File

@ -46,7 +46,7 @@ int main(int argc, char* argv[])
parser.process(app); parser.process(app);
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.load(QUrl("qrc:///photosurface.qml")); engine.load(QUrl("qrc:/qt/qml/photosurface/photosurface.qml"));
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())
return -1; return -1;

View File

@ -1,5 +1,6 @@
// Copyright (C) 2017 The Qt Company Ltd. // Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtCore
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Dialogs import QtQuick.Dialogs
@ -160,9 +161,17 @@ Window {
Shortcut { sequence: StandardKey.Quit; onActivated: Qt.quit() } Shortcut { sequence: StandardKey.Quit; onActivated: Qt.quit() }
Component.onCompleted: { Component.onCompleted: {
let lastArg = Application.arguments.slice(-1)[0] const lastArg = Application.arguments.slice(-1)[0]
if (/.*hotosurface.*|--+/.test(lastArg)) const standardPicturesLocations = StandardPaths.standardLocations(StandardPaths.PicturesLocation)
folderDialog.open() 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 else
folderModel.folder = Qt.resolvedUrl("file:" + lastArg) folderModel.folder = Qt.resolvedUrl("file:" + lastArg)
} }

View File

@ -1,5 +1,5 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/qt/qml/photosurface">
<file>photosurface.qml</file> <file>photosurface.qml</file>
<file>resources/folder.png</file> <file>resources/folder.png</file>
<file>resources/MomentumAnimation.qml</file> <file>resources/MomentumAnimation.qml</file>