1 #ifndef SCHEDULEWIDGET_H_
2 #define SCHEDULEWIDGET_H_
4 #include "ObservedWidget.h"
7 #include "DisplaySettings.h"
8 #include <QTableWidget>
10 class QTableWidgetItem;
13 //! UserInterface class. Customizes the QTableWidget class.
15 * UserInterface class. inherites QTableWidget to draw a custom table.
17 class ScheduleTableWidget : public QTableWidget
21 //! Container for a meeting.
22 struct MeetingContainer
33 * Constructor to initialize ScheduleTableWidget instance.
34 * \param aRows number of rows
35 * \param aColumns number of columns
36 * \param aParent parent widget
38 ScheduleTableWidget( int aRows, int aColumns, QWidget *aParent = 0 );
41 ~ScheduleTableWidget();
44 //! Handles drawing of main table area.
46 * Handles drawing of main table area.
49 void paintEvent( QPaintEvent* aEvent );
51 //! Forwards relevant information to activateMeeting().
53 * Forwards relevant information to activateMeeting().
54 * \param aEvent event.
56 void tabletEvent( QTabletEvent* aEvent );
60 * Implemented as empty method for preventing unwanted QTableWidget behavior.
61 * \param aEvent event.
63 void mouseMoveEvent( QMouseEvent* aEvent );
65 //! Forwards relevant information to activateMeeting().
67 * Forwards relevant information to activateMeeting().
68 * \param aEvent event.
70 void mousePressEvent( QMouseEvent* aEvent );
74 //! Populates meeting list.
76 * Populates meeting list.
78 void populateMeetingList();
80 //! Finds overlapping meetings.
82 * Finds overlapping meetings.
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.
88 bool findOverlappingMeetings( int aDay, Meeting* aMeeting, QList<int>& aResult );
90 //! Activates a meeting.
92 * Activates a meeting.
93 * \param x x coordinate
94 * \param y y coordinate
96 void activateMeeting( int x, int y );
98 //! Computes y coordinate in viewport for a given time.
100 * Computes y coordinate in viewport for a given time.
102 * \return y coordinate
104 int computeViewportY( QTime aTime );
108 //! Array of list of meetings, for each day.
109 QList<MeetingContainer>* iMeetingsByDay;
111 //! Timer for tablet event blocking
114 //! Flag telling if tablet events are blocked
118 //! UserInterface class. Defines a custom weekly calendar on the screen. Used by thr WeeklyViewWidget.
120 * UserInterface class. Defines a custom weekly calendar on the screen. Used by thr WeeklyViewWidget.
122 class ScheduleWidget : public ObservedWidget
126 friend class ScheduleTableWidget;
132 * Constructor to initialize ScheduleWidget instance.
133 * \param aCurrentDateTime Current date and time.
134 * \param aSettings Display settings.
135 * \param aParent Parent widget.
137 ScheduleWidget( QDateTime aCurrentDateTime, DisplaySettings *aSettings, QWidget *aParent = 0 );
140 virtual ~ScheduleWidget();
142 //! Gets number of current week.
144 * Gets number of current week.
145 * \return Number of week.
149 //! Gets number of shown week.
151 * Gets number of shown week.
152 * \return The week which is currently shown.
156 //! Gets the first day of shown week.
158 * Gets the first day of shown week.
159 * \return First day of the shown week.
161 QDate beginningOfShownWeek();
163 //! Gets current meeting.
165 * Gets current meeting.
166 * \return current meeting, 0 if none.
168 Meeting* currentMeeting();
170 //! Gets meeting at a specified date and time.
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.
176 Meeting* meeting( QDateTime aAt );
180 //! Signal. Emitted if a meeting is activated.
182 * Signal. Emitted if a meeting is activated, i.e. the user clicks on a meeting rectangle.
183 * \param aMeeting Actived meeting.
185 void meetingActivated( Meeting *aMeeting );
187 //! Signal. Emitted when the current meeting changes to another.
189 * Signal. Emitted when the current meeting changes to another.
190 * \param aNewMeeting New meeting.
192 void currentMeetingChanged( Meeting *aNewMeeting );
194 //! Signal. Emitted if the shown week has been changed.
196 * Signal. Emitted if the shown week has been changed.
197 * \param aDate The first date of the shown week.
199 void shownWeekChanged( QDate aDate );
203 //! Slot. Clears all meetings.
205 * Slot. Clears all meetings.
209 //! Slot. Clears meetings based on a range.
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.
215 void clear( QDateTime aFrom, QDateTime aUntil );
217 //! Slot. Refreshes display.
219 * Slot. Refreshes display.
223 //! Slot. Sets current date and time.
225 * Slot. Sets current date and time.
226 * \param aCurrentDateTime Current date and time.
228 void setCurrentDateTime( QDateTime aCurrentDateTime );
230 //! Slot. Inserts a meeting to the schedule.
232 * Slot. Inserts a meeting to the schedule.
233 * \param aMeeting Meeting to be inserted.
235 void insertMeeting( Meeting *aMeeting );
237 //! Slot. Removes a meeting from the schedule.
239 * Slot. Removes a meeting from the schedule.
240 * \param aMeeting Meeting to be removed.
242 void removeMeeting( Meeting *aMeeting );
244 //! Slot. Updates a meeting in the schedule. (TODO)
246 * Slot updates a meeting in the schedule.
247 * \param aMeeting Meeting was updated.
249 void updateMeeting( Meeting */*aMeeting*/ ) {};
251 //! Slot. Shows previous week.
253 * Slot. Shows previous week.
255 void showPreviousWeek();
257 //! Slot. Shows current week.
259 * Slot. Shows current week.
261 void showCurrentWeek();
263 //! Slot. Shows next week.
265 * Slot. Shows next week.
271 //! Computes header row.
273 * Computes header row number in schedule table based on given time.
275 * \return header Row.
277 int computeHeaderRow( QTime aTime );
279 //! Gets week length as days.
281 * Gets week length as days.
282 * \return Lenght of the week in days.
284 int weekLengthAsDays();
286 //! Computes proper cell sizes for the schedule table.
288 * Computes proper cell sizes for the schedule table.
289 * \param aEvent Resize event.
291 void resizeEvent( QResizeEvent *aEvent );
294 //! Schedule table widget.
295 ScheduleTableWidget *iScheduleTable;
297 //! Current date and time.
298 QDateTime iCurrentDateTime;
301 QList<Meeting*> iMeetings; /*! Not owned */
303 //! Currently shown week.
306 //! Starting hour of the schedule.
309 //! Number of hours in the schedule.
312 //! Variable indicates the length of the week.
313 DisplaySettings::DaysInSchedule iDaysInSchedule;
315 //! When refresh() was called previously
318 //! Color for a free cell.
319 static const QColor sFreeBackground;
321 //! Color for a busy cell.
322 static const QColor sBusyBackground;
324 //! Color for headers.
325 static const QColor sHeaderBackground;
327 //! Color for current day highlight.
328 static const QColor sDayHighlightColor;
330 //! Color for current time highlight.
331 static const QColor sTimeHighlightColor;
333 //! Color for main grid.
334 static const QColor sMainGridColor;
336 //! Color for half grid.
337 static const QColor sHalfGridColor;
340 static const QColor sFrameColor;
342 //! Refresh interval.
343 static const int sRefreshIntervalInSeconds = 60;
346 #endif /*SCHEDULEWIDGET_H_*/