Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Copy to Clipboard for VersionInfo dialog #3318

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
64 changes: 63 additions & 1 deletion src/dialogs/VersionInfoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QTreeWidget>
#include <QContextMenuEvent>
#include <QClipboard>

VersionInfoDialog::VersionInfoDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::VersionInfoDialog), core(Core())
Expand All @@ -17,10 +19,70 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent)

// Get version information
fillVersionInfo();

// Setup context menu and actions
copyActionLeftTreewidget = new QAction(tr("Copy"), this);
copyActionLeftTreewidget->setIcon(QIcon(":/img/icons/copy.svg"));
copyActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::Copy);
copyActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

copyActionRightTreewidget = new QAction(tr("Copy"), this);
copyActionRightTreewidget->setIcon(QIcon(":/img/icons/copy.svg"));
copyActionRightTreewidget->setShortcut(QKeySequence::StandardKey::Copy);
copyActionRightTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

selAllActionLeftTreewidget = new QAction(tr("Select All"), this);
selAllActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll);
selAllActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

selAllActionRightTreewidget = new QAction(tr("Select All"), this);
selAllActionRightTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll);
selAllActionRightTreewidget->setShortcutContext(
Qt::ShortcutContext::WidgetWithChildrenShortcut);

connect(copyActionLeftTreewidget, &QAction::triggered, this,
[this]() { CopyTreeWidgetSelection(ui->leftTreeWidget); });

connect(copyActionRightTreewidget, &QAction::triggered, this,
[this]() { CopyTreeWidgetSelection(ui->rightTreeWidget); });

connect(selAllActionLeftTreewidget, &QAction::triggered, this,
[this]() { ui->leftTreeWidget->selectAll(); });

connect(selAllActionRightTreewidget, &QAction::triggered, this,
[this]() { ui->rightTreeWidget->selectAll(); });

ui->leftTreeWidget->addAction(copyActionLeftTreewidget);
ui->leftTreeWidget->addAction(selAllActionLeftTreewidget);

ui->rightTreeWidget->addAction(copyActionRightTreewidget);
ui->rightTreeWidget->addAction(selAllActionRightTreewidget);

contextMenu = new QMenu(this);
}

VersionInfoDialog::~VersionInfoDialog() {}

void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t)
{
const int keyColumnIndex = 0, valueColumnIndex = 1;
QString vinfo, row;

for (QTreeWidgetItem *x : t->selectedItems()) {
r3yc0n1c marked this conversation as resolved.
Show resolved Hide resolved
row = x->text(keyColumnIndex) + " = " + x->text(valueColumnIndex) + "\n";
vinfo.append(row);
}

QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(vinfo.trimmed());
}

void VersionInfoDialog::contextMenuEvent(QContextMenuEvent *event)
{
contextMenu->exec(event->globalPos());
event->accept();
}
r3yc0n1c marked this conversation as resolved.
Show resolved Hide resolved

void VersionInfoDialog::fillVersionInfo()
{
RzCoreLocked core(Core());
Expand Down Expand Up @@ -236,4 +298,4 @@ void VersionInfoDialog::fillVersionInfo()
}
qhelpers::adjustColumns(ui->rightTreeWidget, 0);
}
}
}
14 changes: 13 additions & 1 deletion src/dialogs/VersionInfoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ class VersionInfoDialog : public QDialog
explicit VersionInfoDialog(QWidget *parent = nullptr);
~VersionInfoDialog();

private slots:
void CopyTreeWidgetSelection(QTreeWidget *t);

protected:
QMenu *contextMenu = nullptr;
QAction *copyActionLeftTreewidget = nullptr;
QAction *copyActionRightTreewidget = nullptr;
QAction *selAllActionLeftTreewidget = nullptr;
QAction *selAllActionRightTreewidget = nullptr;

void contextMenuEvent(QContextMenuEvent *event) override;

private:
std::unique_ptr<Ui::VersionInfoDialog> ui;
CutterCore *core;

void fillVersionInfo();
};

#endif // VERSIONINFODIALOG_H
#endif // VERSIONINFODIALOG_H
14 changes: 13 additions & 1 deletion src/dialogs/VersionInfoDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="leftTreeWidget">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down Expand Up @@ -103,6 +109,12 @@
</item>
<item>
<widget class="QTreeWidget" name="rightTreeWidget">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down Expand Up @@ -139,4 +151,4 @@
</widget>
<resources/>
<connections/>
</ui>
</ui>
Loading