From kde-commits Mon Jul 31 23:33:00 2017 From: Christian Mollekopf Date: Mon, 31 Jul 2017 23:33:00 +0000 To: kde-commits Subject: [kube/develop] framework: SelectableLabel with same mechanism as SelectableItem. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=150154399522568 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/Se= lectableLabel.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/ContextMenuO= verlay.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 =3D mouseX + menu.y =3D mouseY + menu.open() + mouse.accepted =3D 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 =3D 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/SelectableIte= m.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 li= nebreak after every line and a space otherwise. - */ - function gatherText() { - var gatheredText =3D ""; - var length =3D layout.visibleChildren.length - for (var i =3D 0; i < length; i++) { - var item =3D layout.visibleChildren[i] - - if (item && item.text) { - gatheredText +=3D item.text; - } - if (layout.columns && (((i + 1) % layout.columns) =3D= =3D 0)) { - gatheredText +=3D "\n"; - } else if (i !=3D length - 1){ - gatheredText +=3D " "; - } - } - // 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 =3D ""; + var length =3D layout.visibleChildren.length + for (var i =3D 0; i < length; i++) { + var item =3D 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 +=3D item.text; } - MouseArea { - id: mouseArea - anchors.fill: parent - hoverEnabled: true - acceptedButtons: Qt.RightButton - z: 1 - onClicked: { - menu.x =3D mouseX - menu.y =3D mouseY - menu.open() - mouse.accepted =3D true - } + if (layout.columns && (((i + 1) % layout.columns) =3D=3D 0)) { + gatheredText +=3D "\n"; + } else if (i !=3D length - 1){ + gatheredText +=3D " "; } - 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 =3D root.text - } else { - clipboard.text =3D 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 =3D root.text + } else { + clipboard.text =3D gatherText() } + menu.close() } Kube.Clipboard { id: clipboard diff --git a/framework/qml/SelectableLabel.qml b/framework/qml/SelectableLa= bel.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 =3D root.text - Kube.Clipboard { - id: clipboard + Kube.TextButton { + id: button + text: qsTr("Copy") + onClicked: { + clipboard.text =3D 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