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
43 changes: 43 additions & 0 deletions src/dialogs/VersionInfoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,28 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent)
selAllActionRightTreewidget->setShortcutContext(
Qt::ShortcutContext::WidgetWithChildrenShortcut);

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

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

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

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

// Connect selection handles
connect(ui->leftTreeWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this,
[this]() { ui->rightTreeWidget->clearSelection(); });
connect(ui->rightTreeWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this,
[this]() { ui->leftTreeWidget->clearSelection(); });
connect(this, &VersionInfoDialog::finished, this, &VersionInfoDialog::clearSelectionOnClose);

// Add actions to context menu
ui->leftTreeWidget->addAction(copyActionLeftTreewidget);
ui->leftTreeWidget->addAction(selAllActionLeftTreewidget);

Expand All @@ -61,6 +71,18 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent)

VersionInfoDialog::~VersionInfoDialog() {}

void VersionInfoDialog::clearSelectionOnClose()
{
ui->leftTreeWidget->clearSelection();
ui->rightTreeWidget->clearSelection();

// remove default "current" item selection after dialog close
auto model = ui->leftTreeWidget->model();
ui->leftTreeWidget->setCurrentIndex(model->index(-1, -1));
r3yc0n1c marked this conversation as resolved.
Show resolved Hide resolved
model = ui->rightTreeWidget->model();
ui->leftTreeWidget->setCurrentIndex(model->index(-1, -1));
r3yc0n1c marked this conversation as resolved.
Show resolved Hide resolved
}

void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t)
{
QString vinfo, row;
Expand All @@ -79,6 +101,27 @@ void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t)
clipboard->setText(vinfo.trimmed());
}

/*
void VersionInfoDialog::leftTreeWidgetItemSelectionChanged()
{
auto index = ui->leftTreeWidget->currentIndex();
if (!ui->leftTreeWidget->selectionModel()->hasSelection() || !index.isValid()) {
return;
}
ui->leftTreeWidget->clearSelection();
}

void VersionInfoDialog::rightTreeWidgetItemSelectionChanged()
{
auto index = ui->rightTreeWidget->currentIndex();
if (!ui->rightTreeWidget->selectionModel()->hasSelection() || !index.isValid()) {
return;
}
if (ui->rightTreeWidget->selectionModel()->hasSelection())
ui->rightTreeWidget->clearSelection();
}
*/
r3yc0n1c marked this conversation as resolved.
Show resolved Hide resolved

void VersionInfoDialog::fillVersionInfo()
{
RzCoreLocked core(Core());
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/VersionInfoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class VersionInfoDialog : public QDialog

private slots:
void CopyTreeWidgetSelection(QTreeWidget *t);
void clearSelectionOnClose();

protected:
QAction *copyActionLeftTreewidget = nullptr;
Expand Down
Loading