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