Skip to content

Commit

Permalink
Add Copy to Clipboard for VersionInfo dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
r3yc0n1c committed Mar 12, 2024
1 parent bffe193 commit cf23b1e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
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()
{
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());
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

0 comments on commit cf23b1e

Please sign in to comment.