2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2013 Philipp Spitzer, gregor herrmann, Stefan Stahl
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"
30 #include "appsettings.h"
35 TreeView::TreeView(QWidget *aParent)
38 connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex)));
41 void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
43 QModelIndex index = currentIndex();
44 QPoint point = aEvent->pos();
46 // test whether we have handled the mouse event
47 if(!testForControlClicked(index,point))
49 // pass the event to the Base class, so item clicks/events are handled correctly
50 QTreeView::mouseReleaseEvent(aEvent);
54 // returns bool if some Control was clicked
55 bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
62 int confId = Conference::activeConference();
63 // QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
64 Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
65 switch(delegate->whichControlClicked(aIndex,aPoint))
67 case Delegate::FavouriteControlOn:
68 case Delegate::FavouriteControlOff:
70 // handle Favourite Control clicked
71 Event event = Event::getById(aIndex.data().toInt(),confId);
73 QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
74 event.setFavourite(!event.isFavourite());
75 event.update("favourite");
77 if(event.isFavourite())
79 // event has became 'favourite' and so 'conflicts' list may have changed
80 conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
83 // have to emit 'eventChanged' signal on all events in conflict
84 for(int i=0; i<conflicts.count(); i++)
85 emit eventChanged(conflicts[i].id(), false);
87 // since the Favourite icon has changed, update TreeViews accordingly
88 // all TreeViews have to listen on this signal
89 emit eventChanged(event.id(), true);
94 case Delegate::AlarmControlOn:
95 case Delegate::AlarmControlOff:
97 // handle Alarm Control clicked
98 Event event = Event::getById(aIndex.data().toInt(),confId);
101 event.setHasAlarm(false); // update DB
103 // remove alarm from the 'alarmd' alarms list
105 alarm.deleteAlarm(event.conferenceId(), event.id());
110 event.setHasAlarm(true);
112 // add alarm to the 'alarmd'
114 alarm.addAlarm(event.conferenceId(), event.id(), event.title(),event.start().addSecs(-AppSettings::preEventAlarmSec()));
117 event.update("alarm");
118 // since the Alarm icon has changed, update TreeView accordingly
119 // all TreeViews have to listen on this signal
120 emit eventChanged(event.id(), false);
124 case Delegate::WarningControl:
127 emit(requestForConflicts(aIndex));
131 case Delegate::ControlNone:
134 // item was clicked, but not a control
142 void TreeView::handleItemClicked(const QModelIndex &index)
144 if(!index.parent().isValid()) // time-group
146 if(isExpanded(index))
147 setExpanded(index, false);
149 setExpanded(index, true);
153 void TreeView::setAllExpanded(bool aExpanded)
155 for(int i=0; i<model()->rowCount(QModelIndex()); i++)
157 setExpanded(model()->index(i,0,QModelIndex()),aExpanded);