summaryrefslogtreecommitdiffstats
path: root/framework/qml/SelectableItem.qml
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-31 17:30:41 -0600
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-31 17:32:54 -0600
commit804466dba970174ed00289b1cde3d8862b111042 (patch)
treeca93f039c5235ff7660e01ddf3954d3351c2ee1b /framework/qml/SelectableItem.qml
parent36b2ee162ffd57c70d21c27ff25801f894886569 (diff)
downloadkube-804466dba970174ed00289b1cde3d8862b111042.tar.gz
kube-804466dba970174ed00289b1cde3d8862b111042.zip
SelectableLabel with same mechanism as SelectableItem.
Note that we can not easily integrate it with Label due to recursive use of Kube.Label via the Button component. (Would be doable via dynamic loading, but that stuff is a PITA to do).
Diffstat (limited to 'framework/qml/SelectableItem.qml')
-rw-r--r--framework/qml/SelectableItem.qml105
1 files changed, 35 insertions, 70 deletions
diff --git a/framework/qml/SelectableItem.qml b/framework/qml/SelectableItem.qml
index feb70d8b..32d0f8b1 100644
--- a/framework/qml/SelectableItem.qml
+++ b/framework/qml/SelectableItem.qml
@@ -24,86 +24,51 @@ import QtQuick.Layouts 1.3
24 24
25QtObject { 25QtObject {
26 id: root 26 id: root
27 property string text: null 27 property string text: ""
28 property var layout: null 28 property var layout: null
29 property var visualParent: layout.parent 29 property var visualParent: layout ? layout.parent : null
30 onVisualParentChanged: { 30 onVisualParentChanged: {
31 component.createObject(visualParent) 31 component.createObject(visualParent)
32 } 32 }
33 33
34 property var comp: Component { 34 /**
35 id: component 35 * This assumes a layout filled with labels.
36 Item { 36 * We iterate over all elements, extract the text, insert a linebreak after every line and a space otherwise.
37 anchors.fill: layout 37 */
38 38 function gatherText() {
39 /** 39 var gatheredText = "";
40 * This assumes a layout filled with labels. 40 var length = layout.visibleChildren.length
41 * We iterate over all elements, extract the text, insert a linebreak after every line and a space otherwise. 41 for (var i = 0; i < length; i++) {
42 */ 42 var item = layout.visibleChildren[i]
43 function gatherText() {
44 var gatheredText = "";
45 var length = layout.visibleChildren.length
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 43
62 Rectangle { 44 if (item && item.text) {
63 anchors.fill: parent 45 gatheredText += item.text;
64 color: "transparent"
65 border.color: Kube.Colors.highlightColor
66 border.width: 1
67 visible: mouseArea.containsMouse || menu.visible
68 } 46 }
69 MouseArea { 47 if (layout.columns && (((i + 1) % layout.columns) == 0)) {
70 id: mouseArea 48 gatheredText += "\n";
71 anchors.fill: parent 49 } else if (i != length - 1){
72 hoverEnabled: true 50 gatheredText += " ";
73 acceptedButtons: Qt.RightButton
74 z: 1
75 onClicked: {
76 menu.x = mouseX
77 menu.y = mouseY
78 menu.open()
79 mouse.accepted = true
80 }
81 } 51 }
82 Menu { 52 }
83 id: menu 53 // console.warn("Gathered text: ", gatheredText)
54 return gatheredText
55 }
84 56
85 height: menuLayout.height 57 property var comp: Component {
86 width: menuLayout.width 58 id: component
87 background: Rectangle { 59 ContextMenuOverlay {
88 anchors.fill: parent 60 id: menu
89 color: Kube.Colors.backgroundColor 61 anchors.fill: layout
90 } 62 Kube.TextButton {
91 RowLayout { 63 id: button
92 id: menuLayout 64 text: qsTr("Copy")
93 width: button.width 65 onClicked: {
94 height: button.height 66 if (root.text) {
95 Kube.TextButton { 67 clipboard.text = root.text
96 id: button 68 } else {
97 text: "Copy" 69 clipboard.text = gatherText()
98 onClicked: {
99 if (root.text) {
100 clipboard.text = root.text
101 } else {
102 clipboard.text = gatherText()
103 }
104 menu.close()
105 }
106 } 70 }
71 menu.close()
107 } 72 }
108 Kube.Clipboard { 73 Kube.Clipboard {
109 id: clipboard 74 id: clipboard