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 | |
---|
13 | TabContainer::TabContainer(QWidget *aParent) |
---|
14 | : QWidget(aParent) |
---|
15 | { |
---|
16 | setupUi(this); |
---|
17 | |
---|
18 | treeView->setHeaderHidden(true); |
---|
19 | treeView->setRootIsDecorated(false); |
---|
20 | treeView->setIndentation(0); |
---|
21 | treeView->setAnimated(true); |
---|
22 | treeView->setModel(new EventModel()); |
---|
23 | treeView->setItemDelegate(new Delegate(treeView)); |
---|
24 | |
---|
25 | connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &))); |
---|
26 | |
---|
27 | connect(treeView, SIGNAL(eventHasChanged(int)), SIGNAL(eventHasChanged(int))); |
---|
28 | connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
29 | connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); |
---|
30 | connect(treeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); |
---|
31 | |
---|
32 | if(!Conference::getAll().count()) // no conference(s) in the DB |
---|
33 | { |
---|
34 | dayNavigator->hide(); // hide DayNavigatorWidget |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | QDate aStartDate = Conference::getById(Conference::activeConference()).start(); |
---|
39 | QDate aEndDate = Conference::getById(Conference::activeConference()).end(); |
---|
40 | dayNavigator->setDates(aStartDate, aEndDate); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | void TabContainer::updateTreeView(const QDate &aDate) |
---|
45 | { |
---|
46 | dayNavigator->show(); |
---|
47 | loadEvents( aDate, Conference::activeConference() ); |
---|
48 | treeView->reset(); |
---|
49 | } |
---|
50 | |
---|
51 | void TabContainer::itemClicked(const QModelIndex &aIndex) |
---|
52 | { |
---|
53 | // have to handle only events, not time-groups |
---|
54 | if(!aIndex.parent().isValid()) // time-group |
---|
55 | return; |
---|
56 | |
---|
57 | EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
58 | connect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int))); |
---|
59 | dialog.exec(); |
---|
60 | disconnect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int))); |
---|
61 | } |
---|
62 | |
---|
63 | void TabContainer::displayMap(const QModelIndex &aIndex) |
---|
64 | { |
---|
65 | Event *event = static_cast<Event*>(aIndex.internalPointer()); |
---|
66 | |
---|
67 | // room names are stored in lower-case format |
---|
68 | // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png" |
---|
69 | QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove(".")); |
---|
70 | if(!QFile::exists(mapPath)) |
---|
71 | mapPath = QString(":/maps/rooms/not-available.png"); |
---|
72 | |
---|
73 | QString roomName; |
---|
74 | if(mapPath.contains("not-available", Qt::CaseInsensitive)) |
---|
75 | roomName = QString("Map is not available: %1").arg(event->room()); |
---|
76 | else |
---|
77 | roomName = event->room(); |
---|
78 | |
---|
79 | QPixmap map(mapPath); |
---|
80 | MapWindow window(map,roomName,this); |
---|
81 | window.exec(); |
---|
82 | } |
---|
83 | |
---|
84 | void TabContainer::displayWarning(const QModelIndex &aIndex) |
---|
85 | { |
---|
86 | Q_UNUSED(aIndex); |
---|
87 | |
---|
88 | QMessageBox::warning( |
---|
89 | this, |
---|
90 | tr("Time Conflict Warning"), |
---|
91 | tr("This event happens at the same time than another one of your favourites.") ); |
---|
92 | } |
---|
93 | |
---|
94 | void TabContainer::updateTreeViewModel(int aEventId) |
---|
95 | { |
---|
96 | static_cast<EventModel*>(treeView->model())->updateModel(aEventId); |
---|
97 | } |
---|
98 | |
---|
99 | void TabContainer::setDates(const QDate &aStart, const QDate &aEnd) |
---|
100 | { |
---|
101 | dayNavigator->setDates(aStart, aEnd); |
---|
102 | } |
---|
103 | |
---|