Map button/compass icon added
[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::MapControl:
46             {
47                 // handle Alarm Control clicked
48                 qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
49             }
50         break;
51         case Delegate::ControlNone:
52         default:
53             {
54                 // item was clicked, but not a control
55             }
56     };
57 }
58