source: src/mvc/treeview.cpp

Last change on this file was ffb6be7, checked in by gregor herrmann <gregor@…>, 4 months ago

Bump copyright years.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2021 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, aEvent->button()))
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, Qt::MouseButton button)
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::FavouriteControlStrong:
68        case Delegate::FavouriteControlWeak:
69        case Delegate::FavouriteControlNo:
70            {
71                // handle Favourite Control clicked
72                Event event = Event::getById(aIndex.data().toInt(),confId);
73
74                QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
75                event.cycleFavourite(button == Qt::RightButton);
76                event.update("favourite");
77
78                // event has became 'favourite' and so 'conflicts' list may have changed
79                conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
80
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);
84
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);
88
89                handled = true;
90            }
91            break;
92        case Delegate::AlarmControlOn:
93        case Delegate::AlarmControlOff:
94            {
95                // handle Alarm Control clicked
96                Event event = Event::getById(aIndex.data().toInt(),confId);
97                if(event.hasAlarm())
98                {
99                    event.setHasAlarm(false); // update DB
100#ifdef MAEMO
101                    // remove alarm from the 'alarmd' alarms list
102                    Alarm alarm;
103                    alarm.deleteAlarm(event.conferenceId(), event.id());
104#endif /* MAEMO */
105                }
106                else
107                {
108                    event.setHasAlarm(true);
109#ifdef MAEMO
110                    // add alarm to the 'alarmd'
111                    Alarm alarm;
112                    alarm.addAlarm(event.conferenceId(), event.id(), event.title(),event.start().addSecs(-AppSettings::preEventAlarmSec()));
113#endif /* MAEMO */
114                }
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);
119                handled = true;
120            }
121            break;
122        case Delegate::WarningControl:
123        {
124
125            emit(requestForConflicts(aIndex));
126            handled = true;
127        }
128        break;
129        case Delegate::ControlNone:
130        default:
131            {
132                // item was clicked, but not a control
133                handled = false;
134            }
135    };
136
137    return handled;
138}
139
140void TreeView::handleItemClicked(const QModelIndex &index)
141{
142    if(!index.parent().isValid()) // time-group
143    {
144        if(isExpanded(index))
145            setExpanded(index, false);
146        else
147            setExpanded(index, true);
148    }
149}
150
151void TreeView::setAllExpanded(bool aExpanded)
152{
153    for(int i=0; i<model()->rowCount(QModelIndex()); i++)
154    {
155        setExpanded(model()->index(i,0,QModelIndex()),aExpanded);
156    }
157}
158
Note: See TracBrowser for help on using the repository browser.