cherish
ListDelegate.h
1 #ifndef LISTDELEGATE_H
2 #define LISTDELEGATE_H
3 
4 #include <QStyledItemDelegate>
5 #include <QPainter>
6 #include <QModelIndex>
7 #include <QStyle>
8 
9 /* BookmarkDelegate is class responsible for look and functionality of
10  * BookmarkWidget. More precisely, it provides info on how and where to locate
11  * a "delete" button within each of the bookmark.
12  * Whenever the button is pressed, a dialogue is popped up asking the user to confirm
13  * if they really want to delete the corresponding bookmark.
14  *
15  * For more info on Qt delegates, refer to offician Qt doc pages: model/view framework,
16  * and delegates.
17 */
18 
22 class BookmarkDelegate : public QStyledItemDelegate
23 {
24  Q_OBJECT
25 
26 public:
28  BookmarkDelegate(QObject* parent=0);
29 
31  virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
32 
34  bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
35 
36 signals:
38  void clickedDelete(const QModelIndex& index);
39 
41  void clickedMove(const QModelIndex& index);
42 
44  void clickedApplyState(const QModelIndex& index);
45 
46 private:
47  QRect getButtonDeleteRect(const QRect& rect) const;
48  QRect getButtonMoveRect(const QRect& rect) const;
49  QRect getButtonStateRect(const QRect& rect) const;
50 
51  bool isInside(int clickX, int clickY, const QRect& rect) const;
52 };
53 
57 class CanvasDelegate : public QStyledItemDelegate
58 {
59  Q_OBJECT
60 public:
62  CanvasDelegate(QObject* parent=0);
63 
65  virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
66 
68  bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
69 
71  virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
72 
73 signals:
75  void clickedDelete(const QModelIndex& index);
76 
78  void clickedDeletePhoto(const QModelIndex& index);
79 
81  void clickedVisibilitySet(int index);
82 
84  void clickedTransparencyPlus(const QModelIndex& index);
85 
87  void clickedTransparencyMinus(const QModelIndex& index);
88 
89 public: // made public to make sure tests have access to these methods
90 #ifndef DOXYGEN_SHOULD_SKIP_THIS
91  QRect getButtonDeleteRect(const QRect& rect) const;
92  QRect getButtonVisibilityRect(const QRect& rect) const;
93  QRect getButtonPlusRect(const QRect& rect) const;
94  QRect getButtonMinusRect(const QRect& rect) const;
95 #endif // DOXYGEN_SHOULD_SKIP_THIS
96 };
97 
98 #endif // LISTDELEGATE_H
Inherited from QStyledItemDelegate, it defines the look and functionality of BookmarkWidget.
Definition: ListDelegate.h:22
void clickedMove(const QModelIndex &index)
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
Definition: ListDelegate.cpp:53
BookmarkDelegate(QObject *parent=0)
Definition: ListDelegate.cpp:17
void clickedApplyState(const QModelIndex &index)
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: ListDelegate.cpp:22
Inherited from QStyledItemDelegate, it defines the look and functionality of CanvasPhotoWidget.
Definition: ListDelegate.h:57
void clickedDelete(const QModelIndex &index)