~renatofilho/telephony-service/fix-phone-number-field-cursor

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
63
import QtQuick 1.1

ColoredButton {
    id: button
    property alias icon: icon.source
    property alias text: label.text
    property alias iconWidth: icon.width
    property alias iconHeight: icon.height
    property alias fontSize: label.fontSize

    /**
     * The location of the text relative to the icon.
     * top, bottom, left or right.
     */
    property string iconLocation: "left"

    signal clicked

    Image {
        id: icon
        fillMode: Image.PreserveAspectFit
        anchors.margins: 10
    }

    TextCustom {
        id: label
        anchors.margins: 10
    }

    MouseArea {
        anchors.fill: parent
        onClicked: button.clicked()
    }

    function alignIconText() {
        if (iconLocation=="top") {
            icon.anchors.top = button.top;
            icon.anchors.horizontalCenter = button.horizontalCenter;
            label.anchors.top = icon.bottom;
            label.anchors.horizontalCenter = button.horizontalCenter;
        } else if (iconLocation=="bottom") {
            icon.anchors.bottom = button.bottom;
            icon.anchors.horizontalCenter = button.horizontalCenter;
            label.anchors.bottom = icon.top;
            label.anchors.horizontalCenter = button.horizontalCenter;
        } else if (iconLocation=="right") {
            icon.height = button.height - 10;
            icon.anchors.right = button.right;
            icon.anchors.verticalCenter = button.verticalCenter;
            label.anchors.right = icon.left;
            label.anchors.verticalCenter = button.verticalCenter;
        } else if (iconLocation=="left") {
            icon.height = button.height - 10;
            icon.anchors.left = button.left;
            icon.anchors.verticalCenter = button.verticalCenter;
            label.anchors.left = icon.right;
            label.anchors.verticalCenter = button.verticalCenter;
        } // if textlocation
    } // alignIconText

    Component.onCompleted: alignIconText()
}