UI: Add text context menu.

This commit is contained in:
Nodir Temirkhodjaev 2017-10-26 08:52:49 +05:00
parent f28e93fe0a
commit 76b88cf4d4
6 changed files with 71 additions and 2 deletions

View File

@ -1,6 +1,8 @@
<RCC>
<qresource prefix="/">
<file>qml/controls/TextAreaFrame.qml</file>
<file>qml/controls/TextContextMenu.qml</file>
<file>qml/controls/TextFieldFrame.qml</file>
<file>qml/main.qml</file>
<file>qml/pages/ActivityPage.qml</file>
<file>qml/pages/AddressesPage.qml</file>

View File

@ -16,8 +16,10 @@ Frame {
TextArea {
id: textArea
clip: true // to clip placeholder text
persistentSelection: true
selectByMouse: true
onTextChanged: frame.textChanged()
onReleased: textContextMenu.show(event, textArea)
}
}
}

View File

@ -0,0 +1,51 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
Menu {
id: contextMenu
property Item textField
onClosed: {
textField = null;
}
function show(mouseEvent, field) {
if (mouseEvent.button !== Qt.RightButton)
return;
mouseEvent.accepted = true;
textField = field;
const pos = textField.mapToItem(null, mouseEvent.x, mouseEvent.y);
x = pos.x;
y = pos.y;
open();
}
MenuItem {
text: qsTranslate("qml", "Copy")
enabled: textField && textField.selectedText
onTriggered: textField.copy()
}
MenuItem {
text: qsTranslate("qml", "Cut")
enabled: textField && textField.selectedText
onTriggered: textField.cut()
}
MenuItem {
text: qsTranslate("qml", "Paste")
enabled: textField && textField.canPaste
onTriggered: textField.paste()
}
MenuSeparator {}
MenuItem {
text: qsTranslate("qml", "Clear")
enabled: textField && textField.text
onTriggered: textField.clear()
}
}

View File

@ -0,0 +1,8 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
TextField {
id: textField
persistentSelection: true
onReleased: textContextMenu.show(event, textField)
}

View File

@ -1,5 +1,6 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import "controls"
import "pages"
import com.fortfirewall 1.0
@ -40,6 +41,10 @@ ApplicationWindow {
id: osUtil
}
TextContextMenu {
id: textContextMenu
}
Loader {
anchors.fill: parent
sourceComponent: appWindow.visible ? mainPageComponent : undefined

View File

@ -1,6 +1,7 @@
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import "../controls"
import "apps"
import com.fortfirewall 1.0
@ -57,9 +58,9 @@ BasePage {
anchors.fill: parent
RowLayout {
TextField {
enabled: appGroupsCount < 16
TextFieldFrame {
id: editGroupName
enabled: appGroupsCount < 16
placeholderText: translationManager.dummyBool
&& qsTranslate("qml", "Group Name")
}