Skip to content

Commit

Permalink
Implement a time picker component
Browse files Browse the repository at this point in the history
- Fixes papyros#148
- Closes papyros#217
  • Loading branch information
Steve Coffey authored and iBelieve committed Jun 22, 2015
1 parent b382e69 commit 34d07bb
Show file tree
Hide file tree
Showing 7 changed files with 686 additions and 15 deletions.
58 changes: 58 additions & 0 deletions demo/TimePickerDemo.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import QtQuick 2.0
import Material 0.1


Item {

TimePickerDialog {
id: timePicker
onTimePicked: {
updateLabelForDate(timePicked)
}
prefer24Hour: twentyFourHourSwitch.checked
}

Column {
anchors.centerIn: parent
spacing: Units.dp(20)

Button {
text: "Show Time Picker Dialog"
anchors.horizontalCenter: parent.horizontalCenter
elevation: 1
onClicked: {
timePicker.show()
}
}

Label {
id: timeLabel
style: "display1"
anchors.horizontalCenter: parent.horizontalCenter
}

Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: Units.dp(16)

Label {
text: "24 hour clock:"
style: "dialog"
}

Switch {
id: twentyFourHourSwitch
checked: false
}
}
}

Component.onCompleted: {
var date = new Date(Date.now())
updateLabelForDate(new Date(Date.now()))
}

function updateLabelForDate(date) {
timeLabel.text = date.toLocaleTimeString(Qt.locale(), "hh:mm ap")
}
}
2 changes: 1 addition & 1 deletion demo/demo.qmlproject
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Project {
directory: "."
}

importPaths: [ "../modules" ]
importPaths: [ "../modules"]
}
2 changes: 1 addition & 1 deletion demo/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ApplicationWindow {
]

property var compoundComponents: [
"Bottom Sheet", "Dialog", "Forms", "List Items", "Page Stack"
"Bottom Sheet", "Dialog", "Forms", "List Items", "Page Stack", "Time Picker"
]

property var sections: [ styles, basicComponents, compoundComponents ]
Expand Down
23 changes: 10 additions & 13 deletions modules/Material/Dialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Material.Extras 0.1
/*!
\qmltype Dialog
\inqmlmodule Material 0.1
\brief Dialogs inform users about critical information, require users to make
decisions, or encapsulate multiple tasks within a discrete process
*/
Expand All @@ -42,12 +41,12 @@ PopupBase {
width: Math.max(minimumWidth,
content.contentWidth + 2 * contentMargins)

height: Math.min(Units.dp(350),
headerView.height + Units.dp(32) +
height: Math.min(parent.height - Units.dp(64),
headerView.height + (contentMargins * 2) +
content.contentHeight +
content.topMargin +
content.bottomMargin +
buttonContainer.height)
(floatingActions ? 0 : buttonContainer.height))

property int contentMargins: Units.dp(16)

Expand All @@ -58,15 +57,13 @@ PopupBase {

/*!
\qmlproperty Button negativeButton
The negative button, displayed as the leftmost button on the right of the dialog buttons.
This is usually used to dismiss the dialog.
*/
property alias negativeButton: negativeButton

/*!
\qmlproperty Button primaryButton
The primary button, displayed as the rightmost button in the dialog buttons row. This is
usually used to accept the dialog's action.
*/
Expand All @@ -77,6 +74,7 @@ PopupBase {
property alias positiveButtonEnabled: positiveButton.enabled

property bool hasActions: true
property bool floatingActions: false

default property alias dialogContent: column.data

Expand Down Expand Up @@ -176,7 +174,7 @@ PopupBase {

leftMargin: Units.dp(16)
rightMargin: Units.dp(16)
topMargin: Units.dp(16)
topMargin: title == "" && text == "" ? 0 : Units.dp(16)
}

Label {
Expand All @@ -185,7 +183,7 @@ PopupBase {
width: parent.width
wrapMode: Text.Wrap
style: "title"
visible: text != ""
visible: title != ""
}

Label {
Expand Down Expand Up @@ -213,13 +211,13 @@ PopupBase {
left: parent.left
right: parent.right
top: headerView.bottom
topMargin: Units.dp(8)
topMargin: title == "" && text == "" ? 0 :Units.dp(8)
bottomMargin: Units.dp(-8)
bottom: buttonContainer.top
bottom: floatingActions ? parent.bottom : buttonContainer.top
}

interactive: contentHeight + Units.dp(8) > height
bottomMargin: hasActions ? 0 : Units.dp(8)
bottomMargin: hasActions || contentMargins == 0 ? 0 : Units.dp(8)

Rectangle {
Column {
Expand Down Expand Up @@ -258,7 +256,7 @@ PopupBase {
height: hasActions ? positiveButton.implicitHeight + Units.dp(8) : 0
visible: hasActions

backgroundColor: "white"
backgroundColor: floatingActions ? "transparent" : "white"
elevation: content.atYEnd ? 0 : 1
fullWidth: true
elevationInverted: true
Expand Down Expand Up @@ -311,5 +309,4 @@ PopupBase {
}
}
}

}
Loading

0 comments on commit 34d07bb

Please sign in to comment.