summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-31 16:29:01 -0600
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-31 17:32:54 -0600
commit36b2ee162ffd57c70d21c27ff25801f894886569 (patch)
tree2d91883719791960721c8c6734d8fb16a8e7b488
parent6bf396f79b926d6a1ea04226474550d9962d52a8 (diff)
downloadkube-36b2ee162ffd57c70d21c27ff25801f894886569.tar.gz
kube-36b2ee162ffd57c70d21c27ff25801f894886569.zip
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.
-rw-r--r--components/kube/contents/ui/LogView.qml20
-rw-r--r--framework/qml/SelectableItem.qml133
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 {
125 } 125 }
126 color: Kube.Colors.viewBackgroundColor 126 color: Kube.Colors.viewBackgroundColor
127 GridLayout { 127 GridLayout {
128 anchors.fill: parent 128 id: gridLayout
129 anchors {
130 top: parent.top
131 left: parent.left
132 }
129 columns: 2 133 columns: 2
130 Kube.Label { 134 Kube.Label {
131 text: qsTr("Account:") 135 text: qsTr("Account:")
132 visible: details.accountName 136 visible: details.accountName
133 } 137 }
134 Kube.SelectableLabel { 138 Kube.Label {
135 text: details.accountName 139 text: details.accountName
136 visible: details.accountName 140 visible: details.accountName
137 } 141 }
@@ -139,7 +143,7 @@ Controls.SplitView {
139 text: qsTr("Account Id:") 143 text: qsTr("Account Id:")
140 visible: details.accountId 144 visible: details.accountId
141 } 145 }
142 Kube.SelectableLabel { 146 Kube.Label {
143 text: details.accountId 147 text: details.accountId
144 visible: details.accountId 148 visible: details.accountId
145 } 149 }
@@ -147,20 +151,20 @@ Controls.SplitView {
147 text: qsTr("Resource Id:") 151 text: qsTr("Resource Id:")
148 visible: details.resourceId 152 visible: details.resourceId
149 } 153 }
150 Kube.SelectableLabel { 154 Kube.Label {
151 text: details.resourceId 155 text: details.resourceId
152 visible: details.resourceId 156 visible: details.resourceId
153 } 157 }
154 Kube.Label { 158 Kube.Label {
155 text: qsTr("Timestamp:") 159 text: qsTr("Timestamp:")
156 } 160 }
157 Kube.SelectableLabel { 161 Kube.Label {
158 text: Qt.formatDateTime(details.timestamp, " hh:mm:ss dd MMM yyyy") 162 text: Qt.formatDateTime(details.timestamp, " hh:mm:ss dd MMM yyyy")
159 } 163 }
160 Kube.Label { 164 Kube.Label {
161 text: qsTr("Message:") 165 text: qsTr("Message:")
162 } 166 }
163 Kube.SelectableLabel { 167 Kube.Label {
164 text: details.message 168 text: details.message
165 wrapMode: Text.Wrap 169 wrapMode: Text.Wrap
166 Layout.fillWidth: true 170 Layout.fillWidth: true
@@ -171,6 +175,10 @@ Controls.SplitView {
171 } 175 }
172 //TODO offer a possible explanation for known errors and a path to resolution. 176 //TODO offer a possible explanation for known errors and a path to resolution.
173 } 177 }
178
179 Kube.SelectableItem {
180 layout: gridLayout
181 }
174 } 182 }
175 } 183 }
176} 184}
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
22import org.kube.framework 1.0 as Kube 22import org.kube.framework 1.0 as Kube
23import QtQuick.Layouts 1.3 23import QtQuick.Layouts 1.3
24 24
25// QtObject { 25QtObject {
26Item {
27 id: root 26 id: root
28 property string text 27 property string text: null
29 Rectangle { 28 property var layout: null
30 anchors.fill: parent 29 property var visualParent: layout.parent
31 color: "transparent" 30 onVisualParentChanged: {
32 border.color: Kube.Colors.highlightColor 31 component.createObject(visualParent)
33 border.width: 1
34 visible: mouseArea.containsMouse || menu.visible
35 } 32 }
36 MouseArea {
37 id: mouseArea
38 anchors.fill: parent
39 hoverEnabled: true
40 acceptedButtons: Qt.RightButton
41 z: 1
42 onClicked: {
43 menu.x = mouseX
44 menu.y = mouseY
45 menu.open()
46 mouse.accepted = true
47 }
48 }
49 Menu {
50 id: menu
51 33
52 height: layout.height 34 property var comp: Component {
53 width: layout.width 35 id: component
54 background: Rectangle { 36 Item {
55 anchors.fill: parent 37 anchors.fill: layout
56 color: "transparent" 38
57 } 39 /**
58 RowLayout { 40 * This assumes a layout filled with labels.
59 id: layout 41 * We iterate over all elements, extract the text, insert a linebreak after every line and a space otherwise.
60 width: button.width 42 */
61 height: button.height 43 function gatherText() {
62 Kube.TextButton { 44 var gatheredText = "";
63 id: button 45 var length = layout.visibleChildren.length
64 text: "Copy" 46 for (var i = 0; i < length; i++) {
47 var item = layout.visibleChildren[i]
48
49 if (item && item.text) {
50 gatheredText += item.text;
51 }
52 if (layout.columns && (((i + 1) % layout.columns) == 0)) {
53 gatheredText += "\n";
54 } else if (i != length - 1){
55 gatheredText += " ";
56 }
57 }
58 // console.warn("Gathered text: ", gatheredText)
59 return gatheredText
60 }
61
62 Rectangle {
63 anchors.fill: parent
64 color: "transparent"
65 border.color: Kube.Colors.highlightColor
66 border.width: 1
67 visible: mouseArea.containsMouse || menu.visible
68 }
69 MouseArea {
70 id: mouseArea
71 anchors.fill: parent
72 hoverEnabled: true
73 acceptedButtons: Qt.RightButton
74 z: 1
65 onClicked: { 75 onClicked: {
66 if (root.text) { 76 menu.x = mouseX
67 clipboard.text = root.text 77 menu.y = mouseY
78 menu.open()
79 mouse.accepted = true
80 }
81 }
82 Menu {
83 id: menu
84
85 height: menuLayout.height
86 width: menuLayout.width
87 background: Rectangle {
88 anchors.fill: parent
89 color: Kube.Colors.backgroundColor
90 }
91 RowLayout {
92 id: menuLayout
93 width: button.width
94 height: button.height
95 Kube.TextButton {
96 id: button
97 text: "Copy"
98 onClicked: {
99 if (root.text) {
100 clipboard.text = root.text
101 } else {
102 clipboard.text = gatherText()
103 }
104 menu.close()
105 }
68 } 106 }
69 menu.close() 107 }
108 Kube.Clipboard {
109 id: clipboard
70 } 110 }
71 } 111 }
72 } 112 }
73 } 113 }
74 // Kube.IconButton {
75 // anchors {
76 // left: parent.right
77 // verticalCenter: parent.verticalCenter
78 // }
79 // iconName: Kube.Icons.copy
80 // visible: mouseArea.containsMouse || hovered
81 // color: Kube.Colors.backgroundColor
82 // onClicked: clipboard.text = root.text
83 // }
84 Kube.Clipboard {
85 id: clipboard
86 }
87} 114}