diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-04-16 15:09:23 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-04-16 15:09:23 (GMT) |
commit | e51448532f837d3ac28ea3c9b03f711df1940803 (patch) | |
tree | ad8582a7a311384002e16e706dcc376c50fd7e2d /Swift/QtUI/EventViewer/EventDelegate.cpp | |
parent | 1e42aa0003876f5416f723d535ca27e7b2f6dc68 (diff) | |
download | swift-e51448532f837d3ac28ea3c9b03f711df1940803.zip swift-e51448532f837d3ac28ea3c9b03f711df1940803.tar.bz2 |
Slighly better rendering for the Event view.
Diffstat (limited to 'Swift/QtUI/EventViewer/EventDelegate.cpp')
-rw-r--r-- | Swift/QtUI/EventViewer/EventDelegate.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/Swift/QtUI/EventViewer/EventDelegate.cpp b/Swift/QtUI/EventViewer/EventDelegate.cpp index 61a9fbd..8bdeb46 100644 --- a/Swift/QtUI/EventViewer/EventDelegate.cpp +++ b/Swift/QtUI/EventViewer/EventDelegate.cpp @@ -6,9 +6,54 @@ #include "EventDelegate.h" +#include <QDebug> + +#include "Swiften/Events/MessageEvent.h" +#include "Swiften/Events/ErrorEvent.h" +#include "Swiften/Events/SubscriptionRequestEvent.h" + namespace Swift { -EventDelegate::EventDelegate() : QStyledItemDelegate() { +EventDelegate::EventDelegate() : QStyledItemDelegate(), messageDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false), subscriptionDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true), errorDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true) { + +} + +QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { + QtEvent* item = static_cast<QtEvent*>(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); + default: return QStyledItemDelegate::sizeHint(option, index); + } +} + +void EventDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + QtEvent* item = static_cast<QtEvent*>(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; + default: QStyledItemDelegate::paint(painter, option, index); + } +} + +EventType EventDelegate::getEventType(boost::shared_ptr<StanzaEvent> event) const { + boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event); + if (messageEvent) return MessageEventType; + boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event); + if (subscriptionEvent) return SubscriptionEventType; + boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event); + if (errorEvent) return ErrorEventType; + //I don't know what this is. + assert(false); } |