Browse Source

refactor: Add pure virtual methods for main actions in chat

reviewable/pr4810/r2
Diadlo 8 years ago
parent
commit
1eb0c4af26
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 14
      src/widget/chatformheader.cpp
  2. 3
      src/widget/form/chatform.cpp
  3. 6
      src/widget/form/chatform.h
  4. 16
      src/widget/form/genericchatform.cpp
  5. 3
      src/widget/form/genericchatform.h
  6. 11
      src/widget/form/groupchatform.cpp
  7. 4
      src/widget/form/groupchatform.h

14
src/widget/chatformheader.cpp

@ -33,8 +33,6 @@ @@ -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[] = { @@ -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) @@ -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);

3
src/widget/form/chatform.cpp

@ -164,9 +164,6 @@ ChatForm::ChatForm(Friend* chatFriend, History* history) @@ -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);

6
src/widget/form/chatform.h

@ -73,12 +73,13 @@ public slots: @@ -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: @@ -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();

16
src/widget/form/genericchatform.cpp

@ -111,18 +111,21 @@ const QString STYLE_PATH = QStringLiteral(":/ui/chatForm/buttons.css"); @@ -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) @@ -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) @@ -203,7 +206,6 @@ GenericChatForm::GenericChatForm(QWidget* parent)
menu.addSeparator();
connect(emoteButton, &QPushButton::clicked, this, &GenericChatForm::onEmoteButtonClicked);
connect(chatWidget, &ChatLog::customContextMenuRequested, this,
&GenericChatForm::onChatContextMenuRequested);

3
src/widget/form/genericchatform.h

@ -86,6 +86,9 @@ public slots: @@ -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();

11
src/widget/form/groupchatform.cpp

@ -78,6 +78,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup) @@ -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 @@ -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
*/

4
src/widget/form/groupchatform.h

@ -41,7 +41,9 @@ public: @@ -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();

Loading…
Cancel
Save