Skip to content

Commit

Permalink
exp: versioninfo Copy feat
Browse files Browse the repository at this point in the history
  • Loading branch information
r3yc0n1c committed Mar 17, 2024
1 parent bffe193 commit 0c29709
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

37 changes: 37 additions & 0 deletions 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 @@ -21,6 +23,41 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent)

VersionInfoDialog::~VersionInfoDialog() {}

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

for(QTreeWidgetItem *x: t->selectedItems()){
row = x->text(keyColumnIndex) + " = " + x->text(valueColumnIndex) + "\n";
vinfo.append(row);
}

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

void VersionInfoDialog::contextMenuEvent(QContextMenuEvent *event){
QAction *copyAction = new QAction(tr("Copy"), this);
copyAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
copyAction->setShortcut(QKeySequence::Copy);

connect(copyAction, &QAction::triggered, this, [this](){
if(ui->rightTreeWidget->hasFocus()){
CopyTreeWidgetSelection(ui->rightTreeWidget);
}
else if(ui->leftTreeWidget->hasFocus()){
CopyTreeWidgetSelection(ui->leftTreeWidget);
}
});

QMenu menu(this);
menu.addAction(copyAction);
menu.exec(event->globalPos());

addAction(copyAction);
}

void VersionInfoDialog::fillVersionInfo()
{
RzCoreLocked core(Core());
Expand Down
6 changes: 6 additions & 0 deletions src/dialogs/VersionInfoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class VersionInfoDialog : public QDialog
explicit VersionInfoDialog(QWidget *parent = nullptr);
~VersionInfoDialog();

private slots:
void CopyTreeWidgetSelection(QTreeWidget *t);

protected:
void contextMenuEvent(QContextMenuEvent *event) override;

private:
std::unique_ptr<Ui::VersionInfoDialog> ui;
CutterCore *core;
Expand Down
6 changes: 6 additions & 0 deletions src/dialogs/VersionInfoDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="leftTreeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down Expand Up @@ -103,6 +106,9 @@
</item>
<item>
<widget class="QTreeWidget" name="rightTreeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down

0 comments on commit 0c29709

Please sign in to comment.