[ui] MessageDialog: add "Copy Message to Clipboard" button

Add a button to copy the textual content of a MessageDialog to the clipboard.
* use hidden TextEdit to perform the copy operation
* add function to modify this text in inherited components
* move icon to title
This commit is contained in:
Yann Lanthony 2018-07-25 16:47:08 +02:00
parent a4a40de8b8
commit 02dc58f144

View file

@ -1,3 +1,4 @@
import QtQuick 2.9
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import MaterialIcons 2.2 import MaterialIcons 2.2
@ -12,6 +13,16 @@ Dialog {
default property alias children: layout.children default property alias children: layout.children
// the content of this MessageDialog as a string
readonly property string asString: title + "\n\n" + text + "\n" + detailedText + "\n" + helperText + "\n"
/// Return the text content of this dialog as a simple string.
/// Used when copying the message in the system clipboard.
/// Can be overriden in components extending MessageDialog
function getAsString() {
return asString
}
x: parent.width/2 - width/2 x: parent.width/2 - width/2
y: parent.height/2 - height/2 y: parent.height/2 - height/2
modal: true modal: true
@ -19,38 +30,67 @@ Dialog {
padding: 15 padding: 15
standardButtons: Dialog.Ok standardButtons: Dialog.Ok
RowLayout { header: Pane {
spacing: 12 padding: 6
leftPadding: 8
rightPadding: leftPadding
// Icon background: Item {
Label { // hidden text edit to perform copy in clipboard
id: iconLabel TextEdit {
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop id: textContent
font.family: MaterialIcons.fontFamily visible: false
font.pointSize: 14 }
visible: text != ""
} }
ColumnLayout { RowLayout {
id: layout width: parent.width
// Text // Icon
spacing: 12
Label { Label {
id: textLabel id: iconLabel
font.family: MaterialIcons.fontFamily
font.pointSize: 14
visible: text != ""
}
Label {
Layout.fillWidth: true
text: title
font.bold: true font.bold: true
visible: text != ""
} }
// Detailed text ToolButton {
Label { font.family: MaterialIcons.fontFamily
id: detailedLabel text: MaterialIcons.content_copy
text: text ToolTip.text: "Copy Message to Clipboard"
visible: text != "" ToolTip.visible: hovered
} font.pointSize: 12
// Additional helper text onClicked: {
Label { textContent.text = getAsString()
id: helperLabel textContent.selectAll(); textContent.copy()
visible: text != "" }
} }
} }
} }
ColumnLayout {
id: layout
// Text
spacing: 12
Label {
id: textLabel
font.bold: true
visible: text != ""
}
// Detailed text
Label {
id: detailedLabel
text: text
visible: text != ""
}
// Additional helper text
Label {
id: helperLabel
visible: text != ""
}
}
} }