diff options
Diffstat (limited to 'Swift/QtUI')
| -rw-r--r-- | Swift/QtUI/QtChatView.cpp | 28 | ||||
| -rw-r--r-- | Swift/QtUI/QtChatView.h | 2 | ||||
| -rw-r--r-- | Swift/QtUI/QtHistoryWindow.cpp | 10 | ||||
| -rw-r--r-- | Swift/QtUI/QtHistoryWindow.h | 3 | 
4 files changed, 34 insertions, 9 deletions
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index ef39b23..4ae613a 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(); +} +  } diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h index d778f6f..dada46a 100644 --- a/Swift/QtUI/QtChatView.h +++ b/Swift/QtUI/QtChatView.h @@ -61,6 +61,7 @@ namespace Swift {  			void handleLinkClicked(const QUrl&);  			void handleKeyPressEvent(QKeyEvent* event);  			void resetView(); +			void resetTopInsertPoint();  			void increaseFontSize(int numSteps = 1);  			void decreaseFontSize();  			void resizeFont(int fontSizeSteps); @@ -86,6 +87,7 @@ namespace Swift {  			int fontSizeSteps_;  			QtChatTheme* theme_;  			QWebElement newInsertPoint_; +			QWebElement topInsertPoint_;  			QWebElement lineSeparator_;  			QWebElement lastElement_;  			QWebElement firstElement_; diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp index a0ccbf9..d9b587f 100644 --- a/Swift/QtUI/QtHistoryWindow.cpp +++ b/Swift/QtUI/QtHistoryWindow.cpp @@ -117,8 +117,8 @@ void QtHistoryWindow::addMessage(const std::string &message, const std::string &  	QString qAvatarPath =  scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();  	if (addAtTheTop) { -		// bool appendToPrevious = ((senderIsSelf && previousTopMessageWasSelf_) || (!senderIsSelf && !previousTopMessageWasSelf_&& previousTopSenderName_ == P2QSTRING(senderName))); -		conversation_->addMessageTop(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, false, theme_, P2QSTRING(id)))); +		bool appendToPrevious = ((senderIsSelf && previousTopMessageWasSelf_) || (!senderIsSelf && !previousTopMessageWasSelf_&& previousTopSenderName_ == P2QSTRING(senderName))); +		conversation_->addMessageTop(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id))));  		previousTopMessageWasSelf_ = senderIsSelf;  		previousTopSenderName_ = P2QSTRING(senderName); @@ -206,4 +206,10 @@ void QtHistoryWindow::handleFontResized(int fontSizeSteps) {  	emit fontResized(fontSizeSteps);  } +void QtHistoryWindow::resetConversationViewTopInsertPoint() { +	previousTopMessageWasSelf_ = false; +	previousTopSenderName_ = QString(); +	conversation_->resetTopInsertPoint(); +} +  } diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h index c813b82..13d3f14 100644 --- a/Swift/QtUI/QtHistoryWindow.h +++ b/Swift/QtUI/QtHistoryWindow.h @@ -23,8 +23,9 @@ namespace Swift {  			~QtHistoryWindow();  			void activate();  			void setRosterModel(Roster*); -			void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop); +			void addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop);  			void resetConversationView(); +			void resetConversationViewTopInsertPoint();  			void setDate(const boost::gregorian::date& date);  			void closeEvent(QCloseEvent* event);  | 
 Swift