1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

ChatLog: insertChatlineAtBottom, refactoring

This commit is contained in:
krepa098 2015-01-04 19:28:27 +01:00
parent b09805f9bf
commit 12a1fa1549
3 changed files with 29 additions and 4 deletions

View File

@ -353,7 +353,7 @@ void ChatLog::repositionDownTo(int start, qreal end)
}
}
void ChatLog::insertChatline(ChatLine::Ptr l)
void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
{
if(!l.get())
return;
@ -365,6 +365,7 @@ void ChatLog::insertChatline(ChatLine::Ptr l)
l->setRowIndex(lines.size());
lines.append(l);
//partial refresh
layout(lines.last()->getRowIndex() - 1, lines.size(), useableWidth());
updateSceneRect();
@ -374,6 +375,30 @@ void ChatLog::insertChatline(ChatLine::Ptr l)
checkVisibility();
}
void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
{
if(!l.get())
return;
//move all lines down by 1
for(ChatLine::Ptr l : lines)
l->setRowIndex(l->getRowIndex() + 1);
//add the new line
l->addToScene(scene);
l->setRowIndex(0);
lines.prepend(l);
//full refresh is required
layout(0, lines.size(), useableWidth());
updateSceneRect();
if(stickToBtm)
scrollToBottom();
checkVisibility();
}
bool ChatLog::stickToBottom()
{
return verticalScrollBar()->value() == verticalScrollBar()->maximum();

View File

@ -37,7 +37,8 @@ public:
explicit ChatLog(QWidget* parent = 0);
virtual ~ChatLog();
void insertChatline(ChatLine::Ptr l);
void insertChatlineAtBottom(ChatLine::Ptr l);
void insertChatlineOnTop(ChatLine::Ptr l);
void clearSelection();
void clear();
void copySelectedText() const;

View File

@ -30,10 +30,9 @@
#include <QDesktopServices>
Text::Text(const QString& txt, QFont font, bool enableElide, const QString &rwText)
: ChatLineContent()
: rawText(rwText)
, elide(enableElide)
, defFont(font)
, rawText(rwText)
{
setText(txt);
setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);