diff options
author | Kevin Smith <git@kismith.co.uk> | 2009-07-26 19:17:46 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2009-07-26 19:17:46 (GMT) |
commit | 46e59e0e6bfceee216db3414680825cbdae60daf (patch) | |
tree | d1e078bb0eec292d628e7d44fccc8345ecc1d911 | |
parent | ce74ccc7c8d2ce4c032a90b1ebc0ebd30b4ea4c8 (diff) | |
download | swift-46e59e0e6bfceee216db3414680825cbdae60daf.zip swift-46e59e0e6bfceee216db3414680825cbdae60daf.tar.bz2 |
Use a (boring) delegate for roster rendering.
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.cpp | 3 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidgetItem.cpp | 16 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidgetItem.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/Roster/RosterDelegate.cpp | 16 | ||||
-rw-r--r-- | Swift/QtUI/Roster/RosterDelegate.h | 10 |
6 files changed, 41 insertions, 8 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index 0aebc24..714beb2 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -10,6 +10,8 @@ QtTreeWidget::QtTreeWidget(QWidget* parent) : QTreeView(parent) { model_ = new RosterModel(); model_->setRoot(treeRoot_); setModel(model_); + delegate_ = new RosterDelegate(); + setItemDelegate(delegate_); setHeaderHidden(true); #ifdef SWIFT_PLATFORM_MACOSX setAlternatingRowColors(true); @@ -22,6 +24,7 @@ QtTreeWidget::QtTreeWidget(QWidget* parent) : QTreeView(parent) { QtTreeWidget::~QtTreeWidget() { delete model_; + delete delegate_; } QtTreeWidgetItem* QtTreeWidget::getRoot() { diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h index 73ac86c..b8d3c23 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.h +++ b/Swift/QtUI/Roster/QtTreeWidget.h @@ -9,6 +9,7 @@ #include "Swift/QtUI/Roster/QtTreeWidgetItem.h" #include "Swift/QtUI/Roster/QtTreeWidget.h" #include "Swift/QtUI/Roster/RosterModel.h" +#include "Swift/QtUI/Roster/RosterDelegate.h" namespace Swift { @@ -24,6 +25,7 @@ class QtTreeWidget : public QTreeView, public TreeWidget { private: void drawBranches(QPainter*, const QRect&, const QModelIndex&) const; RosterModel* model_; + RosterDelegate* delegate_; QtTreeWidgetItem* treeRoot_; }; diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp index 6ebeb7f..2c05053 100644 --- a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp @@ -14,17 +14,17 @@ void QtTreeWidgetItem::setText(const String& text) { } void QtTreeWidgetItem::setTextColor(unsigned long color) { - // QTreeWidgetItem::setTextColor(0, QColor( - // ((color & 0xFF0000)>>16), - // ((color & 0xFF00)>>8), - // (color & 0xFF))); + textColor_ = QColor( + ((color & 0xFF0000)>>16), + ((color & 0xFF00)>>8), + (color & 0xFF)); } void QtTreeWidgetItem::setBackgroundColor(unsigned long color) { - // QTreeWidgetItem::setBackgroundColor(0, QColor( - // ((color & 0xFF0000)>>16), - // ((color & 0xFF00)>>8), - // (color & 0xFF))); + backgroundColor_ = QColor( + ((color & 0xFF0000)>>16), + ((color & 0xFF00)>>8), + (color & 0xFF)); } void QtTreeWidgetItem::setExpanded(bool b) { diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h index daffcc2..017258b 100644 --- a/Swift/QtUI/Roster/QtTreeWidgetItem.h +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h @@ -43,6 +43,8 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem { QList<QtTreeWidgetItem*> children_; QtTreeWidgetItem* parent_; QString displayName_; + QColor textColor_; + QColor backgroundColor_; }; } diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index e69de29..925f66c 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -0,0 +1,16 @@ +#include "RosterDelegate.h" + +#include <QPainter> + +namespace Swift { +QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { + return QSize(100,50); +} + +void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex index) const { + painter->save(); + QStyledItemDelegate::paint(painter, option, index); + painter->restore(); +} + +}
\ No newline at end of file diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h index e69de29..32bba80 100644 --- a/Swift/QtUI/Roster/RosterDelegate.h +++ b/Swift/QtUI/Roster/RosterDelegate.h @@ -0,0 +1,10 @@ +#pragma once + +#import <QStyledItemDelegate> + +namespace Swift { + class RosterDelegate : public QStyledItemDelegate { + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex index) const; + }; +}
\ No newline at end of file |