6 #include "conference.h"
7 #include "eventmodel.h"
15 TreeView::TreeView(QWidget *aParent)
18 connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex)));
21 void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
23 QModelIndex index = currentIndex();
24 QPoint point = aEvent->pos();
26 // test whether we have handled the mouse event
27 if(!testForControlClicked(index,point))
29 // pass the event to the Base class, so item clicks/events are handled correctly
30 QTreeView::mouseReleaseEvent(aEvent);
34 // returns bool if some Control was clicked
35 bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
42 QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
43 Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
44 switch(delegate->whichControlClicked(aIndex,aPoint))
46 case Delegate::FavouriteControlOn:
47 case Delegate::FavouriteControlOff:
49 // handle Favourite Control clicked
50 Event event = Event::getById(aIndex.data().toInt(),1);
52 QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
53 if(event.isFavourite())
54 event.setFavourite(false);
56 event.setFavourite(true);
57 event.update("favourite");
59 qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
60 // update EVENT_CONFLICT table
61 event.updateConflicts();
62 if(event.isFavourite())
64 // event has became 'favourite' and so 'conflicts' list may have changed
65 conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
68 // since the Favourite icon has changed, update TreeViews accordingly
69 // all TreeViews have to listen on this signal
70 emit(eventHasChanged(event.id()));
72 // have to emit 'eventHasChanged' signal on all events in conflict
73 for(int i=0; i<conflicts.count(); i++)
74 emit(eventHasChanged(conflicts[i].id()));
79 case Delegate::AlarmControlOn:
80 case Delegate::AlarmControlOff:
82 // handle Alarm Control clicked
83 Event event = Event::getById(aIndex.data().toInt(),1);
86 event.setHasAlarm(false); // update DB
88 // remove alarm from the 'alarmd' alrms list
90 alarm.deleteAlarm(event.id());
91 // TODO: test if removing was successfull
96 event.setHasAlarm(true);
98 // add alarm to the 'alarmd'
100 int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10));
101 qDebug() << "cookie: " << cookie;
104 event.update("alarm");
105 qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
106 // since the Alarm icon has changed, update TreeView accordingly
107 // all TreeViews have to listen on this signal
108 emit(eventHasChanged(event.id()));
112 case Delegate::MapControl:
114 // handle Alarm Control clicked
115 qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
116 emit(requestForMap(aIndex));
120 case Delegate::WarningControl:
123 qDebug() << "WARNING CLICKED: " << qVariantValue<QString>(aIndex.data());
124 emit(requestForConflicts(aIndex));
128 case Delegate::ControlNone:
131 // item was clicked, but not a control
139 void TreeView::handleItemClicked(const QModelIndex &index)
141 if(!index.parent().isValid()) // time-group
143 if(isExpanded(index))
144 setExpanded(index, false);
146 setExpanded(index, true);
150 void TreeView::setAllExpanded(bool aExpanded)
152 for(int i=0; i<model()->rowCount(QModelIndex()); i++)
154 setExpanded(model()->index(i,0,QModelIndex()),aExpanded);