4 #include <QItemDelegate>
8 class Delegate : public QItemDelegate
24 Control(ControlId aControlId, const QString &aImageName)
26 , mImage(new QImage(aImageName))
27 , mDrawPoint(QPoint(0,0))
29 inline QImage *image() const { return mImage; }
30 inline void setDrawPoint(const QPoint &aPoint) { mDrawPoint = aPoint; }
31 inline QPoint drawPoint(const QRect &aRect) const // for painter to draw Control
33 return QPoint(aRect.x()+aRect.width(),aRect.y()) + mDrawPoint;
35 inline QRect drawRect(const QRect &aRect) const // helper for determining if Control was clicked
37 return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
42 QPoint mDrawPoint; // relative 'start-drawing' position (may hold negative values)
45 Delegate(QTreeView *aParent); // the delegate 'owner' has to be specified in the constructor - it's used to obtain visualRect of selected item/index
48 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
49 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
51 Delegate::ControlId whichControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) const;
52 bool isPointFromRect(const QPoint &aPoint, const QRect &aRect) const;
55 bool hasParent( const QModelIndex &index ) const;
56 bool isLast( const QModelIndex &index ) const;
57 bool isExpanded( const QModelIndex &index ) const;
58 void defineControls();
61 QPointer<QTreeView> mViewPtr;
62 QMap<ControlId,Control*> mControls;
65 #endif /* DELEGATE_H */