80fbd281fbe43f4e30998d334de1e0569eac2c76
[toast/confclerk.git] / src / mvc / treeview.cpp
1 #include <QMouseEvent>
2
3 #include "treeview.h"
4 #include "delegate.h"
5
6 #include <QDebug>
7
8 TreeView::TreeView(QWidget *aParent)
9     : QTreeView(aParent)
10 {
11 }
12
13 void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
14 {
15     QModelIndex index = currentIndex();
16     QPoint point = aEvent->pos();
17
18     testForControlClicked(index,point);
19
20     // pass the event to the Base class, so item clicks/events are handled correctly
21     QTreeView::mouseReleaseEvent(aEvent);
22 }
23
24 void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) 
25 {
26     if(!aIndex.isValid())
27         return;
28
29     QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
30     Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
31     switch(delegate->whichControlClicked(aIndex,aPoint))
32     {
33         case Delegate::FavouriteControl:
34             {
35                 // handle Favourite Control clicked
36                 qDebug() << "FAVOURITE CLICKED: " << qVariantValue<QString>(aIndex.data());
37             }
38             break;
39         case Delegate::AlarmControl:
40             {
41                 // handle Alarm Control clicked
42                 qDebug() << "ALARM CLICKED: " << qVariantValue<QString>(aIndex.data());
43             }
44             break;
45         case Delegate::ControlNone:
46         default:
47             {
48                 // item was clicked, but not a control
49             }
50     };
51 }
52