From 9ced0ec74259802c5fcaec26d3601f18c067cd3f Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 27 Mar 2021 17:58:38 +0100 Subject: [PATCH] mainwindow: add right click menu to preview labels --- gui/mainwindow.cpp | 37 +++++++++++++++++++++++++++---------- gui/mainwindow.h | 1 + 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index fa15f60..00e47db 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -160,6 +160,16 @@ void MainWindow::pdfPreviewReceived(PdfPreview preview) QDesktopServices::openUrl(QUrl::fromLocalFile(docPath)); } }); + connect(label, &ClickLabel::rightClick, + [this, docPath, previewPage]() + { + QFileInfo fileInfo{docPath}; + QMenu menu("labeRightClick", this); + createSearchResutlMenu(menu, fileInfo); + menu.addAction("Copy page number", [previewPage] + { QGuiApplication::clipboard()->setText(QString::number(previewPage)); }); + menu.exec(QCursor::pos()); + }); } } @@ -269,6 +279,20 @@ void MainWindow::handleSearchError(QString error) ui->lblSearchResults->setText("Error:" + error); } +void MainWindow::createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo) +{ + menu.addAction("Copy filename to clipboard", + [&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.fileName()); }); + menu.addAction("Copy full path to clipboard", + [&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.absoluteFilePath()); }); + menu.addAction("Open containing folder", + [&fileInfo] + { + QString dir = fileInfo.absolutePath(); + QDesktopServices::openUrl(QUrl::fromLocalFile(dir)); + }); +} + void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int i) { QDesktopServices::openUrl(QUrl::fromLocalFile(item->text(1))); @@ -281,16 +305,9 @@ void MainWindow::showSearchResultsContextMenu(const QPoint &point) { return; } - QMenu menu("SearchResult", this); - menu.addAction("Copy filename to clipboard", [&] { QGuiApplication::clipboard()->setText(item->text(0)); }); - menu.addAction("Copy full path to clipboard", [&] { QGuiApplication::clipboard()->setText(item->text(1)); }); - menu.addAction("Open containing folder", - [&] - { - QFileInfo pathinfo(item->text(1)); - QString dir = pathinfo.absolutePath(); - QDesktopServices::openUrl(QUrl::fromLocalFile(dir)); - }); + QFileInfo pathinfo(item->text(1)); + QMenu menu("SearchResults", this); + createSearchResutlMenu(menu, pathinfo); menu.exec(QCursor::pos()); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index b5b5237..224d039 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -44,6 +44,7 @@ class MainWindow : public QMainWindow void handleSearchError(QString error); QSSQuery currentQuery; int pdfPreviewsPerPage; + void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo); private slots: void lineEditReturnPressed(); void treeSearchItemActivated(QTreeWidgetItem *item, int i);