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
40 changes: 40 additions & 0 deletions src/dialogs/VersionInfoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QTreeWidget>
#include <QClipboard>

VersionInfoDialog::VersionInfoDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::VersionInfoDialog), core(Core())
Expand All @@ -21,6 +22,45 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent)

VersionInfoDialog::~VersionInfoDialog() {}

void VersionInfoDialog::on_buttonBox_rejected()
r3yc0n1c marked this conversation as resolved.
Show resolved Hide resolved
{
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;
r3yc0n1c marked this conversation as resolved.
Show resolved Hide resolved

while (*itl) {
QString row = (*itl)->text(keyColumnIndex) + " : " + (*itl)->text(valueColumnIndex) + "\n";
r3yc0n1c marked this conversation as resolved.
Show resolved Hide resolved
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());
Expand Down
10 changes: 10 additions & 0 deletions src/dialogs/VersionInfoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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::VersionInfoDialog> ui;
CutterCore *core;
Expand Down
23 changes: 23 additions & 0 deletions src/dialogs/VersionInfoDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@
</item>
</layout>
</item>

<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="copyVersionInfoButton">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/img/icons/copy.svg</normaloff>:/img/icons/copy.svg</iconset>
</property>
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
Expand Down
Loading