StatesDelegate.qml 3.78 KB
Newer Older
1
2
/****************************************************************************
**
3
4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5
6
7
8
9
10
11
**
** This file is part of Qt Creator.
**
** 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.
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.
23
24
25
26
27
28
29
30
31
**
****************************************************************************/

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1

Rectangle {
    border.width: 1
32
    property bool isBaseState
33
    property bool isCurrentState
34
    property color baseColor
35
36
37
38
    property string delegateStateName
    property string delegateStateImageSource
    property int delegateStateImageSize

39
    color: baseColor
40
    border.color: creatorTheme.QmlDesignerBackgroundColorDarker
41
42
43

    MouseArea {
        anchors.fill: parent
44

45
        acceptedButtons: Qt.LeftButton
46
        onClicked: {
47
48
            focus = true
            root.currentStateInternalId = internalNodeId
49
        }
50
51
52
53
54
    }

    ToolButton {
        id: removeStateButton

55
56
        style: ButtonStyle {
            background: Rectangle {
57
                color: control.hovered ? Qt.lighter(baseColor, 1.2)  : "transparent"
58
59
60
61
62
                Image {
                    source: "image://icons/close"
                    height: 16
                    width: 16
                }
63
64
65
66
            }
        }


67
        anchors.right: parent.right
68
        anchors.rightMargin: 2
69
70
71
        anchors.verticalCenter: stateNameField.verticalCenter
        height: 16
        width: 16
72
        visible: !isBaseState
73

74
        onClicked: root.deleteState(internalNodeId)
75
76
77
78
    }

    TextField {
        id: stateNameField
79
        y: 4
80
        font.pixelSize: 11
81
82
        anchors.left: parent.left
        // use the spacing which the image to the delegate rectangle has
83
        anchors.leftMargin: 4
84
        anchors.right: removeStateButton.left
85
        anchors.rightMargin: 4
86
87
        style: DesignerTextFieldStyle {}
        readOnly: isBaseState
88

89
90
91
92
93
        onActiveFocusChanged: {
            if (activeFocus)
                 root.currentStateInternalId = internalNodeId
        }

94
95
        Component.onCompleted: {
            text = delegateStateName
96
97
            if (isBaseState)
                __panel.visible = false
98
        }
99

100
101
        onEditingFinished: {
            if (text != delegateStateName)
102
                statesEditorModel.renameState(internalNodeId, text)
103
        }
104

105
106
107
108
    }

    Item {
        id: stateImageArea
109
        anchors.topMargin: 4
110
111
112
113
114
        anchors.left: stateNameField.left
        anchors.top: stateNameField.bottom

        height: delegateStateImageSize + 2
        width: delegateStateImageSize + 2
115
116

        visible: expanded
117
118
119
120
        Rectangle {
            anchors.margins: -1
            anchors.fill: stateImage
            border.width: 1
121
            border.color: creatorTheme.QmlDesignerBackgroundColorDarker
122
123
124
125
126
127
128
129
130
        }
        Image {
            id: stateImage
            anchors.centerIn: parent
            source: delegateStateImageSource
        }
    }

}