浏览代码

Добавлен компонент PullToRefresh для ListView

Denis V. Dedkov 1 年之前
父节点
当前提交
15f4f2531f
共有 3 个文件被更改,包括 47 次插入1 次删除
  1. 1 0
      .gitignore
  2. 4 1
      CMakeLists.txt
  3. 42 0
      PoolToRefresh.qml

+ 1 - 0
.gitignore

@@ -72,3 +72,4 @@ CMakeLists.txt.user*
 *.dll
 *.exe
 
+build/

+ 4 - 1
CMakeLists.txt

@@ -12,7 +12,10 @@ qt_add_library(components STATIC)
 qt_add_qml_module(components
     URI ru.ded.components
     VERSION 1.0
-    QML_FILES MainMenu.qml MenuBackButton.qml SubtitledItemDelegate.qml
+    QML_FILES MainMenu.qml
+              MenuBackButton.qml
+              SubtitledItemDelegate.qml
+              PoolToRefresh.qml
 )
 
 set_target_properties(components PROPERTIES

+ 42 - 0
PoolToRefresh.qml

@@ -0,0 +1,42 @@
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+
+Item {
+    id: root
+
+    signal update()
+
+    property string text: qsTr("Release to update")
+    property real sensivity: 50.0
+    property alias enabled: connections.enabled
+
+    property bool triggered: false
+    property bool trigger: parent.contentY < -1 * sensivity
+    property bool atStart: parent.contentY === 0
+
+    Label {
+        id: label
+
+        anchors.horizontalCenter: root.horizontalCenter
+
+        visible: root.trigger
+        text: root.text
+    }
+
+    Connections {
+        id: connections
+
+        target: root.parent
+
+        function onContentYChanged() {
+            if (root.trigger) {
+                root.triggered = true
+            }
+
+            if (root.atStart && root.triggered) {
+                root.update()
+                root.triggered = false
+            }
+        }
+    }
+}