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

refactor: Add pure virtual methods for main actions in chat

This commit is contained in:
Diadlo 2017-11-17 00:14:51 +03:00
parent e3bb4e735f
commit 1eb0c4af26
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
7 changed files with 35 additions and 22 deletions

View File

@ -33,8 +33,6 @@
#include <QToolButton>
static const QSize AVATAR_SIZE{40, 40};
static const QSize CALL_BUTTONS_SIZE{50, 40};
static const QSize TOOL_BUTTONS_SIZE{22, 18};
static const short HEAD_LAYOUT_SPACING = 5;
static const short MIC_BUTTONS_LAYOUT_SPACING = 4;
static const short BUTTONS_LAYOUT_HOR_SPACING = 4;
@ -78,8 +76,8 @@ const QString MIC_TOOL_TIP[] = {
ChatFormHeader::tr("Mute microphone"),
};
template <class Fun>
QPushButton* createButton(ChatFormHeader* self, const QString& name, Fun onClickSlot)
template <class T, class Fun>
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
{
QPushButton* btn = new QPushButton();
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
@ -130,10 +128,10 @@ ChatFormHeader::ChatFormHeader(QWidget* parent)
headTextLayout->addWidget(nameLabel);
headTextLayout->addStretch();
micButton = createButton(this, "micButton", &ChatFormHeader::micMuteToggle);
volButton = createButton(this, "volButton", &ChatFormHeader::volMuteToggle);
callButton = createButton(this, "callButton", &ChatFormHeader::callTriggered);
videoButton = createButton(this, "videoButton", &ChatFormHeader::videoCallTriggered);
micButton = createButton("micButton", this, &ChatFormHeader::micMuteToggle);
volButton = createButton("volButton", this, &ChatFormHeader::volMuteToggle);
callButton = createButton("callButton", this, &ChatFormHeader::callTriggered);
videoButton = createButton("videoButton", this, &ChatFormHeader::videoCallTriggered);
QVBoxLayout* micButtonsLayout = new QVBoxLayout();
micButtonsLayout->setSpacing(MIC_BUTTONS_LAYOUT_SPACING);

View File

@ -164,9 +164,6 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
connect(av, &CoreAV::avStart, this, &ChatForm::onAvStart);
connect(av, &CoreAV::avEnd, this, &ChatForm::onAvEnd);
connect(sendButton, &QPushButton::clicked, this, &ChatForm::onSendTriggered);
connect(fileButton, &QPushButton::clicked, this, &ChatForm::onAttachClicked);
connect(screenshotButton, &QPushButton::clicked, this, &ChatForm::onScreenshotClicked);
connect(headWidget, &ChatFormHeader::callTriggered, this, &ChatForm::onCallTriggered);
connect(headWidget, &ChatFormHeader::videoCallTriggered, this, &ChatForm::onVideoCallTriggered);
connect(headWidget, &ChatFormHeader::micMuteToggle, this, &ChatForm::onMicMuteToggle);

View File

@ -73,12 +73,13 @@ public slots:
private slots:
void clearChatArea(bool notInForm) override final;
void onSendTriggered() override;
void onAttachClicked() override;
void onScreenshotClicked() override;
void onDeliverOfflineMessages();
void onLoadChatHistory();
void onSendTriggered();
void onTextEditChanged();
void onAttachClicked();
void onCallTriggered();
void onVideoCallTriggered();
void onAnswerCallTriggered(bool video);
@ -95,7 +96,6 @@ private slots:
void onReceiptReceived(quint32 friendId, int receipt);
void onLoadHistory();
void onUpdateTime();
void onScreenshotClicked();
void sendImage(const QPixmap& pixmap);
void doScreenshot();
void onCopyStatusMessage();

View File

@ -111,18 +111,21 @@ const QString STYLE_PATH = QStringLiteral(":/ui/chatForm/buttons.css");
namespace
{
QPushButton* createButton(const QString& name)
template <class T, class Fun>
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
{
QPushButton* btn = new QPushButton();
// Fix for incorrect layouts on OS X as per
// https://bugreports.qt-project.org/browse/QTBUG-14591
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
btn->setObjectName(name);
btn->setProperty("state", "green");
btn->setStyleSheet(Style::getStylesheet(STYLE_PATH));
QObject::connect(btn, &QPushButton::clicked, self, onClickSlot);
return btn;
}
}
GenericChatForm::GenericChatForm(QWidget* parent)
@ -142,11 +145,11 @@ GenericChatForm::GenericChatForm(QWidget* parent)
msgEdit = new ChatTextEdit();
sendButton = createButton("sendButton");
emoteButton = createButton("emoteButton");
sendButton = createButton("sendButton", this, &GenericChatForm::onSendTriggered);
emoteButton = createButton("emoteButton", this, &GenericChatForm::onEmoteButtonClicked);
fileButton = createButton("fileButton");
screenshotButton = createButton("screenshotButton");
fileButton = createButton("fileButton", this, &GenericChatForm::onSendTriggered);
screenshotButton = createButton("screenshotButton", this, &GenericChatForm::onScreenshotClicked);
// TODO: Make updateCallButtons (see ChatForm) abstract
// and call here to set tooltips.
@ -203,7 +206,6 @@ GenericChatForm::GenericChatForm(QWidget* parent)
menu.addSeparator();
connect(emoteButton, &QPushButton::clicked, this, &GenericChatForm::onEmoteButtonClicked);
connect(chatWidget, &ChatLog::customContextMenuRequested, this,
&GenericChatForm::onChatContextMenuRequested);

View File

@ -86,6 +86,9 @@ public slots:
protected slots:
void onChatContextMenuRequested(QPoint pos);
virtual void onScreenshotClicked() = 0;
virtual void onSendTriggered() = 0;
virtual void onAttachClicked() = 0;
void onEmoteButtonClicked();
void onEmoteInsertRequested(QString str);
void onSaveLogClicked();

View File

@ -78,6 +78,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
tabber = new TabCompleter(msgEdit, group);
fileButton->setEnabled(false);
fileButton->setProperty("state", "");
ChatFormHeader::Mode mode = ChatFormHeader::Mode::None;
if (group->isAvGroupchat()) {
mode = ChatFormHeader::Mode::Audio;
@ -186,6 +187,16 @@ void GroupChatForm::onTitleChanged(uint32_t groupId, const QString& author, cons
addSystemInfoMessage(message, ChatMessage::INFO, curTime);
}
void GroupChatForm::onScreenshotClicked()
{
// Unsupported
}
void GroupChatForm::onAttachClicked()
{
// Unsupported
}
/**
* @brief Updates user names' labels at the top of group chat
*/

View File

@ -41,7 +41,9 @@ public:
void peerAudioPlaying(int peer);
private slots:
void onSendTriggered();
void onSendTriggered() override;
void onScreenshotClicked() override;
void onAttachClicked() override;
void onMicMuteToggle();
void onVolMuteToggle();
void onCallClicked();