1 | #include "tabcontainer.h" |
---|
2 | |
---|
3 | #include <QFile> |
---|
4 | #include <QMessageBox> |
---|
5 | #include <QTimer> |
---|
6 | |
---|
7 | #include <appsettings.h> |
---|
8 | |
---|
9 | #include <conference.h> |
---|
10 | |
---|
11 | #include <treeview.h> |
---|
12 | #include <eventmodel.h> |
---|
13 | #include <delegate.h> |
---|
14 | |
---|
15 | #include "eventdialog.h" |
---|
16 | #include "mapwindow.h" |
---|
17 | |
---|
18 | TabContainer::TabContainer(QWidget *aParent) |
---|
19 | : QWidget(aParent) |
---|
20 | , mType(EContainerTypeNone) |
---|
21 | { |
---|
22 | setupUi(this); |
---|
23 | |
---|
24 | searchAgainButton->hide(); |
---|
25 | |
---|
26 | treeView->setHeaderHidden(true); |
---|
27 | treeView->setRootIsDecorated(false); |
---|
28 | treeView->setIndentation(0); |
---|
29 | treeView->setAnimated(true); |
---|
30 | treeView->setModel(new EventModel()); |
---|
31 | treeView->setItemDelegate(new Delegate(treeView)); |
---|
32 | |
---|
33 | connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &))); |
---|
34 | |
---|
35 | connect(treeView, SIGNAL(eventHasChanged(int)), SIGNAL(eventHasChanged(int))); |
---|
36 | connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
37 | connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); |
---|
38 | connect(treeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &))); |
---|
39 | |
---|
40 | if(!Conference::getAll().count()) // no conference(s) in the DB |
---|
41 | { |
---|
42 | dayNavigator->hide(); // hide DayNavigatorWidget |
---|
43 | } |
---|
44 | else |
---|
45 | { |
---|
46 | QDate aStartDate = Conference::getById(AppSettings::confId()).start(); |
---|
47 | QDate aEndDate = Conference::getById(AppSettings::confId()).end(); |
---|
48 | dayNavigator->setDates(aStartDate, aEndDate); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | void TabContainer::setType(TabContainer::Type aType) |
---|
53 | { |
---|
54 | mType = aType; |
---|
55 | if(aType == EContainerTypeNow) |
---|
56 | { |
---|
57 | QTimer *timer = new QTimer( this ); |
---|
58 | connect( timer, SIGNAL(timeout()), SLOT(timerUpdateTreeView()) ); |
---|
59 | timer->start( 30000); // 30 seconds timer |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | void TabContainer::updateTreeView(const QDate &aDate) |
---|
64 | { |
---|
65 | switch(mType) |
---|
66 | { |
---|
67 | case EContainerTypeDay: |
---|
68 | { |
---|
69 | static_cast<EventModel*>(treeView->model())->loadEvents(aDate,AppSettings::confId()); |
---|
70 | } |
---|
71 | break; |
---|
72 | case EContainerTypeFavs: |
---|
73 | { |
---|
74 | static_cast<EventModel*>(treeView->model())->loadFavEvents(aDate,AppSettings::confId()); |
---|
75 | } |
---|
76 | break; |
---|
77 | case EContainerTypeTracks: |
---|
78 | { |
---|
79 | static_cast<EventModel*>(treeView->model())->loadEventsByTrack(aDate, AppSettings::confId()); |
---|
80 | } |
---|
81 | break; |
---|
82 | case EContainerTypeRooms: |
---|
83 | { |
---|
84 | static_cast<EventModel*>(treeView->model())->loadEventsByRoom(aDate, AppSettings::confId()); |
---|
85 | } |
---|
86 | break; |
---|
87 | case EContainerTypeNow: |
---|
88 | { |
---|
89 | static_cast<EventModel*>(treeView->model())->loadNowEvents(AppSettings::confId()); |
---|
90 | treeView->setAllExpanded(true); |
---|
91 | } |
---|
92 | break; |
---|
93 | case EContainerTypeNone: |
---|
94 | default: |
---|
95 | { |
---|
96 | qDebug() << "Container type not specified"; |
---|
97 | } |
---|
98 | } |
---|
99 | treeView->reset(); |
---|
100 | dayNavigator->show(); |
---|
101 | } |
---|
102 | |
---|
103 | void TabContainer::itemClicked(const QModelIndex &aIndex) |
---|
104 | { |
---|
105 | // have to handle only events, not time-groups |
---|
106 | if(!aIndex.parent().isValid()) // time-group |
---|
107 | return; |
---|
108 | |
---|
109 | EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
110 | dialog.exec(); |
---|
111 | } |
---|
112 | |
---|
113 | void TabContainer::displayMap(const QModelIndex &aIndex) |
---|
114 | { |
---|
115 | Event *event = static_cast<Event*>(aIndex.internalPointer()); |
---|
116 | |
---|
117 | // room names are stored in lower-case format |
---|
118 | // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png" |
---|
119 | QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove(".")); |
---|
120 | if(!QFile::exists(mapPath)) |
---|
121 | mapPath = QString(":/maps/rooms/not-available.png"); |
---|
122 | |
---|
123 | QString roomName; |
---|
124 | if(mapPath.contains("not-available", Qt::CaseInsensitive)) |
---|
125 | roomName = QString("Map is not available: %1").arg(event->room()); |
---|
126 | else |
---|
127 | roomName = event->room(); |
---|
128 | |
---|
129 | QPixmap map(mapPath); |
---|
130 | MapWindow window(map,roomName,this); |
---|
131 | window.exec(); |
---|
132 | } |
---|
133 | |
---|
134 | void TabContainer::displayWarning(const QModelIndex &aIndex) |
---|
135 | { |
---|
136 | Q_UNUSED(aIndex); |
---|
137 | |
---|
138 | QMessageBox::warning( |
---|
139 | this, |
---|
140 | tr("Time Conflict Warning"), |
---|
141 | tr("This event happens at the same time than another one of your favourites.") ); |
---|
142 | } |
---|
143 | |
---|
144 | void TabContainer::updateTreeViewModel(int aEventId) |
---|
145 | { |
---|
146 | switch(mType) |
---|
147 | { |
---|
148 | case EContainerTypeFavs: |
---|
149 | { |
---|
150 | // requires special handling |
---|
151 | // we need to reload favourites, because some favourite could be deleted |
---|
152 | //static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId); |
---|
153 | QDate aStartDate = Conference::getById(AppSettings::confId()).start(); |
---|
154 | QDate aEndDate = Conference::getById(AppSettings::confId()).end(); |
---|
155 | dayNavigator->setDates(aStartDate, aEndDate); |
---|
156 | updateTreeView( Conference::getById(AppSettings::confId()).start() ); |
---|
157 | } |
---|
158 | break; |
---|
159 | case EContainerTypeDay: |
---|
160 | case EContainerTypeNone: |
---|
161 | default: |
---|
162 | { |
---|
163 | static_cast<EventModel*>(treeView->model())->updateModel(aEventId); |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | void TabContainer::setDates(const QDate &aStart, const QDate &aEnd) |
---|
169 | { |
---|
170 | dayNavigator->setDates(aStart, aEnd); |
---|
171 | } |
---|
172 | |
---|
173 | void TabContainer::timerUpdateTreeView() |
---|
174 | { |
---|
175 | if(mType == EContainerTypeNow) |
---|
176 | { |
---|
177 | updateTreeView(QDate()); |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|