Commit d0ee2f0f authored by Juraj Oravec's avatar Juraj Oravec Committed by Juraj Oravec
Browse files

SiteInfo: Improve ability to copy data from lists

BUG: 451284



Signed-off-by: Juraj Oravec's avatarJuraj Oravec <jurajoravec@mailo.com>
parent 4a549b03
......@@ -36,6 +36,7 @@
#include <QClipboard>
#include <QTimer>
#include <QGraphicsPixmapItem>
#include <QShortcut>
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<QAction*>(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<QTreeWidgetItem*> 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()
......
......@@ -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:
......
......@@ -135,6 +135,9 @@
</item>
<item row="3" column="0" colspan="4">
<widget class="QTreeWidget" name="treeTags">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
......@@ -221,6 +224,9 @@
<height>0</height>
</size>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment