From fb0c372c81d1593b7ac138629dfc15243d0ca929 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Tue, 13 Jan 2015 23:59:38 +0100 Subject: [PATCH] cleanup --- src/chatlog/chatlog.cpp | 27 ++++++++++++++------------- src/chatlog/chatlog.h | 11 +++-------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 15f62a806..004b084ba 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -207,14 +207,12 @@ void ChatLog::partialUpdate() checkVisibility(); setViewportUpdateMode(oldUpdateMode); - updateSceneRect(); } void ChatLog::fullUpdate() { layout(0, lines.size(), useableWidth()); checkVisibility(); - updateSceneRect(); } 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); if(content) @@ -355,7 +351,7 @@ ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const return nullptr; } -bool ChatLog::isOverSelection(QPointF scenePos) +bool ChatLog::isOverSelection(QPointF scenePos) const { if(selectionMode == Precise) { @@ -373,7 +369,7 @@ bool ChatLog::isOverSelection(QPointF scenePos) return false; } -qreal ChatLog::useableWidth() +qreal ChatLog::useableWidth() const { return width() - verticalScrollBar()->sizeHint().width() - margins.right() - margins.left(); } @@ -398,11 +394,11 @@ void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l) if(!l.get()) return; - l->addToScene(scene); - - stickToBtm = stickToBottom(); + bool stickToBtm = stickToBottom(); + //insert l->setRowIndex(lines.size()); + l->addToScene(scene); lines.append(l); //partial refresh @@ -420,6 +416,8 @@ void ChatLog::insertChatlineOnTop(ChatLine::Ptr l) if(!l.get()) return; + bool stickToBtm = stickToBottom(); + //move all lines down by 1 for(ChatLine::Ptr l : lines) l->setRowIndex(l->getRowIndex() + 1); @@ -444,6 +442,8 @@ void ChatLog::insertChatlineOnTop(const QList& newLines) if(newLines.isEmpty()) return; + bool stickToBtm = stickToBottom(); + //move all lines down by n int n = newLines.size(); for(ChatLine::Ptr l : lines) @@ -467,16 +467,15 @@ void ChatLog::insertChatlineOnTop(const QList& newLines) checkVisibility(); } -bool ChatLog::stickToBottom() +bool ChatLog::stickToBottom() const { return verticalScrollBar()->value() == verticalScrollBar()->maximum(); } void ChatLog::scrollToBottom() { + updateSceneRect(); verticalScrollBar()->setValue(verticalScrollBar()->maximum()); - updateGeometry(); - checkVisibility(); } QString ChatLog::getSelectedText() const @@ -581,6 +580,8 @@ void ChatLog::checkVisibility() if(lines.empty()) return; + updateSceneRect(); + // find first visible row QVector::const_iterator upperBound; upperBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs) diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index b00067174..f92a7a76d 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -58,10 +58,10 @@ protected: ChatLineContent* getContentFromPos(QPointF scenePos) const; qreal layout(int start, int end, qreal width); - bool isOverSelection(QPointF scenePos); - bool stickToBottom(); + bool isOverSelection(QPointF scenePos) const; + bool stickToBottom() const; - qreal useableWidth(); + qreal useableWidth() const; void reposition(int start, int end, qreal deltaY); void updateSceneRect(); @@ -100,10 +100,6 @@ private: QList visibleLines; ChatLine::Ptr typingNotification; - bool multiLineInsert = false; - bool stickToBtm = false; - int insertStartIndex = -1; - // selection int selClickedRow = -1; int selClickedCol = -1; @@ -111,7 +107,6 @@ private: int selLastRow = -1; SelectionMode selectionMode = None; QPointF clickPos; - QPointF lastPos; QGraphicsRectItem* selGraphItem = nullptr; QTimer* selectionTimer = nullptr; QTimer* workerTimer = nullptr;