diff --git a/plasmoid/lib/syncthingapplet.cpp b/plasmoid/lib/syncthingapplet.cpp index bb9f350..c36e09e 100644 --- a/plasmoid/lib/syncthingapplet.cpp +++ b/plasmoid/lib/syncthingapplet.cpp @@ -23,7 +23,9 @@ #include +#include #include +#include #include #include #include @@ -271,6 +273,11 @@ void SyncthingApplet::showDirectoryErrors(unsigned int directoryIndex) const } } +void SyncthingApplet::copyToClipboard(const QString &text) +{ + QGuiApplication::clipboard()->setText(text); +} + /*! * \brief Ensures settings take effect when applied via the settings dialog. * \remarks Does not save the settings to disk. This is done in Settings::save() and Applet::configChanged(). diff --git a/plasmoid/lib/syncthingapplet.h b/plasmoid/lib/syncthingapplet.h index eabbb67..93f52d0 100644 --- a/plasmoid/lib/syncthingapplet.h +++ b/plasmoid/lib/syncthingapplet.h @@ -94,6 +94,7 @@ public Q_SLOTS: void dismissNotifications(); void showInternalErrorsDialog(); void showDirectoryErrors(unsigned int directoryIndex) const; + void copyToClipboard(const QString &text); Q_SIGNALS: /// \remarks Never emitted, just to silence "... depends on non-NOTIFYable ..." diff --git a/plasmoid/package/contents/ui/DetailItem.qml b/plasmoid/package/contents/ui/DetailItem.qml index c98add2..08ee99e 100644 --- a/plasmoid/package/contents/ui/DetailItem.qml +++ b/plasmoid/package/contents/ui/DetailItem.qml @@ -3,17 +3,30 @@ import QtQuick.Layouts 1.1 import org.kde.plasma.components 2.0 as PlasmaComponents RowLayout { + id: detailItem + property string detailName: name ? name : "" + property string detailValue: detail ? detail : "" + PlasmaComponents.Label { Layout.preferredWidth: 100 Layout.leftMargin: units.iconSizes.smallMedium - text: name + text: detailName font.pointSize: theme.defaultFont.pointSize * 0.8 elide: Text.ElideRight } PlasmaComponents.Label { Layout.fillWidth: true - text: detail + text: detailValue font.pointSize: theme.defaultFont.pointSize * 0.8 elide: Text.ElideRight } + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.RightButton + onClicked: { + var view = detailItem.ListView.view + var coordinates = mapToItem(view, mouseX, mouseY) + view.showContextMenu(detailItem, coordinates.x, coordinates.y) + } + } } diff --git a/plasmoid/package/contents/ui/DetailView.qml b/plasmoid/package/contents/ui/DetailView.qml index 87803d9..8b6595a 100644 --- a/plasmoid/package/contents/ui/DetailView.qml +++ b/plasmoid/package/contents/ui/DetailView.qml @@ -1,7 +1,29 @@ import QtQuick 2.7 +import org.kde.plasma.components 2.0 as PlasmaComponents ListView { + id: detailView + property DetailItem contextMenuItem: null currentIndex: -1 interactive: false height: contentHeight + + PlasmaComponents.Menu { + id: contextMenu + PlasmaComponents.MenuItem { + text: qsTr('Copy value') + icon: "edit-copy" + onClicked: { + var item = detailView.contextMenuItem + if (item) { + plasmoid.nativeInterface.copyToClipboard(item.detailValue) + } + } + } + } + + function showContextMenu(item, x, y) { + contextMenuItem = item + contextMenu.open(x, y) + } }