2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
5 * This file is part of ConfClerk.
7 * ConfClerk is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 2 of the License, or (at your option)
12 * ConfClerk is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
20 #include <QMouseEvent>
25 #include "conference.h"
26 #include "eventmodel.h"
34 TreeView::TreeView(QWidget *aParent)
37 connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex)));
40 void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
42 QModelIndex index = currentIndex();
43 QPoint point = aEvent->pos();
45 // test whether we have handled the mouse event
46 if(!testForControlClicked(index,point))
48 // pass the event to the Base class, so item clicks/events are handled correctly
49 QTreeView::mouseReleaseEvent(aEvent);
53 // returns bool if some Control was clicked
54 bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
61 int confId = Conference::activeConference();
62 // QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
63 Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
64 switch(delegate->whichControlClicked(aIndex,aPoint))
66 case Delegate::FavouriteControlOn:
67 case Delegate::FavouriteControlOff:
69 // handle Favourite Control clicked
70 Event event = Event::getById(aIndex.data().toInt(),confId);
72 QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
73 if(event.isFavourite())
74 event.setFavourite(false);
76 event.setFavourite(true);
77 event.update("favourite");
79 if(event.isFavourite())
81 // event has became 'favourite' and so 'conflicts' list may have changed
82 conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
85 // have to emit 'eventHasChanged' signal on all events in conflict
86 for(int i=0; i<conflicts.count(); i++)
87 emit(eventHasChanged(conflicts[i].id()));
89 // since the Favourite icon has changed, update TreeViews accordingly
90 // all TreeViews have to listen on this signal
91 emit(eventHasChanged(event.id(),true));
96 case Delegate::AlarmControlOn:
97 case Delegate::AlarmControlOff:
99 // handle Alarm Control clicked
100 Event event = Event::getById(aIndex.data().toInt(),confId);
103 event.setHasAlarm(false); // update DB
105 // remove alarm from the 'alarmd' alrms list
107 alarm.deleteAlarm(event.id());
108 // TODO: test if removing was successfull
113 event.setHasAlarm(true);
115 // add alarm to the 'alarmd'
117 //int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10)); // testing
118 int cookie = alarm.addAlarm(event.id(),event.start().addSecs(-15*60)); // 15 minutes before real start
121 event.update("alarm");
122 // since the Alarm icon has changed, update TreeView accordingly
123 // all TreeViews have to listen on this signal
124 emit(eventHasChanged(event.id()));
128 case Delegate::MapControl:
130 // handle Alarm Control clicked
131 emit(requestForMap(aIndex));
135 case Delegate::WarningControl:
138 emit(requestForConflicts(aIndex));
142 case Delegate::ControlNone:
145 // item was clicked, but not a control
153 void TreeView::handleItemClicked(const QModelIndex &index)
155 if(!index.parent().isValid()) // time-group
157 if(isExpanded(index))
158 setExpanded(index, false);
160 setExpanded(index, true);
164 void TreeView::setAllExpanded(bool aExpanded)
166 for(int i=0; i<model()->rowCount(QModelIndex()); i++)
168 setExpanded(model()->index(i,0,QModelIndex()),aExpanded);