diff options
author | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-29 13:42:06 (GMT) |
---|---|---|
committer | Cătălin Badea <catalin.badea392@gmail.com> | 2012-08-11 15:59:13 (GMT) |
commit | 94ff6ec9e699a2db97775063eb7fa2f6d24b281a (patch) | |
tree | 80d093df35ea27b258957130c53b859faad5e177 /Swift/QtUI/QtChatView.cpp | |
parent | c0f0ab471345fe3f3a3517bb302c7da1549c8f25 (diff) | |
download | swift-contrib-94ff6ec9e699a2db97775063eb7fa2f6d24b281a.zip swift-contrib-94ff6ec9e699a2db97775063eb7fa2f6d24b281a.tar.bz2 |
Fix adding messages at the top.
Diffstat (limited to 'Swift/QtUI/QtChatView.cpp')
-rw-r--r-- | Swift/QtUI/QtChatView.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 0af1262..3ad957c 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -93,11 +93,8 @@ void QtChatView::addMessageBottom(boost::shared_ptr<ChatSnippet> snippet) { /* If this asserts, the previous queuing code was necessary and should be reinstated */ assert(false); } - - if (firstElement_.isNull()) { - firstElement_ = lastElement_; - } } + void QtChatView::addMessageTop(boost::shared_ptr<ChatSnippet> snippet) { // save scrollbar maximum value if (!topMessageAdded_) { @@ -105,9 +102,22 @@ void QtChatView::addMessageTop(boost::shared_ptr<ChatSnippet> snippet) { } topMessageAdded_ = true; - QWebElement newElement = snippetToDOM(snippet); + QWebElement continuationElement = firstElement_.findFirst("#insert"); + + bool insert = snippet->getAppendToPrevious(); + bool fallback = continuationElement.isNull(); + + boost::shared_ptr<ChatSnippet> newSnippet = (insert && fallback) ? snippet->getContinuationFallbackSnippet() : snippet; + QWebElement newElement = snippetToDOM(newSnippet); + + if (insert && !fallback) { + Q_ASSERT(!continuationElement.isNull()); + continuationElement.replace(newElement); + } else { + continuationElement.removeFromDocument(); + topInsertPoint_.appendOutside(newElement); + } - firstElement_.prependOutside(newElement); firstElement_ = newElement; if (lastElement_.isNull()) { @@ -345,6 +355,8 @@ void QtChatView::resetView() { QWebElement chatElement = document_.findFirst("#Chat"); newInsertPoint_ = chatElement.clone(); newInsertPoint_.setOuterXml("<div id='swift_insert'/>"); + topInsertPoint_ = newInsertPoint_.clone(); + chatElement.appendInside(topInsertPoint_); chatElement.appendInside(newInsertPoint_); Q_ASSERT(!newInsertPoint_.isNull()); @@ -444,4 +456,8 @@ int QtChatView::getSnippetPositionByDate(const QDate& date) { return message.geometry().top(); } +void QtChatView::resetTopInsertPoint() { + firstElement_ = QWebElement(); +} + } |