Skip to content

Commit

Permalink
pinwidget: allow copying to clipboard and saving to file (flameshot-o…
Browse files Browse the repository at this point in the history
…rg#2519)

Co-authored-by: zhangfuwen <zhangfuwen@foxmail.com>
  • Loading branch information
zhangfuwen and zhangfuwen authored Apr 7, 2022
1 parent 850260d commit db5f8a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/tools/pin/pinwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(&copy2ClipboardAction,
SIGNAL(triggered()),
this,
SLOT(copyToClipboard()));
contextMenu.addAction(&copy2ClipboardAction);

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);
}
5 changes: 5 additions & 0 deletions src/tools/pin/pinwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

0 comments on commit db5f8a7

Please sign in to comment.