2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
19 #include <QMouseEvent>
24 #include "conference.h"
25 #include "eventmodel.h"
33 TreeView::TreeView(QWidget *aParent)
36 connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex)));
39 void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
41 QModelIndex index = currentIndex();
42 QPoint point = aEvent->pos();
44 // test whether we have handled the mouse event
45 if(!testForControlClicked(index,point))
47 // pass the event to the Base class, so item clicks/events are handled correctly
48 QTreeView::mouseReleaseEvent(aEvent);
52 // returns bool if some Control was clicked
53 bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
60 int confId = Conference::activeConference();
61 QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
62 Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
63 switch(delegate->whichControlClicked(aIndex,aPoint))
65 case Delegate::FavouriteControlOn:
66 case Delegate::FavouriteControlOff:
68 // handle Favourite Control clicked
69 Event event = Event::getById(aIndex.data().toInt(),confId);
71 QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
72 if(event.isFavourite())
73 event.setFavourite(false);
75 event.setFavourite(true);
76 event.update("favourite");
78 qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
80 if(event.isFavourite())
82 // event has became 'favourite' and so 'conflicts' list may have changed
83 conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
86 // have to emit 'eventHasChanged' signal on all events in conflict
87 for(int i=0; i<conflicts.count(); i++)
88 emit(eventHasChanged(conflicts[i].id()));
90 // since the Favourite icon has changed, update TreeViews accordingly
91 // all TreeViews have to listen on this signal
92 emit(eventHasChanged(event.id(),true));
97 case Delegate::AlarmControlOn:
98 case Delegate::AlarmControlOff:
100 // handle Alarm Control clicked
101 Event event = Event::getById(aIndex.data().toInt(),confId);
104 event.setHasAlarm(false); // update DB
106 // remove alarm from the 'alarmd' alrms list
108 alarm.deleteAlarm(event.id());
109 // TODO: test if removing was successfull
114 event.setHasAlarm(true);
116 // add alarm to the 'alarmd'
118 //int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10)); // testing
119 int cookie = alarm.addAlarm(event.id(),event.start().addSecs(-15*60)); // 15 minutes before real start
120 qDebug() << "cookie: " << cookie;
123 event.update("alarm");
124 qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
125 // since the Alarm icon has changed, update TreeView accordingly
126 // all TreeViews have to listen on this signal
127 emit(eventHasChanged(event.id()));
131 case Delegate::MapControl:
133 // handle Alarm Control clicked
134 qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
135 emit(requestForMap(aIndex));
139 case Delegate::WarningControl:
142 qDebug() << "WARNING CLICKED: " << qVariantValue<QString>(aIndex.data());
143 emit(requestForConflicts(aIndex));
147 case Delegate::ControlNone:
150 // item was clicked, but not a control
158 void TreeView::handleItemClicked(const QModelIndex &index)
160 if(!index.parent().isValid()) // time-group
162 if(isExpanded(index))
163 setExpanded(index, false);
165 setExpanded(index, true);
169 void TreeView::setAllExpanded(bool aExpanded)
171 for(int i=0; i<model()->rowCount(QModelIndex()); i++)
173 setExpanded(model()->index(i,0,QModelIndex()),aExpanded);