summaryrefslogtreecommitdiffstats
path: root/tools/qqem/qml/CustomIconButton.qml
blob: 9e626164a4e8ba74a8c8070a35cb4d8576285526 (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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtQuick.Controls

Item {
    id: rootItem

    property string icon
    property string toggledIcon
    property string description
    property bool toggleButton: false
    property bool toggled: false

    signal clicked

    Image {
        id: iconImage
        property real effectiveOpacity: 1.0
        anchors.centerIn: parent
        height: parent.height * 0.8
        width: parent.width * 0.8
        fillMode: Image.PreserveAspectFit
        source: (toggleButton && toggled) ? rootItem.toggledIcon : rootItem.icon
        mipmap: true
        opacity: rootItem.enabled ? effectiveOpacity : 0.3
    }
    MouseArea {
        id: iconButtomMouseArea
        anchors.fill: parent
        hoverEnabled: true
        onClicked: {
            if (!toggleButton)
                clickAnimation.restart();
            rootItem.clicked();
        }
    }
    SequentialAnimation {
        id: clickAnimation
        NumberAnimation {
            target: iconImage
            property: "effectiveOpacity"
            to: 0.5
            easing.type: Easing.InOutQuad
            duration: 200
        }
        NumberAnimation {
            target: iconImage
            property: "effectiveOpacity"
            to: 1.0
            easing.type: Easing.InOutQuad
            duration: 200
        }
    }
    ToolTip {
        parent: rootItem
        visible: iconButtomMouseArea.containsMouse && description
        delay: 1000
        text: description
    }
}