[SMS App] Select Message Text

Switched from QT Label to Text Edit as QA Label is not allowed to select text
https://stackoverflow.com/questions/49784099/qml-how-to-make-text-or-label-selectable
https://bugreports.qt.io/browse/QTBUG-14077

BUG: 418630 - Cannot select text in messaging app
This commit is contained in:
Ashvin Nihalani 2020-07-05 00:49:31 +00:00 committed by Simon Redman
parent aef817e786
commit c333f2af17
2 changed files with 41 additions and 12 deletions

1
.gitignore vendored
View file

@ -16,6 +16,7 @@ KDEConnect.includes
*.qmlc
*.rej
.vscode
.github/workflows/*
# Eclipse settings
.cproject

View file

@ -31,6 +31,7 @@ Item {
property string messageBody
property bool sentByMe
property string selectedText
property date dateTime
property string name
@ -71,6 +72,31 @@ Item {
}
radius: 6
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: mouse => {
if (mouse.button === Qt.RightButton) {
var selectStart = messageLabel.selectionStart;
var selectEnd = messageLabel.selectionEnd;
selectedText = messageLabel.selectedText;
contextMenu.x = mouse.x;
contextMenu.y = mouse.y;
messageLabel.persistentSelection = true;
contextMenu.open();
}
}
onPressAndHold: {
var selectStart = messageLabel.selectionStart;
var selectEnd = messageLabel.selectionEnd;
selectedText = messageLabel.selectedText;
contextMenu.x = mouse.x;
contextMenu.y = mouse.y;
messageLabel.persistentSelection = true;
contextMenu.open();
}
}
Column {
id: messageColumn
width: parent.width
@ -78,14 +104,17 @@ Item {
property int contentWidth: Math.max(messageLabel.implicitWidth, dateLabel.implicitWidth)
Label {
TextEdit {
id: messageLabel
selectByMouse: true
readOnly: true
leftPadding: Kirigami.Units.largeSpacing
rightPadding: Kirigami.Units.largeSpacing
topPadding: Kirigami.Units.largeSpacing
width: parent.width
horizontalAlignment: root.sentByMe ? Text.AlignRight : Text.AlignLeft
wrapMode: Text.Wrap
color: Kirigami.Theme.textColor
text: root.messageBody
}
@ -101,25 +130,24 @@ Item {
}
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: mouse => {
if (mouse.button === Qt.RightButton) {
contextMenu.popup()
}
}
onPressAndHold: contextMenu.popup()
}
Menu {
id: contextMenu
exit: Transition {PropertyAction { target: messageLabel; property: "persistentSelection"; value: false }}
MenuItem {
text: i18nd("kdeconnect-sms", "Copy Message")
enabled: messageLabel.visible
onTriggered: root.messageCopyRequested(root.messageBody)
}
MenuItem {
text: i18nd("kdeconnect-sms", "Copy Selection")
visible: selectedText != ""
onTriggered: {
root.messageCopyRequested(selectedText)
}
}
}
}
}