Merge pull request #4300 from Ghosty141/feature/screenshot_copy

GH-4044 Implemented copy screenshots to the clipboard
This commit is contained in:
Petr Mrázek 2022-01-30 16:11:47 +01:00 committed by GitHub
commit 2cf04d034a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 0 deletions

View File

@ -250,6 +250,12 @@ bool ScreenshotsPage::eventFilter(QObject *obj, QEvent *evt)
return QWidget::eventFilter(obj, evt);
}
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(evt);
if (keyEvent->matches(QKeySequence::Copy)) {
on_actionCopy_File_s_triggered();
return true;
}
switch (keyEvent->key())
{
case Qt::Key_Delete:
@ -272,6 +278,11 @@ ScreenshotsPage::~ScreenshotsPage()
void ScreenshotsPage::ShowContextMenu(const QPoint& pos)
{
auto menu = ui->toolBar->createContextMenu(this, tr("Context menu"));
if (ui->listView->selectionModel()->selectedRows().size() > 1) {
menu->removeAction( ui->actionCopy_Image );
}
menu->exec(ui->listView->mapToGlobal(pos));
delete menu;
}
@ -377,6 +388,42 @@ void ScreenshotsPage::on_actionUpload_triggered()
m_uploadActive = false;
}
void ScreenshotsPage::on_actionCopy_Image_triggered()
{
auto selection = ui->listView->selectionModel()->selectedRows();
if(selection.size() < 1)
{
return;
}
// You can only copy one image to the clipboard. In the case of multiple selected files, only the first one gets copied.
auto item = selection[0];
auto info = m_model->fileInfo(item);
QImage image(info.absoluteFilePath());
Q_ASSERT(!image.isNull());
QApplication::clipboard()->setImage(image, QClipboard::Clipboard);
}
void ScreenshotsPage::on_actionCopy_File_s_triggered()
{
auto selection = ui->listView->selectionModel()->selectedRows();
if(selection.size() < 1)
{
// Don't do anything so we don't empty the users clipboard
return;
}
QString buf = "";
for (auto item : selection)
{
auto info = m_model->fileInfo(item);
buf += "file:///" + info.absoluteFilePath() + "\r\n";
}
QMimeData* mimeData = new QMimeData();
mimeData->setData("text/uri-list", buf.toLocal8Bit());
QApplication::clipboard()->setMimeData(mimeData);
}
void ScreenshotsPage::on_actionDelete_triggered()
{
auto mbox = CustomMessageBox::selectable(

View File

@ -73,6 +73,8 @@ protected:
private slots:
void on_actionUpload_triggered();
void on_actionCopy_Image_triggered();
void on_actionCopy_File_s_triggered();
void on_actionDelete_triggered();
void on_actionRename_triggered();
void on_actionView_Folder_triggered();

View File

@ -50,6 +50,8 @@
<bool>false</bool>
</attribute>
<addaction name="actionUpload"/>
<addaction name="actionCopy_Image"/>
<addaction name="actionCopy_File_s"/>
<addaction name="actionDelete"/>
<addaction name="actionRename"/>
<addaction name="actionView_Folder"/>
@ -74,6 +76,22 @@
<string>View Folder</string>
</property>
</action>
<action name="actionCopy_Image">
<property name="text">
<string>Copy Image</string>
</property>
<property name="toolTip">
<string>Copy Image</string>
</property>
</action>
<action name="actionCopy_File_s">
<property name="text">
<string>Copy File(s)</string>
</property>
<property name="toolTip">
<string>Copy File(s)</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>