[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 | |
---|
| 29 | connect(treeView, SIGNAL(eventHasChanged(int)), SIGNAL(eventHasChanged(int))); |
---|
| 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 | |
---|
| 34 | if(!Conference::getAll().count()) // no conference(s) in the DB |
---|
| 35 | { |
---|
| 36 | dayNavigator->hide(); // hide DayNavigatorWidget |
---|
| 37 | } |
---|
| 38 | else |
---|
| 39 | { |
---|
[0bb39f5] | 40 | QDate aStartDate = Conference::getById(Conference::activeConference()).start(); |
---|
| 41 | QDate aEndDate = Conference::getById(Conference::activeConference()).end(); |
---|
[05afe5f] | 42 | dayNavigator->setDates(aStartDate, aEndDate); |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | void TabContainer::updateTreeView(const QDate &aDate) |
---|
| 47 | { |
---|
| 48 | dayNavigator->show(); |
---|
[0bb39f5] | 49 | loadEvents( aDate, Conference::activeConference() ); |
---|
[07ae23a] | 50 | treeView->reset(); |
---|
[05afe5f] | 51 | } |
---|
| 52 | |
---|
| 53 | void TabContainer::itemClicked(const QModelIndex &aIndex) |
---|
| 54 | { |
---|
| 55 | // have to handle only events, not time-groups |
---|
| 56 | if(!aIndex.parent().isValid()) // time-group |
---|
| 57 | return; |
---|
| 58 | |
---|
| 59 | EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
[ce59092] | 60 | connect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int))); |
---|
[05afe5f] | 61 | dialog.exec(); |
---|
[ce59092] | 62 | disconnect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int))); |
---|
[05afe5f] | 63 | } |
---|
| 64 | |
---|
| 65 | void TabContainer::displayMap(const QModelIndex &aIndex) |
---|
| 66 | { |
---|
| 67 | Event *event = static_cast<Event*>(aIndex.internalPointer()); |
---|
| 68 | |
---|
| 69 | // room names are stored in lower-case format |
---|
| 70 | // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png" |
---|
| 71 | QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove(".")); |
---|
| 72 | if(!QFile::exists(mapPath)) |
---|
| 73 | mapPath = QString(":/maps/rooms/not-available.png"); |
---|
| 74 | |
---|
| 75 | QString roomName; |
---|
| 76 | if(mapPath.contains("not-available", Qt::CaseInsensitive)) |
---|
| 77 | roomName = QString("Map is not available: %1").arg(event->room()); |
---|
| 78 | else |
---|
| 79 | roomName = event->room(); |
---|
| 80 | |
---|
| 81 | QPixmap map(mapPath); |
---|
| 82 | MapWindow window(map,roomName,this); |
---|
| 83 | window.exec(); |
---|
| 84 | } |
---|
| 85 | |
---|
[ea638ef] | 86 | void TabContainer::displayConflicts(const QModelIndex &aIndex) |
---|
[05afe5f] | 87 | { |
---|
| 88 | Q_UNUSED(aIndex); |
---|
| 89 | |
---|
[ea638ef] | 90 | ConflictsDialog dialog; |
---|
| 91 | connect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int))); |
---|
| 92 | dialog.exec(); |
---|
| 93 | disconnect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int))); |
---|
[05afe5f] | 94 | } |
---|
| 95 | |
---|
| 96 | void TabContainer::updateTreeViewModel(int aEventId) |
---|
| 97 | { |
---|
[07ae23a] | 98 | static_cast<EventModel*>(treeView->model())->updateModel(aEventId); |
---|
[05afe5f] | 99 | } |
---|
| 100 | |
---|
| 101 | void TabContainer::setDates(const QDate &aStart, const QDate &aEnd) |
---|
| 102 | { |
---|
| 103 | dayNavigator->setDates(aStart, aEnd); |
---|
| 104 | } |
---|
| 105 | |
---|