[05afe5f] | 1 | #include "tabcontainer.h" |
---|
| 2 | |
---|
| 3 | #include <QFile> |
---|
| 4 | #include <QMessageBox> |
---|
| 5 | #include <QTimer> |
---|
| 6 | |
---|
| 7 | #include <treeview.h> |
---|
| 8 | #include <delegate.h> |
---|
| 9 | |
---|
| 10 | #include "eventdialog.h" |
---|
| 11 | #include "mapwindow.h" |
---|
| 12 | |
---|
[ea638ef] | 13 | #include "conflictsdialog.h" |
---|
| 14 | |
---|
[05afe5f] | 15 | TabContainer::TabContainer(QWidget *aParent) |
---|
| 16 | : QWidget(aParent) |
---|
| 17 | { |
---|
| 18 | setupUi(this); |
---|
| 19 | |
---|
| 20 | treeView->setHeaderHidden(true); |
---|
| 21 | treeView->setRootIsDecorated(false); |
---|
| 22 | treeView->setIndentation(0); |
---|
| 23 | treeView->setAnimated(true); |
---|
| 24 | treeView->setModel(new EventModel()); |
---|
| 25 | treeView->setItemDelegate(new Delegate(treeView)); |
---|
| 26 | |
---|
| 27 | connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &))); |
---|
| 28 | |
---|
[872aeaa] | 29 | connect(treeView, SIGNAL(eventHasChanged(int,bool)), SIGNAL(eventHasChanged(int,bool))); |
---|
[05afe5f] | 30 | connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
| 31 | connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); |
---|
[ea638ef] | 32 | connect(treeView, SIGNAL(requestForConflicts(const QModelIndex &)), SLOT(displayConflicts(const QModelIndex &))); |
---|
[05afe5f] | 33 | |
---|
[bb6f7d6] | 34 | // day navigator is hidden by default |
---|
| 35 | dayNavigator->hide(); |
---|
[05afe5f] | 36 | } |
---|
| 37 | |
---|
| 38 | void TabContainer::updateTreeView(const QDate &aDate) |
---|
| 39 | { |
---|
| 40 | dayNavigator->show(); |
---|
[0bb39f5] | 41 | loadEvents( aDate, Conference::activeConference() ); |
---|
[07ae23a] | 42 | treeView->reset(); |
---|
[05afe5f] | 43 | } |
---|
| 44 | |
---|
| 45 | void TabContainer::itemClicked(const QModelIndex &aIndex) |
---|
| 46 | { |
---|
| 47 | // have to handle only events, not time-groups |
---|
| 48 | if(!aIndex.parent().isValid()) // time-group |
---|
| 49 | return; |
---|
| 50 | |
---|
| 51 | EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
[5d22816] | 52 | #ifdef N810 |
---|
| 53 | dialog.setFixedWidth(static_cast<QWidget*>(parent())->width()); |
---|
| 54 | #endif |
---|
[872aeaa] | 55 | connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
[05afe5f] | 56 | dialog.exec(); |
---|
[872aeaa] | 57 | disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
[05afe5f] | 58 | } |
---|
| 59 | |
---|
| 60 | void TabContainer::displayMap(const QModelIndex &aIndex) |
---|
| 61 | { |
---|
| 62 | Event *event = static_cast<Event*>(aIndex.internalPointer()); |
---|
| 63 | |
---|
| 64 | // room names are stored in lower-case format |
---|
| 65 | // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png" |
---|
| 66 | QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove(".")); |
---|
| 67 | if(!QFile::exists(mapPath)) |
---|
| 68 | mapPath = QString(":/maps/rooms/not-available.png"); |
---|
| 69 | |
---|
| 70 | QString roomName; |
---|
| 71 | if(mapPath.contains("not-available", Qt::CaseInsensitive)) |
---|
| 72 | roomName = QString("Map is not available: %1").arg(event->room()); |
---|
| 73 | else |
---|
| 74 | roomName = event->room(); |
---|
| 75 | |
---|
| 76 | QPixmap map(mapPath); |
---|
| 77 | MapWindow window(map,roomName,this); |
---|
| 78 | window.exec(); |
---|
| 79 | } |
---|
| 80 | |
---|
[ea638ef] | 81 | void TabContainer::displayConflicts(const QModelIndex &aIndex) |
---|
[05afe5f] | 82 | { |
---|
[d49254d] | 83 | ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
[5d22816] | 84 | #ifdef N810 |
---|
| 85 | dialog.setFixedWidth(static_cast<QWidget*>(parent())->width()); |
---|
| 86 | #endif |
---|
[872aeaa] | 87 | connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
[ea638ef] | 88 | dialog.exec(); |
---|
[872aeaa] | 89 | disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
[05afe5f] | 90 | } |
---|
| 91 | |
---|
[872aeaa] | 92 | void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel) |
---|
[05afe5f] | 93 | { |
---|
[872aeaa] | 94 | if(aReloadModel) |
---|
| 95 | { |
---|
| 96 | // requires special handling |
---|
| 97 | // eg. in case of favourities - some favourities may have changed |
---|
| 98 | // and so we need to reload them |
---|
| 99 | int confId = Conference::activeConference(); |
---|
| 100 | QDate startDate = Conference::getById(confId).start(); |
---|
| 101 | QDate endDate = Conference::getById(confId).end(); |
---|
| 102 | dayNavigator->setDates(startDate, endDate); |
---|
| 103 | updateTreeView( Conference::getById(confId).start() ); |
---|
| 104 | } |
---|
| 105 | else |
---|
| 106 | { |
---|
| 107 | // just update event in the question |
---|
| 108 | static_cast<EventModel*>(treeView->model())->updateModel(aEventId); |
---|
| 109 | } |
---|
[05afe5f] | 110 | } |
---|
| 111 | |
---|
| 112 | void TabContainer::setDates(const QDate &aStart, const QDate &aEnd) |
---|
| 113 | { |
---|
| 114 | dayNavigator->setDates(aStart, aEnd); |
---|
| 115 | } |
---|
| 116 | |
---|