From 241533f1f8e7c3af815e717125cafad1ae0f9c13 Mon Sep 17 00:00:00 2001 From: Kirill Anisimov <kirill.anisimov@demlabs.net> Date: Mon, 20 Jan 2020 16:23:47 +0300 Subject: [PATCH] Added DapScrollView element. --- libdap-qt-ui-qml.qrc | 2 + widgets/DapScrollView.qml | 109 +++++++++++++++++++++++++++++++ widgets/DapScrollViewForm.ui.qml | 37 +++++++++++ 3 files changed, 148 insertions(+) create mode 100644 widgets/DapScrollView.qml create mode 100644 widgets/DapScrollViewForm.ui.qml diff --git a/libdap-qt-ui-qml.qrc b/libdap-qt-ui-qml.qrc index 244e6b0..4bf602f 100644 --- a/libdap-qt-ui-qml.qrc +++ b/libdap-qt-ui-qml.qrc @@ -20,5 +20,7 @@ <file>Device.qml</file> <file>widgets/DapRadioButton.qml</file> <file>widgets/DapRadioButtonForm.ui.qml</file> + <file>widgets/DapScrollView.qml</file> + <file>widgets/DapScrollViewForm.ui.qml</file> </qresource> </RCC> diff --git a/widgets/DapScrollView.qml b/widgets/DapScrollView.qml new file mode 100644 index 0000000..fd9159a --- /dev/null +++ b/widgets/DapScrollView.qml @@ -0,0 +1,109 @@ +import QtQuick 2.4 + +DapScrollViewForm +{ + property var contentPos: 0.0 + viewData.onContentYChanged: + { + if (viewData.atYBeginning) + { + scrollButton.state = "goUp" + } + else if (viewData.atYEnd) + { + scrollButton.state = "goDown" + } + else if (contentPos < viewData.contentItem.y) + { + scrollButton.state = "goUp" + } + else + { + scrollButton.state = "goDown" + } + } + + onEntered: + { + scrollButton.visible = true; + } + + onExited: + { + scrollButton.visible = false; + } + + scrollButton.onEntered: + { + if (scrollButton.state === "goUp") + { + scrollButton.imageSource = "qrc:/res/icons/ic_scroll-down_hover.png" + } + else if (scrollButton.state === "goDown") + { + scrollButton.imageSource = "qrc:/res/icons/ic_scroll-up_hover.png" + } + } + + scrollButton.onExited: + { + if (scrollButton.state === "goUp") + { + scrollButton.imageSource = "qrc:/res/icons/ic_scroll-down.png" + } + else if (scrollButton.state === "goDown") + { + scrollButton.imageSource = "qrc:/res/icons/ic_scroll-up.png" + } + } + + scrollButton.onClicked: + { + if(scrollButton.state === "goUp") + { + viewData.positionViewAtEnd(); + scrollButton.state = "goDown"; + } + else if(scrollButton.state === "goDown") + { + viewData.positionViewAtBeginning(); + scrollButton.state = "goUp"; + } + } + + scrollButton.states: + [ + State + { + name: "goDown" + PropertyChanges + { + target: scrollButton + onStateChanged: + { + scrollButton.anchors.top = undefined + scrollButton.anchors.bottom = parent.bottom + scrollButton.exited() + } + } + }, + + State + { + name: "goUp" + PropertyChanges + { + target: scrollButton + onStateChanged: + { + scrollButton.anchors.bottom = undefined + scrollButton.anchors.top = parent.top + scrollButton.exited() + } + } + } + + ] + + scrollButton.state: "goUp" +} diff --git a/widgets/DapScrollViewForm.ui.qml b/widgets/DapScrollViewForm.ui.qml new file mode 100644 index 0000000..62d4e1d --- /dev/null +++ b/widgets/DapScrollViewForm.ui.qml @@ -0,0 +1,37 @@ +import QtQuick 2.4 + +MouseArea +{ + id: dapScrollMouseArea + ////@ ListView to attach the ScrollButton + property ListView viewData: ListView {} + property alias scrollMouseArea: dapScrollMouseArea + property alias scrollButton: dapScrollButton + + anchors.fill: parent + hoverEnabled: true + + MouseArea + { + id: dapScrollButton + property string imageSource: "qrc:/res/icons/ic_scroll-down.png" + width: 36 * pt + height: width + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 * pt + anchors.topMargin: 10 * pt + anchors.rightMargin: 10 * pt + hoverEnabled: true + visible: false + + Image + { + anchors.fill: parent + fillMode: Image.PreserveAspectFit + source: dapScrollButton.imageSource + sourceSize.height: parent.height + sourceSize.width: parent.width + } + } +} -- GitLab