Skip to content

Commit

Permalink
Merge pull request #199 from krnekhelesh/master
Browse files Browse the repository at this point in the history
[Ubuntu Touch] Switched to native date and time pickers
  • Loading branch information
smurfy committed May 20, 2015
2 parents 2c4e741 + 011ae6f commit 868aff9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 288 deletions.
1 change: 0 additions & 1 deletion fahrplan2.pro
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ ubuntu: {
src/gui/ubuntu/JourneyDetailsResultsPage.qml \
src/gui/ubuntu/TimeTableResultsPage.qml \
src/gui/ubuntu/main.qml \
src/gui/ubuntu/components/Scroller.qml \
src/gui/ubuntu/components/StationSelect.qml \
src/gui/ubuntu/components/DatePicker.qml \
src/gui/ubuntu/components/TimePicker.qml \
Expand Down
4 changes: 2 additions & 2 deletions src/gui/ubuntu/MainPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Page {

onClicked: {
var selectedDateTime = fahrplanBackend.dateTime
var popupObj = PopupUtils.open(datePicker, datePickerButton, {day: selectedDateTime.getDate(), month: selectedDateTime.getMonth(), year: selectedDateTime.getFullYear()})
var popupObj = PopupUtils.open(datePicker, datePickerButton, {date: selectedDateTime})
popupObj.accepted.connect(function(day, month, year) {
var newDate = selectedDateTime
newDate.setFullYear(year, month, day)
Expand All @@ -253,7 +253,7 @@ Page {

onClicked: {
var selectedDateTime = fahrplanBackend.dateTime;
var popupObj = PopupUtils.open(timePicker, timePickerButton, {hour: selectedDateTime.getHours(), minute: selectedDateTime.getMinutes()});
var popupObj = PopupUtils.open(timePicker, timePickerButton, {time: selectedDateTime});
popupObj.accepted.connect(function(hour, minute) {
var newDate = selectedDateTime
newDate.setHours(hour, minute)
Expand Down
109 changes: 17 additions & 92 deletions src/gui/ubuntu/components/DatePicker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,122 +19,47 @@

import QtQuick 2.3
import Ubuntu.Components 1.1
import Ubuntu.Components.Popups 0.1
import Ubuntu.Components.Popups 1.0
import Ubuntu.Components.Pickers 1.0

Dialog {
id: root

title: qsTr("<b>Date</b>")

// 1 - 31
property int day: priv.now.getDate()
// 0 - 11
property alias month: monthScroller.currentIndex
property int year: priv.now.getFullYear()
property alias minYear: yearScroller.min
property alias maxYear: yearScroller.max
property alias date: datePicker.date

signal accepted(int day, int month, int year)
signal rejected()

QtObject {
id: priv

property date now: new Date()

function getDays(month, year) {
switch(monthScroller.currentIndex) {
case 1:
if (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)) {
return 29;
}
return 28;
case 3:
case 5:
case 8:
case 10:
return 30;
default:
return 31;
}
}
}

contents: [
Row {
height: units.gu(24)
Scroller {
id: dayScroller
anchors {
top: parent.top
bottom: parent.bottom
}
width: parent.width / 3
labelText: qsTr("Day")
min: 1
max: priv.getDays(monthScroller.currentIndex + 1, yearScroller.value);
currentIndex: root.day - 1
onCurrentIndexChanged: {
print("currentIndex changed:", currentIndex)
root.day = currentIndex + 1
}
}
Scroller {
id: monthScroller
anchors {
top: parent.top
bottom: parent.bottom
}
width: parent.width / 3
labelText: qsTr("Month")
currentIndex: priv.now.getMonth()

model: ListModel {
ListElement { modelData: "Jan" }
ListElement { modelData: "Feb" }
ListElement { modelData: "Mar" }
ListElement { modelData: "Apr" }
ListElement { modelData: "May" }
ListElement { modelData: "Jun" }
ListElement { modelData: "Jul" }
ListElement { modelData: "Aug" }
ListElement { modelData: "Sep" }
ListElement { modelData: "Oct" }
ListElement { modelData: "Nov" }
ListElement { modelData: "Dec" }
}
}
Scroller {
id: yearScroller
anchors {
top: parent.top
bottom: parent.bottom
}
width: parent.width / 3
labelText: qsTr("Year")
min: 1970
max: 2048
currentIndex: root.year - min
}
DatePicker {
id: datePicker
mode: "Years|Months|Days"
},

Row {
spacing: units.gu(1)
Button {
text: "Cancel"
text: qsTr("Cancel")
color: UbuntuColors.lightGrey
width: (parent.width - parent.spacing) / 2

onClicked: {
root.rejected()
PopupUtils.close(root)
}
width: (parent.width - parent.spacing) / 2
}

Button {
text: "OK"
color: "#dd4814"
text: qsTr("Ok")
color: UbuntuColors.green
width: (parent.width - parent.spacing) / 2

onClicked: {
root.accepted(dayScroller.value, monthScroller.currentIndex, yearScroller.value)
root.accepted(datePicker.day, datePicker.month, datePicker.year)
PopupUtils.close(root)
}
width: (parent.width - parent.spacing) / 2
}
}
]
Expand Down
150 changes: 0 additions & 150 deletions src/gui/ubuntu/components/Scroller.qml

This file was deleted.

Loading

0 comments on commit 868aff9

Please sign in to comment.