source: src/mvc/treeview.cpp @ e6ab8a2

qt5
Last change on this file since e6ab8a2 was e6ab8a2, checked in by Philipp Spitzer <philipp@…>, 11 years ago

Removed the ability to show "pictures" (maps) of rooms and maps of conferences.
The XML file does not contain picture/map/image information of conferences or rooms.
We left the room.picture definition in the database SQL because there is no "drop column"
in sqlite.

  • Property mode set to 100644
File size: 5.3 KB
RevLine 
[ca90cb1]1/*
2 * Copyright (C) 2010 Ixonos Plc.
[68b2df2]3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
[ca90cb1]4 *
[6df32f2]5 * This file is part of ConfClerk.
[ca90cb1]6 *
[6df32f2]7 * ConfClerk is free software: you can redistribute it and/or modify it
[ca90cb1]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 *
[6df32f2]12 * ConfClerk is distributed in the hope that it will be useful, but
[ca90cb1]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
[6df32f2]18 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[ca90cb1]19 */
[66327a0]20#include <QMouseEvent>
21
22#include "treeview.h"
23#include "delegate.h"
[680a4da]24#include "event.h"
[438699c]25#include "conference.h"
[67c59a7]26#include "eventmodel.h"
[66327a0]27
[6bd729b]28#ifdef MAEMO
29#include <alarm.h>
30#endif
31
[66327a0]32#include <QDebug>
33
34TreeView::TreeView(QWidget *aParent)
35    : QTreeView(aParent)
36{
[8fe9bd2]37    connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex)));
[66327a0]38}
39
40void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
41{
42    QModelIndex index = currentIndex();
43    QPoint point = aEvent->pos();
44
[c53a3f4]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    }
[66327a0]51}
52
[c53a3f4]53// returns bool if some Control was clicked
[6831c6a]54bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
[66327a0]55{
[c53a3f4]56    bool handled = false;
57
[66327a0]58    if(!aIndex.isValid())
[c53a3f4]59        return handled;
[66327a0]60
[1fb7a33]61    int confId = Conference::activeConference();
[663fafd]62    // QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
[66327a0]63    Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
64    switch(delegate->whichControlClicked(aIndex,aPoint))
65    {
[680a4da]66        case Delegate::FavouriteControlOn:
67        case Delegate::FavouriteControlOff:
[66327a0]68            {
69                // handle Favourite Control clicked
[1fb7a33]70                Event event = Event::getById(aIndex.data().toInt(),confId);
[438699c]71
72                QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
[680a4da]73                if(event.isFavourite())
[c718a77]74                    event.setFavourite(false);
[680a4da]75                else
76                    event.setFavourite(true);
77                event.update("favourite");
[438699c]78
79                if(event.isFavourite())
80                {
81                    // event has became 'favourite' and so 'conflicts' list may have changed
82                    conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
83                }
84
85                // have to emit 'eventHasChanged' signal on all events in conflict
86                for(int i=0; i<conflicts.count(); i++)
87                    emit(eventHasChanged(conflicts[i].id()));
[6831c6a]88
[872aeaa]89                // since the Favourite icon has changed, update TreeViews accordingly
90                // all TreeViews have to listen on this signal
91                emit(eventHasChanged(event.id(),true));
[438699c]92
[c53a3f4]93                handled = true;
[66327a0]94            }
95            break;
[680a4da]96        case Delegate::AlarmControlOn:
97        case Delegate::AlarmControlOff:
[66327a0]98            {
99                // handle Alarm Control clicked
[1fb7a33]100                Event event = Event::getById(aIndex.data().toInt(),confId);
[b6cd05c]101                if(event.hasAlarm())
102                {
103                    event.setHasAlarm(false); // update DB
[6bd729b]104#ifdef MAEMO
105                    // remove alarm from the 'alarmd' alrms list
106                    Alarm alarm;
107                    alarm.deleteAlarm(event.id());
108                    // TODO: test if removing was successfull
109#endif /* MAEMO */
[b6cd05c]110                }
111                else
112                {
113                    event.setHasAlarm(true);
[6bd729b]114#ifdef MAEMO
115                    // add alarm to the 'alarmd'
116                    Alarm alarm;
[ba48d2f]117                    //int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10)); // testing
118                    int cookie = alarm.addAlarm(event.id(),event.start().addSecs(-15*60)); // 15 minutes before real start
[6bd729b]119#endif /* MAEMO */
[b6cd05c]120                }
121                event.update("alarm");
122                // since the Alarm icon has changed, update TreeView accordingly
[c718a77]123                // all TreeViews have to listen on this signal
124                emit(eventHasChanged(event.id()));
[c53a3f4]125                handled = true;
[66327a0]126            }
127            break;
[336fa33]128        case Delegate::WarningControl:
[a5c1179]129        {
[3f3e22d]130
[ea638ef]131            emit(requestForConflicts(aIndex));
[a5c1179]132            handled = true;
133        }
134        break;
[66327a0]135        case Delegate::ControlNone:
136        default:
137            {
138                // item was clicked, but not a control
[c53a3f4]139                handled = false;
[66327a0]140            }
141    };
[c53a3f4]142
143    return handled;
[66327a0]144}
145
[8fe9bd2]146void TreeView::handleItemClicked(const QModelIndex &index)
147{
148    if(!index.parent().isValid()) // time-group
149    {
[6831c6a]150        if(isExpanded(index))
[8fe9bd2]151            setExpanded(index, false);
152        else
153            setExpanded(index, true);
154    }
155}
156
[b8a3ad1]157void TreeView::setAllExpanded(bool aExpanded)
158{
159    for(int i=0; i<model()->rowCount(QModelIndex()); i++)
160    {
161        setExpanded(model()->index(i,0,QModelIndex()),aExpanded);
162    }
163}
164
Note: See TracBrowser for help on using the repository browser.