Skip to content

Commit

Permalink
pinwidget: allow copying to clipboard and saving to file
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfuwen committed Apr 2, 2022
1 parent c01ffec commit 506c536
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/tools/pin/pinwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include "qguiappcurrentscreen.h"
#include "src/utils/confighandler.h"
#include "src/utils/globalvalues.h"
#include "screenshotsaver.h"

#include <QLabel>
#include <QScreen>
#include <QShortcut>
#include <QVBoxLayout>
#include <QWheelEvent>
#include <QMenu>

namespace {
static constexpr int MARGIN = 7;
Expand Down Expand Up @@ -79,6 +81,11 @@ 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 @@ -205,3 +212,27 @@ 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);
}
6 changes: 6 additions & 0 deletions src/tools/pin/pinwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PinWidget : public QWidget
bool scrollEvent(QWheelEvent* e);
void pinchTriggered(QPinchGesture*);


QPixmap m_pixmap;
QVBoxLayout* m_layout;
QLabel* m_label;
Expand All @@ -46,4 +47,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 506c536

Please sign in to comment.