Summer time/winter time/Timezone changes done
[qtmeetings] / src / UserInterface / Components / ScheduleWidget.h
1 #ifndef SCHEDULEWIDGET_H_
2 #define SCHEDULEWIDGET_H_
3
4 #include "ObservedWidget.h"
5 #include <QDateTime>
6 #include <QList>
7 #include "DisplaySettings.h"
8 #include <QTableWidget>
9
10 class QTableWidgetItem;
11 class Meeting;
12
13 //! UserInterface class. Customizes the QTableWidget class.
14 /*!
15  * UserInterface class. inherites QTableWidget to draw a custom table.
16  */
17 class ScheduleTableWidget : public QTableWidget
18 {
19         Q_OBJECT
20
21         //! Container for a meeting.
22         struct MeetingContainer
23         {
24                 Meeting* meeting;
25                 QRect rect;
26                 bool rectComputed;
27         };
28
29 public:
30
31         //! Constructor.
32         /*!
33          * Constructor to initialize ScheduleTableWidget instance.
34          * \param aRows number of rows
35          * \param aColumns number of columns
36          * \param aParent parent widget
37          */
38         ScheduleTableWidget( int aRows, int aColumns, QWidget *aParent = 0 );
39
40         //! Destructor.
41         ~ScheduleTableWidget();
42
43 protected:
44         //! Handles drawing of main table area.
45         /*!
46          * Handles drawing of main table area.
47          * \param aEvent event
48          */
49         void paintEvent( QPaintEvent* aEvent );
50
51         //! Forwards relevant information to activateMeeting().
52         /*!
53          * Forwards relevant information to activateMeeting().
54          * \param aEvent event.
55          */
56         void tabletEvent( QTabletEvent* aEvent );
57
58         //! Mouse move event.
59         /*!
60          * Implemented as empty method for preventing unwanted QTableWidget behavior.
61          * \param aEvent event.
62          */
63         void mouseMoveEvent( QMouseEvent* aEvent );
64
65         //! Forwards relevant information to activateMeeting().
66         /*!
67          * Forwards relevant information to activateMeeting().
68          * \param aEvent event.
69          */
70         void mousePressEvent( QMouseEvent* aEvent );
71
72         
73 private:
74         //! Populates meeting list.
75         /*!
76          * Populates meeting list.
77          */
78         void populateMeetingList();
79
80         //! Finds overlapping meetings.
81         /*!
82          * Finds overlapping meetings.
83          * \param aDay day.
84          * \param aMeeting meeting to compare.
85          * \param aResult generated list of overlapping meetings, empty if none.
86          * \return true if overlapping meetings were found, otherwise false.
87          */
88         bool findOverlappingMeetings( int aDay, Meeting* aMeeting, QList<int>& aResult );
89
90         //! Activates a meeting.
91         /*!
92          * Activates a meeting.
93          * \param x x coordinate
94          * \param y y coordinate
95          */
96         void activateMeeting( int x, int y );
97
98         //! Computes y coordinate in viewport for a given time.
99         /*!
100          * Computes y coordinate in viewport for a given time.
101          * \param aTime time
102          * \return y coordinate
103          */
104         int computeViewportY( QTime aTime );
105
106 private:
107
108         //! Array of list of meetings, for each day.
109         QList<MeetingContainer>* iMeetingsByDay;
110         
111         //! Timer for tablet event blocking
112         QTime iTime;
113         
114         //! Flag telling if tablet events are blocked
115         bool iTabletBlocked;
116 };
117
118 //! UserInterface class. Defines a custom weekly calendar on the screen. Used by thr WeeklyViewWidget.
119 /*!
120  * UserInterface class. Defines a custom weekly calendar on the screen. Used by thr WeeklyViewWidget.
121  */
122 class ScheduleWidget : public ObservedWidget
123 {
124         Q_OBJECT
125
126         friend class ScheduleTableWidget;
127
128 public:
129
130         //! Constructor.
131         /*!
132          * Constructor to initialize ScheduleWidget instance.
133          * \param aCurrentDateTime Current date and time.
134          * \param aSettings Display settings.
135          * \param aParent Parent widget.
136          */
137         ScheduleWidget( QDateTime aCurrentDateTime, DisplaySettings *aSettings, QWidget *aParent = 0 );
138
139         //! Destructor.
140         virtual ~ScheduleWidget();
141
142         //! Gets number of current week.
143         /*!
144          * Gets number of current week.
145          * \return Number of week.
146          */
147         int     currentWeek();
148
149         //! Gets number of shown week.
150         /*!
151          * Gets number of shown week.
152          * \return The week which is currently shown.
153          */
154         int     shownWeek();
155
156         //! Gets the first day of shown week.
157         /*!
158          * Gets the first day of shown week.
159          * \return First day of the shown week.
160          */
161         QDate beginningOfShownWeek();
162
163         //! Gets current meeting.
164         /*!
165          * Gets current meeting.
166          * \return current meeting, 0 if none.
167          */
168         Meeting* currentMeeting();
169
170         //! Gets meeting at a specified date and time.
171         /*!
172          * Gets meeting at a specified date and time.
173          * \param aAt Time when the meeting is.
174          * \return meeting At the given time, 0 if none.
175          */
176         Meeting* meeting( QDateTime aAt );
177
178 signals:
179
180         //! Signal. Emitted if a meeting is activated.
181         /*!
182          * Signal. Emitted if a meeting is activated, i.e. the user clicks on a meeting rectangle.
183          * \param aMeeting Actived meeting.
184          */
185         void meetingActivated( Meeting *aMeeting );
186
187         //! Signal. Emitted when the current meeting changes to another.
188         /*!
189          * Signal. Emitted when the current meeting changes to another.
190          * \param aNewMeeting New meeting.
191          */
192         void currentMeetingChanged( Meeting *aNewMeeting );
193
194         //! Signal. Emitted if the shown week has been changed.
195         /*!
196          * Signal. Emitted if the shown week has been changed.
197          * \param aDate The first date of the shown week.
198          */
199         void shownWeekChanged( QDate aDate );
200
201 public slots:
202
203         //! Slot. Clears all meetings.
204         /*!
205          * Slot. Clears all meetings.
206          */
207         void clear();
208
209         //! Slot. Clears meetings based on a range.
210         /*!
211          * Slot. Clears meetings based on a range.
212          * \param aFrom Date and time from which the meetings are cleared.
213          * \param aUntil Date and time until which the meetings are cleared.
214          */
215         void clear( QDateTime aFrom, QDateTime aUntil );
216
217         //! Slot. Refreshes display.
218         /*!
219          * Slot. Refreshes display.
220          */
221         void refresh();
222
223         //! Slot. Sets current date and time.
224         /*!
225          * Slot. Sets current date and time.
226          * \param aCurrentDateTime Current date and time.
227          */
228         void setCurrentDateTime( QDateTime aCurrentDateTime );
229
230         //! Slot. Inserts a meeting to the schedule.
231         /*!
232          * Slot. Inserts a meeting to the schedule.
233          * \param aMeeting Meeting to be inserted.
234          */
235         void insertMeeting( Meeting *aMeeting );
236
237         //! Slot. Removes a meeting from the schedule.
238         /*!
239          * Slot. Removes a meeting from the schedule.
240          * \param aMeeting Meeting to be removed.
241          */
242         void removeMeeting( Meeting *aMeeting );
243
244         //! Slot. Updates a meeting in the schedule. (TODO)
245         /*!
246          * Slot updates a meeting in the schedule.
247          * \param aMeeting Meeting was updated.
248          */
249         void updateMeeting( Meeting */*aMeeting*/ ) {};
250
251         //! Slot. Shows previous week.
252         /*!
253          * Slot. Shows previous week.
254          */
255         void showPreviousWeek();
256
257         //! Slot. Shows current week.
258         /*!
259          * Slot. Shows current week.
260          */
261         void showCurrentWeek();
262
263         //! Slot. Shows next week.
264         /*!
265          * Slot. Shows next week.
266          */
267         void showNextWeek();
268
269 private:
270
271         //! Computes header row.
272         /*!
273          * Computes header row number in schedule table based on given time.
274          * \param aTime Time.
275          * \return header Row.
276          */
277         int computeHeaderRow( QTime aTime );
278
279         //! Gets week length as days.
280         /*!
281          * Gets week length as days.
282          * \return Lenght of the week in days.
283          */
284         int weekLengthAsDays();
285
286         //! Computes proper cell sizes for the schedule table.
287         /*!
288          * Computes proper cell sizes for the schedule table.
289          * \param aEvent Resize event.
290          */
291         void resizeEvent( QResizeEvent *aEvent );
292
293 private:
294         //! Schedule table widget.
295         ScheduleTableWidget *iScheduleTable;
296
297         //! Current date and time.
298         QDateTime iCurrentDateTime;
299
300         //! Meetings.
301         QList<Meeting*> iMeetings; /*! Not owned */
302
303         //! Currently shown week.
304         QDate iShownDate;
305
306         //! Starting hour of the schedule.
307         int iStartHour;
308
309         //! Number of hours in the schedule.
310         int iNumberOfHours;
311
312         //! Variable indicates the length of the week.
313         DisplaySettings::DaysInSchedule iDaysInSchedule;
314
315         //! When refresh() was called previously
316         QTime iLastRefresh;
317
318         //! Color for a free cell.
319         static const QColor sFreeBackground;
320
321         //! Color for a busy cell.
322         static const QColor sBusyBackground;
323
324         //! Color for headers.
325         static const QColor sHeaderBackground;
326
327         //! Color for current day highlight.
328         static const QColor sDayHighlightColor;
329
330         //! Color for current time highlight.
331         static const QColor sTimeHighlightColor;
332
333         //! Color for main grid.
334         static const QColor sMainGridColor;
335
336         //! Color for half grid.
337         static const QColor sHalfGridColor;
338
339         //! Color for frame.
340         static const QColor sFrameColor;
341
342         //! Refresh interval.
343         static const int sRefreshIntervalInSeconds = 60;
344 };
345
346 #endif /*SCHEDULEWIDGET_H_*/