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

3
src/widget/form/chatform.cpp

@ -164,9 +164,6 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
connect(av, &CoreAV::avStart, this, &ChatForm::onAvStart); connect(av, &CoreAV::avStart, this, &ChatForm::onAvStart);
connect(av, &CoreAV::avEnd, this, &ChatForm::onAvEnd); 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::callTriggered, this, &ChatForm::onCallTriggered);
connect(headWidget, &ChatFormHeader::videoCallTriggered, this, &ChatForm::onVideoCallTriggered); connect(headWidget, &ChatFormHeader::videoCallTriggered, this, &ChatForm::onVideoCallTriggered);
connect(headWidget, &ChatFormHeader::micMuteToggle, this, &ChatForm::onMicMuteToggle); connect(headWidget, &ChatFormHeader::micMuteToggle, this, &ChatForm::onMicMuteToggle);

6
src/widget/form/chatform.h

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

16
src/widget/form/genericchatform.cpp

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

3
src/widget/form/genericchatform.h

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

11
src/widget/form/groupchatform.cpp

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

4
src/widget/form/groupchatform.h

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

Loading…
Cancel
Save