plasma-framework/src/declarativeimports/plasmastyle/EditMenuTouch.qml
Nate Graham 5447cef2d8 Port to singleton Units
The context property version is slower to access and won't be supported
in Qt6. Let's port away from it and use the singleton version instead.

Here was my full process for making this change:

1. Made the change with `find . -name '*.qml' | xargs perl -pi -e 's/units\./PlasmaCore\.Units\./g'`
2. Verified no more occurrences with `grep -r " units."`
3. Made sure this didn't change any comments in a silly way by inspecting the output of `git diff | grep "+   " | grep "//"`
4. Manually inspected the full git diff to make sure there were no other unintentional or silly changes (there were none)
5. verified that all changed files have the PlasmaCore import with the correct name with `for FILE in `git status | grep modified | cut -d ":" -f 3`; do grep -q "as PlasmaCore" $FILE || echo "$FILE needs the PlasmaCore import"; done` (one needed the import)
2021-03-07 13:34:47 +00:00

141 lines
4.5 KiB
QML

/*
SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Controls.Private 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
Item {
anchors.fill: parent
property Component defaultMenu: PlasmaCore.FrameSvgItem {
id: popup
imagePath: "widgets/background"
visible: false
width: childrenRect.width + margins.left + margins.right
height: childrenRect.height + margins.top + margins.bottom
z: 9999
Component.onCompleted: {
var par = control
//heuristic: if a flickable is found in the parents,
//reparent to it, so it scrolls together
while (par.parent && par.parent.contentY === undefined) {
par = par.parent
}
popup.parent = par
}
function popup(pos) {
popup.x = pos.x;
popup.y = pos.y;
popup.visible = true;
}
function dismiss() {
popup.visible = false;
}
Row {
x: parent.margins.left
y: parent.margins.top
property Item checkedButton
PlasmaComponents.ToolButton {
iconSource: "text-field"
flat: false
visible: input.selectedText == "" && control.echoMode != TextInput.Password
onClicked: {
selectWord();
popupTimer.restart();
}
}
PlasmaComponents.ToolButton {
iconSource: "edit-cut"
flat: false
visible: input.selectedText != "" && control.echoMode != TextInput.Password
onClicked: {
control.cut();
select(input.cursorPosition, input.cursorPosition);
}
}
PlasmaComponents.ToolButton {
iconSource: "edit-copy"
visible: input.selectedText != "" && control.echoMode != TextInput.Password
flat: false
onClicked: {
control.copy();
select(input.cursorPosition, input.cursorPosition);
}
}
PlasmaComponents.ToolButton {
iconSource: "edit-paste"
visible: input.canPaste
flat: false
onClicked: {
control.paste();
}
}
}
}
Connections {
target: mouseArea
function onClicked(mouse) {
if (control.menu && getMenuInstance().__popupVisible) {
select(input.cursorPosition, input.cursorPosition);
} else {
input.activate();
}
if (input.activeFocus) {
var pos = input.positionAt(mouse.x, mouse.y)
input.moveHandles(pos, pos)
}
popupTimer.restart();
}
function onPressAndHold(mouse) {
input.activate();
var pos = input.positionAt(mouseArea.mouseX, mouseArea.mouseY);
input.select(pos, pos);
selectWord();
popupTimer.restart();
}
}
Connections {
target: input
function onSelectionStartChanged() {popupTimer.restart()}
function onSelectionEndChanged() {popupTimer.restart()}
function onActiveFocusChanged() {popupTimer.restart()}
}
Connections {
target: flickable
function onMovingChanged() {popupTimer.restart()}
}
Timer {
id: popupTimer
interval: 1
onTriggered: {
if (control.activeFocus) {
var startRect = input.positionToRectangle(input.selectionStart);
var endRect = input.positionToRectangle(input.selectionEnd);
var pos = getMenuInstance().parent.mapFromItem(input, (startRect.x + endRect.x)/2 - getMenuInstance().width/2, endRect.y);
pos.y += (pos.y + getMenuInstance().height + PlasmaCore.Units.gridUnit) > getMenuInstance().parent.height ? -PlasmaCore.Units.smallSpacing - getMenuInstance().height : PlasmaCore.Units.gridUnit*2;
getMenuInstance().dismiss();
getMenuInstance().popup(pos);
} else {
getMenuInstance().dismiss();
}
}
}
}