diff options
| author | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-09 19:35:27 (GMT) | 
|---|---|---|
| committer | Cătălin Badea <catalin.badea392@gmail.com> | 2012-08-11 15:52:57 (GMT) | 
| commit | 782054cbc9d82646e90a8de4086008e8f7bc640c (patch) | |
| tree | f48b5577371a200e5f2aa43c9c3910fd7052a806 /Swift/QtUI/QtHistoryWindow.cpp | |
| parent | b9b59d265f44e3e5341635baaac160fe57a5685e (diff) | |
| download | swift-contrib-782054cbc9d82646e90a8de4086008e8f7bc640c.zip swift-contrib-782054cbc9d82646e90a8de4086008e8f7bc640c.tar.bz2  | |
Calendar widget follows the currently viewed message
Diffstat (limited to 'Swift/QtUI/QtHistoryWindow.cpp')
| -rw-r--r-- | Swift/QtUI/QtHistoryWindow.cpp | 37 | 
1 files changed, 35 insertions, 2 deletions
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp index 50fd66e..95a47ac 100644 --- a/Swift/QtUI/QtHistoryWindow.cpp +++ b/Swift/QtUI/QtHistoryWindow.cpp @@ -18,6 +18,7 @@  #include <QUrl>  #include <QMenu>  #include <QTextDocument> +#include <QDateTime>  #include <Swift/QtUI/QtScaledAvatarCache.h>  #include <boost/smart_ptr/make_shared.hpp> @@ -51,10 +52,15 @@ QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* even  	setWindowTitle(tr("History"));  	conversationRoster_->onSomethingSelectedChanged.connect(boost::bind(&QtHistoryWindow::handleSomethingSelectedChanged, this, _1)); +	connect(conversation_, SIGNAL(scrollRequested(int)), this, SLOT(handleScrollRequested(int)));  }  QtHistoryWindow::~QtHistoryWindow() { +	disconnect(conversation_, SIGNAL(scrollRequested(int)), this, SLOT(handleScrollRequested(int))); +  	delete theme_; +	delete conversation_; +	// TODO: delete ui_  }  void QtHistoryWindow::activate() { @@ -81,19 +87,46 @@ void QtHistoryWindow::addMessage(const std::string &message, const std::string &  	QString messageHTML(P2QSTRING(message));  	messageHTML = Qt::escape(messageHTML); +	QDateTime qTime = B2QDATE(time); +	QDate date = qTime.date();  	QString qAvatarPath =  scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded(); -	conversation_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, false, theme_, "id"))); -} +	conversation_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, false, theme_, "id"))); +	// keep track of the days viewable in the chatView +	if (!dates_.count(date)) { +		dates_.insert(date); +	} +}  void QtHistoryWindow::handleSomethingSelectedChanged(RosterItem* item) {  	onSelectedContactChanged(item);  }  void QtHistoryWindow::resetConversationView() { +	dates_.clear();  	conversation_->resetView();  } +void QtHistoryWindow::handleScrollRequested(int pos) { +	// first message starts with offset 5 +	if (pos < 5) { +		pos = 5; +	} + +	QDate currentDate; +	foreach (const QDate& date, dates_) { +		int snippetPosition = conversation_->getSnippetPositionByDate(date); +		if (snippetPosition <= pos) { +			currentDate = date; +		} +	} + +	if (currentDate_ != currentDate) { +		currentDate_ = currentDate; +		ui_.calendarWidget_->setSelectedDate(currentDate_); +	} +} +  }  | 
 Swift