47b8e3f371730b8af6ee2950b818392f7c34a067
[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         //! Populates meeting list.
44         /*!
45          * Populates meeting list.
46          */
47         void populateMeetingList();
48
49 protected:
50         //! Handles drawing of main table area.
51         /*!
52          * Handles drawing of main table area.
53          * \param aEvent event
54          */
55         void paintEvent( QPaintEvent* aEvent );
56
57         //! Forwards relevant information to activateMeeting().
58         /*!
59          * Forwards relevant information to activateMeeting().
60          * \param aEvent event.
61          */
62         void tabletEvent( QTabletEvent* aEvent );
63
64         //! Mouse move event.
65         /*!
66          * Implemented as empty method for preventing unwanted QTableWidget behavior.
67          * \param aEvent event.
68          */
69         void mouseMoveEvent( QMouseEvent* aEvent );
70
71         //! Forwards relevant information to activateMeeting().
72         /*!
73          * Forwards relevant information to activateMeeting().
74          * \param aEvent event.
75          */
76         void mousePressEvent( QMouseEvent* aEvent );
77
78         
79 private:
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 the first day of shown week.
150         /*!
151          * Gets the first day of shown week.
152          * \return First day of the shown week.
153          */
154         QDate beginningOfShownWeek();
155
156 signals:
157
158         //! Signal. Emitted if a meeting is activated.
159         /*!
160          * Signal. Emitted if a meeting is activated, i.e. the user clicks on a meeting rectangle.
161          * \param aMeeting Actived meeting.
162          */
163         void meetingActivated( Meeting *aMeeting );
164         //! Signal. Emitted if the shown week has been changed.
165         /*!
166          * Signal. Emitted if the shown week has been changed.
167          * \param aDate The first date of the shown week.
168          */
169         void shownWeekChanged( QDate aDate );
170
171 public slots:
172
173         //! Slot. Refreshes display.
174         /*!
175          * Slot. Refreshes display.
176          * \param aMeetings The meeting list.
177          */
178         void refresh();
179         //! Refreshes the meeting list.
180         /*!
181          * Refreshes the meeting list.
182          * \param aMeetings The list of meetings.
183          */
184         void refreshMeetings( const QList<Meeting*> &aMeetings );
185         
186         //! Slot. Sets current date and time.
187         /*!
188          * Slot. Sets current date and time.
189          * \param aCurrentDateTime Current date and time.
190          */
191         void setCurrentDateTime( QDateTime aCurrentDateTime );
192
193         //! Slot. Shows previous week.
194         /*!
195          * Slot. Shows previous week.
196          */
197         void showPreviousWeek();
198
199         //! Slot. Shows current week.
200         /*!
201          * Slot. Shows current week.
202          */
203         void showCurrentWeek();
204
205         //! Slot. Shows next week.
206         /*!
207          * Slot. Shows next week.
208          */
209         void showNextWeek();
210
211 private:
212
213         //! Computes header row.
214         /*!
215          * Computes header row number in schedule table based on given time.
216          * \param aTime Time.
217          * \return header Row.
218          */
219         int computeHeaderRow( QTime aTime );
220
221         //! Gets week length as days.
222         /*!
223          * Gets week length as days.
224          * \return Lenght of the week in days.
225          */
226         int weekLengthAsDays();
227
228         //! Computes proper cell sizes for the schedule table.
229         /*!
230          * Computes proper cell sizes for the schedule table.
231          * \param aEvent Resize event.
232          */
233         void resizeEvent( QResizeEvent *aEvent );
234
235 private:
236         //! Schedule table widget.
237         ScheduleTableWidget *iScheduleTable;
238
239         //! Current date and time.
240         QDateTime iCurrentDateTime;
241
242         //! Currently shown week.
243         QDate iShownDate;
244
245         //! Starting hour of the schedule.
246         int iStartHour;
247
248         //! Number of hours in the schedule.
249         int iNumberOfHours;
250
251         //! Variable indicates the length of the week.
252         DisplaySettings::DaysInSchedule iDaysInSchedule;
253
254         //! When refresh() was called previously
255         QTime iLastRefresh;
256         
257         //! Meetings.
258         QList<Meeting*> iMeetings; /*! Not owned */
259
260         //! Color for a free cell.
261         static const QColor sFreeBackground;
262
263         //! Color for a busy cell.
264         static const QColor sBusyBackground;
265
266         //! Color for headers.
267         static const QColor sHeaderBackground;
268
269         //! Color for current day highlight.
270         static const QColor sDayHighlightColor;
271
272         //! Color for current time highlight.
273         static const QColor sTimeHighlightColor;
274
275         //! Color for main grid.
276         static const QColor sMainGridColor;
277
278         //! Color for half grid.
279         static const QColor sHalfGridColor;
280
281         //! Color for frame.
282         static const QColor sFrameColor;
283
284         //! Refresh interval.
285         static const int sRefreshIntervalInSeconds = 60;
286 };
287
288 #endif /*SCHEDULEWIDGET_H_*/