source: src/mvc/treeview.cpp @ cdf0332

qt5
Last change on this file since cdf0332 was cdf0332, checked in by gregor herrmann <gregoa@…>, 9 years ago

fix typo in comment

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2012 Philipp Spitzer, gregor herrmann, Stefan Stahl
4 *
5 * This file is part of ConfClerk.
6 *
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)
10 * any later version.
11 *
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
15 * more details.
16 *
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/>.
19 */
20#include <QMouseEvent>
21
22#include "treeview.h"
23#include "delegate.h"
24#include "event.h"
25#include "conference.h"
26#include "eventmodel.h"
27
28#ifdef MAEMO
29#include "alarm.h"
30#endif
31
32#include <QDebug>
33
34TreeView::TreeView(QWidget *aParent)
35    : QTreeView(aParent)
36{
37    connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex)));
38}
39
40void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
41{
42    QModelIndex index = currentIndex();
43    QPoint point = aEvent->pos();
44
45    // test whether we have handled the mouse event
46    if(!testForControlClicked(index,point))
47    {
48        // pass the event to the Base class, so item clicks/events are handled correctly
49        QTreeView::mouseReleaseEvent(aEvent);
50    }
51}
52
53// returns bool if some Control was clicked
54bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
55{
56    bool handled = false;
57
58    if(!aIndex.isValid())
59        return handled;
60
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))
65    {
66        case Delegate::FavouriteControlOn:
67        case Delegate::FavouriteControlOff:
68            {
69                // handle Favourite Control clicked
70                Event event = Event::getById(aIndex.data().toInt(),confId);
71
72                QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
73                event.setFavourite(!event.isFavourite());
74                event.update("favourite");
75
76                if(event.isFavourite())
77                {
78                    // event has became 'favourite' and so 'conflicts' list may have changed
79                    conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
80                }
81
82                // have to emit 'eventChanged' signal on all events in conflict
83                for(int i=0; i<conflicts.count(); i++)
84                    emit eventChanged(conflicts[i].id(), false);
85
86                // since the Favourite icon has changed, update TreeViews accordingly
87                // all TreeViews have to listen on this signal
88                emit eventChanged(event.id(), true);
89
90                handled = true;
91            }
92            break;
93        case Delegate::AlarmControlOn:
94        case Delegate::AlarmControlOff:
95            {
96                // handle Alarm Control clicked
97                Event event = Event::getById(aIndex.data().toInt(),confId);
98                if(event.hasAlarm())
99                {
100                    event.setHasAlarm(false); // update DB
101#ifdef MAEMO
102                    // remove alarm from the 'alarmd' alarms list
103                    Alarm alarm;
104                    alarm.deleteAlarm(event.conferenceId(), event.id());
105#endif /* MAEMO */
106                }
107                else
108                {
109                    event.setHasAlarm(true);
110#ifdef MAEMO
111                    // add alarm to the 'alarmd'
112                    Alarm alarm;
113                    alarm.addAlarm(event.conferenceId(), event.id(), event.title(),event.start().addSecs(PRE_EVENT_ALARM_SEC));
114#endif /* MAEMO */
115                }
116                event.update("alarm");
117                // since the Alarm icon has changed, update TreeView accordingly
118                // all TreeViews have to listen on this signal
119                emit eventChanged(event.id(), false);
120                handled = true;
121            }
122            break;
123        case Delegate::WarningControl:
124        {
125
126            emit(requestForConflicts(aIndex));
127            handled = true;
128        }
129        break;
130        case Delegate::ControlNone:
131        default:
132            {
133                // item was clicked, but not a control
134                handled = false;
135            }
136    };
137
138    return handled;
139}
140
141void TreeView::handleItemClicked(const QModelIndex &index)
142{
143    if(!index.parent().isValid()) // time-group
144    {
145        if(isExpanded(index))
146            setExpanded(index, false);
147        else
148            setExpanded(index, true);
149    }
150}
151
152void TreeView::setAllExpanded(bool aExpanded)
153{
154    for(int i=0; i<model()->rowCount(QModelIndex()); i++)
155    {
156        setExpanded(model()->index(i,0,QModelIndex()),aExpanded);
157    }
158}
159
Note: See TracBrowser for help on using the repository browser.