From f1f42fc23776850f8ecb601ac9227f2c7d1efc8c Mon Sep 17 00:00:00 2001 From: krepa098 Date: Wed, 31 Dec 2014 13:42:06 +0100 Subject: [PATCH] innerStyle, groupchats --- src/chatlog/chatlog.cpp | 26 +++++++----- src/chatlog/chatlog.h | 4 +- src/chatlog/customtextdocument.cpp | 3 +- src/widget/form/chatform.cpp | 2 +- src/widget/form/genericchatform.cpp | 40 ++++++++++--------- src/widget/widget.cpp | 5 +-- ui/chatArea/innerStyle.css | 62 ----------------------------- 7 files changed, 44 insertions(+), 98 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 8447e1186..ca5b09e8a 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -77,20 +77,24 @@ ChatLog::~ChatLog() delete line; } -ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString &msg, bool self) +ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString &msg, bool self, bool alert) { + QString txt = SmileyPack::getInstance().smileyfied(msg); + if(alert) + txt = "
" + txt + "
"; + ChatMessage* line = new ChatMessage(scene, msg); - line->addColumn(new Text(sender, self ? Style::getFont(Style::MediumBold) : Style::getFont(Style::Medium), true), ColumnFormat(75.0, ColumnFormat::FixedSize, ColumnFormat::Right)); - line->addColumn(new Text(SmileyPack::getInstance().smileyfied(msg)), ColumnFormat(1.0, ColumnFormat::VariableSize)); + line->addColumn(new Text(sender, self ? Style::getFont(Style::BigBold) : Style::getFont(Style::Big), true), ColumnFormat(75.0, ColumnFormat::FixedSize, ColumnFormat::Right)); + line->addColumn(new Text(txt, Style::getFont(Style::Big)), ColumnFormat(1.0, ColumnFormat::VariableSize)); line->addColumn(new Spinner(QSizeF(16, 16)), ColumnFormat(50.0, ColumnFormat::FixedSize, ColumnFormat::Right)); insertChatline(line); return line; } -ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString& msg, const QDateTime& timestamp, bool self) +ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString& msg, const QDateTime& timestamp, bool self, bool alert) { - ChatMessage* line = addChatMessage(sender, msg, self); + ChatMessage* line = addChatMessage(sender, msg, self, alert); line->markAsSent(timestamp); return line; @@ -107,8 +111,8 @@ ChatMessage *ChatLog::addChatAction(const QString &sender, const QString &msg, c ChatMessage *ChatLog::addChatAction(const QString &sender, const QString &msg) { ChatMessage* line = new ChatMessage(scene, msg); - line->addColumn(new Text("", Style::getFont(Style::Medium), true), ColumnFormat(75.0, ColumnFormat::FixedSize, ColumnFormat::Right)); - line->addColumn(new Text("*" + sender + " " + SmileyPack::getInstance().smileyfied(msg) + ""), ColumnFormat(1.0, ColumnFormat::VariableSize)); + line->addColumn(new Text(""), ColumnFormat(75.0, ColumnFormat::FixedSize, ColumnFormat::Right)); + line->addColumn(new Text("
*" + sender + " " + SmileyPack::getInstance().smileyfied(msg) + "
", Style::getFont(Style::Big)), ColumnFormat(1.0, ColumnFormat::VariableSize)); line->addColumn(new Spinner(QSizeF(16, 16)), ColumnFormat(50.0, ColumnFormat::FixedSize, ColumnFormat::Right)); line->setAsAction(); @@ -120,8 +124,8 @@ ChatMessage *ChatLog::addSystemMessage(const QString &msg, const QDateTime& time { ChatMessage* line = new ChatMessage(scene, msg); line->addColumn(new Image(QSizeF(16, 16), ":/ui/chatArea/info.png"), ColumnFormat(75.0, ColumnFormat::FixedSize, ColumnFormat::Right)); - line->addColumn(new Text(msg), ColumnFormat(1.0, ColumnFormat::VariableSize)); - line->addColumn(new Text(timestamp.toString("hh:mm")), ColumnFormat(50.0, ColumnFormat::FixedSize, ColumnFormat::Right)); + line->addColumn(new Text(msg, Style::getFont(Style::Big)), ColumnFormat(1.0, ColumnFormat::VariableSize)); + line->addColumn(new Text(timestamp.toString("hh:mm"), Style::getFont(Style::Big)), ColumnFormat(50.0, ColumnFormat::FixedSize, ColumnFormat::Right)); insertChatline(line); return line; @@ -130,9 +134,9 @@ ChatMessage *ChatLog::addSystemMessage(const QString &msg, const QDateTime& time ChatMessage *ChatLog::addFileTransferMessage(const QString &sender, const ToxFile &file, const QDateTime& timestamp, bool self) { ChatMessage* line = new ChatMessage(scene, QString()); - line->addColumn(new Text(sender, self ? Style::getFont(Style::MediumBold) : Style::getFont(Style::Medium), true), ColumnFormat(75.0, ColumnFormat::FixedSize, ColumnFormat::Right)); + line->addColumn(new Text(sender, self ? Style::getFont(Style::BigBold) : Style::getFont(Style::Big), true), ColumnFormat(75.0, ColumnFormat::FixedSize, ColumnFormat::Right)); line->addColumn(new ChatLineContentProxy(new FileTransferWidget(0, file)), ColumnFormat(1.0, ColumnFormat::VariableSize)); - line->addColumn(new Text(timestamp.toString("hh:mm")), ColumnFormat(50.0, ColumnFormat::FixedSize, ColumnFormat::Right)); + line->addColumn(new Text(timestamp.toString("hh:mm"), Style::getFont(Style::Big)), ColumnFormat(50.0, ColumnFormat::FixedSize, ColumnFormat::Right)); insertChatline(line); return line; diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index c0bff59dc..7a6a5b14f 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -35,8 +35,8 @@ public: explicit ChatLog(QWidget* parent = 0); virtual ~ChatLog(); - ChatMessage* addChatMessage(const QString& sender, const QString& msg, const QDateTime& timestamp, bool self); - ChatMessage* addChatMessage(const QString& sender, const QString& msg, bool self); + ChatMessage* addChatMessage(const QString& sender, const QString& msg, const QDateTime& timestamp, bool self, bool alert); + ChatMessage* addChatMessage(const QString& sender, const QString& msg, bool self, bool alert); ChatMessage* addChatAction(const QString& sender, const QString& msg, const QDateTime& timestamp); ChatMessage* addChatAction(const QString& sender, const QString& msg); diff --git a/src/chatlog/customtextdocument.cpp b/src/chatlog/customtextdocument.cpp index 676fbae09..e75dd4225 100644 --- a/src/chatlog/customtextdocument.cpp +++ b/src/chatlog/customtextdocument.cpp @@ -16,6 +16,7 @@ #include "customtextdocument.h" #include "../misc/smileypack.h" +#include "../misc/style.h" #include #include @@ -23,7 +24,7 @@ CustomTextDocument::CustomTextDocument(QObject *parent) : QTextDocument(parent) { - + setDefaultStyleSheet(Style::getStylesheet(":ui/chatArea/innerStyle.css")); } QVariant CustomTextDocument::loadResource(int type, const QUrl &name) diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index f6f39eed1..a3e44ea11 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -716,7 +716,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered) // Show each messages ToxID id = ToxID::fromString(it.sender); - ChatMessage* msg = chatWidget->addChatMessage(Core::getInstance()->getPeerName(id), it.message, id.isMine()); + ChatMessage* msg = chatWidget->addChatMessage(Core::getInstance()->getPeerName(id), it.message, id.isMine(), false); if (it.isSent) { msg->markAsSent(msgDateTime); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index f44d92b63..50b9b6626 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -174,6 +174,18 @@ void GenericChatForm::show(Ui::MainWindow &ui) QWidget::show(); } +void GenericChatForm::addMessage(const QString &author, const QString &message, bool isAction, const QDateTime &datetime) +{ + if(!isAction) + { + chatWidget->addChatMessage(author, message, datetime, false, false); + } + else + { + chatWidget->addChatAction(author, message, datetime); + } +} + void GenericChatForm::onChatContextMenuRequested(QPoint pos) { QWidget* sender = (QWidget*)QObject::sender(); @@ -207,7 +219,7 @@ ChatMessage* GenericChatForm::addMessage(const ToxID& author, const QString &mes if(isAction) msg = chatWidget->addChatAction(authorStr, message); else - msg = chatWidget->addChatMessage(author != previousId ? authorStr : QString(), message, author.isMine()); + msg = chatWidget->addChatMessage(author != previousId ? authorStr : QString(), message, author.isMine(), false); if(isSent) msg->markAsSent(datetime); @@ -223,25 +235,11 @@ ChatMessage* GenericChatForm::addSelfMessage(const QString &message, bool isActi return addMessage(Core::getInstance()->getSelfId(), message, isAction, datetime, isSent); } -/** - * @deprecated The only reason it's still alive is because the groupchat API is a bit limited - */ -//void GenericChatForm::addAlertMessage(const QString& author, QString message, QDateTime datetime) -//{ -// QString date = datetime.toString(Settings::getInstance().getTimestampFormat()); -// AlertAction *alact = new AlertAction(author, message, date); -// alact->markAsSent(); -// chatWidget->insertMessage(ChatActionPtr(alact)); - -// previousId.publicKey = author; -//} - void GenericChatForm::addAlertMessage(const ToxID &author, QString message, QDateTime datetime) { -// QString authorStr = Core::getInstance()->getPeerName(author); -// QString date = datetime.toString(Settings::getInstance().getTimestampFormat()); -// chatWidget->insertMessage(ChatActionPtr(new AlertAction(authorStr, message, date))); -// previousId = author; + QString authorStr = Core::getInstance()->getPeerName(author); + chatWidget->addChatMessage(author != previousId ? authorStr : QString(), message, author.isMine(), true); + previousId = author; } void GenericChatForm::onEmoteButtonClicked() @@ -282,6 +280,12 @@ void GenericChatForm::addSystemInfoMessage(const QString &message, const QString chatWidget->addSystemMessage(message, datetime); } +void GenericChatForm::addAlertMessage(const QString &author, QString message, QDateTime datetime) +{ + ChatMessage* msg = chatWidget->addChatMessage(author, message, false, true); + msg->markAsSent(datetime); +} + //QString GenericChatForm::getElidedName(const QString& name) //{ // // update this whenever you change the font in innerStyle.css diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index ecdfd3144..013121bfb 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -900,10 +900,9 @@ void Widget::onGroupMessageReceived(int groupnumber, const QString& message, con bool targeted = (author != name) && message.contains(name, Qt::CaseInsensitive); if (targeted) - ;//TODO: g->chatForm->addAlertMessage(author, message, QDateTime::currentDateTime()); + g->chatForm->addAlertMessage(author, message, QDateTime::currentDateTime()); else - - ;//TODO: g->chatForm->addMessage(author, message, isAction, QDateTime::currentDateTime()); + g->chatForm->addMessage(author, message, isAction, QDateTime::currentDateTime()); if ((static_cast(g->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow()) { diff --git a/ui/chatArea/innerStyle.css b/ui/chatArea/innerStyle.css index dc1f46d73..63d833105 100644 --- a/ui/chatArea/innerStyle.css +++ b/ui/chatArea/innerStyle.css @@ -1,8 +1,3 @@ -div.name { - color: @black; - font: @bigBold; -} - div.message { color: @black; font: @big; @@ -13,60 +8,10 @@ div.action { font: @big; } -div.date { - color: @black; - font: @big; -} - -div.name_me { - color: @mediumGrey; - font: @big; -} - -div.message_me { - color: @black; - font: @big; -} - -div.date_me { - color: @black; - font: @big; -} - span.quote { color: #6bc260; } -div.green { - margin-top: 6px; - margin-bottom: 6px; - margin-left: 0px; - margin-right: 0px; - color: @white; - background-color: @green; - font: @small; -} - -div.silver { - margin-top: 6px; - margin-bottom: 6px; - margin-left: 0px; - margin-right: 0px; - color: @black; - background-color: @lightGrey; - font: @small; -} - -div.red { - margin-top: 6px; - margin-bottom: 6px; - margin-left: 0px; - margin-right: 0px; - color: @white; - background-color: @red; - font: @small; -} - div.alert { margin-left: 0px; margin-right: 0px; @@ -80,10 +25,3 @@ div.alert_name { background-color: @orange; font: @bigBold; } - -div.button { - margin-top: 0px; - margin-bottom: 0px; - margin-left: 0px; - color: @white; -}