source: src/mvc/treeview.cpp @ 4a87a3b

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

Bump copyright year.

In anticipation of a release in 2015.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2015 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#include "appsettings.h"
31#endif
32
33#include <QDebug>
34
35TreeView::TreeView(QWidget *aParent)
36    : QTreeView(aParent)
37{
38    connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex)));
39}
40
41void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
42{
43    QModelIndex index = currentIndex();
44    QPoint point = aEvent->pos();
45
46    // test whether we have handled the mouse event
47    if(!testForControlClicked(index,point))
48    {
49        // pass the event to the Base class, so item clicks/events are handled correctly
50        QTreeView::mouseReleaseEvent(aEvent);
51    }
52}
53
54// returns bool if some Control was clicked
55bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
56{
57    bool handled = false;
58
59    if(!aIndex.isValid())
60        return handled;
61
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))
66    {
67        case Delegate::FavouriteControlOn:
68        case Delegate::FavouriteControlOff:
69            {
70                // handle Favourite Control clicked
71                Event event = Event::getById(aIndex.data().toInt(),confId);
72
73                QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
74                event.setFavourite(!event.isFavourite());
75                event.update("favourite");
76
77                if(event.isFavourite())
78                {
79                    // event has became 'favourite' and so 'conflicts' list may have changed
80                    conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
81                }
82
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);
86
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);
90
91                handled = true;
92            }
93            break;
94        case Delegate::AlarmControlOn:
95        case Delegate::AlarmControlOff:
96            {
97                // handle Alarm Control clicked
98                Event event = Event::getById(aIndex.data().toInt(),confId);
99                if(event.hasAlarm())
100                {
101                    event.setHasAlarm(false); // update DB
102#ifdef MAEMO
103                    // remove alarm from the 'alarmd' alarms list
104                    Alarm alarm;
105                    alarm.deleteAlarm(event.conferenceId(), event.id());
106#endif /* MAEMO */
107                }
108                else
109                {
110                    event.setHasAlarm(true);
111#ifdef MAEMO
112                    // add alarm to the 'alarmd'
113                    Alarm alarm;
114                    alarm.addAlarm(event.conferenceId(), event.id(), event.title(),event.start().addSecs(-AppSettings::preEventAlarmSec()));
115#endif /* MAEMO */
116                }
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);
121                handled = true;
122            }
123            break;
124        case Delegate::WarningControl:
125        {
126
127            emit(requestForConflicts(aIndex));
128            handled = true;
129        }
130        break;
131        case Delegate::ControlNone:
132        default:
133            {
134                // item was clicked, but not a control
135                handled = false;
136            }
137    };
138
139    return handled;
140}
141
142void TreeView::handleItemClicked(const QModelIndex &index)
143{
144    if(!index.parent().isValid()) // time-group
145    {
146        if(isExpanded(index))
147            setExpanded(index, false);
148        else
149            setExpanded(index, true);
150    }
151}
152
153void TreeView::setAllExpanded(bool aExpanded)
154{
155    for(int i=0; i<model()->rowCount(QModelIndex()); i++)
156    {
157        setExpanded(model()->index(i,0,QModelIndex()),aExpanded);
158    }
159}
160
Note: See TracBrowser for help on using the repository browser.