2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2017 Philipp Spitzer, gregor herrmann, Stefan Stahl
5 * This file is part of ConfClerk.
7 * ConfClerk is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 2 of the License, or (at your option)
12 * ConfClerk is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
25 class Delegate : public QItemDelegate
34 FavouriteControlStrong,
45 Control(ControlId aControlId, const QString &aImageName, const Control* prev_control);
47 inline QImage *image() const { return mImage; }
48 inline void setDrawPoint(const QPoint &aPoint) { mDrawPoint = aPoint; }
49 inline QRect drawRect(const QRect &aRect) const // helper for determining if Control was clicked
51 return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
53 void paint(QPainter* painter, const QRect rect);
55 bool enabled() const { return mEnabled; }
56 void setEnabled(bool v) { mEnabled = v; }
58 inline QPoint drawPoint(const QRect &aRect = QRect()) const // for painter to draw Control
60 if(aRect == QRect()) // null rectangle
61 return mDrawPoint; // returns relative drawing point
63 return QPoint(aRect.x()+aRect.width(),aRect.y()) + mDrawPoint; // returns absolute drawing point
68 QPoint mDrawPoint; // relative 'start-drawing' position (may hold negative values)
72 Delegate(QTreeView *aParent); // the delegate 'owner' has to be specified in the constructor - it's used to obtain visualRect of selected item/index
75 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
76 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
78 Delegate::ControlId whichControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) const;
79 bool isPointFromRect(const QPoint &aPoint, const QRect &aRect) const;
82 bool hasParent( const QModelIndex &index ) const;
83 bool isLast( const QModelIndex &index ) const;
84 bool isExpanded( const QModelIndex &index ) const;
85 void defineControls();
86 // TODO: the better place for these methods would be 'eventmodel'
87 // they are used in 'paint' method and so it's better to obtain number of
88 // favourities/alarms once when the data has changed and not to call
89 // these methods which iterate over all Events in corresponding group
90 // every time it requires them
91 int numberOfFavourities(const QModelIndex &index) const;
92 int numberOfAlarms(const QModelIndex &index) const;
95 QPointer<QTreeView> mViewPtr;
96 QMap<ControlId,Control*> mControls;
99 #endif /* DELEGATE_H */