mainwindow: add right click menu to preview labels

This commit is contained in:
Albert S. 2021-03-27 17:58:38 +01:00
förälder e88d0e57b2
incheckning 9ced0ec742
2 ändrade filer med 28 tillägg och 10 borttagningar

Visa fil

@ -160,6 +160,16 @@ void MainWindow::pdfPreviewReceived(PdfPreview preview)
QDesktopServices::openUrl(QUrl::fromLocalFile(docPath)); 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); 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) void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int i)
{ {
QDesktopServices::openUrl(QUrl::fromLocalFile(item->text(1))); QDesktopServices::openUrl(QUrl::fromLocalFile(item->text(1)));
@ -281,16 +305,9 @@ void MainWindow::showSearchResultsContextMenu(const QPoint &point)
{ {
return; return;
} }
QMenu menu("SearchResult", this); QFileInfo pathinfo(item->text(1));
menu.addAction("Copy filename to clipboard", [&] { QGuiApplication::clipboard()->setText(item->text(0)); }); QMenu menu("SearchResults", this);
menu.addAction("Copy full path to clipboard", [&] { QGuiApplication::clipboard()->setText(item->text(1)); }); createSearchResutlMenu(menu, pathinfo);
menu.addAction("Open containing folder",
[&]
{
QFileInfo pathinfo(item->text(1));
QString dir = pathinfo.absolutePath();
QDesktopServices::openUrl(QUrl::fromLocalFile(dir));
});
menu.exec(QCursor::pos()); menu.exec(QCursor::pos());
} }

Visa fil

@ -44,6 +44,7 @@ class MainWindow : public QMainWindow
void handleSearchError(QString error); void handleSearchError(QString error);
QSSQuery currentQuery; QSSQuery currentQuery;
int pdfPreviewsPerPage; int pdfPreviewsPerPage;
void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo);
private slots: private slots:
void lineEditReturnPressed(); void lineEditReturnPressed();
void treeSearchItemActivated(QTreeWidgetItem *item, int i); void treeSearchItemActivated(QTreeWidgetItem *item, int i);