Drag reservations with “snap to grid”
No drop yet. Had to use MouseArea instead of DragHandler because the latter refuses to work, and instead scrolls the list on click; have not figured out why.
This commit is contained in:
parent
8677051303
commit
ab1ebd61b6
|
@ -24,6 +24,7 @@ qt_add_qml_module(${PROJECT_NAME}
|
|||
MnemonicAction.qml
|
||||
MnemonicLabel.qml
|
||||
PermanentScrollBar.qml
|
||||
Reservation.qml
|
||||
ReservationsPage.qml
|
||||
ReservationsTimeline.qml
|
||||
SelectableLabel.qml
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
Label {
|
||||
id: control
|
||||
|
||||
required property Item dragParent
|
||||
required property string holder
|
||||
required property string reservationStatus
|
||||
|
||||
Drag.active: dragHandler.active
|
||||
Drag.hotSpot.x: 0
|
||||
Drag.hotSpot.y: 0
|
||||
elide: Text.ElideRight
|
||||
padding: 2
|
||||
text: holder
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
z: 1
|
||||
|
||||
background: Rectangle {
|
||||
function backgroundColor(status) {
|
||||
switch (status) {
|
||||
case "created":
|
||||
return "#cbebff";
|
||||
case "cancelled":
|
||||
return "#ffbaa6";
|
||||
case "confirmed":
|
||||
return "#ffe673";
|
||||
case "checked-in":
|
||||
return "#9fefb9";
|
||||
case "invoiced":
|
||||
return "#e1dbd6";
|
||||
}
|
||||
}
|
||||
|
||||
function borderColor(status) {
|
||||
switch (status) {
|
||||
case "created":
|
||||
return "#6fc7fe";
|
||||
case "cancelled":
|
||||
return "#ff7851";
|
||||
case "confirmed":
|
||||
return "#ffd829";
|
||||
case "checked-in":
|
||||
return "#5ae387";
|
||||
case "invoiced":
|
||||
return "#bbaea3";
|
||||
}
|
||||
}
|
||||
|
||||
border.color: borderColor(control.reservationStatus)
|
||||
color: backgroundColor(control.reservationStatus)
|
||||
radius: 5
|
||||
}
|
||||
states: [
|
||||
State {
|
||||
when: dragHandler.active
|
||||
|
||||
ParentChange {
|
||||
parent: control.dragParent
|
||||
target: control
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
MouseArea {
|
||||
id: dragHandler
|
||||
|
||||
property alias active: dragHandler.drag.active
|
||||
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.OpenHandCursor
|
||||
drag.target: control
|
||||
}
|
||||
}
|
|
@ -99,65 +99,32 @@ Control {
|
|||
id: verticalScroll
|
||||
|
||||
}
|
||||
delegate: TimelineView {
|
||||
delegate: DropArea {
|
||||
property real contentWidth: ListView.view.contentWidth
|
||||
required property string name
|
||||
required property TimelineModel timeline
|
||||
property real viewportWidth: ListView.view.width
|
||||
property real viewportX: ListView.view.contentX
|
||||
|
||||
height: control.rowHeight
|
||||
width: contentWidth
|
||||
|
||||
onPositionChanged: function (drag) {
|
||||
drag.source.y = y;
|
||||
drag.source.x = (Math.floor(drag.x / control.dayWidth) + .5) * control.dayWidth;
|
||||
}
|
||||
|
||||
TimelineView {
|
||||
dayWidth: control.dayWidth
|
||||
fromDate: control.fromDate
|
||||
height: control.rowHeight
|
||||
model: timeline
|
||||
height: parent.height
|
||||
model: parent.timeline
|
||||
toDate: control.toDate
|
||||
viewportWidth: ListView.view.width
|
||||
viewportX: ListView.view.contentX
|
||||
viewportWidth: parent.viewportWidth
|
||||
viewportX: parent.viewportX
|
||||
|
||||
delegate: Label {
|
||||
id: reservation
|
||||
|
||||
required property string holder
|
||||
required property string reservationStatus
|
||||
|
||||
elide: Text.ElideRight
|
||||
padding: 2
|
||||
text: holder
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
z: 1
|
||||
|
||||
background: Rectangle {
|
||||
function backgroundColor(status) {
|
||||
switch (status) {
|
||||
case "created":
|
||||
return "#cbebff";
|
||||
case "cancelled":
|
||||
return "#ffbaa6";
|
||||
case "confirmed":
|
||||
return "#ffe673";
|
||||
case "checked-in":
|
||||
return "#9fefb9";
|
||||
case "invoiced":
|
||||
return "#e1dbd6";
|
||||
}
|
||||
}
|
||||
|
||||
function borderColor(status) {
|
||||
switch (status) {
|
||||
case "created":
|
||||
return "#6fc7fe";
|
||||
case "cancelled":
|
||||
return "#ff7851";
|
||||
case "confirmed":
|
||||
return "#ffd829";
|
||||
case "checked-in":
|
||||
return "#5ae387";
|
||||
case "invoiced":
|
||||
return "#bbaea3";
|
||||
}
|
||||
}
|
||||
|
||||
border.color: borderColor(reservation.reservationStatus)
|
||||
color: backgroundColor(reservation.reservationStatus)
|
||||
radius: 5
|
||||
}
|
||||
delegate: Reservation {
|
||||
dragParent: timelineList.contentItem
|
||||
}
|
||||
|
||||
Separator {
|
||||
|
@ -167,6 +134,7 @@ Control {
|
|||
palette: control.palette
|
||||
}
|
||||
}
|
||||
}
|
||||
header: Rectangle {
|
||||
border.color: Fusion.outline(control.palette)
|
||||
color: control.palette.base
|
||||
|
|
Loading…
Reference in New Issue