diff --git a/src/lib/other/siteinfo.cpp b/src/lib/other/siteinfo.cpp index bbe1f6d1b..08a5fa1d3 100644 --- a/src/lib/other/siteinfo.cpp +++ b/src/lib/other/siteinfo.cpp @@ -36,6 +36,7 @@ #include #include #include +#include SiteInfo::SiteInfo(WebView *view) : QDialog(view) @@ -125,10 +126,28 @@ SiteInfo::SiteInfo(WebView *view) connect(ui->listWidget, SIGNAL(currentRowChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int))); connect(ui->treeImages, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(showImagePreview(QTreeWidgetItem*))); connect(ui->treeImages, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(imagesCustomContextMenuRequested(QPoint))); + connect(ui->treeTags, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(tagsCustomContextMenuRequested(QPoint))); + + QShortcut *shortcutTagsCopyAll = new QShortcut(QKeySequence("Ctrl+C"), ui->treeTags); + shortcutTagsCopyAll->setContext(Qt::WidgetShortcut); + connect(shortcutTagsCopyAll, &QShortcut::activated, [=]{copySelectedItems(ui->treeTags, false);}); + + QShortcut *shortcutTagsCopyValues = new QShortcut(QKeySequence("Ctrl+Shift+C"), ui->treeTags); + shortcutTagsCopyValues->setContext(Qt::WidgetShortcut); + connect(shortcutTagsCopyValues, &QShortcut::activated, [=]{copySelectedItems(ui->treeTags, true);}); + + QShortcut *shortcutImagesCopyAll = new QShortcut(QKeySequence("Ctrl+C"), ui->treeImages); + shortcutImagesCopyAll->setContext(Qt::WidgetShortcut); + connect(shortcutImagesCopyAll, &QShortcut::activated, [=]{copySelectedItems(ui->treeImages, false);}); + + QShortcut *shortcutImagesCopyValues = new QShortcut(QKeySequence("Ctrl+Shift+C"), ui->treeImages); + shortcutImagesCopyValues->setContext(Qt::WidgetShortcut); + connect(shortcutImagesCopyValues, &QShortcut::activated, [=]{copySelectedItems(ui->treeImages, true);}); ui->treeImages->setContextMenuPolicy(Qt::CustomContextMenu); ui->treeImages->sortByColumn(-1, Qt::AscendingOrder); + ui->treeTags->setContextMenuPolicy(Qt::CustomContextMenu); ui->treeTags->sortByColumn(-1, Qt::AscendingOrder); QzTools::setWmClass("Site Info", this); @@ -153,18 +172,42 @@ void SiteInfo::imagesCustomContextMenuRequested(const QPoint &p) } QMenu menu; - menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy Image Location"), this, SLOT(copyActionData()))->setData(item->text(1)); - menu.addAction(tr("Copy Image Name"), this, SLOT(copyActionData()))->setData(item->text(0)); + menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy Image Location"), this, [=]{copySelectedItems(ui->treeImages, false);}, QKeySequence("Ctrl+C")); + menu.addAction(tr("Copy Image Name"), this, [=]{copySelectedItems(ui->treeImages, true);}, QKeySequence("Ctrl+Shift+C")); menu.addSeparator(); menu.addAction(QIcon::fromTheme("document-save"), tr("Save Image to Disk"), this, SLOT(saveImage())); menu.exec(ui->treeImages->viewport()->mapToGlobal(p)); } -void SiteInfo::copyActionData() +void SiteInfo::tagsCustomContextMenuRequested(const QPoint &p) { - if (QAction* action = qobject_cast(sender())) { - qApp->clipboard()->setText(action->data().toString()); + QTreeWidgetItem* item = ui->treeTags->itemAt(p); + if (!item) { + return; } + + QMenu menu; + menu.addAction(tr("Copy Values"), this, [=]{copySelectedItems(ui->treeTags, false);}, QKeySequence("Ctrl+C")); + menu.addAction(tr("Copy Tags and Values"), this, [=]{copySelectedItems(ui->treeTags, true);}, QKeySequence("Ctrl+Shift+C")); + menu.exec(ui->treeTags->viewport()->mapToGlobal(p)); +} + +void SiteInfo::copySelectedItems(const QTreeWidget* treeWidget, const bool both) +{ + QList itemList = treeWidget->selectedItems(); + QString tmpText = QSL(""); + + for (int i = 0; i < itemList.size(); ++i) { + if (i != 0) { + tmpText.append(QSL("\n")); + } + if (both) { + tmpText.append((itemList[i])->text(0)); + tmpText.append(QSL("\t")); + } + tmpText.append((itemList[i])->text(1)); + } + qApp->clipboard()->setText(tmpText); } void SiteInfo::saveImage() diff --git a/src/lib/other/siteinfo.h b/src/lib/other/siteinfo.h index 2a90109d8..99cf36162 100644 --- a/src/lib/other/siteinfo.h +++ b/src/lib/other/siteinfo.h @@ -30,6 +30,7 @@ class SiteInfo; class QNetworkReply; class QTreeWidgetItem; +class QTreeWidget; class WebView; class CertificateInfoWidget; @@ -47,7 +48,8 @@ public: private Q_SLOTS: void showImagePreview(QTreeWidgetItem *item); void imagesCustomContextMenuRequested(const QPoint &p); - void copyActionData(); + void tagsCustomContextMenuRequested(const QPoint &p); + void copySelectedItems(const QTreeWidget* treeWidget, const bool both); void saveImage(); private: diff --git a/src/lib/other/siteinfo.ui b/src/lib/other/siteinfo.ui index 8f075e2e0..878474f41 100644 --- a/src/lib/other/siteinfo.ui +++ b/src/lib/other/siteinfo.ui @@ -135,6 +135,9 @@ + + QAbstractItemView::ExtendedSelection + true @@ -221,6 +224,9 @@ 0 + + QAbstractItemView::ExtendedSelection + false