Commit c333f2af authored by Ashvin Nihalani's avatar Ashvin Nihalani Committed by Simon Redman
Browse files

[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
parent aef817e7
Pipeline #25909 passed with stage
in 5 minutes and 37 seconds
......@@ -16,6 +16,7 @@ KDEConnect.includes
*.qmlc
*.rej
.vscode
.github/workflows/*
# Eclipse settings
.cproject
......
......@@ -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)
}
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment