mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
progress
This commit is contained in:
parent
3a34678900
commit
808f8b1cc5
|
@ -111,6 +111,10 @@ void ChatLine::replaceContent(int col, ChatLineContent *lineContent)
|
|||
|
||||
content[col] = lineContent;
|
||||
scene->addItem(content[col]);
|
||||
|
||||
layout(width, pos);
|
||||
content[col]->visibilityChanged(isVisible);
|
||||
content[col]->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,15 +149,9 @@ void ChatLine::layout(qreal w, QPointF scenePos)
|
|||
else
|
||||
width = format[i].size / varWidth * leftover;
|
||||
|
||||
// set the width of the current column as
|
||||
// firstLineVOffset() may depend on the current width
|
||||
// set the width of the current column
|
||||
content[i]->setWidth(width);
|
||||
|
||||
// calculate vertical alignment
|
||||
qreal yOffset = 0.0;
|
||||
if(format[i].vAlignCol >= 0 && format[i].vAlignCol < content.size())
|
||||
yOffset = content[format[i].vAlignCol]->firstLineVOffset() - content[i]->firstLineVOffset();
|
||||
|
||||
// calculate horizontal alignment
|
||||
qreal xAlign = 0.0;
|
||||
switch(format[i].hAlign)
|
||||
|
@ -169,11 +167,23 @@ void ChatLine::layout(qreal w, QPointF scenePos)
|
|||
}
|
||||
|
||||
// reposition
|
||||
content[i]->setPos(pos.x() + xOffset + xAlign, pos.y() + yOffset);
|
||||
content[i]->setPos(pos.x() + xOffset + xAlign, pos.y());
|
||||
|
||||
xOffset += width;
|
||||
}
|
||||
|
||||
for(int i = 0; i < content.size(); ++i)
|
||||
{
|
||||
// calculate vertical alignment
|
||||
// vertical alignment may depend on width, so we do it in a second pass
|
||||
qreal yOffset = 0.0;
|
||||
if(format[i].vAlignCol >= 0 && format[i].vAlignCol < content.size())
|
||||
yOffset = content[format[i].vAlignCol]->firstLineVOffset() - content[i]->firstLineVOffset();
|
||||
|
||||
// reposition
|
||||
content[i]->setPos(content[i]->pos().x(), content[i]->pos().y() + yOffset);
|
||||
}
|
||||
|
||||
updateBBox();
|
||||
}
|
||||
|
||||
|
|
|
@ -68,3 +68,8 @@ void ChatLineContent::visibilityChanged(bool)
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
QString ChatLineContent::toString() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ public:
|
|||
|
||||
virtual void visibilityChanged(bool visible);
|
||||
|
||||
virtual QString toString() const;
|
||||
|
||||
private:
|
||||
friend class ChatLine;
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ ChatMessage::ChatMessage(QGraphicsScene *scene, const QString& author ,ChatLineC
|
|||
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));
|
||||
|
||||
midColumn = content;
|
||||
}
|
||||
|
||||
void ChatMessage::markAsSent(const QDateTime &time)
|
||||
|
@ -17,3 +19,8 @@ void ChatMessage::markAsSent(const QDateTime &time)
|
|||
// remove the spinner and replace it by $time
|
||||
replaceContent(2, new Text(time.toString("hh:mm"), true));
|
||||
}
|
||||
|
||||
QString ChatMessage::toString() const
|
||||
{
|
||||
return midColumn->toString();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@ public:
|
|||
ChatMessage(QGraphicsScene* scene, const QString &author, ChatLineContent* content);
|
||||
|
||||
void markAsSent(const QDateTime& time);
|
||||
QString toString() const;
|
||||
|
||||
private:
|
||||
ChatLineContent* midColumn = nullptr;
|
||||
};
|
||||
|
||||
#endif // CHATMESSAGE_H
|
||||
|
|
|
@ -11,14 +11,15 @@
|
|||
#include <QFontMetrics>
|
||||
#include <QDesktopServices>
|
||||
|
||||
int Text::count = 0;
|
||||
|
||||
Text::Text(const QString& txt, bool enableElide)
|
||||
: ChatLineContent()
|
||||
, elide(enableElide)
|
||||
{
|
||||
setText(txt);
|
||||
setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
|
||||
|
||||
ensureIntegrity();
|
||||
freeResources();
|
||||
//setCacheMode(QGraphicsItem::DeviceCoordinateCache);
|
||||
}
|
||||
|
||||
|
@ -161,6 +162,11 @@ void Text::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
QDesktopServices::openUrl(anchor);
|
||||
}
|
||||
|
||||
QString Text::toString() const
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
void Text::ensureIntegrity()
|
||||
{
|
||||
if(!doc)
|
||||
|
@ -179,18 +185,16 @@ void Text::ensureIntegrity()
|
|||
opt.setWrapMode(QTextOption::NoWrap);
|
||||
doc->setDefaultTextOption(opt);
|
||||
doc->setPlainText(elidedText);
|
||||
|
||||
}
|
||||
|
||||
cursor = QTextCursor(doc);
|
||||
count++;
|
||||
}
|
||||
|
||||
doc->setTextWidth(width);
|
||||
doc->documentLayout()->update();
|
||||
|
||||
if(doc->firstBlock().layout()->lineCount() > 0)
|
||||
vOffset = doc->firstBlock().layout()->lineAt(0).ascent();
|
||||
vOffset = doc->firstBlock().layout()->lineAt(0).height();
|
||||
|
||||
if(size != idealSize())
|
||||
{
|
||||
|
@ -206,8 +210,6 @@ void Text::freeResources()
|
|||
delete doc;
|
||||
doc = nullptr;
|
||||
cursor = QTextCursor();
|
||||
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
static int count;
|
||||
virtual QString toString() const;
|
||||
|
||||
protected:
|
||||
// dynamic resource management
|
||||
|
|
|
@ -198,7 +198,7 @@ void SmileyPack::cacheSmiley(const QString &name)
|
|||
// The -1 is to avoid having the space for descenders under images move the text down
|
||||
// We can't remove it because Qt doesn't support CSS display or vertical-align
|
||||
int fontHeight = QFontInfo(Style::getFont(Style::Big)).pixelSize() - 1;
|
||||
QSize size(fontHeight, fontHeight);
|
||||
QSize size(16, 16);
|
||||
QString filename = QDir(path).filePath(name);
|
||||
QImage img(filename);
|
||||
|
||||
|
|
|
@ -732,7 +732,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
|
||||
ToxID storedPrevId;
|
||||
std::swap(storedPrevId, previousId);
|
||||
//QList<ChatActionPtr> historyMessages;
|
||||
// QList<ChatMessage*> historyMessages;
|
||||
|
||||
// QDate lastDate(1,0,0);
|
||||
// for (const auto &it : msgs)
|
||||
|
@ -743,11 +743,11 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
// if (msgDate > lastDate)
|
||||
// {
|
||||
// lastDate = msgDate;
|
||||
// historyMessages.append(genSystemInfoAction(msgDate.toString(),"",QDateTime()));
|
||||
// //TODO: historyMessages.append(genSystemInfoAction(msgDate.toString(),"",QDateTime()));
|
||||
// }
|
||||
|
||||
// // Show each messages
|
||||
// MessageActionPtr ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, msgDateTime);
|
||||
// ChatMessage* ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, msgDateTime);
|
||||
// if (it.isSent)
|
||||
// {
|
||||
// ca->markAsSent();
|
||||
|
@ -869,26 +869,26 @@ void ChatForm::dischargeReceipt(int receipt)
|
|||
|
||||
void ChatForm::clearReciepts()
|
||||
{
|
||||
// receipts.clear();
|
||||
// undeliveredMsgs.clear();
|
||||
receipts.clear();
|
||||
undeliveredMsgs.clear();
|
||||
}
|
||||
|
||||
void ChatForm::deliverOfflineMsgs()
|
||||
{
|
||||
// if (!Settings::getInstance().getFauxOfflineMessaging())
|
||||
// return;
|
||||
if (!Settings::getInstance().getFauxOfflineMessaging())
|
||||
return;
|
||||
|
||||
// QMap<int, MessageActionPtr> msgs = undeliveredMsgs;
|
||||
// clearReciepts();
|
||||
QMap<int, ChatMessage*> msgs = undeliveredMsgs;
|
||||
clearReciepts();
|
||||
|
||||
// for (auto iter = msgs.begin(); iter != msgs.end(); iter++)
|
||||
// {
|
||||
// QString messageText = iter.value()->getRawMessage();
|
||||
// int rec;
|
||||
for (auto iter = msgs.begin(); iter != msgs.end(); iter++)
|
||||
{
|
||||
QString messageText = iter.value()->toString();
|
||||
int rec;
|
||||
//if (iter.value()->isAction())
|
||||
// rec = Core::getInstance()->sendAction(f->getFriendID(), messageText);
|
||||
;//TODO: rec = Core::getInstance()->sendAction(f->getFriendID(), messageText);
|
||||
//else
|
||||
// rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText);
|
||||
// registerReceipt(rec, iter.key(), iter.value());
|
||||
// }
|
||||
rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText);
|
||||
registerReceipt(rec, iter.key(), iter.value());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "src/friendlist.h"
|
||||
#include "src/friend.h"
|
||||
#include "src/chatlog/content/text.h"
|
||||
#include "src/chatlog/chatmessage.h"
|
||||
|
||||
GenericChatForm::GenericChatForm(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
|
@ -205,12 +206,16 @@ void GenericChatForm::onSaveLogClicked()
|
|||
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);
|
||||
ChatMessage* msg = chatWidget->addChatMessage(Core::getInstance()->getPeerName(author), new Text(SmileyPack::getInstance().smileyfied(message)), datetime);
|
||||
if(isSent)
|
||||
msg->markAsSent(datetime);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
ChatMessage* GenericChatForm::addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent)
|
||||
{
|
||||
return chatWidget->addChatMessage(Core::getInstance()->getUsername(), new Text(message));
|
||||
return chatWidget->addChatMessage(Core::getInstance()->getUsername(), new Text(SmileyPack::getInstance().smileyfied(message)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -743,7 +743,7 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
|
|||
return;
|
||||
|
||||
QDateTime timestamp = QDateTime::currentDateTime();
|
||||
//TODO: f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp, true);
|
||||
f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp, true);
|
||||
|
||||
if (isAction)
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, "/me " + message, f->getToxID().publicKey, timestamp, true);
|
||||
|
@ -773,7 +773,7 @@ void Widget::onReceiptRecieved(int friendId, int receipt)
|
|||
if (!f)
|
||||
return;
|
||||
|
||||
//TODO: f->getChatForm()->dischargeReceipt(receipt);
|
||||
f->getChatForm()->dischargeReceipt(receipt);
|
||||
}
|
||||
|
||||
void Widget::newMessageAlert(GenericChatroomWidget* chat)
|
||||
|
|
Loading…
Reference in New Issue
Block a user