qt5
Last change
on this file since 92995da was
92995da,
checked in by pavelpa <pavelpa@…>, 13 years ago
|
just some directory renaming
- renamed 'model' to 'mvc' (Model-View-Controller), since it contains also 'delegate' and 'view'
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
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 | |
---|
Note: See
TracBrowser
for help on using the repository browser.