diff --git a/org.kde.desktop/private/MobileTextActionsToolBar.qml b/org.kde.desktop/private/MobileTextActionsToolBar.qml index 7517272..36758c5 100644 --- a/org.kde.desktop/private/MobileTextActionsToolBar.qml +++ b/org.kde.desktop/private/MobileTextActionsToolBar.qml @@ -1,85 +1,90 @@ /* * Copyright (C) 2018 by Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. */ pragma Singleton import QtQuick 2.1 import QtQuick.Layouts 1.2 import QtQuick.Window 2.2 import QtQuick.Controls @QQC2_VERSION@ import org.kde.kirigami 2.5 as Kirigami Popup { id: root property Item controlRoot parent: controlRoot ? controlRoot.Window.contentItem : undefined modal: false focus: false closePolicy: Popup.NoAutoClose property bool shouldBeVisible: false - x: controlRoot ? Math.min(Math.max(0, controlRoot.mapToItem(root.parent, controlRoot.positionToRectangle(controlRoot.selectionStart).x, 0).x - root.width/2), controlRoot.Window.contentItem.width - root.width) : 0 + x: { + if (!controlRoot || !controlRoot.Window.contentItem) { + return 0; + } + return Math.min(Math.max(0, controlRoot.mapToItem(root.parent, controlRoot.positionToRectangle(controlRoot.selectionStart).x, 0).x - root.width/2), controlRoot.Window.contentItem.width - root.width); + } y: { - if (!controlRoot) { - return false; + if (!controlRoot || !controlRoot.Window.contentItem) { + return 0; } var desiredY = controlRoot.mapToItem(root.parent, 0, controlRoot.positionToRectangle(controlRoot.selectionStart).y).y - root.height; if (desiredY >= 0) { return Math.min(desiredY, controlRoot.Window.contentItem.height - root.height); } else { return Math.min(Math.max(0, controlRoot.mapToItem(root.parent, 0, controlRoot.positionToRectangle(controlRoot.selectionEnd).y + Math.round(Kirigami.Units.gridUnit*1.5)).y), controlRoot.Window.contentItem.height - root.height); } } visible: controlRoot ? shouldBeVisible && Kirigami.Settings.tabletMode && (controlRoot.selectedText.length > 0 || controlRoot.canPaste) : false width: contentItem.implicitWidth + leftPadding + rightPadding contentItem: RowLayout { ToolButton { focusPolicy: Qt.NoFocus icon.name: "edit-cut" visible: controlRoot && controlRoot.selectedText.length > 0 && (!controlRoot.hasOwnProperty("echoMode") || controlRoot.echoMode === TextInput.Normal) onClicked: { controlRoot.cut(); } } ToolButton { focusPolicy: Qt.NoFocus icon.name: "edit-copy" visible: controlRoot && controlRoot.selectedText.length > 0 && (!controlRoot.hasOwnProperty("echoMode") || controlRoot.echoMode === TextInput.Normal) onClicked: { controlRoot.copy(); } } ToolButton { focusPolicy: Qt.NoFocus icon.name: "edit-paste" visible: controlRoot && controlRoot.canPaste onClicked: { controlRoot.paste(); } } } } diff --git a/tests/LineEditWithClearButton.qml b/tests/LineEditWithClearButton.qml new file mode 100644 index 0000000..c2eb0fe --- /dev/null +++ b/tests/LineEditWithClearButton.qml @@ -0,0 +1,35 @@ +/* + Copyright (c) 2019 Montel Laurent + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2 of the License or + ( at your option ) version 3 or, at the discretion of KDE e.V. + ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +import org.kde.kirigami 2.7 as Kirigami +Kirigami.ActionTextField { + id: __searchField + focus: true + rightActions: [ + Kirigami.Action { + iconName: "edit-clear" + visible: __searchField.text !== "" + onTriggered: { + __searchField.text = "" + __searchField.accepted() + } + } + ] +}