summaryrefslogtreecommitdiffstats
path: root/framework/qml
diff options
context:
space:
mode:
Diffstat (limited to 'framework/qml')
-rw-r--r--framework/qml/ContextMenuOverlay.qml67
-rw-r--r--framework/qml/MailViewer.qml2
-rw-r--r--framework/qml/SelectableItem.qml105
-rw-r--r--framework/qml/SelectableLabel.qml28
4 files changed, 115 insertions, 87 deletions
diff --git a/framework/qml/ContextMenuOverlay.qml b/framework/qml/ContextMenuOverlay.qml
new file mode 100644
index 00000000..c85e2cb2
--- /dev/null
+++ b/framework/qml/ContextMenuOverlay.qml
@@ -0,0 +1,67 @@
1/*
2 * Copyright (C) 2017 Michael Bohlender, <bohlender@kolabsys.com>
3 * Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsys.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick 2.7
21import QtQuick.Controls 2.2
22import org.kube.framework 1.0 as Kube
23import QtQuick.Layouts 1.3
24
25Item {
26 default property alias children: menuLayout.children
27 function close() {
28 menu.close()
29 }
30
31 Rectangle {
32 anchors.fill: parent
33 color: "transparent"
34 border.color: Kube.Colors.highlightColor
35 border.width: 1
36 visible: mouseArea.containsMouse || menu.visible
37 }
38 MouseArea {
39 id: mouseArea
40 anchors.fill: parent
41 hoverEnabled: true
42 acceptedButtons: Qt.RightButton
43 z: 1
44 onClicked: {
45 menu.x = mouseX
46 menu.y = mouseY
47 menu.open()
48 mouse.accepted = true
49 }
50 }
51 Menu {
52 id: menu
53
54 height: menuLayout.height
55 width: menuLayout.width
56 background: Rectangle {
57 anchors.fill: parent
58 color: Kube.Colors.backgroundColor
59 }
60 RowLayout {
61 id: menuLayout
62 width: childrenRect.width
63 height: childrenRect.height
64 }
65 }
66}
67
diff --git a/framework/qml/MailViewer.qml b/framework/qml/MailViewer.qml
index 4c4e1702..2bf71622 100644
--- a/framework/qml/MailViewer.qml
+++ b/framework/qml/MailViewer.qml
@@ -148,7 +148,7 @@ Rectangle {
148 } 148 }
149 } 149 }
150 150
151 Kube.Label { 151 Kube.SelectableLabel {
152 id: subject 152 id: subject
153 153
154 width: to.width 154 width: to.width
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
diff --git a/framework/qml/SelectableLabel.qml b/framework/qml/SelectableLabel.qml
index 920f5c7a..308bf3d6 100644
--- a/framework/qml/SelectableLabel.qml
+++ b/framework/qml/SelectableLabel.qml
@@ -23,23 +23,19 @@ import org.kube.framework 1.0 as Kube
23 23
24Kube.Label { 24Kube.Label {
25 id: root 25 id: root
26 MouseArea { 26 Kube.ContextMenuOverlay {
27 id: mouseArea 27 id: menu
28 anchors.fill: parent 28 anchors.fill: parent
29 hoverEnabled: true 29 Kube.TextButton {
30 z: 1 30 id: button
31 } 31 text: qsTr("Copy")
32 Kube.IconButton { 32 onClicked: {
33 anchors { 33 clipboard.text = root.text
34 left: parent.right 34 menu.close()
35 verticalCenter: parent.verticalCenter 35 }
36 } 36 Kube.Clipboard {
37 iconName: Kube.Icons.copy 37 id: clipboard
38 visible: mouseArea.containsMouse || hovered 38 }
39 color: Kube.Colors.backgroundColor
40 onClicked: clipboard.text = root.text
41 Kube.Clipboard {
42 id: clipboard
43 } 39 }
44 } 40 }
45} 41}