/* * Copyright (c) 2010 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include "EventDelegate.h" #include #include "Swift/Controllers/XMPPEvents/MessageEvent.h" #include "Swift/Controllers/XMPPEvents/ErrorEvent.h" #include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h" #include "Swift/Controllers/XMPPEvents/MUCInviteEvent.h" namespace Swift { EventDelegate::EventDelegate() : QStyledItemDelegate(), messageDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false), subscriptionDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true), errorDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true), mucInviteDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false) { } QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { QtEvent* item = static_cast(index.internalPointer()); if (!item) { return QStyledItemDelegate::sizeHint(option, index); } switch (getEventType(item->getEvent())) { case MessageEventType: return messageDelegate_.sizeHint(option, item); case SubscriptionEventType: return subscriptionDelegate_.sizeHint(option, item); case ErrorEventType: return errorDelegate_.sizeHint(option, item); case MUCInviteEventType: return mucInviteDelegate_.sizeHint(option, item); } assert(false); return QSize(); } void EventDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QtEvent* item = static_cast(index.internalPointer()); if (!item) { QStyledItemDelegate::paint(painter, option, index); return; } switch (getEventType(item->getEvent())) { case MessageEventType: messageDelegate_.paint(painter, option, item);break; case SubscriptionEventType: subscriptionDelegate_.paint(painter, option, item);break; case ErrorEventType: errorDelegate_.paint(painter, option, item);break; case MUCInviteEventType: mucInviteDelegate_.paint(painter, option, item);break; } } EventType EventDelegate::getEventType(boost::shared_ptr event) const { boost::shared_ptr messageEvent = boost::dynamic_pointer_cast(event); if (messageEvent) { return MessageEventType; } boost::shared_ptr subscriptionEvent = boost::dynamic_pointer_cast(event); if (subscriptionEvent) { return SubscriptionEventType; } boost::shared_ptr errorEvent = boost::dynamic_pointer_cast(event); if (errorEvent) { return ErrorEventType; } boost::shared_ptr mucInviteEvent = boost::dynamic_pointer_cast(event); if (mucInviteEvent) { return MUCInviteEventType; } //I don't know what this is. assert(false); return MessageEventType; } }