From 36b2ee162ffd57c70d21c27ff25801f894886569 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 31 Jul 2017 16:29:01 -0600 Subject: Use a regular Label with a SelectableItem in the logview This allows to copy all labels within the layout. Maybe a bit too magic atm. --- components/kube/contents/ui/LogView.qml | 20 +++-- framework/qml/SelectableItem.qml | 133 +++++++++++++++++++------------- 2 files changed, 94 insertions(+), 59 deletions(-) diff --git a/components/kube/contents/ui/LogView.qml b/components/kube/contents/ui/LogView.qml index 299c8e67..e085e449 100644 --- a/components/kube/contents/ui/LogView.qml +++ b/components/kube/contents/ui/LogView.qml @@ -125,13 +125,17 @@ Controls.SplitView { } color: Kube.Colors.viewBackgroundColor GridLayout { - anchors.fill: parent + id: gridLayout + anchors { + top: parent.top + left: parent.left + } columns: 2 Kube.Label { text: qsTr("Account:") visible: details.accountName } - Kube.SelectableLabel { + Kube.Label { text: details.accountName visible: details.accountName } @@ -139,7 +143,7 @@ Controls.SplitView { text: qsTr("Account Id:") visible: details.accountId } - Kube.SelectableLabel { + Kube.Label { text: details.accountId visible: details.accountId } @@ -147,20 +151,20 @@ Controls.SplitView { text: qsTr("Resource Id:") visible: details.resourceId } - Kube.SelectableLabel { + Kube.Label { text: details.resourceId visible: details.resourceId } Kube.Label { text: qsTr("Timestamp:") } - Kube.SelectableLabel { + Kube.Label { text: Qt.formatDateTime(details.timestamp, " hh:mm:ss dd MMM yyyy") } Kube.Label { text: qsTr("Message:") } - Kube.SelectableLabel { + Kube.Label { text: details.message wrapMode: Text.Wrap Layout.fillWidth: true @@ -171,6 +175,10 @@ Controls.SplitView { } //TODO offer a possible explanation for known errors and a path to resolution. } + + Kube.SelectableItem { + layout: gridLayout + } } } } diff --git a/framework/qml/SelectableItem.qml b/framework/qml/SelectableItem.qml index 0e22ede5..feb70d8b 100644 --- a/framework/qml/SelectableItem.qml +++ b/framework/qml/SelectableItem.qml @@ -22,66 +22,93 @@ import QtQuick.Controls 2.2 import org.kube.framework 1.0 as Kube import QtQuick.Layouts 1.3 -// QtObject { -Item { +QtObject { id: root - property string text - Rectangle { - anchors.fill: parent - color: "transparent" - border.color: Kube.Colors.highlightColor - border.width: 1 - visible: mouseArea.containsMouse || menu.visible + property string text: null + property var layout: null + property var visualParent: layout.parent + onVisualParentChanged: { + component.createObject(visualParent) } - MouseArea { - id: mouseArea - anchors.fill: parent - hoverEnabled: true - acceptedButtons: Qt.RightButton - z: 1 - onClicked: { - menu.x = mouseX - menu.y = mouseY - menu.open() - mouse.accepted = true - } - } - Menu { - id: menu - height: layout.height - width: layout.width - background: Rectangle { - anchors.fill: parent - color: "transparent" - } - RowLayout { - id: layout - width: button.width - height: button.height - Kube.TextButton { - id: button - text: "Copy" + property var comp: Component { + id: component + Item { + anchors.fill: layout + + /** + * This assumes a layout filled with labels. + * We iterate over all elements, extract the text, insert a linebreak after every line and a space otherwise. + */ + function gatherText() { + var gatheredText = ""; + var length = layout.visibleChildren.length + for (var i = 0; i < length; i++) { + var item = layout.visibleChildren[i] + + if (item && item.text) { + gatheredText += item.text; + } + if (layout.columns && (((i + 1) % layout.columns) == 0)) { + gatheredText += "\n"; + } else if (i != length - 1){ + gatheredText += " "; + } + } + // console.warn("Gathered text: ", gatheredText) + return gatheredText + } + + Rectangle { + anchors.fill: parent + color: "transparent" + border.color: Kube.Colors.highlightColor + border.width: 1 + visible: mouseArea.containsMouse || menu.visible + } + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + acceptedButtons: Qt.RightButton + z: 1 onClicked: { - if (root.text) { - clipboard.text = root.text + menu.x = mouseX + menu.y = mouseY + menu.open() + mouse.accepted = true + } + } + Menu { + id: menu + + height: menuLayout.height + width: menuLayout.width + background: Rectangle { + anchors.fill: parent + color: Kube.Colors.backgroundColor + } + RowLayout { + id: menuLayout + width: button.width + height: button.height + Kube.TextButton { + id: button + text: "Copy" + onClicked: { + if (root.text) { + clipboard.text = root.text + } else { + clipboard.text = gatherText() + } + menu.close() + } } - menu.close() + } + Kube.Clipboard { + id: clipboard } } } } - // Kube.IconButton { - // anchors { - // left: parent.right - // verticalCenter: parent.verticalCenter - // } - // iconName: Kube.Icons.copy - // visible: mouseArea.containsMouse || hovered - // color: Kube.Colors.backgroundColor - // onClicked: clipboard.text = root.text - // } - Kube.Clipboard { - id: clipboard - } } -- cgit v1.2.3