[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:
parent
aef817e786
commit
c333f2af17
2 changed files with 41 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -16,6 +16,7 @@ KDEConnect.includes
|
||||||
*.qmlc
|
*.qmlc
|
||||||
*.rej
|
*.rej
|
||||||
.vscode
|
.vscode
|
||||||
|
.github/workflows/*
|
||||||
|
|
||||||
# Eclipse settings
|
# Eclipse settings
|
||||||
.cproject
|
.cproject
|
||||||
|
|
|
@ -31,6 +31,7 @@ Item {
|
||||||
|
|
||||||
property string messageBody
|
property string messageBody
|
||||||
property bool sentByMe
|
property bool sentByMe
|
||||||
|
property string selectedText
|
||||||
property date dateTime
|
property date dateTime
|
||||||
property string name
|
property string name
|
||||||
|
|
||||||
|
@ -71,6 +72,31 @@ Item {
|
||||||
}
|
}
|
||||||
radius: 6
|
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 {
|
Column {
|
||||||
id: messageColumn
|
id: messageColumn
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
@ -78,14 +104,17 @@ Item {
|
||||||
|
|
||||||
property int contentWidth: Math.max(messageLabel.implicitWidth, dateLabel.implicitWidth)
|
property int contentWidth: Math.max(messageLabel.implicitWidth, dateLabel.implicitWidth)
|
||||||
|
|
||||||
Label {
|
TextEdit {
|
||||||
id: messageLabel
|
id: messageLabel
|
||||||
|
selectByMouse: true
|
||||||
|
readOnly: true
|
||||||
leftPadding: Kirigami.Units.largeSpacing
|
leftPadding: Kirigami.Units.largeSpacing
|
||||||
rightPadding: Kirigami.Units.largeSpacing
|
rightPadding: Kirigami.Units.largeSpacing
|
||||||
topPadding: Kirigami.Units.largeSpacing
|
topPadding: Kirigami.Units.largeSpacing
|
||||||
width: parent.width
|
width: parent.width
|
||||||
horizontalAlignment: root.sentByMe ? Text.AlignRight : Text.AlignLeft
|
horizontalAlignment: root.sentByMe ? Text.AlignRight : Text.AlignLeft
|
||||||
wrapMode: Text.Wrap
|
wrapMode: Text.Wrap
|
||||||
|
color: Kirigami.Theme.textColor
|
||||||
text: root.messageBody
|
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 {
|
Menu {
|
||||||
id: contextMenu
|
id: contextMenu
|
||||||
|
exit: Transition {PropertyAction { target: messageLabel; property: "persistentSelection"; value: false }}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: i18nd("kdeconnect-sms", "Copy Message")
|
text: i18nd("kdeconnect-sms", "Copy Message")
|
||||||
enabled: messageLabel.visible
|
enabled: messageLabel.visible
|
||||||
onTriggered: root.messageCopyRequested(root.messageBody)
|
onTriggered: root.messageCopyRequested(root.messageBody)
|
||||||
}
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: i18nd("kdeconnect-sms", "Copy Selection")
|
||||||
|
visible: selectedText != ""
|
||||||
|
onTriggered: {
|
||||||
|
root.messageCopyRequested(selectedText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue