aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/material/impl/CursorDelegate.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/quickcontrols/material/impl/CursorDelegate.qml')
-rw-r--r--src/quickcontrols/material/impl/CursorDelegate.qml32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/quickcontrols/material/impl/CursorDelegate.qml b/src/quickcontrols/material/impl/CursorDelegate.qml
new file mode 100644
index 0000000000..811aa89e36
--- /dev/null
+++ b/src/quickcontrols/material/impl/CursorDelegate.qml
@@ -0,0 +1,32 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+import QtQuick
+import QtQuick.Controls.Material
+
+Rectangle {
+ id: cursor
+
+ color: parent.Material.accentColor
+ width: 2
+ visible: parent.activeFocus && !parent.readOnly && parent.selectionStart === parent.selectionEnd
+
+ Connections {
+ target: cursor.parent
+ function onCursorPositionChanged() {
+ // keep a moving cursor visible
+ cursor.opacity = 1
+ timer.restart()
+ }
+ }
+
+ Timer {
+ id: timer
+ running: cursor.parent.activeFocus && !cursor.parent.readOnly && interval != 0
+ repeat: true
+ interval: Qt.styleHints.cursorFlashTime / 2
+ onTriggered: cursor.opacity = !cursor.opacity ? 1 : 0
+ // force the cursor visible when gaining focus
+ onRunningChanged: cursor.opacity = 1
+ }
+}