Advertisement
marquessbr

calendar with custom nabber

Jul 9th, 2017
2,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 5.99 KB | None | 0 0
  1.         // ...
  2.         Rectangle {
  3.             id: navigationbar
  4.             width: (parent.width > parent.height ? parent.width * 0.6 - parent.spacing : parent.width)
  5.             height: (parent.height > parent.width ? parent.height - (parent.height- 50) - parent.spacing : parent.height - (parent.height-50))
  6.             Rectangle {
  7.                 anchors.fill: parent
  8.                 gradient: Gradient {//...}
  9.                 border.width: 1.3
  10.  
  11.                 Image {
  12.                     id: settingsDate
  13.                     // ...
  14.                     MouseArea {
  15.                         id: mouseAreaSett
  16.                         anchors.fill: parent
  17.                         onClicked: {
  18.                             console.debug(aNewMonth)
  19.                             aNewMonth--;
  20.                             // decrement the month
  21.                             currentDate: Date(aNewMonth, aNewDay, aNewYear);
  22.                             calendar.selectedDate.setFullYear(aNewYear, aNewMonth, aNewDay);
  23.                             // this code not work
  24.                         }
  25.                     }
  26.                 }
  27.  
  28.                 Image {
  29.                     id: prevDay
  30.                     // ...
  31.                     MouseArea {
  32.                         id: mouseAreaPrev
  33.                         anchors.fill: parent
  34.                         onClicked: {
  35.                             // prevDay actions ...
  36.                             currentDate: Date(aNewMonth, aNewDay, aNewYear);
  37.                             calendar.selectedDate.setFullYear(aNewYear, aNewMonth, aNewDay);
  38.                             // nope
  39.                         }
  40.                     }
  41.  
  42.                 }
  43.  
  44.                 TextEdit {
  45.                     id: displayDate
  46.                     // ...
  47.                     MouseArea {
  48.                         id: mouseAreaDisp
  49.                         anchors.fill: parent
  50.                         onClicked: {
  51.                             var d = new Date();
  52.                             aNewDay = d.getDate();
  53.                             aNewMonth = d.getMonth();
  54.                             aNewYear = d.getFullYear();
  55.                             currentDate: Date(aNewMonth, aNewDay, aNewYear);
  56.                             calendar.selectedDate.setFullYear(aNewYear, aNewMonth, aNewDay);
  57.                             // the calendar does not respond the choosen date
  58.                         }
  59.                     }
  60.                 }
  61.  
  62.                 Image {
  63.                     id: nextDay
  64.                     // ...
  65.                     MouseArea {
  66.                         id: mouseAreaNext
  67.                         anchors.fill: parent
  68.                         onClicked: {
  69.                             aNewDay++
  70.                             // nextDay actions
  71.                             calendar.selectedDate.setFullYear(aNewYear, aNewMonth, aNewDay);
  72.                             calendar.update();
  73.                             // this does not work
  74.                         }
  75.                     }
  76.                 }
  77.  
  78.                 Image {
  79.                     id: plusMonth
  80.                     // ...
  81.                     MouseArea {
  82.                         id: mouseAreaPlus
  83.                         anchors.fill: parent
  84.                         onClicked: {
  85.                             aNewMonth++;
  86.                             // plus month actions
  87.                             currentDate: Date(aNewMonth, aNewDay, aNewYear);
  88.                             calendar.selectedDate.setFullYear(aNewYear, aNewMonth, aNewDay);
  89.                             // I don't know how to past the choosen date to calendar?
  90.                         }
  91.                     }
  92.                 }
  93.             }
  94.         }
  95.         Calendar {
  96.             id: calendar
  97.             width: (parent.width > parent.height ? parent.width * 0.6 - parent.spacing : parent.width)
  98.             height: (parent.height > parent.width ? parent.height * 0.6 - parent.spacing : parent.height)
  99.             frameVisible: true
  100.             weekNumbersVisible: false
  101.             navigationBarVisible: false
  102.  
  103.             selectedDate: currentDate
  104.             // when the application start this work
  105.             focus: true
  106.             style: CalendarStyle {
  107.                 dayDelegate: Item {
  108.                     readonly property int dpi: Screen.pixelDensity*1.4
  109.                     readonly property color sameMonthDateTextColor: "#444"
  110.                     readonly property color selectedDateColor: Qt.platform.os === "osx" ? "#3778d0" : systemPalette.highlight
  111.                     readonly property color selectedDateTextColor: "white"
  112.                     readonly property color differentMonthDateTextColor: "#bbb000"
  113.                     readonly property color invalidDatecolor: "#dddddd"
  114.  
  115.                     Rectangle {
  116.                         id: selectedDayRect
  117.                         anchors.fill: parent
  118.                         border.color: "transparent"
  119.                         color: styleData.date !== undefined && styleData.selected ? selectedDateColor : "transparent"
  120.                         anchors.margins: styleData.selected ? -1 : 0
  121.                     }
  122.                     // code of my own imags, not relevant here ...
  123.                     Label {
  124.                         id: dayDelegateText
  125.                         text: styleData.date.getDate()
  126.                         anchors.top: parent.top
  127.                         anchors.right: parent.right
  128.                         anchors.margins: 0
  129.                         color: {
  130.                             var color = invalidDatecolor;
  131.                             if (styleData.valid) {
  132.                                 // Date is within the valid range.
  133.                                 color = styleData.visibleMonth ? sameMonthDateTextColor : differentMonthDateTextColor;
  134.                                 if (styleData.selected) {
  135.                                     color = selectedDateTextColor;
  136.                                 }
  137.                             }
  138.                             color;
  139.                         }
  140.                     }                    
  141.                 }
  142.                 // ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement