1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

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
This commit is contained in:
initramfs 2016-04-24 00:15:54 -04:00
parent 6dd1cd0320
commit 57ce030f1d
No known key found for this signature in database
GPG Key ID: 78B8BDF87E9EF0AF
2 changed files with 28 additions and 0 deletions

View File

@ -29,9 +29,11 @@
#include <QBitmap>
#include <QScreen>
#include <QTemporaryFile>
#include <QApplication>
#include <QGuiApplication>
#include <QStyle>
#include <QSplitter>
#include <QClipboard>
#include <cassert>
#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<QWidget*>(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"));

View File

@ -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<uint, FileTransferInstance*> ftransWidgets;
void startCounter();