mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
code cleanup
This commit is contained in:
parent
16949cfdba
commit
aa2f67c983
|
@ -225,7 +225,7 @@ QString FileTransferInstance::getHtmlImage()
|
|||
else
|
||||
rightBtnImg = QImage(":/ui/fileTransferInstance/acceptFileButton.png");
|
||||
|
||||
res = draw2ButtonsForm("green", leftBtnImg, rightBtnImg);
|
||||
res = draw2ButtonsForm("silver", leftBtnImg, rightBtnImg);
|
||||
} else if (state == tsCanceled)
|
||||
{
|
||||
res = drawButtonlessForm("red");
|
||||
|
|
|
@ -4,21 +4,6 @@ div.name_me {
|
|||
padding-right: 3px;
|
||||
}
|
||||
|
||||
div.message_me {
|
||||
color: #646464;
|
||||
padding-right: 3px;
|
||||
padding-left: 3px;
|
||||
}
|
||||
|
||||
div.date_me {
|
||||
color: #646464;
|
||||
padding-left: 3px;
|
||||
}
|
||||
|
||||
div.quote {
|
||||
background-color: #6bc260;
|
||||
}
|
||||
|
||||
div.name {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
|
@ -36,27 +21,43 @@ div.date {
|
|||
padding-left: 3px;
|
||||
}
|
||||
|
||||
div.quote {
|
||||
background-color: #6bc260;
|
||||
}
|
||||
|
||||
div.green {
|
||||
margin-top: 12px;
|
||||
margin-bottom: 12px;
|
||||
margin-left: 12px;
|
||||
margin-right: 12px;
|
||||
color: #ffffff;
|
||||
background-color: #6bc260;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
div.silver {
|
||||
margin-top: 12px;
|
||||
margin-bottom: 12px;
|
||||
margin-left: 12px;
|
||||
margin-right: 12px;
|
||||
color: #000000;
|
||||
background-color: #d1d1d1;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
div.red {
|
||||
margin-top: 12px;
|
||||
margin-bottom: 12px;
|
||||
margin-left: 12px;
|
||||
margin-right: 12px;
|
||||
color: #ffffff;
|
||||
background-color: rgb(200,78,78);
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
div.button {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 0px;
|
||||
margin-left: 0px;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
div.red {
|
||||
margin-top: 12px;
|
||||
margin-bottom: 12px;
|
||||
margin-left: 12px;
|
||||
color: #ffffff;
|
||||
background-color: rgb(200,78,78);
|
||||
font-size: 10px;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "chatareawidget.h"
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QScrollBar>
|
||||
|
||||
ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
|
||||
QTextEdit(parent)
|
||||
|
@ -26,6 +27,12 @@ ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
|
|||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
|
||||
ChatAreaWidget::~ChatAreaWidget()
|
||||
{
|
||||
for (ChatAction *it : messages)
|
||||
delete it;
|
||||
}
|
||||
|
||||
void ChatAreaWidget::mouseReleaseEvent(QMouseEvent * event)
|
||||
{
|
||||
QTextEdit::mouseReleaseEvent(event);
|
||||
|
@ -41,16 +48,58 @@ void ChatAreaWidget::mouseReleaseEvent(QMouseEvent * event)
|
|||
QTextFormat format = cursor.charFormat();
|
||||
if (format.isImageFormat())
|
||||
{
|
||||
QString image = format.toImageFormat().name();
|
||||
if (QRegExp("^data:ftrans.*").exactMatch(image))
|
||||
QString imageName = format.toImageFormat().name();
|
||||
if (QRegExp("^data:ftrans.*").exactMatch(imageName))
|
||||
{
|
||||
image = image.right(image.length() - 12);
|
||||
int endpos = image.indexOf("/png;base64");
|
||||
image = image.left(endpos);
|
||||
int middlepos = image.indexOf(".");
|
||||
emit onFileTranfertInterract(image.left(middlepos),image.right(image.length() - middlepos - 1));
|
||||
QString data = imageName.right(imageName.length() - 12);
|
||||
int endpos = data.indexOf("/png;base64");
|
||||
data = data.left(endpos);
|
||||
int middlepos = data.indexOf(".");
|
||||
QString widgetID = data.left(middlepos);
|
||||
QString widgetBtn = data.right(data.length() - middlepos - 1);
|
||||
emit onFileTranfertInterract(widgetID, widgetBtn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString ChatAreaWidget::getHtmledMessages()
|
||||
{
|
||||
QString res("<table width=100%>\n");
|
||||
|
||||
for (ChatAction *it : messages)
|
||||
{
|
||||
res += it->getHtml();
|
||||
}
|
||||
res += "</table>";
|
||||
return res;
|
||||
}
|
||||
|
||||
void ChatAreaWidget::insertMessage(ChatAction *msgAction)
|
||||
{
|
||||
if (msgAction == nullptr)
|
||||
return;
|
||||
|
||||
messages.append(msgAction);
|
||||
updateChatContent();
|
||||
}
|
||||
|
||||
void ChatAreaWidget::updateChatContent()
|
||||
{
|
||||
QScrollBar* scroll = verticalScrollBar();
|
||||
lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
|
||||
|
||||
setHtml(getHtmledMessages());
|
||||
if (lockSliderToBottom)
|
||||
sliderPosition = scroll->maximum();
|
||||
|
||||
scroll->setValue(sliderPosition);
|
||||
}
|
||||
|
||||
void ChatAreaWidget::clearMessages()
|
||||
{
|
||||
for (ChatAction *it : messages)
|
||||
delete it;
|
||||
updateChatContent();
|
||||
}
|
||||
|
|
|
@ -18,12 +18,17 @@
|
|||
#define CHATAREAWIDGET_H
|
||||
|
||||
#include <QTextEdit>
|
||||
#include <QList>
|
||||
#include "widget/tool/chataction.h"
|
||||
|
||||
class ChatAreaWidget : public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ChatAreaWidget(QWidget *parent = 0);
|
||||
virtual ~ChatAreaWidget();
|
||||
void insertMessage(ChatAction *msgAction);
|
||||
void clearMessages();
|
||||
|
||||
signals:
|
||||
void onFileTranfertInterract(QString widgetName, QString buttonName);
|
||||
|
@ -32,7 +37,13 @@ protected:
|
|||
void mouseReleaseEvent(QMouseEvent * event);
|
||||
|
||||
public slots:
|
||||
void updateChatContent();
|
||||
|
||||
private:
|
||||
QString getHtmledMessages();
|
||||
QList<ChatAction*> messages;
|
||||
bool lockSliderToBottom;
|
||||
int sliderPosition;
|
||||
};
|
||||
|
||||
#endif // CHATAREAWIDGET_H
|
||||
|
|
|
@ -43,7 +43,7 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||
connect(videoButton, &QPushButton::clicked, this, &ChatForm::onVideoCallTriggered);
|
||||
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
||||
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
|
||||
connect(newChatForm, SIGNAL(onFileTranfertInterract(QString,QString)), this, SLOT(onFileTansBtnClicked(QString,QString)));
|
||||
connect(chatWidget, SIGNAL(onFileTranfertInterract(QString,QString)), this, SLOT(onFileTansBtnClicked(QString,QString)));
|
||||
}
|
||||
|
||||
ChatForm::~ChatForm()
|
||||
|
@ -101,10 +101,14 @@ void ChatForm::startFileSend(ToxFile file)
|
|||
connect(Widget::getInstance()->getCore(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
|
||||
connect(fileTrans, SIGNAL(stateUpdated()), this, SLOT(updateChatContent()));
|
||||
connect(fileTrans, SIGNAL(stateUpdated()), chatWidget, SLOT(updateChatContent()));
|
||||
|
||||
messages.append(new FileTransferAction(fileTrans, Widget::getInstance()->getUsername(), QTime::currentTime().toString("hh:mm")));
|
||||
updateChatContent();
|
||||
QString name = Widget::getInstance()->getUsername();
|
||||
if (name == previousName)
|
||||
name = "";
|
||||
previousName = Widget::getInstance()->getUsername();
|
||||
|
||||
chatWidget->insertMessage(new FileTransferAction(fileTrans, name, QTime::currentTime().toString("hh:mm"), true));
|
||||
}
|
||||
|
||||
void ChatForm::onFileRecvRequest(ToxFile file)
|
||||
|
@ -118,7 +122,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
|||
connect(Widget::getInstance()->getCore(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
|
||||
connect(fileTrans, SIGNAL(stateUpdated()), this, SLOT(updateChatContent()));
|
||||
connect(fileTrans, SIGNAL(stateUpdated()), chatWidget, SLOT(updateChatContent()));
|
||||
|
||||
Widget* w = Widget::getInstance();
|
||||
if (!w->isFriendWidgetCurActiveWidget(f)|| w->getIsWindowMinimized() || !w->isActiveWindow())
|
||||
|
@ -128,8 +132,12 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
|||
f->widget->updateStatusLight();
|
||||
}
|
||||
|
||||
messages.append(new FileTransferAction(fileTrans, f->getName(), QTime::currentTime().toString("hh:mm")));
|
||||
updateChatContent();
|
||||
QString name = f->getName();
|
||||
if (name == previousName)
|
||||
name = "";
|
||||
previousName = f->getName();
|
||||
|
||||
chatWidget->insertMessage(new FileTransferAction(fileTrans, name, QTime::currentTime().toString("hh:mm"), false));
|
||||
}
|
||||
|
||||
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
||||
|
@ -435,6 +443,4 @@ void ChatForm::onFileTansBtnClicked(QString widgetName, QString buttonName)
|
|||
it.value()->pressFromHtml(buttonName);
|
||||
else
|
||||
qDebug() << "no filetransferwidget: " << id;
|
||||
|
||||
// QMessageBox::information(nullptr, message, message);
|
||||
}
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
|
||||
#include "genericchatform.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QScrollBar>
|
||||
#include <QFileDialog>
|
||||
#include <QTextStream>
|
||||
#include "smileypack.h"
|
||||
#include "widget/emoticonswidget.h"
|
||||
#include "style.h"
|
||||
|
@ -28,7 +26,6 @@
|
|||
GenericChatForm::GenericChatForm(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
lockSliderToBottom = true;
|
||||
curRow = 0;
|
||||
|
||||
mainWidget = new QWidget(); headWidget = new QWidget();
|
||||
|
@ -40,9 +37,9 @@ GenericChatForm::GenericChatForm(QObject *parent) :
|
|||
QVBoxLayout *mainLayout = new QVBoxLayout();
|
||||
QVBoxLayout *footButtonsSmall = new QVBoxLayout(), *volMicLayout = new QVBoxLayout();
|
||||
|
||||
newChatForm = new ChatAreaWidget();
|
||||
newChatForm->document()->setDefaultStyleSheet(Style::get(":ui/chatArea/innerStyle.css"));
|
||||
newChatForm->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css"));
|
||||
chatWidget = new ChatAreaWidget();
|
||||
chatWidget->document()->setDefaultStyleSheet(Style::get(":ui/chatArea/innerStyle.css"));
|
||||
chatWidget->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css"));
|
||||
|
||||
msgEdit = new ChatTextEdit();
|
||||
|
||||
|
@ -102,7 +99,7 @@ GenericChatForm::GenericChatForm(QObject *parent) :
|
|||
micButton->setStyleSheet(micButtonStylesheet);
|
||||
|
||||
mainWidget->setLayout(mainLayout);
|
||||
mainLayout->addWidget(newChatForm);
|
||||
mainLayout->addWidget(chatWidget);
|
||||
mainLayout->addLayout(mainFootLayout);
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
|
@ -136,7 +133,7 @@ GenericChatForm::GenericChatForm(QObject *parent) :
|
|||
emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
connect(emoteButton, SIGNAL(clicked()), this, SLOT(onEmoteButtonClicked()));
|
||||
connect(newChatForm, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
connect(chatWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
void GenericChatForm::setName(const QString &newName)
|
||||
|
@ -173,7 +170,7 @@ void GenericChatForm::onSaveLogClicked()
|
|||
return;
|
||||
|
||||
QString log;
|
||||
log = newChatForm->toPlainText();
|
||||
log = chatWidget->toPlainText();
|
||||
|
||||
file.write(log.toUtf8());
|
||||
file.close();
|
||||
|
@ -182,19 +179,18 @@ void GenericChatForm::onSaveLogClicked()
|
|||
void GenericChatForm::addMessage(QString author, QString message, QDateTime datetime)
|
||||
{
|
||||
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
||||
bool isMe = (author == Widget::getInstance()->getUsername());
|
||||
|
||||
if (previousName == author)
|
||||
messages.append(new MessageAction("", message, date));
|
||||
else messages.append(new MessageAction(author , message, date));
|
||||
chatWidget->insertMessage(new MessageAction("", message, date, isMe));
|
||||
else chatWidget->insertMessage(new MessageAction(author , message, date, isMe));
|
||||
previousName = author;
|
||||
updateChatContent();
|
||||
}
|
||||
|
||||
GenericChatForm::~GenericChatForm()
|
||||
{
|
||||
delete mainWidget;
|
||||
delete headWidget;
|
||||
for (ChatAction *it : messages)
|
||||
delete it;
|
||||
}
|
||||
|
||||
void GenericChatForm::onEmoteButtonClicked()
|
||||
|
@ -223,27 +219,3 @@ void GenericChatForm::onEmoteInsertRequested(QString str)
|
|||
|
||||
msgEdit->setFocus(); // refocus so that we can continue typing
|
||||
}
|
||||
|
||||
QString GenericChatForm::getHtmledMessages()
|
||||
{
|
||||
QString res("<table width=100%>\n");
|
||||
|
||||
for (ChatAction *it : messages)
|
||||
{
|
||||
res += it->getHtml();
|
||||
}
|
||||
res += "</table>";
|
||||
return res;
|
||||
}
|
||||
|
||||
void GenericChatForm::updateChatContent()
|
||||
{
|
||||
QScrollBar* scroll = newChatForm->verticalScrollBar();
|
||||
lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
|
||||
|
||||
newChatForm->setHtml(getHtmledMessages());
|
||||
if (lockSliderToBottom)
|
||||
sliderPosition = scroll->maximum();
|
||||
|
||||
scroll->setValue(sliderPosition);
|
||||
}
|
||||
|
|
|
@ -18,19 +18,15 @@
|
|||
#define GENERICCHATFORM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QLabel>
|
||||
#include <QPoint>
|
||||
#include <QScrollArea>
|
||||
#include <QTime>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QGridLayout>
|
||||
|
||||
#include "widget/chatareawidget.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
#include "widget/tool/chataction.h"
|
||||
|
||||
// Spacing in px inserted when the author of the last message changes
|
||||
#define AUTHOR_CHANGE_SPACING 5
|
||||
|
@ -60,7 +56,6 @@ protected slots:
|
|||
void onSaveLogClicked();
|
||||
void onEmoteButtonClicked();
|
||||
void onEmoteInsertRequested(QString str);
|
||||
void updateChatContent();
|
||||
|
||||
protected:
|
||||
QLabel *nameLabel, *avatarLabel;
|
||||
|
@ -70,15 +65,8 @@ protected:
|
|||
ChatTextEdit *msgEdit;
|
||||
QPushButton *sendButton;
|
||||
QString previousName;
|
||||
ChatAreaWidget *newChatForm;
|
||||
ChatAreaWidget *chatWidget;
|
||||
int curRow;
|
||||
bool lockSliderToBottom;
|
||||
int sliderPosition;
|
||||
|
||||
QList<ChatAction*> messages;
|
||||
|
||||
private:
|
||||
QString getHtmledMessages();
|
||||
};
|
||||
|
||||
#endif // GENERICCHATFORM_H
|
||||
|
|
|
@ -41,8 +41,10 @@ QString ChatAction::QImage2base64(const QImage &img)
|
|||
|
||||
QString ChatAction::wrapName(const QString &name)
|
||||
{
|
||||
QString res = "<td><div class=name>" + name + "</div></td>\n";
|
||||
return res;
|
||||
if (isMe)
|
||||
return QString("<td><div class=name_me>" + name + "</div></td>\n");
|
||||
else
|
||||
return QString("<td><div class=name>" + name + "</div></td>\n");
|
||||
}
|
||||
|
||||
QString ChatAction::wrapDate(const QString &date)
|
||||
|
@ -63,7 +65,8 @@ QString ChatAction::wrapWholeLine(const QString &line)
|
|||
return res;
|
||||
}
|
||||
|
||||
MessageAction::MessageAction(const QString &author, const QString &message, const QString &date)
|
||||
MessageAction::MessageAction(const QString &author, const QString &message, const QString &date, const bool &me) :
|
||||
ChatAction(me)
|
||||
{
|
||||
QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message));
|
||||
|
||||
|
@ -86,7 +89,8 @@ QString MessageAction::getHtml()
|
|||
return content;
|
||||
}
|
||||
|
||||
FileTransferAction::FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date) :
|
||||
FileTransferAction::FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me) :
|
||||
ChatAction(me),
|
||||
sender(author),
|
||||
timestamp(date)
|
||||
{
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
class ChatAction
|
||||
{
|
||||
public:
|
||||
ChatAction(const bool &me) : isMe(me) {;}
|
||||
virtual ~ChatAction(){;}
|
||||
virtual QString getHtml() = 0;
|
||||
|
||||
|
@ -34,12 +35,15 @@ protected:
|
|||
virtual QString wrapDate(const QString &date);
|
||||
virtual QString wrapMessage(const QString &message);
|
||||
virtual QString wrapWholeLine(const QString &line);
|
||||
|
||||
private:
|
||||
bool isMe;
|
||||
};
|
||||
|
||||
class MessageAction : public ChatAction
|
||||
{
|
||||
public:
|
||||
MessageAction(const QString &author, const QString &message, const QString &date);
|
||||
MessageAction(const QString &author, const QString &message, const QString &date, const bool &me);
|
||||
virtual ~MessageAction(){;}
|
||||
virtual QString getHtml();
|
||||
|
||||
|
@ -50,7 +54,7 @@ private:
|
|||
class FileTransferAction : public ChatAction
|
||||
{
|
||||
public:
|
||||
FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date);
|
||||
FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me);
|
||||
virtual ~FileTransferAction();
|
||||
virtual QString getHtml();
|
||||
virtual QString wrapMessage(const QString &message);
|
||||
|
|
Loading…
Reference in New Issue
Block a user