plasmoid: Add context menu to copy value
This commit is contained in:
parent
312ebd26d2
commit
20eae7fb2c
|
@ -23,7 +23,9 @@
|
|||
|
||||
#include <KConfigGroup>
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
#include <QGuiApplication>
|
||||
#include <QNetworkReply>
|
||||
#include <QQmlEngine>
|
||||
#include <QStringBuilder>
|
||||
|
@ -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().
|
||||
|
|
|
@ -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 ..."
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue