summaryrefslogtreecommitdiffstats
path: root/examples/charts/qmloscilloscope/qml/qmloscilloscope/MultiButton.qml
blob: 62978eeffbcdf5e2d91dce219f58947b42d65b10 (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
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick

Item {
    id: button

    property string text: "Option: "
    property variant items: ["first"]
    property int currentSelection: 0

    signal selectionChanged(variant selection)
    signal clicked

    implicitWidth: buttonText.implicitWidth + 5
    implicitHeight: buttonText.implicitHeight + 10

    Rectangle {
        anchors.fill: parent
        radius: 3
        gradient: button.enabled ? enabledGradient : disabledGradient

        Gradient {
            id: enabledGradient
            GradientStop { position: 0.0; color: "#eeeeee" }
            GradientStop { position: 1.0; color: "#cccccc" }
        }
        Gradient {
            id: disabledGradient
            GradientStop { position: 0.0; color: "#444444" }
            GradientStop { position: 1.0; color: "#666666" }
        }

        Text {
            id: buttonText
            text: button.text + button.items[currentSelection]
            clip: true
            wrapMode: Text.WordWrap
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            anchors.fill: parent
            font.pointSize: 14
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                currentSelection = (currentSelection + 1) % items.length;
                selectionChanged(button.items[currentSelection]);
            }
        }
    }
}