ViewBase added and major changes to use the new architecture
[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                 ViewBase( ViewBase::NormalView, 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( settingsButtonClicked() ) );\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( currentRoomChange( Room * ) ), this, SIGNAL( currentRoomChange( Room * ) ) );\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 \r
52         iSchedule = new ScheduleWidget( aCurrentDateTime, iConfiguration->displaySettings(), this );\r
53         connect( iSchedule, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );\r
54         connect( iSchedule, SIGNAL( meetingActivated( Meeting* ) ), this, SIGNAL( meetingActivated( Meeting* ) ) );\r
55 \r
56         iPreviousWeekButton = new QPushButton( this );\r
57         iPreviousWeekButton->setText( tr( "<<" ) );\r
58         iPreviousWeekButton->setFixedWidth( 60 );\r
59         connect( iPreviousWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showPreviousWeek() ) );\r
60 \r
61         iCurrentWeekButton = new QPushButton( this );\r
62         iCurrentWeekButton->setFixedWidth( 100 );\r
63         iCurrentWeekButton->setText( tr( "Current" ) );\r
64         connect( iCurrentWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showCurrentWeek() ) );\r
65 \r
66         iNextWeekButton = new QPushButton( this );\r
67         iNextWeekButton->setFixedWidth( 60 );\r
68         iNextWeekButton->setText( tr( ">>" ) );\r
69         connect( iNextWeekButton, SIGNAL( clicked() ), iSchedule, SLOT( showNextWeek() ) );\r
70 \r
71         // **********************************\r
72         //              Create the view's layout\r
73         QHBoxLayout *tableLayout = new QHBoxLayout;\r
74         tableLayout->addWidget( iSchedule );\r
75 \r
76         QHBoxLayout *bottomLayout = new QHBoxLayout;\r
77         bottomLayout->addWidget( iRoomsCombo );\r
78         bottomLayout->addWidget( iTimeDisplay );\r
79         QVBoxLayout *dateLayout = new QVBoxLayout;\r
80         dateLayout->addWidget( iCurrentDayLabel );\r
81         dateLayout->addWidget( iCurrentWeekLabel );\r
82         bottomLayout->addLayout( dateLayout );\r
83         bottomLayout->addWidget( iPreviousWeekButton );\r
84         bottomLayout->addWidget( iCurrentWeekButton );\r
85         bottomLayout->addWidget( iNextWeekButton );\r
86         bottomLayout->addWidget( iSettingsButton );\r
87 \r
88         QVBoxLayout *mainLayout = new QVBoxLayout;\r
89         mainLayout->addLayout( tableLayout );\r
90         mainLayout->addLayout( bottomLayout );\r
91         setLayout( mainLayout );\r
92         \r
93         // Set child observing\r
94         observeChild( iRoomsCombo );\r
95         observeChild( iTimeDisplay );\r
96         observeChild( iCurrentDayLabel );\r
97         observeChild( iCurrentWeekLabel );\r
98         observeChild( iPreviousWeekButton );\r
99         observeChild( iCurrentWeekButton );\r
100         observeChild( iNextWeekButton );\r
101         observeChild( iSettingsButton );\r
102 \r
103         QPalette palette;\r
104         palette.setColor( QPalette::Window, Qt::white );\r
105         palette.setColor( QPalette::Foreground, Qt::darkGray );\r
106         setPalette( palette );\r
107 \r
108         // ******************************************\r
109         //              Handle all the signal connections\r
110         // TODO : this solution if interaction monitoring is not elegant enough\r
111 //      connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
112 //      connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
113 //      connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
114 //      connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) );\r
115 //      connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) );\r
116         // TODO: connect RoomCombo signals to change meetings data.\r
117         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( clear() ) );\r
118         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );\r
119         connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( refresh() ) );\r
120 }\r
121 \r
122 WeeklyViewWidget::~WeeklyViewWidget()\r
123 {\r
124         if ( iRoomsCombo )\r
125         {\r
126                 delete iRoomsCombo;\r
127                 iRoomsCombo = 0;\r
128         }\r
129         if ( iTimeDisplay )\r
130         {\r
131                 delete iTimeDisplay;\r
132                 iTimeDisplay = 0;\r
133         }\r
134         if ( iSchedule )\r
135         {\r
136                 delete iSchedule;\r
137                 iSchedule = 0;\r
138         }\r
139         if ( iCurrentDayLabel )\r
140         {\r
141                 delete iCurrentDayLabel;\r
142                 iCurrentDayLabel = 0;\r
143         }\r
144         if ( iCurrentWeekLabel )\r
145         {\r
146                 delete iCurrentWeekLabel;\r
147                 iCurrentWeekLabel = 0;\r
148         }\r
149         if ( iPreviousWeekButton )\r
150         {\r
151                 delete iPreviousWeekButton;\r
152                 iPreviousWeekButton = 0;\r
153         }\r
154         if ( iCurrentWeekButton )\r
155         {\r
156                 delete iCurrentWeekButton;\r
157                 iCurrentWeekButton = 0;\r
158         }\r
159         if ( iNextWeekButton )\r
160         {\r
161                 delete iNextWeekButton;\r
162                 iNextWeekButton = 0;\r
163         }\r
164         if ( iSettingsButton )\r
165         {\r
166                 delete iSettingsButton;\r
167                 iSettingsButton = 0;\r
168         }\r
169 }\r
170 \r
171 Meeting* WeeklyViewWidget::currentMeeting()\r
172 {\r
173         return iSchedule->currentMeeting();\r
174 }\r
175 \r
176 Room* WeeklyViewWidget::currentRoom()\r
177 {\r
178         return iRoomsCombo->currentRoom();\r
179 }\r
180 \r
181 void WeeklyViewWidget::setCurrentDateTime( QDateTime aCurrentDateTime )\r
182 {\r
183         iCurrentDayLabel->setText( aCurrentDateTime.date().toString( iConfiguration->displaySettings()->dateFormat() ) );\r
184         \r
185         iCurrentWeekLabel->setText( tr( "Wk %1" ).arg( aCurrentDateTime.date().weekNumber() ) );\r
186 \r
187         iTimeDisplay->setTime( aCurrentDateTime.time() );\r
188 \r
189         iSchedule->setCurrentDateTime( aCurrentDateTime );\r
190 }\r
191 \r
192 void WeeklyViewWidget::insertMeeting( Meeting *aMeeting )\r
193 {\r
194         iSchedule->insertMeeting( aMeeting );\r
195 }\r
196 \r
197 void WeeklyViewWidget::deleteMeeting( Meeting *aMeeting )\r
198 {\r
199         iSchedule->removeMeeting( aMeeting );\r
200 }\r
201 \r
202 void WeeklyViewWidget::updateMeeting( Meeting *aMeeting )\r
203 {\r
204         iSchedule->updateMeeting( aMeeting );\r
205 }\r
206 \r
207 QDate WeeklyViewWidget::beginnigOfShownWeek()\r
208 {\r
209         return iSchedule->beginningOfShownWeek();\r
210 }\r