[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kube/develop] /: Use a regular Label with a SelectableItem in the logview
From: Christian Mollekopf <null () kde ! org>
Date: 2017-07-31 23:33:00
Message-ID: E1dcKBI-0006GT-Ub () code ! kde ! org
[Download RAW message or body]
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/contents/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/SelectableItem.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 = 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
- }
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic