From 75f2dab3c87d9d88979553792473a5aace4c96bf Mon Sep 17 00:00:00 2001 From: Ghosty Date: Fri, 3 Dec 2021 03:02:58 +0100 Subject: [PATCH 1/3] NOISSUE Implemented copy screenshots to the clipboard - Added context-menu entry - Ctrl+C keybind works as well - If multiple screenshots are selected, only the first one gets copied --- .../ui/pages/instance/ScreenshotsPage.cpp | 22 +++++++++++++++++++ launcher/ui/pages/instance/ScreenshotsPage.h | 1 + launcher/ui/pages/instance/ScreenshotsPage.ui | 9 ++++++++ 3 files changed, 32 insertions(+) diff --git a/launcher/ui/pages/instance/ScreenshotsPage.cpp b/launcher/ui/pages/instance/ScreenshotsPage.cpp index 06c4379f..e391b95d 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.cpp +++ b/launcher/ui/pages/instance/ScreenshotsPage.cpp @@ -250,6 +250,12 @@ bool ScreenshotsPage::eventFilter(QObject *obj, QEvent *evt) return QWidget::eventFilter(obj, evt); } QKeyEvent *keyEvent = static_cast(evt); + + if (keyEvent->matches(QKeySequence::Copy)) { + on_actionCopy_triggered(); + return true; + } + switch (keyEvent->key()) { case Qt::Key_Delete: @@ -372,6 +378,22 @@ void ScreenshotsPage::on_actionUpload_triggered() m_uploadActive = false; } +void ScreenshotsPage::on_actionCopy_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_actionDelete_triggered() { auto mbox = CustomMessageBox::selectable( diff --git a/launcher/ui/pages/instance/ScreenshotsPage.h b/launcher/ui/pages/instance/ScreenshotsPage.h index d2f44837..d32f08ff 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.h +++ b/launcher/ui/pages/instance/ScreenshotsPage.h @@ -73,6 +73,7 @@ protected: private slots: void on_actionUpload_triggered(); + void on_actionCopy_triggered(); void on_actionDelete_triggered(); void on_actionRename_triggered(); void on_actionView_Folder_triggered(); diff --git a/launcher/ui/pages/instance/ScreenshotsPage.ui b/launcher/ui/pages/instance/ScreenshotsPage.ui index ec461087..bb4213de 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.ui +++ b/launcher/ui/pages/instance/ScreenshotsPage.ui @@ -50,6 +50,7 @@ false + @@ -74,6 +75,14 @@ View Folder + + + Copy + + + Copy + + From e9c52ec69663b2cb28a40428c96de749bdf49547 Mon Sep 17 00:00:00 2001 From: Ghosty Date: Fri, 3 Dec 2021 16:08:11 +0100 Subject: [PATCH 2/3] NOISSUE Added Copy File(s) feature for the screenshot page - Ctrl+C now copies the file instead of the image data - Renamed Copy to Copy Image --- .../ui/pages/instance/ScreenshotsPage.cpp | 24 +++++++++++++++++-- launcher/ui/pages/instance/ScreenshotsPage.h | 3 ++- launcher/ui/pages/instance/ScreenshotsPage.ui | 17 +++++++++---- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/launcher/ui/pages/instance/ScreenshotsPage.cpp b/launcher/ui/pages/instance/ScreenshotsPage.cpp index e391b95d..7aead623 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.cpp +++ b/launcher/ui/pages/instance/ScreenshotsPage.cpp @@ -252,7 +252,7 @@ bool ScreenshotsPage::eventFilter(QObject *obj, QEvent *evt) QKeyEvent *keyEvent = static_cast(evt); if (keyEvent->matches(QKeySequence::Copy)) { - on_actionCopy_triggered(); + on_actionCopy_File_s_triggered(); return true; } @@ -378,7 +378,7 @@ void ScreenshotsPage::on_actionUpload_triggered() m_uploadActive = false; } -void ScreenshotsPage::on_actionCopy_triggered() +void ScreenshotsPage::on_actionCopy_Image_triggered() { auto selection = ui->listView->selectionModel()->selectedRows(); if(selection.size() < 1) @@ -394,6 +394,26 @@ void ScreenshotsPage::on_actionCopy_triggered() 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( diff --git a/launcher/ui/pages/instance/ScreenshotsPage.h b/launcher/ui/pages/instance/ScreenshotsPage.h index d32f08ff..2a1fdeee 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.h +++ b/launcher/ui/pages/instance/ScreenshotsPage.h @@ -73,7 +73,8 @@ protected: private slots: void on_actionUpload_triggered(); - void on_actionCopy_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(); diff --git a/launcher/ui/pages/instance/ScreenshotsPage.ui b/launcher/ui/pages/instance/ScreenshotsPage.ui index bb4213de..2e2227a2 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.ui +++ b/launcher/ui/pages/instance/ScreenshotsPage.ui @@ -50,7 +50,8 @@ false - + + @@ -75,12 +76,20 @@ View Folder - + - Copy + Copy Image - Copy + Copy Image + + + + + Copy File(s) + + + Copy File(s) From a97d0a36f4807e082273d0f137186a5cebf6cd5d Mon Sep 17 00:00:00 2001 From: Ghosty Date: Fri, 3 Dec 2021 16:29:28 +0100 Subject: [PATCH 3/3] NOISSUE Copy Image is not shown if the selection is > 1 --- launcher/ui/pages/instance/ScreenshotsPage.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/launcher/ui/pages/instance/ScreenshotsPage.cpp b/launcher/ui/pages/instance/ScreenshotsPage.cpp index 7aead623..ccde78e7 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.cpp +++ b/launcher/ui/pages/instance/ScreenshotsPage.cpp @@ -278,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; }