Plasma

MobileTextActionsToolBar.qml
1 /*
2  SPDX-FileCopyrightText: 2018 Marco Martin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 pragma Singleton
8 
9 import QtQuick 2.1
10 import QtQuick.Layouts 1.2
11 import QtQuick.Window 2.2
12 import QtQuick.Controls @QQC2_VERSION@
13 import org.kde.plasma.core 2.0 as PlasmaCore
14 import org.kde.kirigami 2.5 as Kirigami
15 
16 Popup {
17  id: root
18 
19  property Item controlRoot
20  parent: controlRoot ? controlRoot.Window.contentItem : undefined
21  modal: false
22  focus: false
23  closePolicy: Popup.NoAutoClose
24  property bool shouldBeVisible: false
25 
26  x: parent ? Math.min(Math.max(0, controlRoot.mapToItem(root.parent, controlRoot.positionToRectangle(controlRoot.selectionStart).x, 0).x - root.width/2), parent.width - root.width) : 0
27 
28  y: {
29  if (!parent) {
30  return false;
31  }
32  var desiredY = controlRoot.mapToItem(root.parent, 0, controlRoot.positionToRectangle(controlRoot.selectionStart).y).y - root.height;
33 
34  if (desiredY >= 0) {
35  return Math.min(desiredY, parent.height - root.height);
36  } else {
37  return Math.min(Math.max(0, controlRoot.mapToItem(root.parent, 0, controlRoot.positionToRectangle(controlRoot.selectionEnd).y + Math.round(PlasmaCore.Units.gridUnit*1.5)).y), parent.height - root.height);
38  }
39  }
40 
41 
42  visible: controlRoot ? shouldBeVisible && Kirigami.Settings.tabletMode && (controlRoot.selectedText.length > 0 || controlRoot.canPaste) : false
43 
44  width: contentItem.implicitWidth + leftPadding + rightPadding
45 
46  contentItem: RowLayout {
47  ToolButton {
48  focusPolicy: Qt.NoFocus
49  icon.name: "edit-cut"
50  visible: controlRoot && controlRoot.selectedText.length > 0 && (!controlRoot.hasOwnProperty("echoMode") || controlRoot.echoMode === TextInput.Normal)
51  onClicked: {
52  controlRoot.cut();
53  }
54  }
55  ToolButton {
56  focusPolicy: Qt.NoFocus
57  icon.name: "edit-copy"
58  visible: controlRoot && controlRoot.selectedText.length > 0 && (!controlRoot.hasOwnProperty("echoMode") || controlRoot.echoMode === TextInput.Normal)
59  onClicked: {
60  controlRoot.copy();
61  }
62  }
63  ToolButton {
64  focusPolicy: Qt.NoFocus
65  icon.name: "edit-paste"
66  visible: controlRoot && controlRoot.canPaste
67  onClicked: {
68  controlRoot.paste();
69  }
70  }
71  }
72 }
73 
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 04:05:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.