aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/qmldesigner/connectionseditor/ConnectionsListView.qml
blob: 1827b4f8f43d15e0db926a122a9976b4eaa0ebdc (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

import QtQuick
import QtQuick.Controls
import HelperWidgets as HelperWidgets
import StudioControls as StudioControls
import StudioTheme as StudioTheme
import ConnectionsEditorEditorBackend

ListView {
    id: root

    property StudioTheme.ControlStyle style: StudioTheme.Values.viewBarButtonStyle

    property bool adsFocus: false

    // Temporarily remove due to dockwidget focus issue
    //onAdsFocusChanged: {
    //    if (!root.adsFocus)
    //        dialog.close()
    //}

    clip: true
    interactive: true
    highlightMoveDuration: 0
    highlightResizeDuration: 0
    boundsMovement: Flickable.StopAtBounds
    boundsBehavior: Flickable.StopAtBounds

    HoverHandler { id: hoverHandler }

    ScrollBar.vertical: StudioControls.TransientScrollBar {
        id: verticalScrollBar
        style: StudioTheme.Values.viewStyle
        parent: root
        x: root.width - verticalScrollBar.width
        y: 0
        height: root.availableHeight
        orientation: Qt.Vertical

        show: (hoverHandler.hovered || root.focus || verticalScrollBar.inUse || root.adsFocus)
              && verticalScrollBar.isNeeded
    }

    onVisibleChanged: {
        dialog.hide()
    }

    property int modelCurrentIndex: root.model.currentIndex ?? 0

    // Something weird with currentIndex happens when items are removed added.
    // listView.model.currentIndex contains the persistent index.

    onModelCurrentIndexChanged: {
        root.currentIndex = root.model.currentIndex
    }

    onCurrentIndexChanged: {
        root.currentIndex = root.model.currentIndex
        dialog.backend.currentRow = root.currentIndex
    }

    // Number of columns
    readonly property int numColumns: 3
    // Proper row width calculation
    readonly property int rowSpacing: StudioTheme.Values.toolbarHorizontalMargin
    readonly property int rowSpace: root.width - (root.rowSpacing * (root.numColumns + 1))
                                    - root.style.squareControlSize.width
    property int rowWidth: root.rowSpace / root.numColumns
    property int rowRest: root.rowSpace % root.numColumns

    function addConnection() {
        ConnectionsEditorEditorBackend.connectionModel.add()
        if (root.currentItem)
            dialog.popup(root.currentItem.delegateMouseArea)
    }

    function resetIndex() {
        root.model.currentIndex = -1
        root.currentIndex = -1
        dialog.backend.currentRow = -1
    }

    data: [
        ConnectionsDialog {
            id: dialog
            visible: false
            backend: root.model.delegate

            onClosing: function(event) {
                root.resetIndex()
            }
        }
    ]

    delegate: Rectangle {
        id: itemDelegate

        required property int index

        required property string signal
        required property string target
        required property string action

        property alias delegateMouseArea: mouseArea

        property bool hovered: mouseArea.containsMouse || toolTipArea.containsMouse

        width: ListView.view.width
        height: root.style.squareControlSize.height
        color: itemDelegate.hovered ?
                   itemDelegate.ListView.isCurrentItem ? root.style.interactionHover
                                                       : root.style.background.hover
                                       : "transparent"

        MouseArea {
            id: mouseArea

            anchors.fill: parent
            hoverEnabled: true

            onClicked: {
                root.model.currentIndex = itemDelegate.index
                root.currentIndex = itemDelegate.index
                dialog.backend.currentRow = itemDelegate.index
                dialog.popup(mouseArea)
            }
        }

        Row {
            id: row

            property color textColor: itemDelegate.ListView.isCurrentItem ? root.style.text.selectedText
                                                                          : root.style.icon.idle

            height: itemDelegate.height
            spacing: root.rowSpacing

            Text {
                width: root.rowWidth + root.rowRest
                height: itemDelegate.height
                color: row.textColor
                text: itemDelegate.target
                verticalAlignment: Text.AlignVCenter
                font.bold: false
                leftPadding: root.rowSpacing
                elide: Text.ElideMiddle
            }

            Text {
                width: root.rowWidth
                height: itemDelegate.height
                text: itemDelegate.signal
                color: row.textColor
                verticalAlignment: Text.AlignVCenter
                font.bold: false
                elide: Text.ElideMiddle
            }

            Text {
                width: root.rowWidth
                height: itemDelegate.height
                text: itemDelegate.action
                verticalAlignment: Text.AlignVCenter
                color: row.textColor
                font.bold: false
                elide: Text.ElideMiddle
            }

            Rectangle {
                width: root.style.squareControlSize.width
                height: root.style.squareControlSize.height

                color: toolTipArea.containsMouse ?
                           itemDelegate.ListView.isCurrentItem ? root.style.interactionGlobalHover
                                                               : root.style.background.globalHover
                                               : "transparent"

                visible: itemDelegate.hovered || itemDelegate.ListView.isCurrentItem

                Text {
                    anchors.fill: parent

                    text: StudioTheme.Constants.remove_medium
                    font.family: StudioTheme.Constants.iconFont.family
                    font.pixelSize: root.style.baseIconFontSize

                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter

                    color: row.textColor
                    renderType: Text.QtRendering
                }

                HelperWidgets.ToolTipArea {
                    id: toolTipArea
                    tooltip: qsTr("This is a test.")
                    anchors.fill: parent
                    onClicked: {
                        if (itemDelegate.ListView.isCurrentItem)
                            dialog.close()
                        root.model.remove(itemDelegate.index)
                    }
                }
            }
        }
    }

    highlight: Rectangle {
        color: root.style.interaction
    }
}