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. --- framework/qml/SelectableItem.qml | 133 +++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 53 deletions(-) (limited to 'framework/qml') 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