From 1935d0c6ec781b7cdb14a427a670aef5910e4df0 Mon Sep 17 00:00:00 2001 From: initramfs Date: Sun, 24 Apr 2016 02:05:38 -0400 Subject: [PATCH] feat(status): make status in about dialog copyable --- src/widget/about/aboutuser.cpp | 24 ++++++++++++++++++++++++ src/widget/about/aboutuser.h | 3 +++ src/widget/about/aboutuser.ui | 3 +++ 3 files changed, 30 insertions(+) diff --git a/src/widget/about/aboutuser.cpp b/src/widget/about/aboutuser.cpp index 00a649545..598cf52c7 100644 --- a/src/widget/about/aboutuser.cpp +++ b/src/widget/about/aboutuser.cpp @@ -4,6 +4,8 @@ #include "src/persistence/profile.h" #include "src/nexus.h" +#include +#include #include #include #include @@ -16,10 +18,21 @@ AboutUser::AboutUser(ToxId &toxId, QWidget *parent) : ui->label_4->hide(); ui->aliases->hide(); + statusMessageMenu.addAction(tr("Copy"), this, SLOT(onCopyStatusMessage())); + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AboutUser::onAcceptedClicked); connect(ui->autoaccept, &QCheckBox::clicked, this, &AboutUser::onAutoAcceptClicked); connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutUser::onSelectDirClicked); connect(ui->removeHistory, &QPushButton::clicked, this, &AboutUser::onRemoveHistoryClicked); + connect(ui->statusMessage, &QLabel::customContextMenuRequested, this, [&](const QPoint& pos) + { + if(!ui->statusMessage->text().isEmpty()) + { + QWidget* sender = static_cast(QObject::sender()); + + statusMessageMenu.exec(sender->mapToGlobal(pos)); + } + } ); this->toxId = toxId; QString dir = Settings::getInstance().getAutoAcceptDir(this->toxId); @@ -105,6 +118,17 @@ void AboutUser::onRemoveHistoryClicked() QMessageBox::Ok); } +void AboutUser::onCopyStatusMessage() +{ + QString text = ui->statusMessage->text(); + QClipboard* clipboard = QApplication::clipboard(); + + if (clipboard) + { + clipboard->setText(text, QClipboard::Clipboard); + } +} + AboutUser::~AboutUser() { delete ui; diff --git a/src/widget/about/aboutuser.h b/src/widget/about/aboutuser.h index b206b0395..b0089d5ec 100644 --- a/src/widget/about/aboutuser.h +++ b/src/widget/about/aboutuser.h @@ -2,6 +2,7 @@ #define ABOUTUSER_H #include +#include #include "src/friend.h" @@ -20,6 +21,7 @@ public: private: Ui::AboutUser *ui; + QMenu statusMessageMenu; ToxId toxId; private slots: @@ -27,6 +29,7 @@ private slots: void onAutoAcceptClicked(); void onSelectDirClicked(); void onRemoveHistoryClicked(); + void onCopyStatusMessage(); }; #endif // ABOUTUSER_H diff --git a/src/widget/about/aboutuser.ui b/src/widget/about/aboutuser.ui index d098ac193..83c6128ca 100644 --- a/src/widget/about/aboutuser.ui +++ b/src/widget/about/aboutuser.ui @@ -41,6 +41,9 @@ 0 + + Qt::CustomContextMenu + false