File: mouseeventlistenertest.qml

package info (click to toggle)
kf6-kdeclarative 6.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,320 kB
  • sloc: cpp: 3,020; sh: 18; makefile: 7
file content (82 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download | duplicates (5)
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
/*
    SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

import org.kde.qtextracomponents 2.0
import QtQuick 2.1
import QtQuick.Layouts 1.0


Item
{
    width: 800
    height: 400
    Row {
        anchors.fill: parent
        MouseEventListener {
            width: 400
            height: 400
            id: mouseListener
            acceptedButtons: Qt.LeftButton
            hoverEnabled: true
            onPressed: {
                updateDebug("Pressed", mouse);
            }
            onPressAndHold: {
                updateDebug("Held", mouse);
            }
            onReleased: {
                mouseState.text = "";
                mousePos.text = "";
                screenPos.text = "";
            }

            function updateDebug(state, mouse) {
                mouseState.text = state
                mousePos.text = mouse.x + "," + mouse.y
                screenPos.text = mouse.screenX + "," + mouse.screenY
            }

            Rectangle {
                color: "red"
                anchors.fill: parent

                //MouseEventListener should still get events, even though this has a mousearea
                MouseArea {
                    anchors.fill: parent
                }
            }
        }

        GridLayout {
            width: 400
            columns: 2
            Text {
                text: "Mouse status:"
            }
            Text {
                id: mouseState
            }
            Text {
                text: "Contains Mouse: "
            }
            Text {
                text: mouseListener.containsMouse
            }
            Text {
                text: "Mouse Position: "
            }
            Text {
                id: mousePos
            }
            Text {
                text: "Screen Position: "
            }
            Text {
                id: screenPos
            }
        }
    }
}