diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 359ecae..6866f32 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ qt_add_qml_module(${PROJECT_NAME} MnemonicAction.qml MnemonicLabel.qml PermanentScrollBar.qml + Reservation.qml ReservationsPage.qml ReservationsTimeline.qml SelectableLabel.qml diff --git a/src/Reservation.qml b/src/Reservation.qml new file mode 100644 index 0000000..c675dd9 --- /dev/null +++ b/src/Reservation.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 + } +} diff --git a/src/ReservationsTimeline.qml b/src/ReservationsTimeline.qml index 2870e1f..67c9a3b 100644 --- a/src/ReservationsTimeline.qml +++ b/src/ReservationsTimeline.qml @@ -99,72 +99,40 @@ 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 - dayWidth: control.dayWidth - fromDate: control.fromDate height: control.rowHeight - model: timeline - toDate: control.toDate - viewportWidth: ListView.view.width - viewportX: ListView.view.contentX + width: contentWidth - 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 - } + onPositionChanged: function (drag) { + drag.source.y = y; + drag.source.x = (Math.floor(drag.x / control.dayWidth) + .5) * control.dayWidth; } - Separator { - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.right: parent.right - palette: control.palette + TimelineView { + dayWidth: control.dayWidth + fromDate: control.fromDate + height: parent.height + model: parent.timeline + toDate: control.toDate + viewportWidth: parent.viewportWidth + viewportX: parent.viewportX + + delegate: Reservation { + dragParent: timelineList.contentItem + } + + Separator { + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + palette: control.palette + } } } header: Rectangle {