summaryrefslogtreecommitdiffstats
path: root/tests/manual/examples/quick/customtouchhandle/main.qml
blob: c40b4c73bdab58050bfbedcdad03e8bdb5f2a06c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick.Window
import QtWebEngine
import QtQuick.Layouts
import QtQuick.Controls

ApplicationWindow {
    width: 1024
    height: 750
    visible: true
    header: ToolBar {
        RowLayout {
            anchors.fill: parent

            ToolButton {
                property int itemAction: WebEngineView.Back
                text: webEngineView.action(itemAction).text
                enabled: webEngineView.action(itemAction).enabled
                onClicked: webEngineView.action(itemAction).trigger()
                icon.name: webEngineView.action(itemAction).iconName
                display: AbstractButton.TextUnderIcon
            }

            ToolButton {
                property int itemAction: WebEngineView.Forward
                text: webEngineView.action(itemAction).text
                enabled: webEngineView.action(itemAction).enabled
                onClicked: webEngineView.action(itemAction).trigger()
                icon.name: webEngineView.action(itemAction).iconName
                display: AbstractButton.TextUnderIcon
            }

            ToolButton {
                property int itemAction: webEngineView.loading ? WebEngineView.Stop : WebEngineView.Reload
                text: webEngineView.action(itemAction).text
                enabled: webEngineView.action(itemAction).enabled
                onClicked: webEngineView.action(itemAction).trigger()
                icon.name: webEngineView.action(itemAction).iconName
                display: AbstractButton.TextUnderIcon
            }

            TextField {
                Layout.fillWidth: true
                text: webEngineView.url
                selectByMouse: true
                onEditingFinished: webEngineView.url = text
            }

            Label { text: 'Handle: ' }
            ComboBox {
                model: [ 'Default', 'Circle', 'Square' ]

                onCurrentValueChanged: {
                    if (currentValue == 'Circle')
                        webEngineView.touchHandleDelegate = circleTouchHandle
                    else if (currentValue == 'Square')
                        webEngineView.touchHandleDelegate = rectTouchHandle
                    else
                        webEngineView.touchHandleDelegate = null
                }

                Component.onCompleted: currentIndex = indexOfValue('Square')
            }
        }
    }

    Component {
        id: circleTouchHandle
        Rectangle {
            color: "blue"
            border.color: "black"
            border.width: 2
            radius: 50
        }
    }

    Component {
        id: rectTouchHandle
        Rectangle {
            border.color: "black"
            border.width: 2
            radius: 2
            onVisibleChanged: if (visible) { color = 'yellow'; cAnim.restart(); }
            ColorAnimation on color { id: cAnim; to: 'red'; duration: 1000 }
        }
    }

    WebEngineView {
        anchors.fill: parent
        id: webEngineView
        url: "https://www.qt.io"
    }
}