~renatofilho/ubuntu-calendar-app/fix-1556945

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
64
65
66
67
68
69
70
71
72
73
74
75
import QtQuick 2.4
import Ubuntu.Components.ListItems 1.0 as ListItem
import Ubuntu.Components.Themes.Ambiance 1.0
import Ubuntu.Components.Pickers 1.0

Column {
    id: dateTimeInput
    property alias header: listHeader.text

    property date dateTime;
    property bool showTimePicker;

    function clearFocus() {
        dateInput.focus = false;
        timeInput.focus = false;
    }

    function openDatePicker (element, caller, callerProperty, mode) {
        element.highlighted = true;
        var picker = PickerPanel.openDatePicker(caller, callerProperty, mode);
        if (!picker) return;
        picker.closed.connect(function () {
            element.highlighted = false;
        });
    }

    onDateTimeChanged: {
        dateInput.text = dateTime.toLocaleDateString();
        timeInput.text = Qt.formatTime(dateTime);
    }

    ListItem.Header {
        id: listHeader
    }

    Item {
        anchors {
            left: parent.left
            right: parent.right
            margins: units.gu(2)
        }

        height: dateInput.height

        NewEventEntryField{
            id: dateInput
            objectName: "dateInput"

            text: ""
            anchors.left: parent.left
            width: !showTimePicker ? parent.width : 4 * parent.width / 5

            MouseArea{
                anchors.fill: parent
                onClicked: openDatePicker(dateInput, dateTimeInput, "dateTime", "Years|Months|Days")
            }
        }

        NewEventEntryField{
            id: timeInput
            objectName: "timeInput"

            text: ""
            anchors.right: parent.right
            width: parent.width / 5
            visible: showTimePicker
            horizontalAlignment: Text.AlignRight

            MouseArea{
                anchors.fill: parent
                onClicked: openDatePicker(timeInput, dateTimeInput, "dateTime", "Hours|Minutes")
            }
        }
    }
}