diff --git a/src/tools/pin/pinwidget.cpp b/src/tools/pin/pinwidget.cpp index ca0efeed6e..807e4bb45c 100644 --- a/src/tools/pin/pinwidget.cpp +++ b/src/tools/pin/pinwidget.cpp @@ -6,10 +6,12 @@ #include "pinwidget.h" #include "qguiappcurrentscreen.h" +#include "screenshotsaver.h" #include "src/utils/confighandler.h" #include "src/utils/globalvalues.h" #include +#include #include #include #include @@ -83,6 +85,13 @@ PinWidget::PinWidget(const QPixmap& pixmap, } #endif grabGesture(Qt::PinchGesture); + + this->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, + SIGNAL(customContextMenuRequested(const QPoint&)), + this, + SLOT(showContextMenu(const QPoint&))); } bool PinWidget::scrollEvent(QWheelEvent* event) @@ -209,3 +218,30 @@ void PinWidget::pinchTriggered(QPinchGesture* gesture) m_sizeChanged = true; update(); } + +void PinWidget::showContextMenu(const QPoint& pos) +{ + QMenu contextMenu(tr("Context menu"), this); + + QAction copy2ClipboardAction("Copy to clipboard", this); + connect(©2ClipboardAction, + SIGNAL(triggered()), + this, + SLOT(copyToClipboard())); + contextMenu.addAction(©2ClipboardAction); + + QAction saveToFileAction("Save to file", this); + connect(&saveToFileAction, SIGNAL(triggered()), this, SLOT(saveToFile())); + contextMenu.addAction(&saveToFileAction); + + contextMenu.exec(mapToGlobal(pos)); +} + +void PinWidget::copyToClipboard() +{ + saveToClipboard(m_pixmap); +} +void PinWidget::saveToFile() +{ + saveToFilesystemGUI(m_pixmap); +} diff --git a/src/tools/pin/pinwidget.h b/src/tools/pin/pinwidget.h index 0e17ebaf8b..99dbbc792e 100644 --- a/src/tools/pin/pinwidget.h +++ b/src/tools/pin/pinwidget.h @@ -46,4 +46,9 @@ class PinWidget : public QWidget qreal m_scaleFactor{ 1 }; qreal m_currentStepScaleFactor{ 1 }; bool m_sizeChanged{ false }; + +private slots: + void showContextMenu(const QPoint& pos); + void copyToClipboard(); + void saveToFile(); };