Warning, /plasma/latte-dock/declarativeimports/components/private/MobileCursor.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   Copyright (C) 2018 by Marco Martin <mart@kde.org>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU Library General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  2.010-1301, USA.
0018  */
0019 
0020 import QtQuick 2.1
0021 import org.kde.plasma.core 2.0 as PlasmaCore
0022 import org.kde.kirigami 2.5 as Kirigami
0023 
0024 Item {
0025     id: root
0026     width: 1 //<-important that this is actually a single device pixel
0027     height: units.gridUnit
0028 
0029     property Item target
0030 
0031     property bool selectionStartHandle: false
0032 
0033     visible: Kirigami.Settings.tabletMode && ((target.activeFocus && !selectionStartHandle) || target.selectedText.length > 0)
0034 
0035     Rectangle {
0036         width: Math.round(units.devicePixelRatio * 3)
0037         anchors {
0038             horizontalCenter: parent.horizontalCenter
0039             top: parent.top
0040             bottom: parent.bottom
0041         }
0042         color: Qt.tint(theme.highlightColor, Qt.rgba(1,1,1,0.4))
0043         radius: width
0044         Rectangle {
0045             width: Math.round(units.gridUnit/1.5)
0046             height: width
0047             anchors {
0048                 horizontalCenter: parent.horizontalCenter
0049                 verticalCenter: parent.bottom
0050             }
0051             radius: width
0052             color: Qt.tint(theme.highlightColor, Qt.rgba(1,1,1,0.4))
0053         }
0054         MouseArea {
0055             anchors {
0056                 fill: parent
0057                 margins: -units.gridUnit
0058             }
0059             preventStealing: true
0060             onPositionChanged: {
0061                 var pos = mapToItem(target, mouse.x, mouse.y);
0062                 pos = target.positionAt(pos.x, pos.y);
0063 
0064                 if (target.selectedText.length > 0) {
0065                     if (selectionStartHandle) {
0066                         target.select(Math.min(pos, target.selectionEnd - 1), target.selectionEnd);
0067                     } else {
0068                         target.select(target.selectionStart, Math.max(pos, target.selectionStart + 1));
0069                     }
0070                 } else {
0071                     target.cursorPosition = pos;
0072                 }
0073             }
0074         }
0075     }
0076 }