diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-31 16:29:01 -0600 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-31 17:32:54 -0600 |
commit | 36b2ee162ffd57c70d21c27ff25801f894886569 (patch) | |
tree | 2d91883719791960721c8c6734d8fb16a8e7b488 /framework/qml/SelectableItem.qml | |
parent | 6bf396f79b926d6a1ea04226474550d9962d52a8 (diff) | |
download | kube-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.
Diffstat (limited to 'framework/qml/SelectableItem.qml')
-rw-r--r-- | framework/qml/SelectableItem.qml | 133 |
1 files changed, 80 insertions, 53 deletions
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 | |||
22 | import org.kube.framework 1.0 as Kube | 22 | import org.kube.framework 1.0 as Kube |
23 | import QtQuick.Layouts 1.3 | 23 | import QtQuick.Layouts 1.3 |
24 | 24 | ||
25 | // QtObject { | 25 | QtObject { |
26 | Item { | ||
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 | } |