mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-02-11 04:54:00 +00:00
pinwidget: allow copying to clipboard and saving to file (#2519)
Co-authored-by: zhangfuwen <zhangfuwen@foxmail.com>
This commit is contained in:
@@ -6,10 +6,12 @@
|
||||
|
||||
#include "pinwidget.h"
|
||||
#include "qguiappcurrentscreen.h"
|
||||
#include "screenshotsaver.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/globalvalues.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QScreen>
|
||||
#include <QShortcut>
|
||||
#include <QVBoxLayout>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -46,4 +46,9 @@ private:
|
||||
qreal m_scaleFactor{ 1 };
|
||||
qreal m_currentStepScaleFactor{ 1 };
|
||||
bool m_sizeChanged{ false };
|
||||
|
||||
private slots:
|
||||
void showContextMenu(const QPoint& pos);
|
||||
void copyToClipboard();
|
||||
void saveToFile();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user