From cf23b1ecf2bfb9d0a07c7332b9de7a8070570892 Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Tue, 12 Mar 2024 19:33:01 +0530 Subject: [PATCH] Add Copy to Clipboard for VersionInfo dialog --- src/dialogs/VersionInfoDialog.cpp | 40 +++++++++++++++++++++++++++++++ src/dialogs/VersionInfoDialog.h | 10 ++++++++ src/dialogs/VersionInfoDialog.ui | 23 ++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 9cd5e03c1e..8871ae0534 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -8,6 +8,7 @@ #include #include #include +#include VersionInfoDialog::VersionInfoDialog(QWidget *parent) : QDialog(parent), ui(new Ui::VersionInfoDialog), core(Core()) @@ -21,6 +22,45 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent) VersionInfoDialog::~VersionInfoDialog() {} +void VersionInfoDialog::on_buttonBox_rejected() +{ + close(); +} + +void VersionInfoDialog::on_copyVersionInfoButton_clicked() +{ + QString vinfo = "# " + ui->leftLabel->text() + "\n"; + + // Iterate & Copy leftTreeWidget items + QTreeWidgetItemIterator itl(ui->leftTreeWidget); + + int keyColumnIndex = 0, valueColumnIndex = 1; + + while (*itl) { + QString row = (*itl)->text(keyColumnIndex) + " : " + (*itl)->text(valueColumnIndex) + "\n"; + vinfo.append(row); + ++itl; + } + + vinfo.append("\n# " + ui->rightLabel->text() + "\n"); + + // Iterate & Copy rightTreeWidget items + QTreeWidgetItemIterator itr(ui->rightTreeWidget); + + while (*itr) { + QString row = (*itr)->text(keyColumnIndex) + " : " + (*itr)->text(valueColumnIndex) + "\n"; + vinfo.append(row); + ++itr; + } + + // Copy to Clipboard + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(vinfo); + + QMessageBox::information(this, tr("Copy to Clipboard"), + tr("Version information was successfully copied!")); +} + void VersionInfoDialog::fillVersionInfo() { RzCoreLocked core(Core()); diff --git a/src/dialogs/VersionInfoDialog.h b/src/dialogs/VersionInfoDialog.h index 7974e059db..8803705e7e 100644 --- a/src/dialogs/VersionInfoDialog.h +++ b/src/dialogs/VersionInfoDialog.h @@ -18,6 +18,16 @@ class VersionInfoDialog : public QDialog explicit VersionInfoDialog(QWidget *parent = nullptr); ~VersionInfoDialog(); +private slots: + void on_buttonBox_rejected(); + + /** + * @fn AboutDialog::on_copyVersionInfoButton_clicked() + * + * @brief Copies the table values to Clipboard. + */ + void on_copyVersionInfoButton_clicked(); + private: std::unique_ptr ui; CutterCore *core; diff --git a/src/dialogs/VersionInfoDialog.ui b/src/dialogs/VersionInfoDialog.ui index 54e197b83b..2c48324715 100644 --- a/src/dialogs/VersionInfoDialog.ui +++ b/src/dialogs/VersionInfoDialog.ui @@ -135,6 +135,29 @@ + + + + + + + + :/img/icons/copy.svg:/img/icons/copy.svg + + + Copy + + + + + + + QDialogButtonBox::Close + + + + +