diff options
Diffstat (limited to 'Swift/QtUI/ChatList')
| -rw-r--r-- | Swift/QtUI/ChatList/ChatListDelegate.cpp | 55 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/ChatListDelegate.h | 5 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/ChatListGroupItem.h | 7 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/ChatListMUCItem.h | 12 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.cpp | 22 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.h | 11 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/ChatListRecentItem.cpp | 34 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/ChatListRecentItem.h | 33 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.cpp | 31 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.h | 5 | 
10 files changed, 182 insertions, 33 deletions
| diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp index 274a10a..b2bfe0a 100644 --- a/Swift/QtUI/ChatList/ChatListDelegate.cpp +++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp @@ -1,5 +1,5 @@  /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith   * Licensed under the GNU General Public License v3.   * See Documentation/Licenses/GPLv3.txt for more information.   */ @@ -11,6 +11,7 @@  #include "Swift/QtUI/Roster/GroupItemDelegate.h"  #include "Swift/QtUI/ChatList/ChatListItem.h"  #include "Swift/QtUI/ChatList/ChatListMUCItem.h" +#include "Swift/QtUI/ChatList/ChatListRecentItem.h"  #include "Swift/QtUI/ChatList/ChatListGroupItem.h"  namespace Swift { @@ -27,7 +28,11 @@ QSize ChatListDelegate::sizeHint(const QStyleOptionViewItem& option, const QMode  	ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer());  	if (item && dynamic_cast<ChatListMUCItem*>(item)) {  		return mucSizeHint(option, index); -	} else if (item && dynamic_cast<ChatListGroupItem*>(item)) { +	} +	else if (item && dynamic_cast<ChatListRecentItem*>(item)) { +		return recentSizeHint(option, index); +	} +	else if (item && dynamic_cast<ChatListGroupItem*>(item)) {  		return groupDelegate_->sizeHint(option, index);  	}   	return QStyledItemDelegate::sizeHint(option, index); @@ -40,14 +45,23 @@ QSize ChatListDelegate::mucSizeHint(const QStyleOptionViewItem& /*option*/, cons  	return QSize(150, sizeByText);  } +QSize ChatListDelegate::recentSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { +	return mucSizeHint(option, index); +} +  void ChatListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {  	ChatListItem* item = static_cast<ChatListItem*>(index.internalPointer());  	if (item && dynamic_cast<ChatListMUCItem*>(item)) {  		paintMUC(painter, option, dynamic_cast<ChatListMUCItem*>(item)); -	} else if (item && dynamic_cast<ChatListGroupItem*>(item)) { +	} +	else if (item && dynamic_cast<ChatListRecentItem*>(item)) { +		paintRecent(painter, option, dynamic_cast<ChatListRecentItem*>(item)); +	} +	else if (item && dynamic_cast<ChatListGroupItem*>(item)) {  		ChatListGroupItem* group = dynamic_cast<ChatListGroupItem*>(item);  		groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open);  -	} else { +	} +	else {  		QStyledItemDelegate::paint(painter, option, index);  	}  } @@ -78,9 +92,40 @@ void ChatListDelegate::paintMUC(QPainter* painter, const QStyleOptionViewItem& o  	painter->setPen(QPen(QColor(160,160,160)));  	QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); -	DelegateCommons::drawElidedText(painter, detailRegion, item->data(DetailTextRole).toString()); +	DelegateCommons::drawElidedText(painter, detailRegion, item->data(ChatListMUCItem::DetailTextRole).toString());  	painter->restore();  } +void ChatListDelegate::paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const { +	painter->save(); +	QRect fullRegion(option.rect); +	if ( option.state & QStyle::State_Selected ) { +		painter->fillRect(fullRegion, option.palette.highlight()); +		painter->setPen(option.palette.highlightedText().color()); +	} else { +		QColor nameColor = item->data(Qt::TextColorRole).value<QColor>(); +		painter->setPen(QPen(nameColor)); +	} + +	QFontMetrics nameMetrics(common_.nameFont); +	painter->setFont(common_.nameFont); +	int extraFontWidth = nameMetrics.width("H"); +	int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; +	QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); + +	int nameHeight = nameMetrics.height() + common_.verticalMargin; +	QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); + +	DelegateCommons::drawElidedText(painter, nameRegion, item->data(Qt::DisplayRole).toString()); + +	painter->setFont(common_.detailFont); +	painter->setPen(QPen(QColor(160,160,160))); + +	QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); +	DelegateCommons::drawElidedText(painter, detailRegion, item->data(ChatListRecentItem::DetailTextRole).toString()); + +	painter->restore(); +} +  } diff --git a/Swift/QtUI/ChatList/ChatListDelegate.h b/Swift/QtUI/ChatList/ChatListDelegate.h index f6c6c40..a898df4 100644 --- a/Swift/QtUI/ChatList/ChatListDelegate.h +++ b/Swift/QtUI/ChatList/ChatListDelegate.h @@ -1,5 +1,5 @@  /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith   * Licensed under the GNU General Public License v3.   * See Documentation/Licenses/GPLv3.txt for more information.   */ @@ -12,6 +12,7 @@  namespace Swift {  	class ChatListMUCItem; +	class ChatListRecentItem;  	class ChatListDelegate : public QStyledItemDelegate {  		public:  			ChatListDelegate(); @@ -20,7 +21,9 @@ namespace Swift {  			void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;  		private:  			void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, ChatListMUCItem* item) const; +			void paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const;  			QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const; +			QSize recentSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;  			DelegateCommons common_;  			GroupItemDelegate* groupDelegate_; diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h index cc4d4af..a1e479f 100644 --- a/Swift/QtUI/ChatList/ChatListGroupItem.h +++ b/Swift/QtUI/ChatList/ChatListGroupItem.h @@ -1,5 +1,5 @@  /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith   * Licensed under the GNU General Public License v3.   * See Documentation/Licenses/GPLv3.txt for more information.   */ @@ -13,8 +13,8 @@  namespace Swift {  	class ChatListGroupItem : public ChatListItem {  		public: -			ChatListGroupItem(const QString& name, ChatListGroupItem* parent) : ChatListItem(parent), name_(name) {}; -			void addItem(ChatListItem* item) {items_.push_back(item); qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}; +			ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {}; +			void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}};  			void remove(int index) {items_.removeAt(index);};  			int rowCount() {return items_.size();};  			ChatListItem* item(int i) {return items_[i];}; @@ -30,5 +30,6 @@ namespace Swift {  			QString name_;  			QList<ChatListItem*> items_; +			bool sorted_;  	};  } diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.h b/Swift/QtUI/ChatList/ChatListMUCItem.h index 068f5d6..f26aa67 100644 --- a/Swift/QtUI/ChatList/ChatListMUCItem.h +++ b/Swift/QtUI/ChatList/ChatListMUCItem.h @@ -15,14 +15,14 @@  #include "Swift/QtUI/ChatList/ChatListItem.h"  namespace Swift { -	enum MUCItemRoles { -		DetailTextRole = Qt::UserRole/*, -		AvatarRole = Qt::UserRole + 1, -		PresenceIconRole = Qt::UserRole + 2, -		StatusShowTypeRole = Qt::UserRole + 3*/ -	};  	class ChatListMUCItem : public ChatListItem {  		public: +			enum MUCItemRoles { +				DetailTextRole = Qt::UserRole/*, +				AvatarRole = Qt::UserRole + 1, +				PresenceIconRole = Qt::UserRole + 2, +				StatusShowTypeRole = Qt::UserRole + 3*/ +			};  			ChatListMUCItem(const MUCBookmark& bookmark, ChatListGroupItem* parent);  			const MUCBookmark& getBookmark();  			QVariant data(int role) const; diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp index ba7b766..681c1c2 100644 --- a/Swift/QtUI/ChatList/ChatListModel.cpp +++ b/Swift/QtUI/ChatList/ChatListModel.cpp @@ -1,22 +1,25 @@  /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith   * Licensed under the GNU General Public License v3.   * See Documentation/Licenses/GPLv3.txt for more information.   */ -#include "Swift/QtUI/ChatList/ChatListModel.h" +#include <Swift/QtUI/ChatList/ChatListModel.h> -#include "Swift/QtUI/ChatList/ChatListMUCItem.h" +#include <Swift/QtUI/ChatList/ChatListMUCItem.h> +#include <Swift/QtUI/ChatList/ChatListRecentItem.h>  namespace Swift {  ChatListModel::ChatListModel() { -	root_ = new ChatListGroupItem("", NULL); +	root_ = new ChatListGroupItem("", NULL, false);  	mucBookmarks_ = new ChatListGroupItem(tr("Bookmarked Rooms"), root_); +	recents_ = new ChatListGroupItem(tr("Recent Chats"), root_, false); +	root_->addItem(recents_);  	root_->addItem(mucBookmarks_);  } -void ChatListModel::clear() { +void ChatListModel::clearBookmarks() {  	emit layoutAboutToBeChanged();  	mucBookmarks_->clear();  	emit layoutChanged(); @@ -43,6 +46,15 @@ void ChatListModel::removeMUCBookmark(const Swift::MUCBookmark& bookmark) {  	}  } +void ChatListModel::setRecents(const std::list<ChatListWindow::Chat>& recents) { +	emit layoutAboutToBeChanged(); +	recents_->clear(); +	foreach (const ChatListWindow::Chat chat, recents) { +		recents_->addItem(new ChatListRecentItem(chat, recents_)); +	} +	emit layoutChanged(); +} +  int ChatListModel::columnCount(const QModelIndex& /*parent*/) const {  	return 1;  } diff --git a/Swift/QtUI/ChatList/ChatListModel.h b/Swift/QtUI/ChatList/ChatListModel.h index adde148..8e7828c 100644 --- a/Swift/QtUI/ChatList/ChatListModel.h +++ b/Swift/QtUI/ChatList/ChatListModel.h @@ -1,5 +1,5 @@  /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith   * Licensed under the GNU General Public License v3.   * See Documentation/Licenses/GPLv3.txt for more information.   */ @@ -11,9 +11,10 @@  #include <QAbstractItemModel>  #include <QList> -#include "Swiften/MUC/MUCBookmark.h" +#include <Swiften/MUC/MUCBookmark.h> +#include <Swift/Controllers/UIInterfaces/ChatListWindow.h> -#include "Swift/QtUI/ChatList/ChatListGroupItem.h" +#include <Swift/QtUI/ChatList/ChatListGroupItem.h>  namespace Swift {  	class ChatListModel : public QAbstractItemModel { @@ -28,9 +29,11 @@ namespace Swift {  			QModelIndex parent(const QModelIndex& index) const;  			int rowCount(const QModelIndex& parent = QModelIndex()) const;  			ChatListItem* getItemForIndex(const QModelIndex& index) const; -			void clear(); +			void clearBookmarks(); +			void setRecents(const std::list<ChatListWindow::Chat>& recents);  		private:  			ChatListGroupItem* mucBookmarks_; +			ChatListGroupItem* recents_;  			ChatListGroupItem* root_;  	}; diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.cpp b/Swift/QtUI/ChatList/ChatListRecentItem.cpp new file mode 100644 index 0000000..8b6707c --- /dev/null +++ b/Swift/QtUI/ChatList/ChatListRecentItem.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/QtUI/ChatList/ChatListRecentItem.h> + +#include <Swift/QtUI/QtSwiftUtil.h> + +namespace Swift { +ChatListRecentItem::ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent) : ChatListItem(parent), chat_(chat) { + +} + +const ChatListWindow::Chat& ChatListRecentItem::getChat() { +	return chat_; +} + +QVariant ChatListRecentItem::data(int role) const { +	switch (role) { +		case Qt::DisplayRole: return P2QSTRING(chat_.chatName); +		case DetailTextRole: return P2QSTRING(chat_.activity); +			/*case Qt::TextColorRole: return textColor_; +		case Qt::BackgroundColorRole: return backgroundColor_; +		case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant(); +		case StatusTextRole: return statusText_; +		case AvatarRole: return avatar_; +		case PresenceIconRole: return getPresenceIcon();*/ +		default: return QVariant(); +	} +} + +} diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.h b/Swift/QtUI/ChatList/ChatListRecentItem.h new file mode 100644 index 0000000..c2646cc --- /dev/null +++ b/Swift/QtUI/ChatList/ChatListRecentItem.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QList> + +#include <boost/shared_ptr.hpp> + +#include <Swiften/MUC/MUCBookmark.h> +#include <Swift/Controllers/UIInterfaces/ChatListWindow.h> + +#include <Swift/QtUI/ChatList/ChatListItem.h> + +namespace Swift { +	class ChatListRecentItem : public ChatListItem { +		public: +			enum RecentItemRoles { +				DetailTextRole = Qt::UserRole/*, +				AvatarRole = Qt::UserRole + 1, +				PresenceIconRole = Qt::UserRole + 2, +				StatusShowTypeRole = Qt::UserRole + 3*/ +			}; +			ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent); +			const ChatListWindow::Chat& getChat(); +			QVariant data(int role) const; +		private: +			ChatListWindow::Chat chat_; +	}; +} diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index b532cdb..d71563d 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -1,5 +1,5 @@  /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith   * Licensed under the GNU General Public License v3.   * See Documentation/Licenses/GPLv3.txt for more information.   */ @@ -10,9 +10,11 @@  #include <QContextMenuEvent>  #include "Swift/QtUI/ChatList/ChatListMUCItem.h" +#include "Swift/QtUI/ChatList/ChatListRecentItem.h"  #include "Swift/QtUI/QtAddBookmarkWindow.h"  #include "Swift/QtUI/QtEditBookmarkWindow.h"  #include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" +#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h"  #include "Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h"  #include "Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h"  #include "Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h" @@ -68,19 +70,30 @@ void QtChatListWindow::setupContextMenus() {  }  void QtChatListWindow::handleItemActivated(const QModelIndex& index) { -	if (!bookmarksEnabled_) { -		return; -	}  	ChatListItem* item = model_->getItemForIndex(index);  	ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item); -	if (mucItem) { +	if (bookmarksEnabled_ && mucItem) {  		boost::shared_ptr<UIEvent> event(new JoinMUCUIEvent(mucItem->getBookmark().getRoom(), mucItem->getBookmark().getNick()));  		eventStream_->send(event);  	} +	ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(item); +	if (recentItem) { +		boost::shared_ptr<UIEvent> event; +		if (recentItem->getChat().isMUC) { +			if (!bookmarksEnabled_) { +				return; +			} +			return; +		} +		else { +			event = boost::shared_ptr<UIEvent>(new RequestChatUIEvent(recentItem->getChat().jid)); +		} +		eventStream_->send(event); +	}  } -void QtChatListWindow::clear() { -	model_->clear(); +void QtChatListWindow::clearBookmarks() { +	model_->clearBookmarks();  }  void QtChatListWindow::addMUCBookmark(const MUCBookmark& bookmark) { @@ -91,6 +104,10 @@ void QtChatListWindow::removeMUCBookmark(const MUCBookmark& bookmark) {  	model_->removeMUCBookmark(bookmark);  } +void QtChatListWindow::setRecents(const std::list<ChatListWindow::Chat>& recents) { +	model_->setRecents(recents); +} +  void QtChatListWindow::handleRemoveBookmark() {  	ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_);  	if (!mucItem) return; diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h index 3a3e95f..f5c12f6 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.h +++ b/Swift/QtUI/ChatList/QtChatListWindow.h @@ -1,5 +1,5 @@  /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2011 Kevin Smith   * Licensed under the GNU General Public License v3.   * See Documentation/Licenses/GPLv3.txt for more information.   */ @@ -23,7 +23,8 @@ namespace Swift {  			void addMUCBookmark(const MUCBookmark& bookmark);  			void removeMUCBookmark(const MUCBookmark& bookmark);  			void setBookmarksEnabled(bool enabled); -			void clear(); +			void setRecents(const std::list<ChatListWindow::Chat>& recents); +			void clearBookmarks();  		private slots:  			void handleItemActivated(const QModelIndex&);  			void handleAddBookmark(); | 
 Swift
 Swift