Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(status): add ability to copy status messages
Browse files Browse the repository at this point in the history
Adds the ability to copy status messages via a context menu on the
status message label.

Closes issue #3155
  • Loading branch information
initramfs committed Apr 24, 2016
1 parent 6dd1cd0 commit 57ce030
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"));
Expand Down
3 changes: 3 additions & 0 deletions src/widget/form/chatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private slots:
void onScreenshotTaken(const QPixmap &pixmap);
void doScreenshot();
void onMessageInserted();
void onCopyStatusMessage();

private:
void retranslateUi();
Expand All @@ -101,13 +102,15 @@ private slots:
CoreAV* coreav;
Friend* f;
CroppingLabel *statusMessageLabel;
QMenu statusMessageMenu;
QLabel *callDuration;
QTimer *callDurationTimer;
QTimer typingTimer;
QTimer *disableCallButtonsTimer;
QElapsedTimer timeElapsed;
OfflineMsgEngine *offlineEngine;
QAction* loadHistoryAction;
QAction* copyStatusAction;

QHash<uint, FileTransferInstance*> ftransWidgets;
void startCounter();
Expand Down

0 comments on commit 57ce030

Please sign in to comment.