1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
This commit is contained in:
krepa098 2014-11-12 16:45:24 +01:00
parent de52bad1db
commit 3a34678900
13 changed files with 90 additions and 79 deletions

View File

@ -42,6 +42,7 @@
<file>ui/callButton/callButtonYellowPressed.png</file>
<file>ui/chatArea/chatArea.css</file>
<file>ui/chatArea/innerStyle.css</file>
<file>ui/chatArea/spinner.png</file>
<file>ui/chatArea/scrollBarDownArrow.png</file>
<file>ui/chatArea/scrollBarDownArrowHover.png</file>
<file>ui/chatArea/scrollBarDownArrowPressed.png</file>

View File

@ -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;

View File

@ -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);

View File

@ -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 <b>Hello</b> 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();

View File

@ -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:

View File

@ -1,5 +1,19 @@
#include "chatmessage.h"
#include "content/text.h"
#include "content/spinner.h"
ChatMessage::ChatMessage()
#include <QDateTime>
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));
}

View File

@ -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

View File

@ -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);

View File

@ -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()
{

View File

@ -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<int, int> receipts;
//TODO: QMap<int, MessageActionPtr> undeliveredMsgs;
QMap<int, ChatMessage*> undeliveredMsgs;
};
#endif // CHATFORM_H

View File

@ -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

View File

@ -22,6 +22,7 @@
#include <QDateTime>
#include <QMenu>
#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);

BIN
ui/chatArea/spinner.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB