Plasma-framework

MobileCursor.qml
1/*
2 SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import org.kde.kirigami as Kirigami
10Item {
11 id: root
12 width: 1 //<-important that this is actually a single device pixel
13 height: Kirigami.Units.gridUnit
14
15 property Item target
16
17 property bool selectionStartHandle: false
18
19 visible: Kirigami.Settings.tabletMode && ((target.activeFocus && !selectionStartHandle) || target.selectedText.length > 0)
20
21 Rectangle {
22 width: 3
23 anchors {
24 horizontalCenter: parent.horizontalCenter
25 top: parent.top
26 bottom: parent.bottom
27 }
28 color: Qt.tint(Kirigami.Theme.highlightColor, Qt.rgba(1,1,1,0.4))
29 radius: width
30 Rectangle {
31 width: Math.round(Kirigami.Units.gridUnit / 1.5)
32 height: width
33 visible: MobileTextActionsToolBar.shouldBeVisible
34 anchors {
35 horizontalCenter: parent.horizontalCenter
36 verticalCenter: parent.bottom
37 }
38 radius: width
39 color: Qt.tint(Kirigami.Theme.highlightColor, Qt.rgba(1,1,1,0.4))
40 }
41 MouseArea {
42 anchors {
43 fill: parent
44 margins: -Kirigami.Units.gridUnit
45 }
46 preventStealing: true
47 onPositionChanged: {
48 var pos = mapToItem(target, mouse.x, mouse.y);
49 pos = target.positionAt(pos.x, pos.y);
50
51 if (target.selectedText.length > 0) {
52 if (selectionStartHandle) {
53 target.select(Math.min(pos, target.selectionEnd - 1), target.selectionEnd);
54 } else {
55 target.select(target.selectionStart, Math.max(pos, target.selectionStart + 1));
56 }
57 } else {
58 target.cursorPosition = pos;
59 }
60 }
61 }
62 }
63}
64
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.