From c092d555bd6d3e93a11625bfe76bb59b2e64e994 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 29 Jul 2017 16:42:52 -0600 Subject: SelectableLabel to support copying individual labels --- components/kube/contents/ui/LogView.qml | 10 +++---- framework/qml/Icons.qml | 1 + framework/qml/SelectableLabel.qml | 45 ++++++++++++++++++++++++++++ framework/qmldir | 1 + framework/src/CMakeLists.txt | 1 + framework/src/clipboardproxy.cpp | 52 +++++++++++++++++++++++++++++++++ framework/src/clipboardproxy.h | 39 +++++++++++++++++++++++++ framework/src/frameworkplugin.cpp | 2 ++ icons/copybreeze.sh | 3 +- 9 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 framework/qml/SelectableLabel.qml create mode 100644 framework/src/clipboardproxy.cpp create mode 100644 framework/src/clipboardproxy.h diff --git a/components/kube/contents/ui/LogView.qml b/components/kube/contents/ui/LogView.qml index f655b977..299c8e67 100644 --- a/components/kube/contents/ui/LogView.qml +++ b/components/kube/contents/ui/LogView.qml @@ -131,7 +131,7 @@ Controls.SplitView { text: qsTr("Account:") visible: details.accountName } - Kube.Label { + Kube.SelectableLabel { text: details.accountName visible: details.accountName } @@ -139,7 +139,7 @@ Controls.SplitView { text: qsTr("Account Id:") visible: details.accountId } - Kube.Label { + Kube.SelectableLabel { text: details.accountId visible: details.accountId } @@ -147,20 +147,20 @@ Controls.SplitView { text: qsTr("Resource Id:") visible: details.resourceId } - Kube.Label { + Kube.SelectableLabel { text: details.resourceId visible: details.resourceId } Kube.Label { text: qsTr("Timestamp:") } - Kube.Label { + Kube.SelectableLabel { text: Qt.formatDateTime(details.timestamp, " hh:mm:ss dd MMM yyyy") } Kube.Label { text: qsTr("Message:") } - Kube.Label { + Kube.SelectableLabel { text: details.message wrapMode: Text.Wrap Layout.fillWidth: true diff --git a/framework/qml/Icons.qml b/framework/qml/Icons.qml index 3126c797..d9612013 100644 --- a/framework/qml/Icons.qml +++ b/framework/qml/Icons.qml @@ -42,6 +42,7 @@ Item { property string replyToSender: "mail-reply-sender" property string outbox: "mail-folder-outbox" property string outbox_inverted: "mail-folder-outbox-inverted" + property string copy: "edit-copy" property string menu_inverted: "application-menu-inverted" property string user: "im-user" diff --git a/framework/qml/SelectableLabel.qml b/framework/qml/SelectableLabel.qml new file mode 100644 index 00000000..920f5c7a --- /dev/null +++ b/framework/qml/SelectableLabel.qml @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2017 Michael Bohlender, + * Copyright (C) 2017 Christian Mollekopf, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Templates 2.0 as T +import org.kube.framework 1.0 as Kube + +Kube.Label { + id: root + MouseArea { + id: mouseArea + 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 + } + } +} diff --git a/framework/qmldir b/framework/qmldir index c8e0ae58..d4ec9619 100644 --- a/framework/qmldir +++ b/framework/qmldir @@ -27,6 +27,7 @@ TextArea 1.0 TextArea.qml TextEditor 1.0 TextEditor.qml ToolTip 1.0 ToolTip.qml Label 1.0 Label.qml +SelectableLabel 1.0 SelectableLabel.qml Heading 1.0 Heading.qml View 1.0 View.qml AutocompleteLineEdit 1.0 AutocompleteLineEdit.qml diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 034feba9..85ad8344 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt @@ -40,6 +40,7 @@ set(SRCS fabric.cpp sinkfabric.cpp kubeimage.cpp + clipboardproxy.cpp ) add_library(frameworkplugin SHARED ${SRCS}) diff --git a/framework/src/clipboardproxy.cpp b/framework/src/clipboardproxy.cpp new file mode 100644 index 00000000..aaa5052b --- /dev/null +++ b/framework/src/clipboardproxy.cpp @@ -0,0 +1,52 @@ +/* + Copyright (c) 2016 Christian Mollekofp + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#include "clipboardproxy.h" + +#include +#include + +ClipboardProxy::ClipboardProxy(QObject *parent) + : QObject(parent) +{ + QClipboard *clipboard = QApplication::clipboard(); + QObject::connect(clipboard, &QClipboard::dataChanged, + this, &ClipboardProxy::dataChanged); + QObject::connect(clipboard, &QClipboard::selectionChanged, + this, &ClipboardProxy::selectionChanged); +} + +void ClipboardProxy::setDataText(const QString &text) +{ + QApplication::clipboard()->setText(text, QClipboard::Clipboard); +} + +QString ClipboardProxy::dataText() const +{ + return QGuiApplication::clipboard()->text(QClipboard::Clipboard); +} + +void ClipboardProxy::setSelectionText(const QString &text) +{ + QApplication::clipboard()->setText(text, QClipboard::Selection); +} + +QString ClipboardProxy::selectionText() const +{ + return QApplication::clipboard()->text(QClipboard::Selection); +} diff --git a/framework/src/clipboardproxy.h b/framework/src/clipboardproxy.h new file mode 100644 index 00000000..9a965004 --- /dev/null +++ b/framework/src/clipboardproxy.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2016 Christian Mollekofp + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#pragma once + +#include +class ClipboardProxy : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString text READ dataText WRITE setDataText NOTIFY dataChanged) + Q_PROPERTY(QString selectionText READ selectionText WRITE setSelectionText NOTIFY selectionChanged) +public: + explicit ClipboardProxy(QObject *parent = 0); + + void setDataText(const QString &text); + QString dataText() const; + + void setSelectionText(const QString &text); + QString selectionText() const; + +signals: + void dataChanged(); + void selectionChanged(); +}; diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 9c79f515..33bc8cbc 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp @@ -34,6 +34,7 @@ #include "settings/settings.h" #include "fabric.h" #include "kubeimage.h" +#include "clipboardproxy.h" #include @@ -65,4 +66,5 @@ void FrameworkPlugin::registerTypes (const char *uri) qmlRegisterSingletonType(uri, 1, 0, "Fabric", fabric_singletontype_provider); qmlRegisterType(uri, 1, 0, "KubeImage"); + qmlRegisterType(uri, 1, 0, "Clipboard"); } diff --git a/icons/copybreeze.sh b/icons/copybreeze.sh index da2f1df7..6a245178 100755 --- a/icons/copybreeze.sh +++ b/icons/copybreeze.sh @@ -32,7 +32,8 @@ wantedIcons = [ "mail-message.svg", "list-add.svg", "list-remove.svg", - "checkbox.svg" + "checkbox.svg", + "edit-copy.svg" ] def ensure_dir(file_path): -- cgit v1.2.3