document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. Component {
  2.         id: dataPicker
  3.  
  4.         Rectangle {
  5.             id: root
  6.             anchors.fill: parent
  7.             // color: "black"
  8.             opacity: 0.98
  9.             // layer.enabled: true
  10.             property int startingYear: 1850
  11.             property int span: 200
  12.             property string separator: "/"
  13.             property string format: "dd/MM/yyyy"
  14.             property string currentDate: "11/11/1982"
  15.             signal correctDate(string date)
  16.  
  17.             Rectangle {
  18.                 id: container
  19.                 anchors.centerIn: parent
  20.                 color: "white"
  21.                 z:1
  22.                 width: 300 * AppInfo.ratio
  23.                 height: 300 * AppInfo.ratio
  24.                 border.color: days.item.alert ? "red" : "black"
  25.                 border.width: 2 * AppInfo.ratio
  26.                 radius: 4 * AppInfo.ratio
  27.                 focus: true
  28.  
  29.                 GridLayout {
  30.                     id: grid
  31.                     anchors.fill: parent
  32.                     anchors.margins: 5 * AppInfo.ratio
  33.                     rows: 2
  34.                     columns: 3
  35.                     rowSpacing: 5  * AppInfo.ratio
  36.                     columnSpacing: 5  * AppInfo.ratio
  37.  
  38.  
  39.                     Loader {
  40.                         id: days
  41.                         sourceComponent: calendarComponent
  42.                         Layout.row: 0
  43.                         Layout.column: 0
  44.                         Layout.fillWidth: true
  45.                         Layout.fillHeight: true
  46.                         Layout.preferredWidth: parent.width / 3
  47.                         Layout.preferredHeight: parent.height * 0.8
  48.                         Layout.alignment: Qt.AlignCenter
  49.  
  50.                         onLoaded: {
  51.                             item.model = 31
  52.                             item.offset = 1
  53.                         }
  54.                     }
  55.  
  56.                     Loader {
  57.                         id: months
  58.                         sourceComponent: calendarComponent
  59.                         Layout.row: 0
  60.                         Layout.column: 1
  61.                         Layout.fillWidth: true
  62.                         Layout.fillHeight: true
  63.                         Layout.preferredWidth: parent.width / 3
  64.                         Layout.preferredHeight: parent.height * 0.8
  65.                         Layout.alignment: Qt.AlignCenter
  66.  
  67.                         onLoaded: {
  68.                             item.model = 12
  69.                             item.offset = 1
  70.                         }
  71.                     }
  72.  
  73.                     Loader {
  74.                         id: years
  75.                         sourceComponent: calendarComponent
  76.                         Layout.row: 0
  77.                         Layout.column: 2
  78.                         Layout.fillWidth: true
  79.                         Layout.fillHeight: true
  80.                         Layout.preferredWidth: parent.width / 3
  81.                         Layout.preferredHeight: parent.height * 0.8
  82.                         Layout.alignment: Qt.AlignCenter
  83.  
  84.                         onLoaded: {
  85.                             item.model = root.span
  86.                             item.offset = root.startingYear
  87.                         }
  88.                     }
  89.  
  90.                     RowLayout {
  91.                         Layout.row: 1
  92.                         Layout.column: 0
  93.                         Layout.columnSpan: 3
  94.                         Layout.alignment: Qt.AlignCenter
  95.                         Layout.fillWidth: true
  96.                         Layout.fillHeight: true
  97.                         Layout.preferredWidth: parent.width
  98.                         Layout.preferredHeight: parent.height * 0.2
  99.                         Layout.minimumHeight: 30
  100.  
  101.                         Button {
  102.                             Layout.fillWidth: true
  103.                             Layout.fillHeight: true
  104.                             text: "Conferma"
  105.  
  106.                             onClicked: {
  107.                                 var d = parseInt(days.item.datePart.text)
  108.                                 var m = parseInt(months.item.datePart.text)
  109.                                 var y = parseInt(years.item.datePart.text)
  110.                                 var date = new Date(y, m-1, d)
  111.                                 if (date.getFullYear() != y || date.getMonth() + 1 != m || date.getDate() != d ||
  112.                                         date.setHours(0,0,0,0) >= (new Date()).setHours(0,0,0,0))
  113.                                 {
  114.                                     console.info(d + " " + m + " " + y)
  115.                                     days.item.alert = months.item.alert = years.item.alert = true
  116.                                 }
  117.                                 else
  118.                                 {
  119.                                     days.item.alert = months.item.alert = years.item.alert = false
  120.                                     root.correctDate(Qt.formatDateTime(date, root.format))
  121.                                     root.destroy()
  122.                                 }
  123.                             }
  124.                         }
  125.  
  126.                         Button {
  127.                             Layout.fillWidth: true
  128.                             Layout.fillHeight: true
  129.                             text: "Annulla"
  130.  
  131.                             onClicked: {
  132.                                 root.destroy()
  133.                             }
  134.                         }
  135.                     }
  136.                 }
  137.             }
  138.  
  139.             Component {
  140.                 id: calendarComponent
  141.  
  142.                 Rectangle {
  143.                     property alias model : list.model
  144.                     property alias offset: list.offset
  145.                     property alias currentIndex: list.currentIndex
  146.                     property alias datePart: list.currentItem
  147.                     property bool alert: false
  148.                     property alias pathItemCount: list.pathItemCount
  149.  
  150.                     gradient: Gradient {
  151.                         GradientStop { position: 0.0; color: "gray" }
  152.                         GradientStop { position: 0.1; color: "transparent" }
  153.                         GradientStop { position: 0.9; color: "transparent" }
  154.                         GradientStop { position: 1; color: "gray" }
  155.                     }
  156.                     border.color: alert ? "red" : "gray"
  157.                     border.width: 2 * AppInfo.ratio
  158.                     radius: 4 * AppInfo.ratio
  159.                     property real itemHeight: height / pathItemCount
  160.  
  161.                     PathView {
  162.                         id: list
  163.                         anchors.fill: parent
  164.                         anchors.margins: 2 * AppInfo.ratio
  165.                         clip: true
  166.                         model: 12
  167.                         pathItemCount: 5
  168.                         property int offset: 1
  169.                         property real itemAngle
  170.  
  171.                         highlight: Rectangle {
  172.                             width: list.width
  173.                             height: itemHeight
  174.                             border.color: "darkgray"
  175.                             gradient: Gradient {
  176.                                 GradientStop { position: 0;    color: "#FF6DC300" }
  177.                                 GradientStop { position: .1;   color: "#446DC300" }
  178.                                 GradientStop { position: .5;   color: "#336DC300" }
  179.                                 GradientStop { position: .501; color: "#11000000" }
  180.                                 GradientStop { position: .8;   color: "#116DC300" }
  181.                                 GradientStop { position: 0.95; color: "#556DC300" }
  182.                                 GradientStop { position: 1;    color: "#FF6DC300" }
  183.                             }
  184.                         }
  185.  
  186.                         onCurrentIndexChanged: if(alert) { polish() }
  187.  
  188.                         highlightRangeMode:  PathView.StrictlyEnforceRange
  189.                         preferredHighlightBegin: 0.5
  190.                         preferredHighlightEnd: 0.5
  191.                         snapMode: PathView.SnapToItem
  192.  
  193.                         delegate: Item {
  194.                             id: del
  195.                             width: list.width
  196.                             height: itemHeight
  197.                             property bool currentItem: PathView.view.currentIndex == index
  198.                             property alias text : text.text
  199.                             Text {
  200.                                 id: text
  201.                                 anchors.centerIn: parent
  202.                                 font.pixelSize: 24 * AppInfo.ratio
  203.                                 font.bold: true
  204.                                 text: index + offset
  205.                                 color: currentItem ? "black" : "gray"
  206.                             }
  207.                         }
  208.  
  209.                         path: Path {
  210.                             startX: list.width/2; startY: 0
  211.                             PathLine { x: list.width/2; y: height }
  212.                         }
  213.                     }
  214.                 }
  215.             }
  216.             function polish(){
  217.                 days.item.alert = months.item.alert = years.item.alert = false
  218.             }
  219.  
  220.             function show(date){
  221.                 var tokens = date.split(root.separator)
  222.                 console.info(tokens)
  223.                 var positioners = root.format.split(root.separator)
  224.                 var d = parseInt(tokens[positioners.indexOf("dd")])
  225.                 var m = parseInt(tokens[positioners.indexOf("MM")])
  226.                 var y = parseInt(tokens[positioners.indexOf("yyyy")])
  227.                 days.item.currentIndex = d - 1
  228.                 months.item.currentIndex = m - 1
  229.                 years.item.currentIndex = y - root.startingYear
  230.                 Qt.inputMethod.hide()
  231.             }
  232.  
  233.             MouseArea {     // captures clicks on the application window
  234.                 anchors.fill: parent
  235.             }
  236.  
  237.             onVisibleChanged: if(!visible) root.destroy()
  238.         }
  239.     }
');