/* * Copyright (C) 2010 Ixonos Plc. * Copyright (C) 2011 Philipp Spitzer, gregor herrmann * * This file is part of ConfClerk. * * ConfClerk is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, either version 2 of the License, or (at your option) * any later version. * * ConfClerk is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * ConfClerk. If not, see . */ #include #include "treeview.h" #include "delegate.h" #include "event.h" #include "conference.h" #include "eventmodel.h" #ifdef MAEMO #include #endif #include TreeView::TreeView(QWidget *aParent) : QTreeView(aParent) { connect(this, SIGNAL(clicked(QModelIndex)), SLOT(handleItemClicked(QModelIndex))); } void TreeView::mouseReleaseEvent(QMouseEvent *aEvent) { QModelIndex index = currentIndex(); QPoint point = aEvent->pos(); // test whether we have handled the mouse event if(!testForControlClicked(index,point)) { // pass the event to the Base class, so item clicks/events are handled correctly QTreeView::mouseReleaseEvent(aEvent); } } // returns bool if some Control was clicked bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) { bool handled = false; if(!aIndex.isValid()) return handled; int confId = Conference::activeConference(); // QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list Delegate *delegate = static_cast(itemDelegate(aIndex)); switch(delegate->whichControlClicked(aIndex,aPoint)) { case Delegate::FavouriteControlOn: case Delegate::FavouriteControlOff: { // handle Favourite Control clicked Event event = Event::getById(aIndex.data().toInt(),confId); QList conflicts = Event::conflictEvents(event.id(),Conference::activeConference()); if(event.isFavourite()) event.setFavourite(false); else event.setFavourite(true); event.update("favourite"); if(event.isFavourite()) { // event has became 'favourite' and so 'conflicts' list may have changed conflicts = Event::conflictEvents(event.id(),Conference::activeConference()); } // have to emit 'eventHasChanged' signal on all events in conflict for(int i=0; irowCount(QModelIndex()); i++) { setExpanded(model()->index(i,0,QModelIndex()),aExpanded); } }