From 502229a6f250e3dfa01d5187c09c0958cf755ec0 Mon Sep 17 00:00:00 2001 From: apprb Date: Fri, 5 Sep 2014 22:29:14 +0700 Subject: [PATCH] cleanup --- widget/form/chatform.cpp | 10 ---------- widget/form/chatform.h | 12 ------------ widget/form/genericchatform.cpp | 19 ++++++++++++++++--- widget/form/genericchatform.h | 5 ++++- widget/form/groupchatform.cpp | 21 +++++---------------- widget/form/groupchatform.h | 11 +---------- 6 files changed, 26 insertions(+), 52 deletions(-) diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index 82d919b09..141451c4c 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -16,19 +16,11 @@ #include "chatform.h" #include "friend.h" -#include "smileypack.h" #include "widget/friendwidget.h" #include "widget/widget.h" #include "widget/filetransfertwidget.h" -#include "widget/emoticonswidget.h" -#include "style.h" -#include -#include #include #include -#include -#include -#include #include ChatForm::ChatForm(Friend* chatFriend) @@ -50,8 +42,6 @@ ChatForm::ChatForm(Friend* chatFriend) connect(callButton, &QPushButton::clicked, this, &ChatForm::onCallTriggered); connect(videoButton, &QPushButton::clicked, this, &ChatForm::onVideoCallTriggered); connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered); - connect(chatArea->verticalScrollBar(), &QScrollBar::rangeChanged, this, &ChatForm::onSliderRangeChanged); - connect(chatArea, &QScrollArea::customContextMenuRequested, this, &ChatForm::onChatContextMenuRequested); connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle())); } diff --git a/widget/form/chatform.h b/widget/form/chatform.h index 9b803ae35..6a7a9362d 100644 --- a/widget/form/chatform.h +++ b/widget/form/chatform.h @@ -17,19 +17,7 @@ #ifndef CHATFORM_H #define CHATFORM_H -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "genericchatform.h" -#include "widget/tool/chattextedit.h" -#include "ui_mainwindow.h" #include "core.h" #include "widget/netcamview.h" diff --git a/widget/form/genericchatform.cpp b/widget/form/genericchatform.cpp index b26bedc03..d7727adf7 100644 --- a/widget/form/genericchatform.cpp +++ b/widget/form/genericchatform.cpp @@ -147,6 +147,8 @@ GenericChatForm::GenericChatForm(QObject *parent) : emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); connect(emoteButton, SIGNAL(clicked()), this, SLOT(onEmoteButtonClicked())); + connect(chatArea, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); + connect(chatArea->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged())); } void GenericChatForm::setName(const QString &newName) @@ -214,7 +216,7 @@ void GenericChatForm::onSaveLogClicked() void GenericChatForm::addMessage(QString author, QString message, QString date) { QLabel *authorLabel = new QLabel(author); - QLabel *messageLabel = new QLabel(message); + QLabel *messageLabel = new QLabel(); QLabel *dateLabel = new QLabel(date); QScrollBar* scroll = chatArea->verticalScrollBar(); @@ -253,9 +255,9 @@ void GenericChatForm::addMessage(QString author, QString message, QString date) for (QString& s : messageLines) { if (QRegExp("^[ ]*>.*").exactMatch(s)) - finalMessage += fontTemplate.arg(greentext.name(), s.replace(" ", " ")); + finalMessage += fontTemplate.arg(greentext.name(), toHtmlChars(s)); else - finalMessage += s.replace(" ", " "); + finalMessage += toHtmlChars(s); finalMessage += "
"; } messageLabel->setText(finalMessage.left(finalMessage.length()-4)); @@ -308,3 +310,14 @@ void GenericChatForm::onEmoteInsertRequested(QString str) msgEdit->setFocus(); // refocus so that we can continue typing } + +QString GenericChatForm::toHtmlChars(const QString &str) +{ + static QList> replaceList = {{"&","&"}, {" "," "}, {">",">"}, {"<","<"}}; + QString res = str; + + for (auto &it : replaceList) + res = res.replace(it.first,it.second); + + return res; +} diff --git a/widget/form/genericchatform.h b/widget/form/genericchatform.h index f25ccdc1e..59216f755 100644 --- a/widget/form/genericchatform.h +++ b/widget/form/genericchatform.h @@ -46,7 +46,7 @@ public: virtual void setName(const QString &newName); virtual void show(Ui::MainWindow &ui); - virtual void addMessage(QString author, QString message, QString date=QTime::currentTime().toString("hh:mm")); + void addMessage(QString author, QString message, QString date=QTime::currentTime().toString("hh:mm")); signals: void sendMessage(int, QString); @@ -72,6 +72,9 @@ protected: QString previousName; int curRow; bool lockSliderToBottom; + +private: + QString toHtmlChars(const QString &str); }; #endif // GENERICCHATFORM_H diff --git a/widget/form/groupchatform.cpp b/widget/form/groupchatform.cpp index 0d743feea..e444e0ac3 100644 --- a/widget/form/groupchatform.cpp +++ b/widget/form/groupchatform.cpp @@ -18,20 +18,11 @@ #include "group.h" #include "widget/groupwidget.h" #include "widget/widget.h" -#include "friend.h" -#include "friendlist.h" -#include "style.h" -#include -#include -#include -#include -#include -#include GroupChatForm::GroupChatForm(Group* chatGroup) : group(chatGroup) { - nusers = new QLabel(); + nusersLabel = new QLabel(); namesList = new QLabel(); fileButton->setEnabled(false); @@ -44,8 +35,8 @@ GroupChatForm::GroupChatForm(Group* chatGroup) small.setPixelSize(10); nameLabel->setText(group->widget->name.text()); - nusers->setFont(small); - nusers->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size())); + nusersLabel->setFont(small); + nusersLabel->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size())); avatarLabel->setPixmap(QPixmap(":/img/group_dark.png")); QString names; @@ -60,7 +51,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup) mainChatLayout->setColumnStretch(1,1); mainChatLayout->setHorizontalSpacing(10); - headTextLayout->addWidget(nusers); + headTextLayout->addWidget(nusersLabel); headTextLayout->addWidget(namesList); headTextLayout->setMargin(0); headTextLayout->setSpacing(0); @@ -68,8 +59,6 @@ GroupChatForm::GroupChatForm(Group* chatGroup) connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered())); connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered())); - connect(chatArea->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged())); - connect(chatArea, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); } GroupChatForm::~GroupChatForm() @@ -99,7 +88,7 @@ void GroupChatForm::addGroupMessage(QString message, int peerId) void GroupChatForm::onUserListChanged() { - nusers->setText(tr("%1 users in chat").arg(group->nPeers)); + nusersLabel->setText(tr("%1 users in chat").arg(group->nPeers)); QString names; for (QString& s : group->peers) names.append(s+", "); diff --git a/widget/form/groupchatform.h b/widget/form/groupchatform.h index 63546751e..9b4766180 100644 --- a/widget/form/groupchatform.h +++ b/widget/form/groupchatform.h @@ -17,15 +17,6 @@ #ifndef GROUPCHATFORM_H #define GROUPCHATFORM_H -#include -#include -#include -#include -#include -#include -#include -#include - #include "genericchatform.h" #include "widget/tool/chattextedit.h" #include "ui_mainwindow.h" @@ -46,7 +37,7 @@ private slots: private: Group* group; - QLabel *nusers, *namesList; + QLabel *nusersLabel, *namesList; }; #endif // GROUPCHATFORM_H