Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pinwidget: allow copying to clipboard and saving to file #2519

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -79,6 +81,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 @@ -205,3 +214,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();
};