Fix ImageElements example to use a QML module

Removed the 'content' directory, and placed all images into a 'pics'
directory.

CMakeLists.txt is now also using qt_add_qml_module()

Pick-to: 6.2
Change-Id: I673b7adea1832f304003f95e171118b0822b3c83
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Oliver Eftevaag 2021-08-31 17:54:15 +02:00
parent 633a85cd39
commit 34bc389543
27 changed files with 81 additions and 116 deletions

View File

@ -66,7 +66,7 @@ Item {
curIdx += steps; curIdx += steps;
} }
Image { Image {
source: "arrow.png" source: "pics/arrow.png"
MouseArea{ MouseArea{
anchors.fill: parent anchors.fill: parent
onClicked: selector.advance(-1) onClicked: selector.advance(-1)
@ -78,7 +78,7 @@ Item {
Behavior on opacity {NumberAnimation{}} Behavior on opacity {NumberAnimation{}}
} }
Image { Image {
source: "arrow.png" source: "pics/arrow.png"
mirror: true mirror: true
MouseArea{ MouseArea{
anchors.fill: parent anchors.fill: parent

View File

@ -7,7 +7,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR) if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples") set(INSTALL_EXAMPLESDIR "examples")
@ -15,89 +14,58 @@ endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/imageelements") set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/imageelements")
find_package(Qt6 COMPONENTS Core) find_package(Qt6 COMPONENTS Core Gui Quick Qml)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Quick)
find_package(Qt6 COMPONENTS Qml)
qt_add_executable(imageelements add_subdirectory("../shared" "shared")
qt_add_executable(imageelementsexample
WIN32
MACOSX_BUNDLE
main.cpp main.cpp
) )
set_target_properties(imageelements PROPERTIES
WIN32_EXECUTABLE TRUE target_link_libraries(imageelementsexample PUBLIC
MACOSX_BUNDLE TRUE
)
target_link_libraries(imageelements PUBLIC
Qt::Core Qt::Core
Qt::Gui Qt::Gui
Qt::Qml Qt::Qml
Qt::Quick Qt::Quick
) )
qt_add_qml_module(imageelementsexample
# Resources: URI imageelements
set(imageelements_resource_files VERSION 1.0
QML_FILES
"animatedimage.qml" "animatedimage.qml"
"animatedsprite.qml" "animatedsprite.qml"
"borderimage.qml" "borderimage.qml"
"content/BearSheet.png"
"content/BorderImageSelector.qml"
"content/ImageCell.qml"
"content/MyBorderImage.qml"
"content/ShadowRectangle.qml"
"content/Uniflow_steam_engine.gif"
"content/arrow.png"
"content/bw.png"
"content/colors-round.sci"
"content/colors-stretch.sci"
"content/colors.png"
"content/multi.ico"
"content/qt-logo.png"
"content/shadow.png"
"content/speaker.png"
"framestepping.qml" "framestepping.qml"
"image.qml" "image.qml"
"imageelements.qml" "imageelements.qml"
"multiframeborderimage.qml" "multiframeborderimage.qml"
"shadows.qml" "shadows.qml"
"spritesequence.qml" "spritesequence.qml"
) "BorderImageSelector.qml"
"ImageCell.qml"
"MyBorderImage.qml"
"ShadowRectangle.qml"
RESOURCES
"pics/qt-logo.png"
"pics/shadow.png"
"pics/speaker.png"
"pics/colors.png"
"pics/BearSheet.png"
"pics/Uniflow_steam_engine.gif"
"pics/arrow.png"
"pics/bw.png"
"pics/multi.ico"
"pics/colors-round.sci"
"pics/colors-stretch.sci"
)
qt6_add_resources(imageelements "imageelements" install(TARGETS imageelementsexample
PREFIX
"/imageelements"
FILES
${imageelements_resource_files}
)
set(shared_resource_files
"../shared/Button.qml"
"../shared/CheckBox.qml"
"../shared/FlickrRssModel.qml"
"../shared/Label.qml"
"../shared/LauncherList.qml"
"../shared/SimpleLauncherDelegate.qml"
"../shared/Slider.qml"
"../shared/TabSet.qml"
"../shared/TextField.qml"
"../shared/images/back.png"
"../shared/images/checkmark.png"
"../shared/images/next.png"
"../shared/images/qt-logo.png"
"../shared/images/slider_handle.png"
"../shared/images/tab.png"
)
qt6_add_resources(imageelements "shared"
PREFIX
"/shared"
BASE
"../shared"
FILES
${shared_resource_files}
)
install(TARGETS imageelements
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
) )
bundle_shared(imageelementsexample)

View File

@ -57,7 +57,7 @@ Item {
Image { Image {
id: image id: image
width: parent.width; height: parent.height - captionItem.height width: parent.width; height: parent.height - captionItem.height
source: "qt-logo.png" source: "pics/qt-logo.png"
clip: true // only makes a difference if mode is PreserveAspectCrop clip: true // only makes a difference if mode is PreserveAspectCrop
} }

View File

@ -58,7 +58,7 @@ Item {
anchors.fill: rectangle anchors.fill: rectangle
anchors { leftMargin: -6; topMargin: -6; rightMargin: -8; bottomMargin: -8 } anchors { leftMargin: -6; topMargin: -6; rightMargin: -8; bottomMargin: -8 }
border { left: 10; top: 10; right: 10; bottom: 10 } border { left: 10; top: 10; right: 10; bottom: 10 }
source: "shadow.png" source: "pics/shadow.png"
} }
//! [shadow] //! [shadow]

View File

@ -59,7 +59,7 @@ Column {
//! [image] //! [image]
AnimatedImage { AnimatedImage {
id: animation id: animation
source: "content/Uniflow_steam_engine.gif" source: "pics/Uniflow_steam_engine.gif"
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
speed: speedSlider.value speed: speedSlider.value
TapHandler { TapHandler {

View File

@ -62,7 +62,7 @@ Item {
AnimatedSprite { AnimatedSprite {
id: sprite id: sprite
anchors.centerIn: parent anchors.centerIn: parent
source: "content/speaker.png" source: "pics/speaker.png"
frameCount: 60 frameCount: 60
frameSync: true frameSync: true
frameWidth: 170 frameWidth: 170

View File

@ -49,7 +49,6 @@
****************************************************************************/ ****************************************************************************/
import QtQuick import QtQuick
import "content"
Rectangle { Rectangle {
id: page id: page
@ -81,47 +80,47 @@ Rectangle {
MyBorderImage { MyBorderImage {
minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 200 minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 200
source: Qt.resolvedUrl("content/colors.png"); margin: 30 source: Qt.resolvedUrl("pics/colors.png"); margin: 30
} }
MyBorderImage { MyBorderImage {
minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 200 minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 200
source: Qt.resolvedUrl("content/colors.png"); margin: 30 source: Qt.resolvedUrl("pics/colors.png"); margin: 30
horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat
} }
MyBorderImage { MyBorderImage {
minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 200 minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 200
source: Qt.resolvedUrl("content/colors.png"); margin: 30 source: Qt.resolvedUrl("pics/colors.png"); margin: 30
horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat
} }
MyBorderImage { MyBorderImage {
minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 200 minWidth: 120; maxWidth: 240; minHeight: 120; maxHeight: 200
source: Qt.resolvedUrl("content/colors.png"); margin: 30 source: Qt.resolvedUrl("pics/colors.png"); margin: 30
horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round
} }
MyBorderImage { MyBorderImage {
minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200 minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200
source: Qt.resolvedUrl("content/bw.png"); margin: 10 source: Qt.resolvedUrl("pics/bw.png"); margin: 10
} }
MyBorderImage { MyBorderImage {
minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200 minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200
source: Qt.resolvedUrl("content/bw.png"); margin: 10 source: Qt.resolvedUrl("pics/bw.png"); margin: 10
horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat horizontalMode: BorderImage.Repeat; verticalMode: BorderImage.Repeat
} }
MyBorderImage { MyBorderImage {
minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200 minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200
source: Qt.resolvedUrl("content/bw.png"); margin: 10 source: Qt.resolvedUrl("pics/bw.png"); margin: 10
horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat horizontalMode: BorderImage.Stretch; verticalMode: BorderImage.Repeat
} }
MyBorderImage { MyBorderImage {
minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200 minWidth: 60; maxWidth: 200; minHeight: 40; maxHeight: 200
source: Qt.resolvedUrl("content/bw.png"); margin: 10 source: Qt.resolvedUrl("pics/bw.png"); margin: 10
horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round horizontalMode: BorderImage.Round; verticalMode: BorderImage.Round
} }
} }

View File

@ -49,7 +49,7 @@
\e Shadows shows how to create a drop shadow effect for a rectangular item \e Shadows shows how to create a drop shadow effect for a rectangular item
using a \l BorderImage: using a \l BorderImage:
\snippet imageelements/content/ShadowRectangle.qml shadow \snippet imageelements/ShadowRectangle.qml shadow
\section1 Sprite Animations with AnimatedSprite \section1 Sprite Animations with AnimatedSprite

View File

@ -58,7 +58,7 @@ Rectangle {
id: img id: img
anchors.centerIn: parent anchors.centerIn: parent
cache: true cache: true
source: "content/multi.ico" source: "pics/multi.ico"
Shortcut { Shortcut {
sequence: StandardKey.MoveToNextPage sequence: StandardKey.MoveToNextPage

View File

@ -49,7 +49,6 @@
****************************************************************************/ ****************************************************************************/
import QtQuick import QtQuick
import "content"
Rectangle { Rectangle {
width: 320 width: 320

View File

@ -49,7 +49,7 @@
****************************************************************************/ ****************************************************************************/
import QtQuick import QtQuick
import "../shared" as Shared import shared as Shared
Item { Item {
height: 480 height: 480

View File

@ -1,28 +1,28 @@
<RCC> <RCC>
<qresource prefix="/imageelements"> <qresource prefix="/imageelements">
<file>content/arrow.png</file>
<file>content/BearSheet.png</file>
<file>content/BorderImageSelector.qml</file>
<file>content/bw.png</file>
<file>content/colors-round.sci</file>
<file>content/colors-stretch.sci</file>
<file>content/colors.png</file>
<file>content/ImageCell.qml</file>
<file>content/multi.ico</file>
<file>content/MyBorderImage.qml</file>
<file>content/qt-logo.png</file>
<file>content/shadow.png</file>
<file>content/ShadowRectangle.qml</file>
<file>content/speaker.png</file>
<file>content/Uniflow_steam_engine.gif</file>
<file>imageelements.qml</file>
<file>animatedimage.qml</file> <file>animatedimage.qml</file>
<file>animatedsprite.qml</file> <file>animatedsprite.qml</file>
<file>borderimage.qml</file> <file>borderimage.qml</file>
<file>BorderImageSelector.qml</file>
<file>framestepping.qml</file> <file>framestepping.qml</file>
<file>multiframeborderimage.qml</file> <file>ImageCell.qml</file>
<file>imageelements.qml</file>
<file>image.qml</file> <file>image.qml</file>
<file>multiframeborderimage.qml</file>
<file>MyBorderImage.qml</file>
<file>ShadowRectangle.qml</file>
<file>shadows.qml</file> <file>shadows.qml</file>
<file>spritesequence.qml</file> <file>spritesequence.qml</file>
<file>pics/arrow.png</file>
<file>pics/BearSheet.png</file>
<file>pics/bw.png</file>
<file>pics/colors-round.sci</file>
<file>pics/colors-stretch.sci</file>
<file>pics/colors.png</file>
<file>pics/multi.ico</file>
<file>pics/qt-logo.png</file>
<file>pics/shadow.png</file>
<file>pics/speaker.png</file>
<file>pics/Uniflow_steam_engine.gif</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -59,7 +59,7 @@ Rectangle {
anchors.fill: parent anchors.fill: parent
anchors.margins: 6 anchors.margins: 6
cache: true cache: true
source: "content/multi.ico" source: "pics/multi.ico"
border { left: 19; top: 19; right: 19; bottom: 19 } border { left: 19; top: 19; right: 19; bottom: 19 }
horizontalTileMode: BorderImage.Stretch horizontalTileMode: BorderImage.Stretch

View File

Before

Width:  |  Height:  |  Size: 397 KiB

After

Width:  |  Height:  |  Size: 397 KiB

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

Before

Width:  |  Height:  |  Size: 247 B

After

Width:  |  Height:  |  Size: 247 B

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 974 B

After

Width:  |  Height:  |  Size: 974 B

View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 371 B

View File

Before

Width:  |  Height:  |  Size: 766 KiB

After

Width:  |  Height:  |  Size: 766 KiB

View File

@ -49,7 +49,6 @@
****************************************************************************/ ****************************************************************************/
import QtQuick import QtQuick
import "content"
Rectangle { Rectangle {
id: window id: window

View File

@ -75,7 +75,7 @@ Item {
//! [still] //! [still]
Sprite { Sprite {
name: "still" name: "still"
source: "content/BearSheet.png" source: "pics/BearSheet.png"
frameCount: 1 frameCount: 1
frameWidth: 256 frameWidth: 256
frameHeight: 256 frameHeight: 256
@ -85,7 +85,7 @@ Item {
//! [still] //! [still]
Sprite { Sprite {
name: "blink" name: "blink"
source: "content/BearSheet.png" source: "pics/BearSheet.png"
frameCount: 3 frameCount: 3
frameX: 256 frameX: 256
frameY: 1536 frameY: 1536
@ -96,7 +96,7 @@ Item {
} }
Sprite { Sprite {
name: "floating" name: "floating"
source: "content/BearSheet.png" source: "pics/BearSheet.png"
frameCount: 9 frameCount: 9
frameX: 0 frameX: 0
frameY: 0 frameY: 0
@ -107,7 +107,7 @@ Item {
} }
Sprite { Sprite {
name: "flailing" name: "flailing"
source: "content/BearSheet.png" source: "pics/BearSheet.png"
frameCount: 8 frameCount: 8
frameX: 0 frameX: 0
frameY: 768 frameY: 768
@ -118,7 +118,7 @@ Item {
} }
Sprite { Sprite {
name: "falling" name: "falling"
source: "content/BearSheet.png" source: "pics/BearSheet.png"
frameCount: 5 frameCount: 5
frameY: 1280 frameY: 1280
frameWidth: 256 frameWidth: 256