[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kube/develop] framework: SelectableLabel with same mechanism as SelectableItem.
From:       Christian Mollekopf <null () kde ! org>
Date:       2017-07-31 23:33:00
Message-ID: E1dcKBI-0006GT-Vi () code ! kde ! org
[Download RAW message or body]

Git commit 804466dba970174ed00289b1cde3d8862b111042 by Christian Mollekopf.
Committed on 31/07/2017 at 23:32.
Pushed by cmollekopf into branch 'develop'.

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).

C  +35   -13   framework/qml/ContextMenuOverlay.qml [from: \
framework/qml/SelectableLabel.qml - 054% similarity] M  +1    -1    \
framework/qml/MailViewer.qml M  +35   -70   framework/qml/SelectableItem.qml
M  +12   -16   framework/qml/SelectableLabel.qml
M  +1    -0    framework/qmldir

https://commits.kde.org/kube/804466dba970174ed00289b1cde3d8862b111042

diff --git a/framework/qml/SelectableLabel.qml b/framework/qml/ContextMenuOverlay.qml
similarity index 54%
copy from framework/qml/SelectableLabel.qml
copy to framework/qml/ContextMenuOverlay.qml
index 920f5c7..c85e2cb 100644
--- a/framework/qml/SelectableLabel.qml
+++ b/framework/qml/ContextMenuOverlay.qml
@@ -18,28 +18,50 @@
  */
 
 import QtQuick 2.7
-import QtQuick.Templates 2.0 as T
+import QtQuick.Controls 2.2
 import org.kube.framework 1.0 as Kube
+import QtQuick.Layouts 1.3
 
-Kube.Label {
-    id: root
+Item {
+    default property alias children: menuLayout.children
+    function close() {
+        menu.close()
+    }
+
+    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: {
+            menu.x = mouseX
+            menu.y = mouseY
+            menu.open()
+            mouse.accepted = true
+        }
     }
-    Kube.IconButton {
-        anchors {
-            left: parent.right
-            verticalCenter: parent.verticalCenter
+    Menu {
+        id: menu
+
+        height: menuLayout.height
+        width: menuLayout.width
+        background: Rectangle {
+            anchors.fill: parent
+            color: Kube.Colors.backgroundColor
         }
-        iconName: Kube.Icons.copy
-        visible: mouseArea.containsMouse || hovered
-        color: Kube.Colors.backgroundColor
-        onClicked: clipboard.text = root.text
-        Kube.Clipboard {
-            id: clipboard
+        RowLayout {
+            id: menuLayout
+            width: childrenRect.width
+            height: childrenRect.height
         }
     }
 }
+
diff --git a/framework/qml/MailViewer.qml b/framework/qml/MailViewer.qml
index 4c4e170..2bf7162 100644
--- a/framework/qml/MailViewer.qml
+++ b/framework/qml/MailViewer.qml
@@ -148,7 +148,7 @@ Rectangle {
                 }
             }
 
-            Kube.Label {
+            Kube.SelectableLabel {
                 id: subject
 
                 width: to.width
diff --git a/framework/qml/SelectableItem.qml b/framework/qml/SelectableItem.qml
index feb70d8..32d0f8b 100644
--- a/framework/qml/SelectableItem.qml
+++ b/framework/qml/SelectableItem.qml
@@ -24,86 +24,51 @@ import QtQuick.Layouts 1.3
 
 QtObject {
     id: root
-    property string text: null
+    property string text: ""
     property var layout: null
-    property var visualParent: layout.parent
+    property var visualParent: layout ? layout.parent : null
     onVisualParentChanged: {
         component.createObject(visualParent)
     }
 
-    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
-            }
+    /**
+     * 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]
 
-            Rectangle {
-                anchors.fill: parent
-                color: "transparent"
-                border.color: Kube.Colors.highlightColor
-                border.width: 1
-                visible: mouseArea.containsMouse || menu.visible
+            if (item && item.text) {
+                gatheredText += item.text;
             }
-            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
-                }
+            if (layout.columns && (((i + 1) % layout.columns) == 0)) {
+                gatheredText += "\n";
+            } else if (i != length - 1){
+                gatheredText += " ";
             }
-            Menu {
-                id: menu
+        }
+        // console.warn("Gathered text: ", gatheredText)
+        return gatheredText
+    }
 
-                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()
-                        }
+    property var comp: Component {
+        id: component
+        ContextMenuOverlay {
+            id: menu
+            anchors.fill: layout
+            Kube.TextButton {
+                id: button
+                text: qsTr("Copy")
+                onClicked: {
+                    if (root.text) {
+                        clipboard.text = root.text
+                    } else {
+                        clipboard.text = gatherText()
                     }
+                    menu.close()
                 }
                 Kube.Clipboard {
                     id: clipboard
diff --git a/framework/qml/SelectableLabel.qml b/framework/qml/SelectableLabel.qml
index 920f5c7..308bf3d 100644
--- a/framework/qml/SelectableLabel.qml
+++ b/framework/qml/SelectableLabel.qml
@@ -23,23 +23,19 @@ import org.kube.framework 1.0 as Kube
 
 Kube.Label {
     id: root
-    MouseArea {
-        id: mouseArea
+    Kube.ContextMenuOverlay {
+        id: menu
         anchors.fill: parent
-        hoverEnabled: true
-        z: 1
-    }
-    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
+        Kube.TextButton {
+            id: button
+            text: qsTr("Copy")
+            onClicked: {
+                clipboard.text = root.text
+                menu.close()
+            }
+            Kube.Clipboard {
+                id: clipboard
+            }
         }
     }
 }
diff --git a/framework/qmldir b/framework/qmldir
index fe96835..02a66bb 100644
--- a/framework/qmldir
+++ b/framework/qmldir
@@ -30,6 +30,7 @@ ToolTip 1.0 ToolTip.qml
 Label 1.0 Label.qml
 SelectableLabel 1.0 SelectableLabel.qml
 SelectableItem 1.0 SelectableItem.qml
+ContextMenuOverlay 1.0 ContextMenuOverlay.qml
 Heading 1.0 Heading.qml
 View 1.0 View.qml
 AutocompleteLineEdit 1.0 AutocompleteLineEdit.qml


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic