source: src/mvc/treeview.cpp @ c53a3f4

qt5
Last change on this file since c53a3f4 was c53a3f4, checked in by pavelpa <pavelpa@…>, 12 years ago

single-click is used to open event dialog

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[66327a0]1#include <QMouseEvent>
2
3#include "treeview.h"
4#include "delegate.h"
[680a4da]5#include "event.h"
[67c59a7]6#include "eventmodel.h"
[66327a0]7
[6bd729b]8#ifdef MAEMO
9#include <alarm.h>
10#endif
11
[66327a0]12#include <QDebug>
13
14TreeView::TreeView(QWidget *aParent)
15    : QTreeView(aParent)
16{
17}
18
19void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
20{
21    QModelIndex index = currentIndex();
22    QPoint point = aEvent->pos();
23
[c53a3f4]24    // test whether we have handled the mouse event
25    if(!testForControlClicked(index,point))
26    {
27        // pass the event to the Base class, so item clicks/events are handled correctly
28        QTreeView::mouseReleaseEvent(aEvent);
29    }
[66327a0]30}
31
[c53a3f4]32// returns bool if some Control was clicked
33bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
[66327a0]34{
[c53a3f4]35    bool handled = false;
36
[66327a0]37    if(!aIndex.isValid())
[c53a3f4]38        return handled;
[66327a0]39
40    QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
41    Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
42    switch(delegate->whichControlClicked(aIndex,aPoint))
43    {
[680a4da]44        case Delegate::FavouriteControlOn:
45        case Delegate::FavouriteControlOff:
[66327a0]46            {
47                // handle Favourite Control clicked
[680a4da]48                Event event = Event::getById(aIndex.data().toInt(),1);
49                if(event.isFavourite())
50                {
51                    static_cast<Event*>(aIndex.internalPointer())->setFavourite(false); // list of events
52                    event.setFavourite(false); // update DB
53                }
54                else
55                {
56                    static_cast<Event*>(aIndex.internalPointer())->setFavourite(true); // list of events
57                    event.setFavourite(true);
58                }
59                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
60                event.update("favourite");
[67c59a7]61                // since the Favourite icon has changed, update TreeView accordingly
62                static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
[c53a3f4]63                handled = true;
[66327a0]64            }
65            break;
[680a4da]66        case Delegate::AlarmControlOn:
67        case Delegate::AlarmControlOff:
[66327a0]68            {
69                // handle Alarm Control clicked
[b6cd05c]70                Event event = Event::getById(aIndex.data().toInt(),1);
71                if(event.hasAlarm())
72                {
73                    static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(false); // list of events
74                    event.setHasAlarm(false); // update DB
[6bd729b]75#ifdef MAEMO
76                    // remove alarm from the 'alarmd' alrms list
77                    Alarm alarm;
78                    alarm.deleteAlarm(event.id());
79                    // TODO: test if removing was successfull
80#endif /* MAEMO */
[b6cd05c]81                }
82                else
83                {
84                    static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(true); // list of events
85                    event.setHasAlarm(true);
[6bd729b]86#ifdef MAEMO
87                    // add alarm to the 'alarmd'
88                    Alarm alarm;
89                    int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10));
90                    qDebug() << "cookie: " << cookie;
91#endif /* MAEMO */
[b6cd05c]92                }
93                qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
94                event.update("alarm");
95                // since the Alarm icon has changed, update TreeView accordingly
96                static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
[c53a3f4]97                handled = true;
[66327a0]98            }
99            break;
[03ff157]100        case Delegate::MapControl:
101            {
102                // handle Alarm Control clicked
103                qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
[59c6cfe]104                emit(requestForMap(aIndex));
[c53a3f4]105                handled = true;
[03ff157]106            }
107        break;
[66327a0]108        case Delegate::ControlNone:
109        default:
110            {
111                // item was clicked, but not a control
[c53a3f4]112                handled = false;
[66327a0]113            }
114    };
[c53a3f4]115
116    return handled;
[66327a0]117}
118
Note: See TracBrowser for help on using the repository browser.