Fix: DatePicker component doesn't update the date

This commit is contained in:
Ilya Kitaev 2016-10-08 01:20:55 +03:00
parent 612c497608
commit fd9ed56c54

View File

@ -33,12 +33,13 @@ import QtQuick.Controls.Styles 1.2
Item { Item {
id: datePicker id: datePicker
property bool expanded: false property bool expanded: false
property var currentDate: new Date() property date currentDate
property bool showCurrentDate: true property bool showCurrentDate: true
height: 37 height: 37
width: 156 width: 156
onExpandedChanged: if(expanded) appWindow.currentItem = datePicker onExpandedChanged: if(expanded) appWindow.currentItem = datePicker
function hide() { datePicker.expanded = false } function hide() { datePicker.expanded = false }
function containsPoint(px, py) { function containsPoint(px, py) {
if(px < 0) if(px < 0)
@ -121,12 +122,29 @@ Item {
} }
Row { Row {
id: dateInput
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 10 anchors.leftMargin: 10
function setDate(date) {
var day = date.getDate()
var month = date.getMonth() + 1
dayInput.text = day < 10 ? "0" + day : day
monthInput.text = month < 10 ? "0" + month : month
yearInput.text = date.getFullYear()
}
Connections {
target: datePicker
onCurrentDateChanged: {
dateInput.setDate(datePicker.currentDate)
}
}
TextInput { TextInput {
id: dayInput id: dayInput
readOnly: true
width: 22 width: 22
font.family: "Arial" font.family: "Arial"
font.pixelSize: 18 font.pixelSize: 18
@ -135,6 +153,7 @@ Item {
horizontalAlignment: TextInput.AlignHCenter horizontalAlignment: TextInput.AlignHCenter
validator: IntValidator{bottom: 01; top: 31;} validator: IntValidator{bottom: 01; top: 31;}
KeyNavigation.tab: monthInput KeyNavigation.tab: monthInput
text: { text: {
if(datePicker.showCurrentDate) { if(datePicker.showCurrentDate) {
var day = datePicker.currentDate.getDate() var day = datePicker.currentDate.getDate()
@ -158,6 +177,7 @@ Item {
TextInput { TextInput {
id: monthInput id: monthInput
readOnly: true
width: 22 width: 22
font.family: "Arial" font.family: "Arial"
font.pixelSize: 18 font.pixelSize: 18
@ -277,12 +297,7 @@ Item {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
if(styleData.visibleMonth) { if(styleData.visibleMonth) {
var date = styleData.date currentDate = styleData.date
var day = date.getDate()
var month = date.getMonth() + 1
dayInput.text = day < 10 ? "0" + day : day
monthInput.text = month < 10 ? "0" + month : month
yearInput.text = date.getFullYear()
datePicker.expanded = false datePicker.expanded = false
} else { } else {
var date = styleData.date var date = styleData.date