2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2021 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, aEvent->button()))
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, Qt::MouseButton button)
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::FavouriteControlStrong:
68 case Delegate::FavouriteControlWeak:
69 case Delegate::FavouriteControlNo:
71 // handle Favourite Control clicked
72 Event event = Event::getById(aIndex.data().toInt(),confId);
74 QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
75 event.cycleFavourite(button == Qt::RightButton);
76 event.update("favourite");
78 // event has became 'favourite' and so 'conflicts' list may have changed
79 conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
81 // have to emit 'eventChanged' signal on all events in conflict
82 for(int i=0; i<conflicts.count(); i++)
83 emit eventChanged(conflicts[i].id(), false);
85 // since the Favourite icon has changed, update TreeViews accordingly
86 // all TreeViews have to listen on this signal
87 emit eventChanged(event.id(), true);
92 case Delegate::AlarmControlOn:
93 case Delegate::AlarmControlOff:
95 // handle Alarm Control clicked
96 Event event = Event::getById(aIndex.data().toInt(),confId);
99 event.setHasAlarm(false); // update DB
101 // remove alarm from the 'alarmd' alarms list
103 alarm.deleteAlarm(event.conferenceId(), event.id());
108 event.setHasAlarm(true);
110 // add alarm to the 'alarmd'
112 alarm.addAlarm(event.conferenceId(), event.id(), event.title(),event.start().addSecs(-AppSettings::preEventAlarmSec()));
115 event.update("alarm");
116 // since the Alarm icon has changed, update TreeView accordingly
117 // all TreeViews have to listen on this signal
118 emit eventChanged(event.id(), false);
122 case Delegate::WarningControl:
125 emit(requestForConflicts(aIndex));
129 case Delegate::ControlNone:
132 // item was clicked, but not a control
140 void TreeView::handleItemClicked(const QModelIndex &index)
142 if(!index.parent().isValid()) // time-group
144 if(isExpanded(index))
145 setExpanded(index, false);
147 setExpanded(index, true);
151 void TreeView::setAllExpanded(bool aExpanded)
153 for(int i=0; i<model()->rowCount(QModelIndex()); i++)
155 setExpanded(model()->index(i,0,QModelIndex()),aExpanded);