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
This commit is contained in:
Ghosty 2021-12-03 03:02:58 +01:00
parent ffcef673de
commit 75f2dab3c8
3 changed files with 32 additions and 0 deletions

View File

@ -250,6 +250,12 @@ bool ScreenshotsPage::eventFilter(QObject *obj, QEvent *evt)
return QWidget::eventFilter(obj, evt); return QWidget::eventFilter(obj, evt);
} }
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(evt); QKeyEvent *keyEvent = static_cast<QKeyEvent *>(evt);
if (keyEvent->matches(QKeySequence::Copy)) {
on_actionCopy_triggered();
return true;
}
switch (keyEvent->key()) switch (keyEvent->key())
{ {
case Qt::Key_Delete: case Qt::Key_Delete:
@ -372,6 +378,22 @@ void ScreenshotsPage::on_actionUpload_triggered()
m_uploadActive = false; 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() void ScreenshotsPage::on_actionDelete_triggered()
{ {
auto mbox = CustomMessageBox::selectable( auto mbox = CustomMessageBox::selectable(

View File

@ -73,6 +73,7 @@ protected:
private slots: private slots:
void on_actionUpload_triggered(); void on_actionUpload_triggered();
void on_actionCopy_triggered();
void on_actionDelete_triggered(); void on_actionDelete_triggered();
void on_actionRename_triggered(); void on_actionRename_triggered();
void on_actionView_Folder_triggered(); void on_actionView_Folder_triggered();

View File

@ -50,6 +50,7 @@
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionUpload"/> <addaction name="actionUpload"/>
<addaction name="actionCopy"/>
<addaction name="actionDelete"/> <addaction name="actionDelete"/>
<addaction name="actionRename"/> <addaction name="actionRename"/>
<addaction name="actionView_Folder"/> <addaction name="actionView_Folder"/>
@ -74,6 +75,14 @@
<string>View Folder</string> <string>View Folder</string>
</property> </property>
</action> </action>
<action name="actionCopy">
<property name="text">
<string>Copy</string>
</property>
<property name="toolTip">
<string>Copy</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>