From 57ce030f1d19f4a16f309149addc80bed53b8b2d Mon Sep 17 00:00:00 2001 From: initramfs Date: Sun, 24 Apr 2016 00:15:54 -0400 Subject: [PATCH 1/4] feat(status): add ability to copy status messages Adds the ability to copy status messages via a context menu on the status message label. Closes issue #3155 --- src/widget/form/chatform.cpp | 25 +++++++++++++++++++++++++ src/widget/form/chatform.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 2d8fb4fc7..919ba583e 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -29,9 +29,11 @@ #include #include #include +#include #include #include #include +#include #include #include "chatform.h" #include "src/audio/audio.h" @@ -79,6 +81,7 @@ ChatForm::ChatForm(Friend* chatFriend) statusMessageLabel->setFont(Style::getFont(Style::Medium)); statusMessageLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize()); statusMessageLabel->setTextFormat(Qt::PlainText); + statusMessageLabel->setContextMenuPolicy(Qt::CustomContextMenu); callConfirm = nullptr; offlineEngine = new OfflineMsgEngine(f); @@ -100,6 +103,7 @@ ChatForm::ChatForm(Friend* chatFriend) connect(this, &GenericChatForm::messageInserted, this, &ChatForm::onMessageInserted); loadHistoryAction = menu.addAction(QString(), this, SLOT(onLoadHistory())); + copyStatusAction = statusMessageMenu.addAction(QString(), this, SLOT(onCopyStatusMessage())); connect(core, &Core::fileSendStarted, this, &ChatForm::startFileSend); connect(sendButton, &QPushButton::clicked, this, &ChatForm::onSendTriggered); @@ -111,6 +115,15 @@ ChatForm::ChatForm(Friend* chatFriend) connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged); connect(core, &Core::fileSendFailed, this, &ChatForm::onFileSendFailed); connect(this, &ChatForm::chatAreaCleared, getOfflineMsgEngine(), &OfflineMsgEngine::removeAllReceipts); + connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this, [&](const QPoint& pos) + { + if(!statusMessageLabel->text().isEmpty()) + { + QWidget* sender = static_cast(QObject::sender()); + + statusMessageMenu.exec(sender->mapToGlobal(pos)); + } + } ); connect(&typingTimer, &QTimer::timeout, this, [=]{ Core::getInstance()->sendTyping(f->getFriendID(), false); isTyping = false; @@ -826,6 +839,17 @@ void ChatForm::onMessageInserted() netcam->setShowMessages(true, true); } +void ChatForm::onCopyStatusMessage() +{ + QString text = statusMessageLabel->text(); + QClipboard* clipboard = QApplication::clipboard(); + + if (clipboard) + { + clipboard->setText(text, QClipboard::Clipboard); + } +} + void ChatForm::startCounter() { if (!callDurationTimer) @@ -975,6 +999,7 @@ void ChatForm::retranslateUi() QString volObjectName = volButton->objectName(); QString micObjectName = micButton->objectName(); loadHistoryAction->setText(tr("Load chat history...")); + copyStatusAction->setText(tr("Copy")); if (volObjectName == QStringLiteral("green")) volButton->setToolTip(tr("Mute call")); diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 842af1ac0..938a6e8d0 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -84,6 +84,7 @@ private slots: void onScreenshotTaken(const QPixmap &pixmap); void doScreenshot(); void onMessageInserted(); + void onCopyStatusMessage(); private: void retranslateUi(); @@ -101,6 +102,7 @@ private: CoreAV* coreav; Friend* f; CroppingLabel *statusMessageLabel; + QMenu statusMessageMenu; QLabel *callDuration; QTimer *callDurationTimer; QTimer typingTimer; @@ -108,6 +110,7 @@ private: QElapsedTimer timeElapsed; OfflineMsgEngine *offlineEngine; QAction* loadHistoryAction; + QAction* copyStatusAction; QHash ftransWidgets; void startCounter(); From 1935d0c6ec781b7cdb14a427a670aef5910e4df0 Mon Sep 17 00:00:00 2001 From: initramfs Date: Sun, 24 Apr 2016 02:05:38 -0400 Subject: [PATCH 2/4] 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 From ae24311237519cdaacfb88b0461ab54541220422 Mon Sep 17 00:00:00 2001 From: initramfs Date: Mon, 25 Apr 2016 14:12:42 -0400 Subject: [PATCH 3/4] refactor(status): enable text selection in about friend dialog Enables text selection in the about friend dialog, allowing selection and copying of status and username. --- src/widget/about/aboutuser.cpp | 24 ------------------------ src/widget/about/aboutuser.h | 3 --- src/widget/about/aboutuser.ui | 14 ++++++++++---- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/widget/about/aboutuser.cpp b/src/widget/about/aboutuser.cpp index 598cf52c7..00a649545 100644 --- a/src/widget/about/aboutuser.cpp +++ b/src/widget/about/aboutuser.cpp @@ -4,8 +4,6 @@ #include "src/persistence/profile.h" #include "src/nexus.h" -#include -#include #include #include #include @@ -18,21 +16,10 @@ 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); @@ -118,17 +105,6 @@ 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 b0089d5ec..b206b0395 100644 --- a/src/widget/about/aboutuser.h +++ b/src/widget/about/aboutuser.h @@ -2,7 +2,6 @@ #define ABOUTUSER_H #include -#include #include "src/friend.h" @@ -21,7 +20,6 @@ public: private: Ui::AboutUser *ui; - QMenu statusMessageMenu; ToxId toxId; private slots: @@ -29,7 +27,6 @@ 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 83c6128ca..7ae77ec68 100644 --- a/src/widget/about/aboutuser.ui +++ b/src/widget/about/aboutuser.ui @@ -31,19 +31,19 @@ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + - + 0 0 - - Qt::CustomContextMenu - false @@ -56,6 +56,12 @@ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + From 63af0d7500f98db4d7e2ada78166730ffc420249 Mon Sep 17 00:00:00 2001 From: initramfs Date: Tue, 26 Apr 2016 09:59:21 +0800 Subject: [PATCH 4/4] fix(status): explictly refer to this within lambda Workaround for a potential gcc bug in which lambda expressions are not being executed in the correct context. --- src/widget/form/chatform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 919ba583e..d6744d92f 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -119,7 +119,7 @@ ChatForm::ChatForm(Friend* chatFriend) { if(!statusMessageLabel->text().isEmpty()) { - QWidget* sender = static_cast(QObject::sender()); + QWidget* sender = static_cast(this->sender()); statusMessageMenu.exec(sender->mapToGlobal(pos)); }