~renatofilho/ubuntu-calendar-app/new-view-canvas

« back to all changes in this revision

Viewing changes to CalendarCanvas/CalendarGridLines.qml

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2016-09-30 13:38:15 UTC
  • Revision ID: renato.filho@canonical.com-20160930133815-dx67jqyocwxq5cqk
Refactory DayView and WeekView to use a new calendar canvas component.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.4
 
2
import QtQuick.Layouts 1.1
 
3
import Ubuntu.Components 1.3
 
4
 
 
5
Item {
 
6
    id: root
 
7
 
 
8
    property real columnWidth: units.gu(10)
 
9
    property real headerWidth: units.gu(10)
 
10
    property alias columns: columns.model
 
11
 
 
12
    readonly property real hourHeight: (height / 24) - units.gu(0.5)
 
13
 
 
14
    function refresh()
 
15
    {
 
16
        var hoursInADay = []
 
17
        var today = new Date()
 
18
 
 
19
        today.setMinutes(0)
 
20
        for(var h=0; h < 24; h++) {
 
21
            today.setHours(h)
 
22
            //TODO: format to local time 24h or AM/PM
 
23
            hoursInADay.push(Qt.formatTime(today))
 
24
        }
 
25
 
 
26
        hourRepeater.model = hoursInADay
 
27
    }
 
28
 
 
29
    opacity: 0.3
 
30
    implicitWidth: root.headerWidth + (root.columnWidth * root.columns)
 
31
    implicitHeight: units.gu(7) * hourRepeater.count
 
32
 
 
33
    Column {
 
34
        id: horizontalLines
 
35
        spacing: units.gu(0.5)
 
36
 
 
37
        anchors.fill: parent
 
38
        Repeater {
 
39
            id: hourRepeater
 
40
 
 
41
            Label {
 
42
                width: root.headerWidth
 
43
                height: root.hourHeight
 
44
                horizontalAlignment: Text.AlignHCenter
 
45
                text: modelData
 
46
                SimpleDivider {
 
47
                    width: root.width
 
48
 
 
49
                    anchors {
 
50
                        left: parent.left
 
51
                        bottom: parent.bottom
 
52
                    }
 
53
                }
 
54
            }
 
55
        }
 
56
    }
 
57
 
 
58
    Row {
 
59
        anchors{
 
60
            fill: parent
 
61
            leftMargin: root.headerWidth
 
62
        }
 
63
 
 
64
        Repeater {
 
65
            id: columns
 
66
 
 
67
            Item {
 
68
                anchors {
 
69
                    top: parent ? parent.top : undefined
 
70
                    bottom: parent ? parent.bottom : undefined
 
71
                }
 
72
                width: root.columnWidth
 
73
 
 
74
                SimpleDivider {
 
75
                    width: units.gu(0.1)
 
76
 
 
77
                    anchors {
 
78
                        top: parent.top
 
79
                        bottom: parent.bottom
 
80
                        left: parent.left
 
81
                    }
 
82
                }
 
83
            }
 
84
        }
 
85
    }
 
86
 
 
87
    Component.onCompleted: root.refresh()
 
88
}