Added context menu to copy or open paths
This commit is contained in:
orang tua
96fe3e08f6
melakukan
fe26454f85
24
window.cpp
24
window.cpp
@ -24,6 +24,8 @@
|
|||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QFileIconProvider>
|
#include <QFileIconProvider>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QClipboard>
|
||||||
Window::Window(const QVector<EntryConfig> &configs, const QString &dbpath)
|
Window::Window(const QVector<EntryConfig> &configs, const QString &dbpath)
|
||||||
{
|
{
|
||||||
this->userEntryButtons = generateEntryButtons(configs);
|
this->userEntryButtons = generateEntryButtons(configs);
|
||||||
@ -57,6 +59,28 @@ void Window::initTreeWidgets()
|
|||||||
treeFileSearchResults.setHeaderLabels(headers);
|
treeFileSearchResults.setHeaderLabels(headers);
|
||||||
treeFileSearchResults.header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
treeFileSearchResults.header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
connect(&treeFileSearchResults, &QTreeWidget::itemActivated, this, &Window::treeSearchItemActivated);
|
connect(&treeFileSearchResults, &QTreeWidget::itemActivated, this, &Window::treeSearchItemActivated);
|
||||||
|
treeFileSearchResults.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
||||||
|
connect(&treeFileSearchResults, &QTreeWidget::customContextMenuRequested, this, &Window::showSearchResultsContextMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Window::showSearchResultsContextMenu(const QPoint &point)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *item = treeFileSearchResults.itemAt(point);
|
||||||
|
if(item == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QMenu menu("Test", 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));
|
||||||
|
|
||||||
|
});
|
||||||
|
menu.exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<EntryPushButton*> Window::generateEntryButtons(const QVector<EntryConfig> &configs)
|
QVector<EntryPushButton*> Window::generateEntryButtons(const QVector<EntryConfig> &configs)
|
||||||
|
1
window.h
1
window.h
@ -69,6 +69,7 @@ class Window : public QWidget
|
|||||||
void handleSearchResults(const QVector<QString> &results);
|
void handleSearchResults(const QVector<QString> &results);
|
||||||
void handleCancelledSearch();
|
void handleCancelledSearch();
|
||||||
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
||||||
|
void showSearchResultsContextMenu(const QPoint &point);
|
||||||
signals:
|
signals:
|
||||||
void beginFileSearch(const QString &query);
|
void beginFileSearch(const QString &query);
|
||||||
void beginContentSearch(const QString &query);
|
void beginContentSearch(const QString &query);
|
||||||
|
Memuat…
Reference in New Issue
Block a user