2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
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)
11 * fosdem-schedule is distributed in the hope that it will be useful, but
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
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
19 #include "tabcontainer.h"
22 #include <QMessageBox>
28 #include "eventdialog.h"
29 #include "mapwindow.h"
31 #include "errormessage.h"
33 #include "conflictsdialog.h"
35 TabContainer::TabContainer(QWidget *aParent)
40 treeView->setHeaderHidden(true);
41 treeView->setRootIsDecorated(false);
42 treeView->setIndentation(0);
43 treeView->setAnimated(true);
44 treeView->setModel(new EventModel());
45 treeView->setItemDelegate(new Delegate(treeView));
47 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
49 connect(treeView, SIGNAL(eventHasChanged(int,bool)), SIGNAL(eventHasChanged(int,bool)));
50 connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
51 connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
52 connect(treeView, SIGNAL(requestForConflicts(const QModelIndex &)), SLOT(displayConflicts(const QModelIndex &)));
54 // day navigator is hidden by default
58 void TabContainer::updateTreeView(const QDate &aDate)
60 int active_id = Conference::activeConference();
63 loadEvents(aDate, active_id);
65 static_cast<EventModel*>(treeView->model())->clearModel();
69 void TabContainer::itemClicked(const QModelIndex &aIndex)
71 // have to handle only events, not time-groups
72 if(!aIndex.parent().isValid()) // time-group
75 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
77 dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
79 connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
81 disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
84 void TabContainer::displayMap(const QModelIndex &aIndex)
86 Event *event = static_cast<Event*>(aIndex.internalPointer());
88 QVariant mapPathV = event->room()->map();
90 if (!mapPathV.isValid()) {
91 error_message("No map for this room");
94 mapPath = mapPathV.toString();
95 if (!QFile::exists(mapPath)) {
96 error_message("Map for this room not found: " + mapPath);
101 QPixmap map(mapPath);
102 MapWindow window(map, event->room()->name(),this);
106 void TabContainer::displayConflicts(const QModelIndex &aIndex)
108 ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
110 dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
112 connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
114 disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
117 void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel)
121 // requires special handling
122 // eg. in case of favourities - some favourities may have changed
123 // and so we need to reload them
124 int confId = Conference::activeConference();
125 QDate startDate = Conference::getById(confId).start();
126 QDate endDate = Conference::getById(confId).end();
127 dayNavigator->setDates(startDate, endDate);
128 updateTreeView( Conference::getById(confId).start() );
132 // just update event in the question
133 static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
137 void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
139 dayNavigator->setDates(aStart, aEnd);
142 void TabContainer::clearModel()
144 static_cast<EventModel*>(treeView->model())->clearModel();