source: src/mvc/treeview.cpp @ 6df32f2

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

Update GPL blurb in source files.

  • Property mode set to 100644
File size: 5.8 KB
RevLine 
[ca90cb1]1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
[6df32f2]4 * This file is part of ConfClerk.
[ca90cb1]5 *
[6df32f2]6 * ConfClerk is free software: you can redistribute it and/or modify it
[ca90cb1]7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
9 * any later version.
10 *
[6df32f2]11 * ConfClerk is distributed in the hope that it will be useful, but
[ca90cb1]12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
[6df32f2]17 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[ca90cb1]18 */
[66327a0]19#include <QMouseEvent>
20
21#include "treeview.h"
22#include "delegate.h"
[680a4da]23#include "event.h"
[438699c]24#include "conference.h"
[67c59a7]25#include "eventmodel.h"
[66327a0]26
[6bd729b]27#ifdef MAEMO
28#include <alarm.h>
29#endif
30
[66327a0]31#include <QDebug>
32
33TreeView::TreeView(QWidget *aParent)
34    : QTreeView(aParent)
35{
[8fe9bd2]36    connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex)));
[66327a0]37}
38
39void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
40{
41    QModelIndex index = currentIndex();
42    QPoint point = aEvent->pos();
43
[c53a3f4]44    // test whether we have handled the mouse event
45    if(!testForControlClicked(index,point))
46    {
47        // pass the event to the Base class, so item clicks/events are handled correctly
48        QTreeView::mouseReleaseEvent(aEvent);
49    }
[66327a0]50}
51
[c53a3f4]52// returns bool if some Control was clicked
[6831c6a]53bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
[66327a0]54{
[c53a3f4]55    bool handled = false;
56
[66327a0]57    if(!aIndex.isValid())
[c53a3f4]58        return handled;
[66327a0]59
[1fb7a33]60    int confId = Conference::activeConference();
[66327a0]61    QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
62    Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
63    switch(delegate->whichControlClicked(aIndex,aPoint))
64    {
[680a4da]65        case Delegate::FavouriteControlOn:
66        case Delegate::FavouriteControlOff:
[66327a0]67            {
68                // handle Favourite Control clicked
[1fb7a33]69                Event event = Event::getById(aIndex.data().toInt(),confId);
[438699c]70
71                QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
[680a4da]72                if(event.isFavourite())
[c718a77]73                    event.setFavourite(false);
[680a4da]74                else
75                    event.setFavourite(true);
76                event.update("favourite");
[438699c]77
[c718a77]78                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
[412cef6]79
[438699c]80                if(event.isFavourite())
81                {
82                    // event has became 'favourite' and so 'conflicts' list may have changed
83                    conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
84                }
85
86                // have to emit 'eventHasChanged' signal on all events in conflict
87                for(int i=0; i<conflicts.count(); i++)
88                    emit(eventHasChanged(conflicts[i].id()));
[6831c6a]89
[872aeaa]90                // since the Favourite icon has changed, update TreeViews accordingly
91                // all TreeViews have to listen on this signal
92                emit(eventHasChanged(event.id(),true));
[438699c]93
[c53a3f4]94                handled = true;
[66327a0]95            }
96            break;
[680a4da]97        case Delegate::AlarmControlOn:
98        case Delegate::AlarmControlOff:
[66327a0]99            {
100                // handle Alarm Control clicked
[1fb7a33]101                Event event = Event::getById(aIndex.data().toInt(),confId);
[b6cd05c]102                if(event.hasAlarm())
103                {
104                    event.setHasAlarm(false); // update DB
[6bd729b]105#ifdef MAEMO
106                    // remove alarm from the 'alarmd' alrms list
107                    Alarm alarm;
108                    alarm.deleteAlarm(event.id());
109                    // TODO: test if removing was successfull
110#endif /* MAEMO */
[b6cd05c]111                }
112                else
113                {
114                    event.setHasAlarm(true);
[6bd729b]115#ifdef MAEMO
116                    // add alarm to the 'alarmd'
117                    Alarm alarm;
[ba48d2f]118                    //int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10)); // testing
119                    int cookie = alarm.addAlarm(event.id(),event.start().addSecs(-15*60)); // 15 minutes before real start
[6bd729b]120                    qDebug() << "cookie: " << cookie;
121#endif /* MAEMO */
[b6cd05c]122                }
123                event.update("alarm");
[c718a77]124                qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
[b6cd05c]125                // since the Alarm icon has changed, update TreeView accordingly
[c718a77]126                // all TreeViews have to listen on this signal
127                emit(eventHasChanged(event.id()));
[c53a3f4]128                handled = true;
[66327a0]129            }
130            break;
[03ff157]131        case Delegate::MapControl:
132            {
133                // handle Alarm Control clicked
134                qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
[59c6cfe]135                emit(requestForMap(aIndex));
[c53a3f4]136                handled = true;
[03ff157]137            }
138        break;
[336fa33]139        case Delegate::WarningControl:
[a5c1179]140        {
[3f3e22d]141
142            qDebug() << "WARNING CLICKED: " << qVariantValue<QString>(aIndex.data());
[ea638ef]143            emit(requestForConflicts(aIndex));
[a5c1179]144            handled = true;
145        }
146        break;
[66327a0]147        case Delegate::ControlNone:
148        default:
149            {
150                // item was clicked, but not a control
[c53a3f4]151                handled = false;
[66327a0]152            }
153    };
[c53a3f4]154
155    return handled;
[66327a0]156}
157
[8fe9bd2]158void TreeView::handleItemClicked(const QModelIndex &index)
159{
160    if(!index.parent().isValid()) // time-group
161    {
[6831c6a]162        if(isExpanded(index))
[8fe9bd2]163            setExpanded(index, false);
164        else
165            setExpanded(index, true);
166    }
167}
168
[b8a3ad1]169void TreeView::setAllExpanded(bool aExpanded)
170{
171    for(int i=0; i<model()->rowCount(QModelIndex()); i++)
172    {
173        setExpanded(model()->index(i,0,QModelIndex()),aExpanded);
174    }
175}
176
Note: See TracBrowser for help on using the repository browser.