diff options
author | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-16 09:42:35 (GMT) |
---|---|---|
committer | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-16 09:42:35 (GMT) |
commit | cc6459b1b5b4f8d7853623fe9d85817f0d14ca26 (patch) | |
tree | 3d7a1edb12367e193316a826086fb2f5de19a148 /Swift/QtUI/QtChatView.cpp | |
parent | b629b5c198020e0992ee6cf01669b7a5191e23ef (diff) | |
download | swift-contrib-cc6459b1b5b4f8d7853623fe9d85817f0d14ca26.zip swift-contrib-cc6459b1b5b4f8d7853623fe9d85817f0d14ca26.tar.bz2 |
Allow adding top messages in the chatview.
Diffstat (limited to 'Swift/QtUI/QtChatView.cpp')
-rw-r--r-- | Swift/QtUI/QtChatView.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 153e3f9..0a58517 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -86,13 +86,31 @@ void QtChatView::handleKeyPressEvent(QKeyEvent* event) { webView_->keyPressEvent(event); } -void QtChatView::addMessage(boost::shared_ptr<ChatSnippet> snippet) { +void QtChatView::addMessageBottom(boost::shared_ptr<ChatSnippet> snippet) { if (viewReady_) { addToDOM(snippet); } else { /* 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_) { + scrollBarMaximum_ = webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical); + } + topMessageAdded_ = true; + + QWebElement newElement = snippetToDOM(snippet); + firstElement_.prependOutside(newElement); + firstElement_ = newElement; + if (lastElement_.isNull()) { + lastElement_ = firstElement_; + } } QWebElement QtChatView::snippetToDOM(boost::shared_ptr<ChatSnippet> snippet) { @@ -241,6 +259,13 @@ void QtChatView::scrollToBottom() { } void QtChatView::handleFrameSizeChanged() { + if (topMessageAdded_) { + // adjust new scrollbar position + int newMaximum = webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical); + webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, newMaximum - scrollBarMaximum_); + topMessageAdded_ = false; + } + if (isAtBottom_) { scrollToBottom(); } @@ -283,6 +308,9 @@ void QtChatView::resizeFont(int fontSizeSteps) { void QtChatView::resetView() { lastElement_ = QWebElement(); + firstElement_ = lastElement_; + topMessageAdded_ = false; + scrollBarMaximum_ = 0; QString pageHTML = theme_->getTemplate(); pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3"); pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase()); @@ -386,8 +414,17 @@ void QtChatView::setMUCInvitationJoined(QString id) { } void QtChatView::handleScrollRequested(int, int dy, const QRect&) { - int pos = webPage_->mainFrame()->scrollBarValue(Qt::Vertical); - emit scrollRequested(pos - dy); + rememberScrolledToBottom(); + + int pos = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) - dy; + emit scrollRequested(pos); + + if (pos == 0) { + emit scrollReachedTop(); + } + else if (pos == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical)) { + emit scrollReachedBottom(); + } } int QtChatView::getSnippetPositionByDate(const QDate& date) { |