4 #include <QItemDelegate>
8 class Delegate : public QItemDelegate
29 Control(ControlId aControlId, const QString &aImageName)
31 , mImage(new QImage(aImageName))
32 , mDrawPoint(QPoint(0,0))
34 inline QImage *image() const { return mImage; }
35 inline void setDrawPoint(const QPoint &aPoint) { mDrawPoint = aPoint; }
36 inline QPoint drawPoint(const QRect &aRect = QRect()) const // for painter to draw Control
38 if(aRect == QRect()) // null rectangle
39 return mDrawPoint; // returns relative drawing point
41 return QPoint(aRect.x()+aRect.width(),aRect.y()) + mDrawPoint; // returns absolute drawing point
43 inline QRect drawRect(const QRect &aRect) const // helper for determining if Control was clicked
45 return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
51 QPoint mDrawPoint; // relative 'start-drawing' position (may hold negative values)
54 Delegate(QTreeView *aParent); // the delegate 'owner' has to be specified in the constructor - it's used to obtain visualRect of selected item/index
57 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
58 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
60 Delegate::ControlId whichControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) const;
61 bool isPointFromRect(const QPoint &aPoint, const QRect &aRect) const;
64 bool hasParent( const QModelIndex &index ) const;
65 bool isLast( const QModelIndex &index ) const;
66 bool isExpanded( const QModelIndex &index ) const;
67 void defineControls();
68 // TODO: the better place for these methods would be 'eventmodel'
69 // they are used in 'paint' method and so it's better to obtain number of
70 // favourities/alarms once when the data has changed and not to call
71 // these methods which iterate over all Events in corresponding group
72 // every time it requires them
73 int numberOfFavourities(const QModelIndex &index) const;
74 int numberOfAlarms(const QModelIndex &index) const;
75 bool hasTimeConflict(const QModelIndex &index, const QModelIndex &parent) const;
78 QPointer<QTreeView> mViewPtr;
79 QMap<ControlId,Control*> mControls;
82 #endif /* DELEGATE_H */