summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-10-04 10:26:17 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-10-04 10:26:17 (GMT)
commit168405b68c8ce2dd174c86ce3938fbabff93efd7 (patch)
tree3d7a49add14b26b06435b214dcaae9af6cbd948e /Swift/QtUI/QtChatView.cpp
parent219b1e5e4684323e0dbd0f1ad7de7beaf4d75f50 (diff)
downloadswift-168405b68c8ce2dd174c86ce3938fbabff93efd7.zip
swift-168405b68c8ce2dd174c86ce3938fbabff93efd7.tar.bz2
Fix chat logs scrolling to bottom.
(bug introduced since beta6) Resolves: #591
Diffstat (limited to 'Swift/QtUI/QtChatView.cpp')
-rw-r--r--Swift/QtUI/QtChatView.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 1ad274f..70bb0e8 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -44,15 +44,13 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) {
mainLayout->addWidget(webView_);
#endif
-
-
-
webPage_ = new QWebPage(this);
webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
webView_->setPage(webPage_);
connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
viewReady_ = false;
+ isAtBottom_ = true;
resetView();
}
@@ -76,7 +74,7 @@ QWebElement QtChatView::snippetToDOM(boost::shared_ptr<ChatSnippet> snippet) {
}
void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) {
- bool bottom = isScrolledToBottom();
+ rememberScrolledToBottom();
QWebElement newElement = snippetToDOM(snippet);
QWebElement continuationElement = lastElement_.findFirst("#insert");
if (snippet->getAppendToPrevious()) {
@@ -87,27 +85,21 @@ void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) {
newInsertPoint_.prependOutside(newElement);
}
lastElement_ = newElement;
- if (bottom) {
- /* Warning: I'm not confident about this, although it does work.*/
- QTimer::singleShot(0, this, SLOT(scrollToBottom()));
- }
}
void QtChatView::replaceLastMessage(const QString& newMessage) {
assert(viewReady_);
/* FIXME: must be queued? */
- bool bottom = isScrolledToBottom();
+ rememberScrolledToBottom();
assert(!lastElement_.isNull());
QWebElement replace = lastElement_.findFirst("span.swift_message");
assert(!replace.isNull());
QString old = lastElement_.toOuterXml();
replace.setInnerXml(ChatSnippet::escape(newMessage));
- if (bottom) {
- QTimer::singleShot(0, this, SLOT(scrollToBottom()));
- }
}
void QtChatView::replaceLastMessage(const QString& newMessage, const QString& note) {
+ rememberScrolledToBottom();
replaceLastMessage(newMessage);
QWebElement replace = lastElement_.findFirst("span.swift_time");
assert(!replace.isNull());
@@ -129,14 +121,21 @@ void QtChatView::setAckXML(const QString& id, const QString& xml) {
ackElement.setInnerXml(xml);
}
-bool QtChatView::isScrolledToBottom() const {
- return webPage_->mainFrame()->scrollBarValue(Qt::Vertical) == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical);
+void QtChatView::rememberScrolledToBottom() {
+ isAtBottom_ = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical);
}
void QtChatView::scrollToBottom() {
+ isAtBottom_ = true;
webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical));
}
+void QtChatView::handleFrameSizeChanged() {
+ if (isAtBottom_) {
+ scrollToBottom();
+ }
+}
+
void QtChatView::handleLinkClicked(const QUrl& url) {
QDesktopServices::openUrl(url);
}
@@ -180,6 +179,8 @@ void QtChatView::resetView() {
newInsertPoint_.setOuterXml("<div id='swift_insert'/>");
chatElement.appendInside(newInsertPoint_);
Q_ASSERT(!newInsertPoint_.isNull());
+
+ connect(webPage_->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), this, SLOT(handleFrameSizeChanged()), Qt::UniqueConnection);
}
}