mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
cleanup
This commit is contained in:
parent
29fc6ab03f
commit
fb0c372c81
|
@ -207,14 +207,12 @@ void ChatLog::partialUpdate()
|
||||||
checkVisibility();
|
checkVisibility();
|
||||||
|
|
||||||
setViewportUpdateMode(oldUpdateMode);
|
setViewportUpdateMode(oldUpdateMode);
|
||||||
updateSceneRect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::fullUpdate()
|
void ChatLog::fullUpdate()
|
||||||
{
|
{
|
||||||
layout(0, lines.size(), useableWidth());
|
layout(0, lines.size(), useableWidth());
|
||||||
checkVisibility();
|
checkVisibility();
|
||||||
updateSceneRect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::mousePressEvent(QMouseEvent* ev)
|
void ChatLog::mousePressEvent(QMouseEvent* ev)
|
||||||
|
@ -292,10 +290,8 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(selectionMode != None && ev->pos() != lastPos)
|
if(selectionMode != None)
|
||||||
{
|
{
|
||||||
lastPos = ev->pos();
|
|
||||||
|
|
||||||
ChatLineContent* content = getContentFromPos(scenePos);
|
ChatLineContent* content = getContentFromPos(scenePos);
|
||||||
|
|
||||||
if(content)
|
if(content)
|
||||||
|
@ -355,7 +351,7 @@ ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatLog::isOverSelection(QPointF scenePos)
|
bool ChatLog::isOverSelection(QPointF scenePos) const
|
||||||
{
|
{
|
||||||
if(selectionMode == Precise)
|
if(selectionMode == Precise)
|
||||||
{
|
{
|
||||||
|
@ -373,7 +369,7 @@ bool ChatLog::isOverSelection(QPointF scenePos)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal ChatLog::useableWidth()
|
qreal ChatLog::useableWidth() const
|
||||||
{
|
{
|
||||||
return width() - verticalScrollBar()->sizeHint().width() - margins.right() - margins.left();
|
return width() - verticalScrollBar()->sizeHint().width() - margins.right() - margins.left();
|
||||||
}
|
}
|
||||||
|
@ -398,11 +394,11 @@ void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
|
||||||
if(!l.get())
|
if(!l.get())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
l->addToScene(scene);
|
bool stickToBtm = stickToBottom();
|
||||||
|
|
||||||
stickToBtm = stickToBottom();
|
|
||||||
|
|
||||||
|
//insert
|
||||||
l->setRowIndex(lines.size());
|
l->setRowIndex(lines.size());
|
||||||
|
l->addToScene(scene);
|
||||||
lines.append(l);
|
lines.append(l);
|
||||||
|
|
||||||
//partial refresh
|
//partial refresh
|
||||||
|
@ -420,6 +416,8 @@ void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
|
||||||
if(!l.get())
|
if(!l.get())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool stickToBtm = stickToBottom();
|
||||||
|
|
||||||
//move all lines down by 1
|
//move all lines down by 1
|
||||||
for(ChatLine::Ptr l : lines)
|
for(ChatLine::Ptr l : lines)
|
||||||
l->setRowIndex(l->getRowIndex() + 1);
|
l->setRowIndex(l->getRowIndex() + 1);
|
||||||
|
@ -444,6 +442,8 @@ void ChatLog::insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines)
|
||||||
if(newLines.isEmpty())
|
if(newLines.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool stickToBtm = stickToBottom();
|
||||||
|
|
||||||
//move all lines down by n
|
//move all lines down by n
|
||||||
int n = newLines.size();
|
int n = newLines.size();
|
||||||
for(ChatLine::Ptr l : lines)
|
for(ChatLine::Ptr l : lines)
|
||||||
|
@ -467,16 +467,15 @@ void ChatLog::insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines)
|
||||||
checkVisibility();
|
checkVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatLog::stickToBottom()
|
bool ChatLog::stickToBottom() const
|
||||||
{
|
{
|
||||||
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
|
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::scrollToBottom()
|
void ChatLog::scrollToBottom()
|
||||||
{
|
{
|
||||||
|
updateSceneRect();
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||||
updateGeometry();
|
|
||||||
checkVisibility();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ChatLog::getSelectedText() const
|
QString ChatLog::getSelectedText() const
|
||||||
|
@ -581,6 +580,8 @@ void ChatLog::checkVisibility()
|
||||||
if(lines.empty())
|
if(lines.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
updateSceneRect();
|
||||||
|
|
||||||
// find first visible row
|
// find first visible row
|
||||||
QVector<ChatLine::Ptr>::const_iterator upperBound;
|
QVector<ChatLine::Ptr>::const_iterator upperBound;
|
||||||
upperBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs)
|
upperBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs)
|
||||||
|
|
|
@ -58,10 +58,10 @@ protected:
|
||||||
ChatLineContent* getContentFromPos(QPointF scenePos) const;
|
ChatLineContent* getContentFromPos(QPointF scenePos) const;
|
||||||
|
|
||||||
qreal layout(int start, int end, qreal width);
|
qreal layout(int start, int end, qreal width);
|
||||||
bool isOverSelection(QPointF scenePos);
|
bool isOverSelection(QPointF scenePos) const;
|
||||||
bool stickToBottom();
|
bool stickToBottom() const;
|
||||||
|
|
||||||
qreal useableWidth();
|
qreal useableWidth() const;
|
||||||
|
|
||||||
void reposition(int start, int end, qreal deltaY);
|
void reposition(int start, int end, qreal deltaY);
|
||||||
void updateSceneRect();
|
void updateSceneRect();
|
||||||
|
@ -100,10 +100,6 @@ private:
|
||||||
QList<ChatLine::Ptr> visibleLines;
|
QList<ChatLine::Ptr> visibleLines;
|
||||||
ChatLine::Ptr typingNotification;
|
ChatLine::Ptr typingNotification;
|
||||||
|
|
||||||
bool multiLineInsert = false;
|
|
||||||
bool stickToBtm = false;
|
|
||||||
int insertStartIndex = -1;
|
|
||||||
|
|
||||||
// selection
|
// selection
|
||||||
int selClickedRow = -1;
|
int selClickedRow = -1;
|
||||||
int selClickedCol = -1;
|
int selClickedCol = -1;
|
||||||
|
@ -111,7 +107,6 @@ private:
|
||||||
int selLastRow = -1;
|
int selLastRow = -1;
|
||||||
SelectionMode selectionMode = None;
|
SelectionMode selectionMode = None;
|
||||||
QPointF clickPos;
|
QPointF clickPos;
|
||||||
QPointF lastPos;
|
|
||||||
QGraphicsRectItem* selGraphItem = nullptr;
|
QGraphicsRectItem* selGraphItem = nullptr;
|
||||||
QTimer* selectionTimer = nullptr;
|
QTimer* selectionTimer = nullptr;
|
||||||
QTimer* workerTimer = nullptr;
|
QTimer* workerTimer = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user