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();
43 //! Populates meeting list.
45 * Populates meeting list.
47 void populateMeetingList();
50 //! Handles drawing of main table area.
52 * Handles drawing of main table area.
55 void paintEvent( QPaintEvent* aEvent );
57 //! Forwards relevant information to activateMeeting().
59 * Forwards relevant information to activateMeeting().
60 * \param aEvent event.
62 void tabletEvent( QTabletEvent* aEvent );
66 * Implemented as empty method for preventing unwanted QTableWidget behavior.
67 * \param aEvent event.
69 void mouseMoveEvent( QMouseEvent* aEvent );
71 //! Forwards relevant information to activateMeeting().
73 * Forwards relevant information to activateMeeting().
74 * \param aEvent event.
76 void mousePressEvent( QMouseEvent* aEvent );
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 the first day of shown week.
151 * Gets the first day of shown week.
152 * \return First day of the shown week.
154 QDate beginningOfShownWeek();
158 //! Signal. Emitted if a meeting is activated.
160 * Signal. Emitted if a meeting is activated, i.e. the user clicks on a meeting rectangle.
161 * \param aMeeting Actived meeting.
163 void meetingActivated( Meeting *aMeeting );
164 //! Signal. Emitted if the shown week has been changed.
166 * Signal. Emitted if the shown week has been changed.
167 * \param aDate The first date of the shown week.
169 void shownWeekChanged( QDate aDate );
173 //! Slot. Refreshes display.
175 * Slot. Refreshes display.
176 * \param aMeetings The meeting list.
179 //! Refreshes the meeting list.
181 * Refreshes the meeting list.
182 * \param aMeetings The list of meetings.
184 void refreshMeetings( const QList<Meeting*> &aMeetings );
186 //! Slot. Sets current date and time.
188 * Slot. Sets current date and time.
189 * \param aCurrentDateTime Current date and time.
191 void setCurrentDateTime( QDateTime aCurrentDateTime );
193 //! Slot. Shows previous week.
195 * Slot. Shows previous week.
197 void showPreviousWeek();
199 //! Slot. Shows current week.
201 * Slot. Shows current week.
203 void showCurrentWeek();
205 //! Slot. Shows next week.
207 * Slot. Shows next week.
213 //! Computes header row.
215 * Computes header row number in schedule table based on given time.
217 * \return header Row.
219 int computeHeaderRow( QTime aTime );
221 //! Gets week length as days.
223 * Gets week length as days.
224 * \return Lenght of the week in days.
226 int weekLengthAsDays();
228 //! Computes proper cell sizes for the schedule table.
230 * Computes proper cell sizes for the schedule table.
231 * \param aEvent Resize event.
233 void resizeEvent( QResizeEvent *aEvent );
236 //! Schedule table widget.
237 ScheduleTableWidget *iScheduleTable;
239 //! Current date and time.
240 QDateTime iCurrentDateTime;
242 //! Currently shown week.
245 //! Starting hour of the schedule.
248 //! Number of hours in the schedule.
251 //! Variable indicates the length of the week.
252 DisplaySettings::DaysInSchedule iDaysInSchedule;
254 //! When refresh() was called previously
258 QList<Meeting*> iMeetings; /*! Not owned */
260 //! Color for a free cell.
261 static const QColor sFreeBackground;
263 //! Color for a busy cell.
264 static const QColor sBusyBackgroundStart;
266 //! Color for a busy cell.
267 static const QColor sBusyBackground;
269 //! Color for a busy cell.
270 static const QColor sCurrentBackgroundStart;
272 //! Color for a busy cell.
273 static const QColor sCurrentBackground;
275 //! Color for headers.
276 static const QColor sHeaderBackground;
278 //! Color for current day highlight.
279 static const QColor sDayHighlightColor;
281 //! Color for current time highlight.
282 static const QColor sTimeHighlightColor;
284 //! Color for main grid.
285 static const QColor sMainGridColor;
287 //! Color for half grid.
288 static const QColor sHalfGridColor;
291 static const QColor sFrameColor;
293 //! Refresh interval.
294 static const int sRefreshIntervalInSeconds = 60;
297 #endif /*SCHEDULEWIDGET_H_*/