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