@@ -4,64 +4,127 @@ import QtQuick.Controls 2.15
44import  "qrc:/qml/" 
55
66// CalendarGrid.qml 
7- GridLayout  {
8-     id:  calendarGrid
9-     columns:  7 
10-     rowSpacing:  0 
11-     columnSpacing:  0 
7+ ColumnLayout  {
8+     id:  calendarGridRoot
129    Layout .fillWidth :  true 
13-     Layout .fillHeight :  true 
14-     Layout .margins :  20 
15-     Layout .topMargin :  10 
1610
11+     //  Properties
1712    property alias calendarModel:  repeater .model 
13+     property alias eventListModel:  eventLabel .eventModel 
1814    property var  theme
1915
16+     //  Signals
2017    signal dayClicked (var  panchanga)
2118
22-     Repeater {
23-         id:  repeater
24-         delegate:  Item {
25-             Layout .fillWidth :  true 
26-             Layout .fillHeight :  modelData .type  ===  " day" ||  modelData .type  ===  " empty" 
27-             Layout .preferredHeight :  modelData .type  ===  " header" ?  35  :  - 1 
19+     //  Components
2820
29-             Loader {
30-                 id:  delegateLoader
31-                 anchors .fill :  parent
21+     //  Calendar grid layout
22+     GridLayout {
23+         id:  calendarGrid
24+         columns:  7 
25+         rowSpacing:  0 
26+         columnSpacing:  0 
27+         Layout .fillWidth :  true 
28+         Layout .preferredHeight :  parent .width 
29+         Layout .margins :  10 
30+         Layout .topMargin :  10 
31+ 
32+         Repeater {
33+             id:  repeater
34+             delegate:  Item {
35+                 Layout .fillWidth :  true 
36+                 Layout .fillHeight :  modelData .type  ===  " day" ||  modelData .type  ===  " empty" 
37+                 Layout .preferredHeight :  modelData .type  ===  " header" ?  35  :  - 1 
38+ 
39+                 Loader {
40+                     id:  delegateLoader
41+                     anchors .fill :  parent
42+ 
43+                     sourceComponent:  {
44+                         if  (modelData .type  ===  " header" 
45+                             return  headerComponent;
46+                         } else  if  (modelData .type  ===  " day" 
47+                             return  dayComponent;
48+                         } else  {
49+                             return  emptyComponent;
50+                         }
51+                     }
52+ 
53+                     onLoaded:  {
54+                         if  (modelData .type  ===  " day" 
55+                             item .bsDay  =  modelData .bsDay ;
56+                             item .adDay  =  modelData .adDay ;
57+                             item .tithi  =  modelData .tithi ;
58+                             item .isToday  =  modelData .isToday ;
59+                             item .isSaturday  =  modelData .isSaturday ;
60+                             item .hasEvent  =  modelData .hasEvent ;
61+                             item .theme  =  calendarGridRoot .theme ;
62+ 
63+                             var  isHoliday =  false ;
64+                             if  (modelData .panchanga  &&  modelData .panchanga .events ) {
65+                                 for  (var  i =  0 ; i <  modelData .panchanga .events .length ; i++ ) {
66+                                     if  (modelData .panchanga .events [i].holiday ) {
67+                                         isHoliday =  true ;
68+                                         break ;
69+                                     }
70+                                 }
71+                             }
72+                             item .isHoliday  =  isHoliday;
3273
33-                 sourceComponent:  {
34-                     if  (modelData .type  ===  " header" 
35-                         return  headerComponent;
36-                     } else  if  (modelData .type  ===  " day" 
37-                         return  dayComponent;
38-                     } else  { //  for "empty" type
39-                         return  emptyComponent;
74+                             item .clicked .connect (function () {
75+                                 calendarGridRoot .dayClicked (modelData .panchanga )
76+                             });
77+                         } else  if  (modelData .type  ===  " header" 
78+                             item .text  =  modelData .text ;
79+                             item .theme  =  calendarGridRoot .theme ;
80+                             item .cellIndex  =  index;
81+                         }
4082                    }
4183                }
84+             }
85+         }
86+     }
87+ 
88+     //  Event List Footer
89+     Rectangle {
90+         id:  eventFooter
91+         Layout .fillWidth :  true 
92+         implicitHeight:  eventLabel .paintedHeight  +  20 
93+         color:  theme .secondaryBg 
94+         radius:  6 
95+         visible:  eventLabel .eventModel  &&  eventLabel .eventModel .length  >  0 
96+ 
97+         Label {
98+             id:  eventLabel
99+             anchors .fill :  parent
100+             anchors .margins :  10 
101+ 
102+             property var  eventModel:  [] //  Model reference
42103
43-                 onLoaded:  {
44-                     if  (modelData .type  ===  " day" 
45-                         item .bsDay  =  modelData .bsDay ;
46-                         item .adDay  =  modelData .adDay ;
47-                         item .tithi  =  modelData .tithi ;
48-                         item .isToday  =  modelData .isToday ;
49-                         item .isSaturday  =  modelData .isSaturday ;
50-                         item .theme  =  calendarGrid .theme ;
51-                         item .clicked .connect (function () {
52-                             calendarGrid .dayClicked (modelData .panchanga )
53-                         });
54-                     } else  if  (modelData .type  ===  " header" 
55-                         item .text  =  modelData .text ;
56-                         item .theme  =  calendarGrid .theme ;
57-                         item .cellIndex  =  index;
104+             text:  {
105+                 var  str =  " " 
106+                 if  (eventModel) {
107+                     for  (var  i =  0 ; i <  eventModel .length ; i++ ) {
108+                         var  item =  eventModel[i];
109+                         str +=  item .bsDay  +  "  :\u00A0 " +  item .eventName ;
110+                         if  (i <  eventModel .length  -  1 ) {
111+                             str +=  "   •  " 
112+                         }
58113                    }
59114                }
115+                 return  str;
60116            }
117+ 
118+             font .pixelSize :  12 
119+             color:  theme ?  theme .secondaryText  :  " black" 
120+             wrapMode:  Text .WordWrap 
121+             horizontalAlignment:  Text .AlignHCenter 
122+             verticalAlignment:  Text .AlignVCenter 
61123        }
62124    }
63125
64126
127+     //  Component Definitions
65128    Component {
66129        id:  headerComponent
67130        Item {
@@ -78,56 +141,15 @@ GridLayout {
78141                border .color :  theme .borderColor 
79142            }
80143
81-             Rectangle {
82-                 visible:  cellIndex ===  0 
83-                 width:  headerBackground .radius 
84-                 height:  headerBackground .radius 
85-                 color:  headerBackground .color 
86-                 anchors .top :  parent .top 
87-                 anchors .right :  parent .right 
88-             }
89-             Rectangle {
90-                 visible:  cellIndex ===  0 
91-                 width:  headerBackground .radius 
92-                 height:  headerBackground .radius 
93-                 color:  headerBackground .color 
94-                 anchors .bottom :  parent .bottom 
95-                 anchors .left :  parent .left 
96-             }
97-             Rectangle {
98-                 visible:  cellIndex ===  6 
99-                 width:  headerBackground .radius 
100-                 height:  headerBackground .radius 
101-                 color:  headerBackground .color 
102-                 anchors .top :  parent .top 
103-                 anchors .left :  parent .left 
104-             }
105-             Rectangle {
106-                 visible:  cellIndex ===  6 
107-                 width:  headerBackground .radius 
108-                 height:  headerBackground .radius 
109-                 color:  headerBackground .color 
110-                 anchors .bottom :  parent .bottom 
111-                 anchors .left :  parent .left 
112-             }
113-             Rectangle {
114-                 visible:  cellIndex ===  0  ||  cellIndex ===  6 
115-                 width:  headerBackground .radius 
116-                 height:  headerBackground .radius 
117-                 color:  headerBackground .color 
118-                 anchors .bottom :  parent .bottom 
119-                 anchors .right :  parent .right 
120-             }
144+             Rectangle { visible:  cellIndex ===  0 ; width:  headerBackground .radius ; height:  headerBackground .radius ; color:  headerBackground .color ; anchors .top :  parent .top ; anchors .right :  parent .right  }
145+             Rectangle { visible:  cellIndex ===  0 ; width:  headerBackground .radius ; height:  headerBackground .radius ; color:  headerBackground .color ; anchors .bottom :  parent .bottom ; anchors .left :  parent .left  }
146+             Rectangle { visible:  cellIndex ===  6 ; width:  headerBackground .radius ; height:  headerBackground .radius ; color:  headerBackground .color ; anchors .top :  parent .top ; anchors .left :  parent .left  }
147+             Rectangle { visible:  cellIndex ===  6 ; width:  headerBackground .radius ; height:  headerBackground .radius ; color:  headerBackground .color ; anchors .bottom :  parent .bottom ; anchors .left :  parent .left  }
148+             Rectangle { visible:  cellIndex ===  0  ||  cellIndex ===  6 ; width:  headerBackground .radius ; height:  headerBackground .radius ; color:  headerBackground .color ; anchors .bottom :  parent .bottom ; anchors .right :  parent .right  }
121149
122150            Label {
123151                text:  headerItemContainer .text 
124-                 color:  {
125-                     if  (cellIndex ===  6 ) {
126-                         return  " #E4080A" 
127-                     } else  {
128-                         return  theme .accentText ;
129-                     }
130-                 }
152+                 color:  (cellIndex ===  6 ) ?  " #E4080A" :  theme .accentText 
131153                font .bold :  true 
132154                font .pixelSize :  14 
133155                anchors .centerIn :  parent
0 commit comments