b33e5172c250aba4e66678cd7c9cd626480f1c9b
[qtmeetings] / src / UserInterface / Views / WeeklyViewWidget.cpp
1 #include "WeeklyViewWidget.h"\r
2 \r
3 #include <QLabel>\r
4 #include <QPushButton>\r
5 #include <QVBoxLayout>\r
6 #include <QPixmap>\r
7 #include <QTimer>\r
8 #include <QKeyEvent>\r
9 #include <QTabletEvent>\r
10 #include "Configuration.h"\r
11 #include "DisplaySettings.h"\r
12 #include "Meeting.h"\r
13 #include "Room.h"\r
14 #include "MeetingRoomCombo.h"\r
15 #include "DigitalTimeDisplayWidget.h"\r
16 #include "ScheduleWidget.h"\r
17 #include "ToolBox.h"\r
18 #include "MeetingInfoDialog.h"\r
19 \r
20 #include <QtDebug>\r
21 \r
22 WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *aConfiguration, QWidget *aParent ) :\r
23                 ObservedWidget( aParent ), iConfiguration( aConfiguration )\r
24 {\r
25 \r
26         // *****************************************\r
27         //              Construct all the needed widgets\r
28         QFont importantTextFont;\r
29         importantTextFont.setBold( true );\r
30         importantTextFont.setPointSize( 20 );\r
31 \r
32         QFont regularTextFont;\r
33         regularTextFont.setBold( true );\r
34         regularTextFont.setPointSize( 12 );\r
35 \r
36         iSettingsButton = new QPushButton;\r
37         iSettingsButton->setIcon( QPixmap( ":button_settings" ) );\r
38         iSettingsButton->setFixedWidth( 36 );\r
39         connect( iSettingsButton, SIGNAL( clicked() ), this, SIGNAL( showSettingsView() ) );\r
40 \r
41         iCurrentDayLabel = ToolBox::createLabel( aCurrentDateTime.toString( iConfiguration->displaySettings()->dateFormat() ), regularTextFont );\r
42         iCurrentWeekLabel = ToolBox::createLabel( tr( "Wk %1" ).arg( aCurrentDateTime.date().weekNumber() ), regularTextFont );\r
43 \r
44         iRoomsCombo = new MeetingRoomCombo( iConfiguration->rooms(), this );\r
45         iRoomsCombo->setCurrentRoom( iConfiguration->defaultRoom() );\r
46         connect( iRoomsCombo, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );\r
47 \r
48         iTimeDisplay = new DigitalTimeDisplayWidget( aCurrentDateTime.time(), iConfiguration->displaySettings()->timeFormat(), this );\r
49         iTimeDisplay->setFrameVisible( false );\r
50         iTimeDisplay->setFont( regularTextFont );\r
51         connect( iTimeDisplay, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );\r
52 \r
53         iSchedule = new ScheduleWidget( aCurrentDateTime, iConfiguration->displaySettings(), this );\r
54         connect( iSchedule, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );\r
55         connect( iSchedule, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );\r
56         connect( iSchedule, SIGNAL( meetingActivated( Meeting* ) ), this, SIGNAL( meetingActivated( Meeting* ) ) );\r
57 \r
58         iPreviousWeekButton = new QPushButton( this );\r
59         iPreviousWeekButton->setText( tr( "<<" ) );\r
60         iPreviousWeekButton->setFixedWidth( 60 );\r
61         connect( iPreviousWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showPreviousWeek() ) );\r
62 \r
63         iCurrentWeekButton = new QPushButton( this );\r
64         iCurrentWeekButton->setFixedWidth( 100 );\r
65         iCurrentWeekButton->setText( tr( "Current" ) );\r
66         connect( iCurrentWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showCurrentWeek() ) );\r
67 \r
68         iNextWeekButton = new QPushButton( this );\r
69         iNextWeekButton->setFixedWidth( 60 );\r
70         iNextWeekButton->setText( tr( ">>" ) );\r
71         connect( iNextWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showNextWeek() ) );\r
72 \r
73         // **********************************\r
74         //              Create the view's layout\r
75         QHBoxLayout *tableLayout = new QHBoxLayout;\r
76         tableLayout->addWidget( iSchedule );\r
77 \r
78         QHBoxLayout *bottomLayout = new QHBoxLayout;\r
79         bottomLayout->addWidget( iRoomsCombo );\r
80         bottomLayout->addWidget( iTimeDisplay );\r
81         QVBoxLayout *dateLayout = new QVBoxLayout;\r
82         dateLayout->addWidget( iCurrentDayLabel );\r
83         dateLayout->addWidget( iCurrentWeekLabel );\r
84         bottomLayout->addLayout( dateLayout );\r
85         bottomLayout->addWidget( iPreviousWeekButton );\r
86         bottomLayout->addWidget( iCurrentWeekButton );\r
87         bottomLayout->addWidget( iNextWeekButton );\r
88         bottomLayout->addWidget( iSettingsButton );\r
89 \r
90         QVBoxLayout *mainLayout = new QVBoxLayout;\r
91         mainLayout->addLayout( tableLayout );\r
92         mainLayout->addLayout( bottomLayout );\r
93         setLayout( mainLayout );\r
94 \r
95         QPalette palette;\r
96         palette.setColor( QPalette::Window, Qt::white );\r
97         palette.setColor( QPalette::Foreground, Qt::darkGray );\r
98         setPalette( palette );\r
99 \r
100         // ******************************************\r
101         //              Handle all the signal connections\r
102         // TODO : this solution if interaction monitoring is not elegant enough\r
103         connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
104         connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
105         connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
106         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) );\r
107         connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) );\r
108         // TODO: connect RoomCombo signals to change meetings data.\r
109         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( clear() ) );\r
110         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );\r
111         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( refresh() ) );\r
112 }\r
113 \r
114 WeeklyViewWidget::~WeeklyViewWidget()\r
115 {\r
116         if ( iRoomsCombo )\r
117         {\r
118                 delete iRoomsCombo;\r
119                 iRoomsCombo = 0;\r
120         }\r
121         if ( iTimeDisplay )\r
122         {\r
123                 delete iTimeDisplay;\r
124                 iTimeDisplay = 0;\r
125         }\r
126         if ( iSchedule )\r
127         {\r
128                 delete iSchedule;\r
129                 iSchedule = 0;\r
130         }\r
131         if ( iCurrentDayLabel )\r
132         {\r
133                 delete iCurrentDayLabel;\r
134                 iCurrentDayLabel = 0;\r
135         }\r
136         if ( iCurrentWeekLabel )\r
137         {\r
138                 delete iCurrentWeekLabel;\r
139                 iCurrentWeekLabel = 0;\r
140         }\r
141         if ( iPreviousWeekButton )\r
142         {\r
143                 delete iPreviousWeekButton;\r
144                 iPreviousWeekButton = 0;\r
145         }\r
146         if ( iCurrentWeekButton )\r
147         {\r
148                 delete iCurrentWeekButton;\r
149                 iCurrentWeekButton = 0;\r
150         }\r
151         if ( iNextWeekButton )\r
152         {\r
153                 delete iNextWeekButton;\r
154                 iNextWeekButton = 0;\r
155         }\r
156         if ( iSettingsButton )\r
157         {\r
158                 delete iSettingsButton;\r
159                 iSettingsButton = 0;\r
160         }\r
161 }\r
162 \r
163 Meeting* WeeklyViewWidget::currentMeeting()\r
164 {\r
165         return iSchedule->currentMeeting();\r
166 }\r
167 \r
168 Room* WeeklyViewWidget::currentRoom()\r
169 {\r
170         return iRoomsCombo->currentRoom();\r
171 }\r
172 \r
173 void WeeklyViewWidget::setCurrentDateTime( QDateTime aCurrentDateTime )\r
174 {\r
175         iCurrentDayLabel->setText( aCurrentDateTime.date().toString( iConfiguration->displaySettings()->dateFormat() ) );\r
176         \r
177         iCurrentWeekLabel->setText( tr( "Wk %1" ).arg( aCurrentDateTime.date().weekNumber() ) );\r
178 \r
179         iTimeDisplay->setTime( aCurrentDateTime.time() );\r
180 \r
181         iSchedule->setCurrentDateTime( aCurrentDateTime );\r
182 }\r
183 \r
184 void WeeklyViewWidget::insertMeeting( Meeting *aMeeting )\r
185 {\r
186         iSchedule->insertMeeting( aMeeting );\r
187 }\r
188 \r
189 void WeeklyViewWidget::deleteMeeting( Meeting *aMeeting )\r
190 {\r
191         iSchedule->removeMeeting( aMeeting );\r
192 }\r
193 \r
194 void WeeklyViewWidget::updateMeeting( Meeting *aMeeting )\r
195 {\r
196         iSchedule->updateMeeting( aMeeting );\r
197 }\r
198 \r
199 QDate WeeklyViewWidget::beginnigOfShownWeek()\r
200 {\r
201         return iSchedule->beginningOfShownWeek();\r
202 }\r