Status bar fixed
[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( 12 );\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( 28 );\r
77         QPixmap pixmap(":ixonos_logo");\r
78         iStatusBar->setPixmap( pixmap );\r
79         iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );\r
80 \r
81         iSchedule = new ScheduleWidget( aCurrentDateTime, iConfiguration->displaySettings(), this );\r
82         connect( iSchedule, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );\r
83         connect( iSchedule, SIGNAL( meetingActivated( Meeting* ) ), this, SIGNAL( meetingActivated( Meeting* ) ) );\r
84 \r
85         iPreviousWeekButton = new QPushButton( this );\r
86         iPreviousWeekButton->setText( tr( "<" ) );\r
87         iPreviousWeekButton->setFixedWidth( 50 );\r
88         iPreviousWeekButton->setFixedHeight( 100 );\r
89         iPreviousWeekButton->setFont( buttonFont );\r
90         connect( iPreviousWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showPreviousWeek() ) );\r
91 \r
92         iCurrentWeekButton = new QPushButton( this );\r
93         iCurrentWeekButton->setFixedWidth( 100 );\r
94         iCurrentWeekButton->setFixedHeight( 46 );\r
95         iCurrentWeekButton->setText( tr( "Today" ) );\r
96         iCurrentWeekButton->setFont( buttonFont );\r
97 \r
98         connect( iCurrentWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showCurrentWeek() ) );\r
99 \r
100         iNextWeekButton = new QPushButton( this );\r
101         iNextWeekButton->setFixedWidth( 50 );\r
102         iNextWeekButton->setFixedHeight( 100 );\r
103         iNextWeekButton->setText( tr( ">" ) );\r
104         iNextWeekButton->setFont( buttonFont );\r
105         connect( iNextWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showNextWeek() ) );\r
106 \r
107         // **********************************\r
108         //              Create the view's layout\r
109         QVBoxLayout *leftLayout = new QVBoxLayout;\r
110         QVBoxLayout *centerLayout = new QVBoxLayout;\r
111         QVBoxLayout *rightLayout = new QVBoxLayout;\r
112 \r
113         leftLayout->addWidget( iPreviousWeekButton );\r
114         rightLayout->addWidget( iNextWeekButton );\r
115 \r
116         QHBoxLayout *tableLayout = new QHBoxLayout;\r
117         tableLayout->addWidget( iSchedule );\r
118 \r
119         QGridLayout *naviLayout = new QGridLayout;\r
120         naviLayout->addWidget( iCurrentWeekButton, 0, 0, Qt::AlignLeft );\r
121         naviLayout->addWidget( iTimeDisplay, 0, 1, Qt::AlignCenter );\r
122         naviLayout->addWidget( iRoomsCombo, 0, 2, Qt::AlignRight );\r
123 \r
124 //      QVBoxLayout *dateLayout = new QVBoxLayout;\r
125 //      dateLayout->addWidget( iCurrentDayLabel );\r
126 //      dateLayout->addWidget( iCurrentWeekLabel );\r
127 //      bottomLayout->addLayout( dateLayout );\r
128 //      bottomLayout->addWidget( iSettingsButton );\r
129 \r
130         centerLayout->addLayout( naviLayout );\r
131         centerLayout->addLayout( tableLayout );\r
132         centerLayout->addWidget( iStatusBar );\r
133 \r
134         QHBoxLayout *mainLayout = new QHBoxLayout;\r
135         mainLayout->addLayout( leftLayout );\r
136         mainLayout->addLayout( centerLayout );\r
137         mainLayout->addLayout( rightLayout );\r
138         setLayout( mainLayout );\r
139         \r
140         // Set child observing\r
141         observeChild( iRoomsCombo );\r
142         observeChild( iStatusBar );\r
143         observeChild( iTimeDisplay );\r
144         observeChild( iCurrentDayLabel );\r
145         observeChild( iCurrentWeekLabel );\r
146         observeChild( iPreviousWeekButton );\r
147         observeChild( iCurrentWeekButton );\r
148         observeChild( iNextWeekButton );\r
149         observeChild( iSettingsButton );\r
150 \r
151         QPalette palette;\r
152         palette.setColor( QPalette::Window, Qt::white );\r
153         palette.setColor( QPalette::Foreground, Qt::darkGray );\r
154         setPalette( palette );\r
155 \r
156         setAutoFillBackground( true );\r
157 \r
158         // ******************************************\r
159         //              Handle all the signal connections\r
160         // TODO : this solution if interaction monitoring is not elegant enough\r
161 //      connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
162 //      connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
163 //      connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
164 //      connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) );\r
165 //      connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) );\r
166         // TODO: connect RoomCombo signals to change meetings data.\r
167         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );\r
168         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( refresh() ) );\r
169 }\r
170 \r
171 WeeklyViewWidget::~WeeklyViewWidget()\r
172 {\r
173         if ( iRoomsCombo )\r
174         {\r
175                 delete iRoomsCombo;\r
176                 iRoomsCombo = 0;\r
177         }\r
178         if ( iTimeDisplay )\r
179         {\r
180                 delete iTimeDisplay;\r
181                 iTimeDisplay = 0;\r
182         }\r
183         if ( iStatusBar )\r
184         {\r
185                 delete iStatusBar;\r
186                 iStatusBar = 0;\r
187         }\r
188 \r
189         if ( iSchedule )\r
190         {\r
191                 delete iSchedule;\r
192                 iSchedule = 0;\r
193         }\r
194         if ( iCurrentDayLabel )\r
195         {\r
196                 delete iCurrentDayLabel;\r
197                 iCurrentDayLabel = 0;\r
198         }\r
199         if ( iCurrentWeekLabel )\r
200         {\r
201                 delete iCurrentWeekLabel;\r
202                 iCurrentWeekLabel = 0;\r
203         }\r
204         if ( iPreviousWeekButton )\r
205         {\r
206                 delete iPreviousWeekButton;\r
207                 iPreviousWeekButton = 0;\r
208         }\r
209         if ( iCurrentWeekButton )\r
210         {\r
211                 delete iCurrentWeekButton;\r
212                 iCurrentWeekButton = 0;\r
213         }\r
214         if ( iNextWeekButton )\r
215         {\r
216                 delete iNextWeekButton;\r
217                 iNextWeekButton = 0;\r
218         }\r
219         if ( iSettingsButton )\r
220         {\r
221                 delete iSettingsButton;\r
222                 iSettingsButton = 0;\r
223         }\r
224 }\r
225 \r
226 Room* WeeklyViewWidget::currentRoom()\r
227 {\r
228         return iRoomsCombo->currentRoom();\r
229 }\r
230 \r
231 void WeeklyViewWidget::setConnectionStatus( QDateTime aCurrentTime, bool aConnected,\r
232                 QTime aLastUpdated, QString aError )\r
233 {\r
234         iCurrentDayLabel->setText( aCurrentTime.date().toString( iConfiguration->displaySettings()->dateFormat() ) );\r
235         iCurrentWeekLabel->setText( tr( "Wk %1" ).arg( aCurrentTime.date().weekNumber() ) );\r
236         iSchedule->setCurrentDateTime( aCurrentTime );\r
237         \r
238         iTimeDisplay->setText( aCurrentTime.toString( iConfiguration->displaySettings()->timeFormat() ) );\r
239         if ( aLastUpdated.isNull() )\r
240                 iStatusBar->setText( tr("Disconnected") , BorderedBarWidget::LeftAlign );\r
241         else if ( !aConnected )\r
242         {\r
243                 iStatusBar->setText( tr("Disconnected")\r
244                                 .arg(aLastUpdated.toString(iConfiguration->displaySettings()->timeFormat()))\r
245                                 , BorderedBarWidget::LeftAlign );\r
246         }\r
247         else\r
248         {\r
249                 iStatusBar->setText( tr("Connected - Last update %1")\r
250                                 .arg(aLastUpdated.toString(iConfiguration->displaySettings()->timeFormat())) ,\r
251                                 BorderedBarWidget::LeftAlign );\r
252         }\r
253         showError( aError );\r
254  }\r
255 \r
256 void WeeklyViewWidget::showError( QString aError )\r
257 {\r
258         iStatusBar->setText( aError );\r
259 }\r
260 \r
261 QDate WeeklyViewWidget::beginnigOfShownWeek()\r
262 {\r
263         return iSchedule->beginningOfShownWeek();\r
264 }\r
265 \r
266 void WeeklyViewWidget::refreshMeetings( const QList<Meeting*> &aMeetings )\r
267 {\r
268         qDebug() << "WeeklyViewWidget::refreshMeetings()";\r
269         iSchedule->refreshMeetings( aMeetings );\r
270 }\r
271 \r
272 void WeeklyViewWidget::showCurrentWeek()\r
273 {\r
274         iSchedule->showCurrentWeek();\r
275 }\r
276 \r
277 void WeeklyViewWidget::setDefaultRoom()\r
278 {\r
279         iRoomsCombo->setCurrentRoom( iConfiguration->defaultRoom() );\r
280 }\r
281 \r
282 void WeeklyViewWidget::connectionEstablished()\r
283 {\r
284         ViewBase::connectionEstablished();\r
285 }\r
286 \r
287 void WeeklyViewWidget::connectionLost()\r
288 {\r
289         ViewBase::connectionLost();\r
290 }\r