summaryrefslogtreecommitdiff
path: root/components/custom/BasicButton.qml
blob: 41f6935db0fc1f5c7dc179764356fd503d35f0bc (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
import QtQuick 1.1
import "./behaviors"    // ButtonBehavior

Item {
    id: button

    signal clicked
    property alias pressed: behavior.pressed
    property alias containsMouse: behavior.containsMouse
    property alias checkable: behavior.checkable  // button toggles between checked and !checked
    property alias checked: behavior.checked

    property Component background: null

    property color backgroundColor: syspal.button
    property color textColor: syspal.text;

    property int minimumWidth: defaultStyle.minimumWidth
    property int minimumHeight: defaultStyle.minimumHeight
    property bool activeFocusOnPress: true
    property string tooltip

    signal toolTipTriggered

    // implementation

    property string __position: "only"
    implicitWidth: Math.max(minimumWidth, backgroundLoader.item.width)
    implicitHeight: Math.max(minimumHeight, backgroundLoader.item.height)

    Loader {
        id: backgroundLoader
        anchors.fill: parent
        sourceComponent: background
        property alias styledItem: button
        property alias position: button.__position
    }

    ButtonBehavior {
        id: behavior
        anchors.fill: parent
        onClicked: button.clicked()
        onPressedChanged: if (activeFocusOnPress) button.focus = true
        onMouseMoved: {tiptimer.restart()}
        Timer{
            id: tiptimer
            interval:1000
            running:containsMouse && tooltip.length
            onTriggered: button.toolTipTriggered()
        }
    }

    SystemPalette { id: syspal }
}