diff options
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_); + } +} + } |