82d18c226eb5bb9c4b6156f6bc0955fff37598e0
[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 #include "BorderedBarWidget.h"\r
20 \r
21 #include <QtDebug>\r
22 \r
23 WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *aConfiguration, QWidget *aParent ) :\r
24                 ViewBase( ViewBase::NormalView, aParent ), iConfiguration( aConfiguration )\r
25 {\r
26 \r
27         // *****************************************\r
28         //              Construct all the needed widgets\r
29         QFont importantTextFont;\r
30         importantTextFont.setBold( true );\r
31         importantTextFont.setPointSize( 20 );\r
32 \r
33         QFont regularTextFont;\r
34         regularTextFont.setBold( true );\r
35         regularTextFont.setPointSize( 12 );\r
36 \r
37         QFont clockFont;\r
38         clockFont.setStyleHint( QFont::Helvetica );\r
39         clockFont.setBold( true );\r
40         clockFont.setPixelSize( 36 );\r
41 \r
42         QFont statusBarFont;\r
43         statusBarFont.setStyleHint( QFont::Helvetica );\r
44         statusBarFont.setPixelSize( 18 );\r
45 \r
46         QFont buttonFont;\r
47         buttonFont.setStyleHint( QFont::Helvetica );\r
48         buttonFont.setBold( true );\r
49         buttonFont.setPixelSize( 18 );\r
50 \r
51         iSettingsButton = new QPushButton;\r
52         iSettingsButton->setIcon( QPixmap( ":button_settings" ) );\r
53         iSettingsButton->setFixedWidth( 36 );\r
54         connect( iSettingsButton, SIGNAL( clicked() ), this, SIGNAL( settingsButtonClicked() ) );\r
55 \r
56         iCurrentDayLabel = ToolBox::createLabel( aCurrentDateTime.toString( iConfiguration->displaySettings()->dateFormat() ), regularTextFont );\r
57         iCurrentWeekLabel = ToolBox::createLabel( tr( "Wk %1" ).arg( aCurrentDateTime.date().weekNumber() ), regularTextFont );\r
58 \r
59         iTimeDisplay = new BorderedBarWidget( this );\r
60         iTimeDisplay->setFaceColor( Qt::darkGray );\r
61         iTimeDisplay->setBackgroundColor( Qt::white);\r
62         iTimeDisplay->setBorderWidth( 6 );\r
63         iTimeDisplay->setFixedWidth( 170 );\r
64         iTimeDisplay->setFixedHeight( 50 );\r
65         iTimeDisplay->setFont( clockFont );\r
66 \r
67         iRoomsCombo = new MeetingRoomCombo( iConfiguration->rooms(), this );\r
68         iRoomsCombo->setCurrentRoom( iConfiguration->defaultRoom() );\r
69         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );\r
70 \r
71         iStatusBar = new BorderedBarWidget( this );\r
72         iStatusBar->setFaceColor( Qt::darkGray );\r
73         iStatusBar->setBackgroundColor( Qt::white );\r
74         iStatusBar->setBorderWidth( 4 );\r
75         iStatusBar->setFont(statusBarFont);\r
76         iStatusBar->setFixedHeight( 36 );\r
77         iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );\r
78 \r
79         iSchedule = new ScheduleWidget( aCurrentDateTime, iConfiguration->displaySettings(), this );\r
80         connect( iSchedule, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );\r
81         connect( iSchedule, SIGNAL( meetingActivated( Meeting* ) ), this, SIGNAL( meetingActivated( Meeting* ) ) );\r
82 \r
83         iPreviousWeekButton = new QPushButton( this );\r
84         iPreviousWeekButton->setText( tr( "<" ) );\r
85         iPreviousWeekButton->setFixedWidth( 50 );\r
86         iPreviousWeekButton->setFixedHeight( 100 );\r
87         iPreviousWeekButton->setFont( buttonFont );\r
88         connect( iPreviousWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showPreviousWeek() ) );\r
89 \r
90         iCurrentWeekButton = new QPushButton( this );\r
91         iCurrentWeekButton->setFixedWidth( 100 );\r
92         iCurrentWeekButton->setFixedHeight( 46 );\r
93         iCurrentWeekButton->setText( tr( "Today" ) );\r
94         iCurrentWeekButton->setFont( buttonFont );\r
95 \r
96         connect( iCurrentWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showCurrentWeek() ) );\r
97 \r
98         iNextWeekButton = new QPushButton( this );\r
99         iNextWeekButton->setFixedWidth( 50 );\r
100         iNextWeekButton->setFixedHeight( 100 );\r
101         iNextWeekButton->setText( tr( ">" ) );\r
102         iNextWeekButton->setFont( buttonFont );\r
103         connect( iNextWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showNextWeek() ) );\r
104 \r
105         // **********************************\r
106         //              Create the view's layout\r
107         QVBoxLayout *leftLayout = new QVBoxLayout;\r
108         QVBoxLayout *centerLayout = new QVBoxLayout;\r
109         QVBoxLayout *rightLayout = new QVBoxLayout;\r
110 \r
111         leftLayout->addWidget( iPreviousWeekButton );\r
112         rightLayout->addWidget( iNextWeekButton );\r
113 \r
114         QHBoxLayout *tableLayout = new QHBoxLayout;\r
115         tableLayout->addWidget( iSchedule );\r
116 \r
117         QGridLayout *naviLayout = new QGridLayout;\r
118         naviLayout->addWidget( iCurrentWeekButton, 0, 0, Qt::AlignLeft );\r
119         naviLayout->addWidget( iTimeDisplay, 0, 1, Qt::AlignCenter );\r
120         naviLayout->addWidget( iRoomsCombo, 0, 2, Qt::AlignRight );\r
121 \r
122 //      QVBoxLayout *dateLayout = new QVBoxLayout;\r
123 //      dateLayout->addWidget( iCurrentDayLabel );\r
124 //      dateLayout->addWidget( iCurrentWeekLabel );\r
125 //      bottomLayout->addLayout( dateLayout );\r
126 //      bottomLayout->addWidget( iSettingsButton );\r
127 \r
128         centerLayout->addLayout( naviLayout );\r
129         centerLayout->addLayout( tableLayout );\r
130         centerLayout->addWidget( iStatusBar );\r
131 \r
132         QHBoxLayout *mainLayout = new QHBoxLayout;\r
133         mainLayout->addLayout( leftLayout );\r
134         mainLayout->addLayout( centerLayout );\r
135         mainLayout->addLayout( rightLayout );\r
136         setLayout( mainLayout );\r
137         \r
138         // Set child observing\r
139         observeChild( iRoomsCombo );\r
140         observeChild( iStatusBar );\r
141         observeChild( iTimeDisplay );\r
142         observeChild( iCurrentDayLabel );\r
143         observeChild( iCurrentWeekLabel );\r
144         observeChild( iPreviousWeekButton );\r
145         observeChild( iCurrentWeekButton );\r
146         observeChild( iNextWeekButton );\r
147         observeChild( iSettingsButton );\r
148 \r
149         QPalette palette;\r
150         palette.setColor( QPalette::Window, Qt::white );\r
151         palette.setColor( QPalette::Foreground, Qt::darkGray );\r
152         setPalette( palette );\r
153 \r
154         setAutoFillBackground( true );\r
155 \r
156         // ******************************************\r
157         //              Handle all the signal connections\r
158         // TODO : this solution if interaction monitoring is not elegant enough\r
159 //      connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
160 //      connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
161 //      connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
162 //      connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) );\r
163 //      connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) );\r
164         // TODO: connect RoomCombo signals to change meetings data.\r
165         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );\r
166         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( refresh() ) );\r
167 }\r
168 \r
169 WeeklyViewWidget::~WeeklyViewWidget()\r
170 {\r
171         if ( iRoomsCombo )\r
172         {\r
173                 delete iRoomsCombo;\r
174                 iRoomsCombo = 0;\r
175         }\r
176         if ( iTimeDisplay )\r
177         {\r
178                 delete iTimeDisplay;\r
179                 iTimeDisplay = 0;\r
180         }\r
181         if ( iStatusBar )\r
182         {\r
183                 delete iStatusBar;\r
184                 iStatusBar = 0;\r
185         }\r
186 \r
187         if ( iSchedule )\r
188         {\r
189                 delete iSchedule;\r
190                 iSchedule = 0;\r
191         }\r
192         if ( iCurrentDayLabel )\r
193         {\r
194                 delete iCurrentDayLabel;\r
195                 iCurrentDayLabel = 0;\r
196         }\r
197         if ( iCurrentWeekLabel )\r
198         {\r
199                 delete iCurrentWeekLabel;\r
200                 iCurrentWeekLabel = 0;\r
201         }\r
202         if ( iPreviousWeekButton )\r
203         {\r
204                 delete iPreviousWeekButton;\r
205                 iPreviousWeekButton = 0;\r
206         }\r
207         if ( iCurrentWeekButton )\r
208         {\r
209                 delete iCurrentWeekButton;\r
210                 iCurrentWeekButton = 0;\r
211         }\r
212         if ( iNextWeekButton )\r
213         {\r
214                 delete iNextWeekButton;\r
215                 iNextWeekButton = 0;\r
216         }\r
217         if ( iSettingsButton )\r
218         {\r
219                 delete iSettingsButton;\r
220                 iSettingsButton = 0;\r
221         }\r
222 }\r
223 \r
224 Room* WeeklyViewWidget::currentRoom()\r
225 {\r
226         return iRoomsCombo->currentRoom();\r
227 }\r
228 \r
229 void WeeklyViewWidget::setConnectionStatus( QDateTime aCurrentTime, bool aConnected,\r
230                 QTime aLastUpdated, QString aError )\r
231 {\r
232         iCurrentDayLabel->setText( aCurrentTime.date().toString( iConfiguration->displaySettings()->dateFormat() ) );\r
233         iCurrentWeekLabel->setText( tr( "Wk %1" ).arg( aCurrentTime.date().weekNumber() ) );\r
234         iSchedule->setCurrentDateTime( aCurrentTime );\r
235         \r
236         iTimeDisplay->setText( aCurrentTime.toString( iConfiguration->displaySettings()->timeFormat() ) );\r
237         if ( aLastUpdated.isNull() )\r
238                 iStatusBar->setText( tr("Disconnected") , BorderedBarWidget::LeftAlign );\r
239         else if ( !aConnected )\r
240         {\r
241                 iStatusBar->setText( tr("Disconnected")\r
242                                 .arg(aLastUpdated.toString(iConfiguration->displaySettings()->timeFormat()))\r
243                                 , BorderedBarWidget::LeftAlign );\r
244         }\r
245         else\r
246         {\r
247                 iStatusBar->setText( tr("Connected - Last update %1")\r
248                                 .arg(aLastUpdated.toString(iConfiguration->displaySettings()->timeFormat())) ,\r
249                                 BorderedBarWidget::LeftAlign );\r
250         }\r
251         showError( aError );\r
252  }\r
253 \r
254 void WeeklyViewWidget::showError( QString aError )\r
255 {\r
256         iStatusBar->setText( aError );\r
257 }\r
258 \r
259 QDate WeeklyViewWidget::beginnigOfShownWeek()\r
260 {\r
261         return iSchedule->beginningOfShownWeek();\r
262 }\r
263 \r
264 void WeeklyViewWidget::refreshMeetings( const QList<Meeting*> &aMeetings )\r
265 {\r
266         qDebug() << "WeeklyViewWidget::refreshMeetings()";\r
267         iSchedule->refreshMeetings( aMeetings );\r
268 }\r
269 \r
270 void WeeklyViewWidget::showCurrentWeek()\r
271 {\r
272         iSchedule->showCurrentWeek();\r
273 }\r
274 \r
275 void WeeklyViewWidget::setDefaultRoom()\r
276 {\r
277         iRoomsCombo->setCurrentRoom( iConfiguration->defaultRoom() );\r
278 }\r
279 \r
280 void WeeklyViewWidget::connectionEstablished()\r
281 {\r
282         ViewBase::connectionEstablished();\r
283 }\r
284 \r
285 void WeeklyViewWidget::connectionLost()\r
286 {\r
287         ViewBase::connectionLost();\r
288 }\r