mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge branch 'chatlog_merge_v3'
Conflicts: src/chatlog/chatlog.h
This commit is contained in:
commit
73e51865e7
|
@ -610,6 +610,11 @@ void ChatLog::selectAll()
|
||||||
updateMultiSelectionRect();
|
updateMultiSelectionRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatLog::forceRelayout()
|
||||||
|
{
|
||||||
|
startResizeWorker();
|
||||||
|
}
|
||||||
|
|
||||||
void ChatLog::checkVisibility()
|
void ChatLog::checkVisibility()
|
||||||
{
|
{
|
||||||
if(lines.empty())
|
if(lines.empty())
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
void setTypingNotificationVisible(bool visible);
|
void setTypingNotificationVisible(bool visible);
|
||||||
void scrollToLine(ChatLine::Ptr line);
|
void scrollToLine(ChatLine::Ptr line);
|
||||||
void selectAll();
|
void selectAll();
|
||||||
|
void forceRelayout();
|
||||||
|
|
||||||
QString getSelectedText() const;
|
QString getSelectedText() const;
|
||||||
|
|
||||||
|
@ -138,7 +139,7 @@ private:
|
||||||
ChatLine::Ptr workerAnchorLine;
|
ChatLine::Ptr workerAnchorLine;
|
||||||
|
|
||||||
// layout
|
// layout
|
||||||
QMargins margins = QMargins(10.0,10.0,10.0,10.0);
|
QMargins margins = QMargins(10,10,10,10);
|
||||||
qreal lineSpacing = 5.0f;
|
qreal lineSpacing = 5.0f;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,11 +35,14 @@ ChatMessage::ChatMessage()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QString &rawMessage, bool isAction, bool alert, bool isMe, const QDateTime &date)
|
ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QString &rawMessage, MessageType type, bool isMe, const QDateTime &date)
|
||||||
{
|
{
|
||||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
||||||
|
|
||||||
QString text = toHtmlChars(rawMessage);
|
QString text = toHtmlChars(rawMessage);
|
||||||
|
QString senderText = sender;
|
||||||
|
|
||||||
|
const QColor actionColor = QColor("#1818FF"); // has to match the color in innerStyle.css (div.action)
|
||||||
|
|
||||||
//smileys
|
//smileys
|
||||||
if(Settings::getInstance().getUseEmoticons())
|
if(Settings::getInstance().getUseEmoticons())
|
||||||
|
@ -48,18 +51,23 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt
|
||||||
//quotes (green text)
|
//quotes (green text)
|
||||||
text = detectQuotes(detectAnchors(text));
|
text = detectQuotes(detectAnchors(text));
|
||||||
|
|
||||||
if(isAction)
|
switch(type)
|
||||||
{
|
{
|
||||||
text = QString("<div class=action>%1 %2</div>").arg(sender, text);
|
case ACTION:
|
||||||
|
senderText = "*";
|
||||||
|
text = wrapDiv(QString("%1 %2").arg(sender, text), "action");
|
||||||
msg->setAsAction();
|
msg->setAsAction();
|
||||||
}
|
break;
|
||||||
else if(alert)
|
case ALERT:
|
||||||
{
|
text = wrapDiv(text, "alert");
|
||||||
text = "<div class=alert>" + text + "</div>";
|
break;
|
||||||
|
default:
|
||||||
|
text = wrapDiv(text, "msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
msg->addColumn(new Text(isAction ? "<div class=action>*</div>" : sender, isMe ? Style::getFont(Style::BigBold) : Style::getFont(Style::Big), isAction ? false : true, sender), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
// Note: Eliding cannot be enabled for RichText items. (QTBUG-17207)
|
||||||
msg->addColumn(new Text(text, Style::getFont(Style::Big), false, isAction ? QString("*%1 %2*").arg(sender, rawMessage) : rawMessage), ColumnFormat(1.0, ColumnFormat::VariableSize));
|
msg->addColumn(new Text(senderText, isMe ? Style::getFont(Style::BigBold) : Style::getFont(Style::Big), true, sender, type == ACTION ? actionColor : Qt::black), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||||
|
msg->addColumn(new Text(text, Style::getFont(Style::Big), false, type == ACTION ? QString("*%1 %2*").arg(sender, rawMessage) : rawMessage), ColumnFormat(1.0, ColumnFormat::VariableSize));
|
||||||
msg->addColumn(new Spinner(":/ui/chatArea/spinner.svg", QSize(16, 16), 360.0/1.6), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
msg->addColumn(new Spinner(":/ui/chatArea/spinner.svg", QSize(16, 16), 360.0/1.6), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||||
|
|
||||||
if(!date.isNull())
|
if(!date.isNull())
|
||||||
|
@ -219,3 +227,8 @@ QString ChatMessage::toHtmlChars(const QString &str)
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ChatMessage::wrapDiv(const QString &str, const QString &div)
|
||||||
|
{
|
||||||
|
return QString("<div class=%1>%2</div>").arg(div, str);
|
||||||
|
}
|
||||||
|
|
|
@ -35,9 +35,16 @@ public:
|
||||||
TYPING,
|
TYPING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum MessageType
|
||||||
|
{
|
||||||
|
NORMAL,
|
||||||
|
ACTION,
|
||||||
|
ALERT,
|
||||||
|
};
|
||||||
|
|
||||||
ChatMessage();
|
ChatMessage();
|
||||||
|
|
||||||
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage, bool isAction, bool alert, bool isMe, const QDateTime& date = QDateTime());
|
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage, MessageType type, bool isMe, const QDateTime& date = QDateTime());
|
||||||
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type, const QDateTime& date);
|
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type, const QDateTime& date);
|
||||||
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, ToxFile file, bool isMe, const QDateTime& date);
|
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, ToxFile file, bool isMe, const QDateTime& date);
|
||||||
static ChatMessage::Ptr createTypingNotification();
|
static ChatMessage::Ptr createTypingNotification();
|
||||||
|
@ -54,6 +61,7 @@ protected:
|
||||||
static QString detectAnchors(const QString& str);
|
static QString detectAnchors(const QString& str);
|
||||||
static QString detectQuotes(const QString& str);
|
static QString detectQuotes(const QString& str);
|
||||||
static QString toHtmlChars(const QString& str);
|
static QString toHtmlChars(const QString& str);
|
||||||
|
static QString wrapDiv(const QString& str, const QString& div);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool action = false;
|
bool action = false;
|
||||||
|
|
|
@ -306,6 +306,8 @@ void FileTransferWidget::onFileTransferPaused(ToxFile file)
|
||||||
|
|
||||||
void FileTransferWidget::onFileTransferFinished(ToxFile file)
|
void FileTransferWidget::onFileTransferFinished(ToxFile file)
|
||||||
{
|
{
|
||||||
|
static const QStringList openExtensions = { "png", "jpeg", "jpg", "gif", "zip", "rar" };
|
||||||
|
|
||||||
if(fileInfo != file)
|
if(fileInfo != file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -316,14 +318,10 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file)
|
||||||
setupButtons();
|
setupButtons();
|
||||||
hideWidgets();
|
hideWidgets();
|
||||||
|
|
||||||
static const QStringList openExtensions = { "png", "jpeg", "jpg", "gif", "zip", "rar" };
|
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/yes.svg"));
|
||||||
|
ui->topButton->setObjectName("ok");
|
||||||
if(openExtensions.contains(QFileInfo(file.fileName).suffix()))
|
ui->topButton->setEnabled(openExtensions.contains(QFileInfo(file.fileName).suffix()));
|
||||||
{
|
ui->topButton->show();
|
||||||
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/yes.svg"));
|
|
||||||
ui->topButton->setObjectName("ok");
|
|
||||||
ui->topButton->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
// preview
|
// preview
|
||||||
if(fileInfo.direction == ToxFile::RECEIVING)
|
if(fileInfo.direction == ToxFile::RECEIVING)
|
||||||
|
|
|
@ -28,10 +28,11 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QTextFragment>
|
#include <QTextFragment>
|
||||||
|
|
||||||
Text::Text(const QString& txt, QFont font, bool enableElide, const QString &rwText)
|
Text::Text(const QString& txt, QFont font, bool enableElide, const QString &rwText, const QColor c)
|
||||||
: rawText(rwText)
|
: rawText(rwText)
|
||||||
, elide(enableElide)
|
, elide(enableElide)
|
||||||
, defFont(font)
|
, defFont(font)
|
||||||
|
, color(c)
|
||||||
{
|
{
|
||||||
setText(txt);
|
setText(txt);
|
||||||
setAcceptedMouseButtons(Qt::LeftButton);
|
setAcceptedMouseButtons(Qt::LeftButton);
|
||||||
|
@ -52,9 +53,6 @@ void Text::setText(const QString& txt)
|
||||||
|
|
||||||
void Text::setWidth(qreal w)
|
void Text::setWidth(qreal w)
|
||||||
{
|
{
|
||||||
if(w == width)
|
|
||||||
return;
|
|
||||||
|
|
||||||
width = w;
|
width = w;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
|
||||||
|
@ -171,6 +169,7 @@ void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWid
|
||||||
sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160));
|
sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160));
|
||||||
sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black);
|
sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black);
|
||||||
ctx.selections.append(sel);
|
ctx.selections.append(sel);
|
||||||
|
ctx.palette.setColor(QPalette::Text, color);
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
doc->documentLayout()->draw(painter, ctx);
|
doc->documentLayout()->draw(painter, ctx);
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Text : public ChatLineContent
|
||||||
public:
|
public:
|
||||||
// txt: may contain html code
|
// txt: may contain html code
|
||||||
// rawText: does not contain html code
|
// rawText: does not contain html code
|
||||||
Text(const QString& txt = "", QFont font = QFont(), bool enableElide = false, const QString& rawText = QString());
|
Text(const QString& txt = "", QFont font = QFont(), bool enableElide = false, const QString& rawText = QString(), const QColor c = Qt::black);
|
||||||
virtual ~Text();
|
virtual ~Text();
|
||||||
|
|
||||||
void setText(const QString& txt);
|
void setText(const QString& txt);
|
||||||
|
@ -83,6 +83,7 @@ private:
|
||||||
qreal ascent = 0.0;
|
qreal ascent = 0.0;
|
||||||
qreal width = 0.0;
|
qreal width = 0.0;
|
||||||
QFont defFont;
|
QFont defFont;
|
||||||
|
QColor color;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -785,7 +785,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
||||||
if (msgDate > lastDate)
|
if (msgDate > lastDate)
|
||||||
{
|
{
|
||||||
lastDate = msgDate;
|
lastDate = msgDate;
|
||||||
historyMessages.append(ChatMessage::createChatInfoMessage(msgDate.toString(), ChatMessage::INFO, QDateTime::currentDateTime()));
|
historyMessages.append(ChatMessage::createChatInfoMessage(msgDate.toString(), ChatMessage::INFO, QDateTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show each messages
|
// Show each messages
|
||||||
|
@ -795,7 +795,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
||||||
|
|
||||||
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
|
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
|
||||||
isAction ? it.message.right(it.message.length() - 4) : it.message,
|
isAction ? it.message.right(it.message.length() - 4) : it.message,
|
||||||
isAction, false,
|
isAction ? ChatMessage::ACTION : ChatMessage::NORMAL,
|
||||||
authorId.isMine(),
|
authorId.isMine(),
|
||||||
QDateTime());
|
QDateTime());
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,8 @@ GenericChatForm::GenericChatForm(QWidget *parent)
|
||||||
chatWidget = new ChatLog(this);
|
chatWidget = new ChatLog(this);
|
||||||
chatWidget->setBusyNotification(ChatMessage::createBusyNotification());
|
chatWidget->setBusyNotification(ChatMessage::createBusyNotification());
|
||||||
|
|
||||||
|
connect(&Settings::getInstance(), &Settings::emojiFontChanged, this, [this]() { chatWidget->forceRelayout(); });
|
||||||
|
|
||||||
msgEdit = new ChatTextEdit();
|
msgEdit = new ChatTextEdit();
|
||||||
|
|
||||||
sendButton = new QPushButton();
|
sendButton = new QPushButton();
|
||||||
|
@ -211,12 +213,12 @@ ChatMessage::Ptr GenericChatForm::addMessage(const ToxID& author, const QString
|
||||||
ChatMessage::Ptr msg;
|
ChatMessage::Ptr msg;
|
||||||
if(isAction)
|
if(isAction)
|
||||||
{
|
{
|
||||||
msg = ChatMessage::createChatMessage(authorStr, message, true, false, false);
|
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, false);
|
||||||
previousId.clear();
|
previousId.clear();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
msg = ChatMessage::createChatMessage(authorStr, message, false, false, author.isMine());
|
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, author.isMine());
|
||||||
if(author == previousId)
|
if(author == previousId)
|
||||||
msg->hideSender();
|
msg->hideSender();
|
||||||
|
|
||||||
|
@ -239,7 +241,7 @@ ChatMessage::Ptr GenericChatForm::addSelfMessage(const QString &message, bool is
|
||||||
void GenericChatForm::addAlertMessage(const ToxID &author, QString message, QDateTime datetime)
|
void GenericChatForm::addAlertMessage(const ToxID &author, QString message, QDateTime datetime)
|
||||||
{
|
{
|
||||||
QString authorStr = resolveToxID(author);
|
QString authorStr = resolveToxID(author);
|
||||||
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, false, true, author.isMine(), datetime);
|
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, author.isMine(), datetime);
|
||||||
insertChatMessage(msg);
|
insertChatMessage(msg);
|
||||||
|
|
||||||
if(author == previousId)
|
if(author == previousId)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
div.message {
|
div.msg {
|
||||||
color: @black;
|
color: @black;
|
||||||
font: @big;
|
font: @big;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user