StatesList.qml 4.83 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Thomas Murach's avatar
Thomas Murach committed
2
**
3
4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Thomas Murach's avatar
Thomas Murach committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Thomas Murach's avatar
Thomas Murach committed
7
**
hjk's avatar
hjk committed
8
9
10
11
** 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
12
13
14
** 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.
Thomas Murach's avatar
Thomas Murach committed
15
**
16
17
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
18
19
20
21
22
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
Thomas Murach's avatar
Thomas Murach committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
Thomas Murach's avatar
Thomas Murach committed
25

26
27
28
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
29
import "../common"
30

31
FocusScope {
32
    id: root
33

34
    height: expanded ? 136 : 30
35
    signal createNewState
36
    signal deleteState(int internalNodeId)
37
38
    signal duplicateCurrentState

39
40
    property int stateImageSize: 100
    property int delegateWidth: stateImageSize + 10
41
    property int padding: 2
42
    property int delegateHeight: root.height - padding * 2 + 1
43
    property int innerSpacing: -1
44
    property int currentStateInternalId : 0
45

46
47
    property bool expanded: true

48
49
    Connections {
        target: statesEditorModel
50
        onChangedToState: root.currentStateInternalId = n
51
52
    }

53
54
    SystemPalette {
        id: palette
55
    }
56

57
58
59
    Rectangle {
        id: background
        anchors.fill: parent
60
        color: creatorTheme.QmlDesignerBackgroundColorDarkAlternate
61
    }
62

63
64
    MouseArea {
        anchors.fill: parent
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        acceptedButtons: Qt.LeftButton | Qt.RightButton

        onClicked: {
            if (mouse.button === Qt.LeftButton)
                focus = true
            else if (mouse.button === Qt.RightButton)
                contextMenu.popup()
        }

        Menu {
            id: contextMenu

            MenuItem {
                text: root.expanded ? qsTr("Collapse") : qsTr("Expand")
                onTriggered: {
                    root.expanded = !root.expanded
                }

            }
        }
85
86
    }

87
    Item {
88
        id: addStateItem
89

90
        property int buttonLeftSpacing: 0
91

92
93
94
        anchors.right: parent.right
        width: delegateHeight / 2 + buttonLeftSpacing
        height: delegateHeight
95

96
97
98
        Button {
            id: addStateButton
            visible: canAddNewStates
99

100
101
            tooltip: qsTr("Add a new state.")

102
            anchors.right: parent.right
103
            anchors.rightMargin: 8
104
            anchors.verticalCenter: parent.verticalCenter
105
            width: Math.max(parent.height / 2 - 8, 18)
106
            height: width
107

108
            onClicked: root.createNewState()
109
110
111

            style: ButtonStyle {
                background: Rectangle {
112
                    property color buttonBaseColor: Qt.darker(creatorTheme.QmlDesignerBackgroundColorDarkAlternate, 1.1)
113
                    color: control.hovered ? Qt.lighter(buttonBaseColor, 1.2)  : buttonBaseColor
114
                    border.color: creatorTheme.QmlDesignerBackgroundColorDarker
115
                    border.width: 1
116
117
118
119
120
121
122
                    Image {
                        source: "image://icons/plus"
                        width: 16
                        height: 16
                        anchors.centerIn: parent
                        smooth: false
                    }
123
124
                }
            }
125
        }
126
    }
127

128
129
130
131
    ScrollView {
        anchors.left: parent.left
        anchors.right: addStateItem.left
        height: delegateHeight
132
133
134
        y: padding
        anchors.leftMargin: padding
        anchors.rightMargin: padding
135

136
137
138
        style: DesignerScrollViewStyle {
        }

139
140
141
142
143
144
145
146
147
148
        ListView {
            anchors.fill: parent
            model: statesEditorModel
            orientation: ListView.Horizontal
            spacing: innerSpacing

            delegate: StatesDelegate {
                id: statesDelegate
                width: delegateWidth
                height: delegateHeight
149
                isBaseState: 0 == internalNodeId
150
                isCurrentState: root.currentStateInternalId == internalNodeId
151
                baseColor: isCurrentState ? creatorTheme.QmlDesigner_HighlightColor : background.color
152
153
154
                delegateStateName: stateName
                delegateStateImageSource: stateImageSource
                delegateStateImageSize: stateImageSize
155
156
157
158
            }
        }
    }
}