Replace custom button component with QQC2 buttons

Now that we've moved qtquickcontrols2 into the qtdeclarative submodule.
We want our examples to simply use qqc2 controls, rather than custom
made buttons and other controls.

This example used a custom made button component, which this patch will
replace with qqc2.

It will also use qqc2 in other places where it makes sense, like replacing
a TextEdit with a qqc2 TextArea, and Text components with qqc2 Labels.

Task-number: QTBUG-95733
Pick-to: 6.2
Change-Id: Ic733cd592cd10ef2cf45058aaf08a0f6b2f5bd2c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
Oliver Eftevaag 2021-08-12 17:07:36 +02:00
parent 8976c46f46
commit dad9a15c9c
9 changed files with 85 additions and 104 deletions

View File

@ -1,5 +1,6 @@
# Generated from qml.pro. # Generated from qml.pro.
add_subdirectory(dynamicscene)
add_subdirectory(referenceexamples) add_subdirectory(referenceexamples)
add_subdirectory(tutorials) add_subdirectory(tutorials)
qt_internal_add_example(shell) qt_internal_add_example(shell)

View File

@ -0,0 +1,67 @@
# Generated from dynamicscene.pro.
cmake_minimum_required(VERSION 3.14)
project(dynamicscene LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/dynamicscene")
find_package(Qt6 COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Quick)
find_package(Qt6 COMPONENTS Qml)
qt_add_executable(dynamicscene
main.cpp
)
set_target_properties(dynamicscene PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(dynamicscene PUBLIC
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
)
# Resources:
set(dynamicscene_resource_files
"content/GenericSceneItem.qml"
"content/PaletteItem.qml"
"content/PerspectiveItem.qml"
"content/Sun.qml"
"content/images/NOTE"
"content/images/face-smile.png"
"content/images/moon.png"
"content/images/rabbit_brown.png"
"content/images/rabbit_bw.png"
"content/images/star.png"
"content/images/sun.png"
"content/images/tree_s.png"
"content/itemCreation.js"
"dynamicscene.qml"
)
qt6_add_resources(dynamicscene "dynamicscene"
PREFIX
"/"
FILES
${dynamicscene_resource_files}
)
install(TARGETS dynamicscene
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -1,87 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.0
Rectangle {
id: container
property variant text
signal clicked
height: text.height + 10; width: text.width + 20
border.width: 1
radius: 4
antialiasing: true
gradient: Gradient {
GradientStop {
position: 0.0
color: !mouseArea.pressed ? "#eeeeee" : "#888888"
}
GradientStop {
position: 1.0
color: !mouseArea.pressed ? "#888888" : "#333333"
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: container.clicked()
}
Text {
id: text
anchors.centerIn:parent
font.pointSize: 10
text: parent.text
}
}

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the examples of the Qt Toolkit. ** This file is part of the examples of the Qt Toolkit.
@ -48,7 +48,7 @@
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.0 import QtQuick
Image { Image {
property bool created: false property bool created: false

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the examples of the Qt Toolkit. ** This file is part of the examples of the Qt Toolkit.
@ -48,7 +48,7 @@
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.0 import QtQuick
import "itemCreation.js" as Code import "itemCreation.js" as Code
Image { Image {

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the examples of the Qt Toolkit. ** This file is part of the examples of the Qt Toolkit.
@ -48,7 +48,7 @@
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.0 import QtQuick
Image { Image {
id: rootItem id: rootItem

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the examples of the Qt Toolkit. ** This file is part of the examples of the Qt Toolkit.
@ -48,7 +48,7 @@
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.0 import QtQuick
Image { Image {
id: sun id: sun

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2017 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the examples of the Qt Toolkit. ** This file is part of the examples of the Qt Toolkit.
@ -48,8 +48,9 @@
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.0 import QtQuick
import QtQuick.Particles 2.0 import QtQuick.Particles
import QtQuick.Controls
import "content" import "content"
Item { Item {
@ -82,7 +83,7 @@ Item {
dialogAnim.start(); dialogAnim.start();
} }
Text { Label {
id: dialogText id: dialogText
x: 3; y: 3 x: 3; y: 3
font.pixelSize: 14 font.pixelSize: 14
@ -156,7 +157,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
spacing: 8 spacing: 8
Text { text: "Drag an item into the scene." } Label { text: "Drag an item into the scene." }
Rectangle { Rectangle {
width: palette.width + 10; height: palette.height + 10 width: palette.width + 10; height: palette.height + 10
@ -200,7 +201,7 @@ Item {
} }
} }
Text { text: "Active Suns: " + window.activeSuns } Label { text: "Active Suns: " + window.activeSuns }
} }
} }
@ -226,7 +227,7 @@ Item {
Row { Row {
height: createButton.height height: createButton.height
spacing: 8 spacing: 8
Text { text: "Custom QML:"; anchors.verticalCenter: parent.verticalCenter } Label { text: "Custom QML:"; anchors.verticalCenter: parent.verticalCenter }
Button { Button {
id: popupButton id: popupButton
text: popupToolbox.poppedUp ? "Hide" : "Show" text: popupToolbox.poppedUp ? "Hide" : "Show"
@ -249,7 +250,7 @@ Item {
Rectangle { Rectangle {
width: 360; height: 240 width: 360; height: 240
TextEdit { TextArea {
id: qmlText id: qmlText
anchors.fill: parent; anchors.margins: 5 anchors.fill: parent; anchors.margins: 5
readOnly: false readOnly: false

View File

@ -9,7 +9,6 @@
<file>content/images/star.png</file> <file>content/images/star.png</file>
<file>content/images/sun.png</file> <file>content/images/sun.png</file>
<file>content/images/tree_s.png</file> <file>content/images/tree_s.png</file>
<file>content/Button.qml</file>
<file>content/GenericSceneItem.qml</file> <file>content/GenericSceneItem.qml</file>
<file>content/itemCreation.js</file> <file>content/itemCreation.js</file>
<file>content/PaletteItem.qml</file> <file>content/PaletteItem.qml</file>