From 3a346789007d50256daaeae265bf0af848fe2e6c Mon Sep 17 00:00:00 2001 From: krepa098 Date: Wed, 12 Nov 2014 16:45:24 +0100 Subject: [PATCH] progress --- res.qrc | 1 + src/chatlog/chatline.cpp | 12 +++++++ src/chatlog/chatline.h | 1 + src/chatlog/chatlog.cpp | 36 ++++++-------------- src/chatlog/chatlog.h | 8 ++--- src/chatlog/chatmessage.cpp | 16 ++++++++- src/chatlog/chatmessage.h | 6 +++- src/chatlog/content/spinner.cpp | 2 +- src/widget/form/chatform.cpp | 49 ++++++++++++++-------------- src/widget/form/chatform.h | 4 +-- src/widget/form/genericchatform.cpp | 28 ++++++---------- src/widget/form/genericchatform.h | 6 ++-- ui/chatArea/spinner.png | Bin 0 -> 1044 bytes 13 files changed, 90 insertions(+), 79 deletions(-) create mode 100644 ui/chatArea/spinner.png diff --git a/res.qrc b/res.qrc index 239df056e..4e2db2712 100644 --- a/res.qrc +++ b/res.qrc @@ -42,6 +42,7 @@ ui/callButton/callButtonYellowPressed.png ui/chatArea/chatArea.css ui/chatArea/innerStyle.css + ui/chatArea/spinner.png ui/chatArea/scrollBarDownArrow.png ui/chatArea/scrollBarDownArrowHover.png ui/chatArea/scrollBarDownArrowPressed.png diff --git a/src/chatlog/chatline.cpp b/src/chatlog/chatline.cpp index a531b42f4..39254da0f 100644 --- a/src/chatlog/chatline.cpp +++ b/src/chatlog/chatline.cpp @@ -102,6 +102,18 @@ void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt) content << item; } +void ChatLine::replaceContent(int col, ChatLineContent *lineContent) +{ + if(col >= 0 && col < content.size() && lineContent) + { + scene->removeItem(content[col]); + delete content[col]; + + content[col] = lineContent; + scene->addItem(content[col]); + } +} + void ChatLine::layout(qreal w, QPointF scenePos) { width = w; diff --git a/src/chatlog/chatline.h b/src/chatlog/chatline.h index 13038b434..1354dab5e 100644 --- a/src/chatlog/chatline.h +++ b/src/chatlog/chatline.h @@ -46,6 +46,7 @@ public: virtual QRectF boundingSceneRect() const; void addColumn(ChatLineContent* item, ColumnFormat fmt); + void replaceContent(int col, ChatLineContent* lineContent); void layout(qreal width, QPointF scenePos); void layout(QPointF scenePos); diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index e3f8c2d1f..d4158778a 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -1,5 +1,6 @@ #include "chatlog.h" #include "chatline.h" +#include "chatmessage.h" #include "chatlinecontent.h" #include "chatlinecontentproxy.h" #include "content/text.h" @@ -52,26 +53,21 @@ ChatLog::~ChatLog() delete line; } -void ChatLog::addTextLine(const QString& sender, const QString& text, QDateTime timestamp) +ChatMessage* ChatLog::addChatMessage(const QString& sender, ChatLineContent* content) { - ChatLine* line = new ChatLine(scene); - - line->addColumn(new Text(sender, true), ColumnFormat(75.0, ColumnFormat::FixedSize, 1, ColumnFormat::Right)); - line->addColumn(new Text(text), ColumnFormat(1.0, ColumnFormat::VariableSize)); - line->addColumn(new Text(timestamp.toString("hh:mm")), ColumnFormat(50.0, ColumnFormat::FixedSize, 1)); - + ChatMessage* line = new ChatMessage(scene, sender, content); insertChatline(line); + + return line; } -void ChatLog::addWidgetLine(const QString& sender, QDateTime timestamp) +ChatMessage* ChatLog::addChatMessage(const QString& sender, ChatLineContent* content, const QDateTime& timestamp) { - ChatLine* line = new ChatLine(scene); - - line->addColumn(new Text(sender, true), ColumnFormat(75.0, ColumnFormat::FixedSize, 1)); - line->addColumn(new ChatLineContentProxy(new FileTransferWidget()), ColumnFormat(1.0, ColumnFormat::VariableSize)); - line->addColumn(new Spinner(QSizeF(16, 16)), ColumnFormat(50.0, ColumnFormat::FixedSize, 1, ColumnFormat::Right)); - + ChatMessage* line = new ChatMessage(scene, sender, content); + line->markAsSent(timestamp); insertChatline(line); + + return line; } void ChatLog::clearSelection() @@ -86,18 +82,6 @@ void ChatLog::clearSelection() selLastCol = -1; } -void ChatLog::dbgPopulate() -{ - for(int i = 0; i < 2000; i++) - addTextLine("Jemp longlong name foo moth", "Line " + QString::number(i) + - " Lorem ipsum Hello dolor sit amet, " - "consectetur adipisicing elit, sed do eiusmod " - "tempor incididunt ut labore et dolore magna " - "aliqua. Ut enim ad minim veniam, quis nostrud " - "exercitation ullamco laboris nisi ut aliquip ex " - "ea commodo consequat. "); -} - QRect ChatLog::getVisibleRect() const { return mapToScene(viewport()->rect()).boundingRect().toRect(); diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 5a9b31fb4..a4ff93c57 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -7,6 +7,7 @@ class QGraphicsScene; class ChatLine; class ChatLineContent; +class ChatMessage; class ChatLog : public QGraphicsView { @@ -15,8 +16,9 @@ public: explicit ChatLog(QWidget* parent = 0); virtual ~ChatLog(); - void addTextLine(const QString& sender, const QString& text, QDateTime timestamp = QDateTime::currentDateTime()); - void addWidgetLine(const QString& sender, QDateTime timestamp = QDateTime::currentDateTime()); + ChatMessage* addChatMessage(const QString& sender, ChatLineContent* content, const QDateTime& timestamp); + ChatMessage* addChatMessage(const QString& sender, ChatLineContent* content); + void insertChatline(ChatLine* l); void clearSelection(); @@ -24,8 +26,6 @@ public: void copySelectedText() const; QString getSelectedText() const; - void dbgPopulate(); - signals: public slots: diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index a6350843e..1136d453c 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -1,5 +1,19 @@ #include "chatmessage.h" +#include "content/text.h" +#include "content/spinner.h" -ChatMessage::ChatMessage() +#include + +ChatMessage::ChatMessage(QGraphicsScene *scene, const QString& author ,ChatLineContent *content) + : ChatLine(scene) { + addColumn(new Text(author, true), ColumnFormat(75.0, ColumnFormat::FixedSize, 1, ColumnFormat::Right)); + addColumn(content, ColumnFormat(1.0, ColumnFormat::VariableSize)); + addColumn(new Spinner(QSizeF(16, 16)), ColumnFormat(50.0, ColumnFormat::FixedSize, 1, ColumnFormat::Right)); +} + +void ChatMessage::markAsSent(const QDateTime &time) +{ + // remove the spinner and replace it by $time + replaceContent(2, new Text(time.toString("hh:mm"), true)); } diff --git a/src/chatlog/chatmessage.h b/src/chatlog/chatmessage.h index a0d487292..f61b744b5 100644 --- a/src/chatlog/chatmessage.h +++ b/src/chatlog/chatmessage.h @@ -3,10 +3,14 @@ #include "chatline.h" +class QGraphicsScene; + class ChatMessage : public ChatLine { public: - ChatMessage(); + ChatMessage(QGraphicsScene* scene, const QString &author, ChatLineContent* content); + + void markAsSent(const QDateTime& time); }; #endif // CHATMESSAGE_H diff --git a/src/chatlog/content/spinner.cpp b/src/chatlog/content/spinner.cpp index 67330f862..39d15c772 100644 --- a/src/chatlog/content/spinner.cpp +++ b/src/chatlog/content/spinner.cpp @@ -6,7 +6,7 @@ Spinner::Spinner(QSizeF Size) : size(Size) { - pmap.load(":/media/spinner.png"); + pmap.load(":/ui/chatArea/spinner.png"); timer.setInterval(33); // 30Hz timer.setSingleShot(false); diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 23b8d9da7..0245e8343 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -38,6 +38,7 @@ #include "src/misc/style.h" #include "src/misc/settings.h" #include "src/misc/cstring.h" +#include "src/chatlog/chatmessage.h" ChatForm::ChatForm(Friend* chatFriend) : f(chatFriend) @@ -119,7 +120,8 @@ void ChatForm::onSendTriggered() int id = HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, qt_msg_hist, Core::getInstance()->getSelfId().publicKey, timestamp, status); - //MessageActionPtr ma = addSelfMessage(msg, isAction, timestamp, false); + + ChatMessage* ma = addSelfMessage(msg, isAction, timestamp, false); int rec; if (isAction) @@ -127,7 +129,7 @@ void ChatForm::onSendTriggered() else rec = Core::getInstance()->sendMessage(f->getFriendID(), msg); - //registerReceipt(rec, id, ma); + registerReceipt(rec, id, ma); } msgEdit->clear(); @@ -842,29 +844,28 @@ QString ChatForm::secondsToDHMS(quint32 duration) return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds); } -//void ChatForm::registerReceipt(int receipt, int messageID, MessageActionPtr msg) -//{ -// receipts[receipt] = messageID; -// undeliveredMsgs[messageID] = msg; -//} +void ChatForm::registerReceipt(int receipt, int messageID, ChatMessage* msg) +{ + receipts[receipt] = messageID; + undeliveredMsgs[messageID] = msg; +} -//void ChatForm::dischargeReceipt(int receipt) -//{ -// auto it = receipts.find(receipt); -// if (it != receipts.end()) -// { -// int mID = it.value(); -// auto msgIt = undeliveredMsgs.find(mID); -// if (msgIt != undeliveredMsgs.end()) -// { -// HistoryKeeper::getInstance()->markAsSent(mID); -// msgIt.value()->markAsSent(); -// msgIt.value()->featureUpdate(); -// undeliveredMsgs.erase(msgIt); -// } -// receipts.erase(it); -// } -//} +void ChatForm::dischargeReceipt(int receipt) +{ + auto it = receipts.find(receipt); + if (it != receipts.end()) + { + int mID = it.value(); + auto msgIt = undeliveredMsgs.find(mID); + if (msgIt != undeliveredMsgs.end()) + { + HistoryKeeper::getInstance()->markAsSent(mID); + msgIt.value()->markAsSent(QDateTime::currentDateTime()); + undeliveredMsgs.erase(msgIt); + } + receipts.erase(it); + } +} void ChatForm::clearReciepts() { diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index faf1b5400..2f9ee98d5 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -89,7 +89,7 @@ protected: // drag & drop void dragEnterEvent(QDragEnterEvent* ev); void dropEvent(QDropEvent* ev); - //TODO: void registerReceipt(int receipt, int messageID, MessageActionPtr msg); + void registerReceipt(int receipt, int messageID, ChatMessage* msg); private: Friend* f; @@ -107,7 +107,7 @@ private: void stopCounter(); QString secondsToDHMS(quint32 duration); QHash receipts; - //TODO: QMap undeliveredMsgs; + QMap undeliveredMsgs; }; #endif // CHATFORM_H diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 785b63354..adbf37767 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -28,7 +28,7 @@ #include "src/core.h" #include "src/friendlist.h" #include "src/friend.h" -#include "src/chatlog/chatlog.h" +#include "src/chatlog/content/text.h" GenericChatForm::GenericChatForm(QWidget *parent) : QWidget(parent), @@ -202,24 +202,16 @@ void GenericChatForm::onSaveLogClicked() // chatWidget->insertMessage(ca); //} -//MessageActionPtr GenericChatForm::addMessage(const ToxID& author, const QString &message, bool isAction, -// const QDateTime &datetime, bool isSent) -//{ -// MessageActionPtr ca = genMessageActionAction(author, message, isAction, datetime); -// if (isSent) -// ca->markAsSent(); -// chatWidget->insertMessage(ca); -// return ca; -//} +ChatMessage* GenericChatForm::addMessage(const ToxID& author, const QString &message, bool isAction, + const QDateTime &datetime, bool isSent) +{ + return chatWidget->addChatMessage(Core::getInstance()->getPeerName(author), new Text(message), datetime); +} -//MessageActionPtr GenericChatForm::addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent) -//{ -// MessageActionPtr ca = genSelfActionAction(message, isAction, datetime); -// if (isSent) -// ca->markAsSent(); -// chatWidget->insertMessage(ca); -// return ca; -//} +ChatMessage* GenericChatForm::addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent) +{ + return chatWidget->addChatMessage(Core::getInstance()->getUsername(), new Text(message)); +} /** * @deprecated The only reason it's still alive is because the groupchat API is a bit limited diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 9d967125a..29828ffb8 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -22,6 +22,7 @@ #include #include #include "src/corestructs.h" +#include "src/chatlog/chatlog.h" // Spacing in px inserted when the author of the last message changes #define AUTHOR_CHANGE_SPACING 5 // why the hell is this a thing? surely the different font is enough? @@ -32,6 +33,7 @@ class QPushButton; class CroppingLabel; class ChatTextEdit; class ChatLog; +class ChatMessage; class MaskablePixmapWidget; struct ToxID; @@ -49,8 +51,8 @@ public: virtual void show(Ui::MainWindow &ui); void addMessage(const QString& author, const QString &message, bool isAction, const QDateTime &datetime); ///< Deprecated -// TODO: MessageActionPtr addMessage(const ToxID& author, const QString &message, bool isAction, const QDateTime &datetime, bool isSent); -// MessageActionPtr addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent); + ChatMessage* addMessage(const ToxID& author, const QString &message, bool isAction, const QDateTime &datetime, bool isSent); + ChatMessage* addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent); void addSystemInfoMessage(const QString &message, const QString &type, const QDateTime &datetime); void addAlertMessage(const QString& author, QString message, QDateTime datetime); ///< Deprecated void addAlertMessage(const ToxID& author, QString message, QDateTime datetime); diff --git a/ui/chatArea/spinner.png b/ui/chatArea/spinner.png new file mode 100644 index 0000000000000000000000000000000000000000..22a1d8b2ee9eb49dbb9b1701ea73deabe642ab3e GIT binary patch literal 1044 zcmV+v1nc{WP)Gc$|L)Rbo4Kq{5Gtz0foh{!X*wkGNZBJ!4qWU|@pFKq*4GMU)o;^Hyj z72xJ3jO+EUs!o>6<>Rxnvr8=jjE;_OFPF<70Q=i8uGeqY+J4{nzi$d4l}g=FsZ>4# z?%4$Ms;+i)bnKg&n)<0Bfa|(90bc+QHYj#YM9!+}8Q?5%tE%>i$S$C-!MO!%?LOc4 zFE#=w0EZ(A6jk-5rKP3!3WdV8umsn2p9IE%MsQrJA`YGc zju>MuMa0+1^SooK`g%n8HDgR>9e{|4>$>x*x+~mV1o6V*JSZhOPx2it0RREzgJEAXaK0vWpTwtX;)dTFg z(Ew|$*z>$uRXtJ{4^;J$d_F(lu0cAT?pj`6J}Dx%*Y2z8l|&-3x3&|W2sz&&B6I0< zx~pA)QmOQ+i0lRKs$C*-Vq#*VvIfxG+xsDKKBUHdrBW$ssx_47dHt-6=6V%@H=%AE zyRLf}D1;Rgk-5&!&KD;qCyULPCzHwNL}Uht*T+=#jeI^oz5!qr;#1(Uh`N_VWH6V@ zos2Rb85!AWtvw1n8PF~K>FQH_4&2fJqE-EEt$o7x{V!`bov_SoHhT`(!^%x(GqemG zsyB}W05HZ}s8lKs18)PiO=AV#2X-1`PK6~jbv5%m?*Uak4jd%<`>uCZ{a8fCjWORe z%4-Uss-dBw-grEIsP1yQ4fvIs%c