Git commit 36b2ee162ffd57c70d21c27ff25801f894886569 by Christian Mollekopf. Committed on 31/07/2017 at 23:32. Pushed by cmollekopf into branch 'develop'. 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. M +14 -6 components/kube/contents/ui/LogView.qml M +80 -53 framework/qml/SelectableItem.qml https://commits.kde.org/kube/36b2ee162ffd57c70d21c27ff25801f894886569 diff --git a/components/kube/contents/ui/LogView.qml b/components/kube/cont= ents/ui/LogView.qml index 299c8e6..e085e44 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/SelectableIte= m.qml index 0e22ede..feb70d8 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 =3D mouseX - menu.y =3D mouseY - menu.open() - mouse.accepted =3D 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 li= nebreak after every line and a space otherwise. + */ + function gatherText() { + var gatheredText =3D ""; + var length =3D layout.visibleChildren.length + for (var i =3D 0; i < length; i++) { + var item =3D layout.visibleChildren[i] + + if (item && item.text) { + gatheredText +=3D item.text; + } + if (layout.columns && (((i + 1) % layout.columns) =3D= =3D 0)) { + gatheredText +=3D "\n"; + } else if (i !=3D length - 1){ + gatheredText +=3D " "; + } + } + // 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 =3D root.text + menu.x =3D mouseX + menu.y =3D mouseY + menu.open() + mouse.accepted =3D 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 =3D root.text + } else { + clipboard.text =3D 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 =3D root.text - // } - Kube.Clipboard { - id: clipboard - } }