User interface and menu fixes
[qtmeetings] / src / UserInterface / Views / RoomStatusIndicatorWidget.cpp
1 #include "RoomStatusIndicatorWidget.h"
2
3 #include <QLabel>
4 #include <QFont>
5 #include <QVBoxLayout>
6 #include "BorderedBarWidget.h"
7
8 #include "ToolBox.h"
9
10 #include <QEvent>
11
12 #include <QtDebug>
13
14 QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0);
15
16 RoomStatusIndicatorWidget::RoomStatusIndicatorWidget(Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent) :
17         ViewBase(ViewBase::ObservedView, aParent), iTimeFormat(aTimeFormat)
18 {
19         QFont clockFont;
20         clockFont.setStyleHint( QFont::Helvetica );
21         clockFont.setBold( true );
22         clockFont.setPixelSize( 36 );
23
24         QFont textFont;
25         textFont.setStyleHint( QFont::Helvetica );
26         textFont.setBold( true );
27         textFont.setPixelSize( 48 );
28
29         QFont statusBarFont;
30         statusBarFont.setStyleHint( QFont::Helvetica );
31         statusBarFont.setPixelSize( 18 );
32
33         // display for current time
34         // Note: the time display receives current time info from Engine::clock()
35         iTimeDisplay = new BorderedBarWidget( this );
36         iTimeDisplay->setFaceColor( Qt::darkGray );
37         iTimeDisplay->setBackgroundColor( Qt::white );
38         iTimeDisplay->setBorderWidth( 6 );
39         iTimeDisplay->setFixedWidth( 170 );
40         iTimeDisplay->setFixedHeight( 50 );
41         iTimeDisplay->setFont( clockFont );
42
43         iStatusBar = new BorderedBarWidget( this );
44         iStatusBar->setFaceColor( Qt::darkGray );
45         iStatusBar->setBackgroundColor( Qt::white );
46         iStatusBar->setBorderWidth( 4 );
47         iStatusBar->setFont(statusBarFont);
48         iStatusBar->setFixedHeight( 36 );
49         iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );
50
51         // Pegasus
52         iDefaultRoomLabel
53                         = ToolBox::createLabel(aDefaultRoom->name(), textFont);
54         iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
55         iDefaultRoomLabel->setHidden( true );
56
57         // is busy
58         iStatusLabel = ToolBox::createLabel(tr( "is %1" ).arg(statusToText(aStatus) ), textFont);
59         iStatusLabel->setAlignment( Qt::AlignHCenter );
60         iStatusLabel->setHidden( true );
61
62         // until 13:22
63         iUntilTextLabel
64                         = ToolBox::createLabel(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ), textFont);
65         iUntilTextLabel->setAlignment( Qt::AlignHCenter );
66         iUntilTextLabel->setHidden( true );
67
68         QHBoxLayout *topLayout = new QHBoxLayout;
69         topLayout->addWidget(iTimeDisplay);
70
71         QVBoxLayout *textLayout = new QVBoxLayout;
72         textLayout->addWidget(iDefaultRoomLabel);
73         textLayout->addWidget(iStatusLabel);
74         textLayout->addWidget(iUntilTextLabel);
75         textLayout->addSpacing( 250 );
76
77         QHBoxLayout *centerLayout = new QHBoxLayout;
78         centerLayout->addLayout( textLayout );
79         centerLayout->addSpacing( 250 );
80
81         QHBoxLayout *bottomLayout = new QHBoxLayout;
82         bottomLayout->addSpacing( 56 );
83         bottomLayout->addWidget( iStatusBar );
84         bottomLayout->addSpacing( 56 );
85
86         QVBoxLayout *mainLayout = new QVBoxLayout;
87         mainLayout->addLayout( topLayout );
88         mainLayout->addSpacing( 50 );
89         mainLayout->addLayout( centerLayout );
90         mainLayout->addLayout( bottomLayout );
91         setLayout(mainLayout);
92
93         statusChanged(aStatus, aUntil);
94
95         QPalette palette;
96         palette.setColor( QPalette::Window, Qt::white );
97         palette.setColor( QPalette::WindowText, Qt::darkGray );
98         setPalette( palette );
99
100         setAutoFillBackground( true );
101         setFocusPolicy(Qt::StrongFocus);
102         setEnabled( true); // enable mouse & key events
103 }
104
105 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
106 {
107         delete iTimeDisplay;
108         iTimeDisplay = 0;
109
110         delete iStatusBar;
111         iStatusBar = 0;
112 }
113
114 QString RoomStatusIndicatorWidget::statusToText(const Room::Status aStatus)
115 {
116         return (aStatus == Room::BusyStatus ) ? tr("busy") : tr("free");
117 }
118
119 QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
120 {
121         QString
122                         image =
123                                         aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
124         QPixmap pixmap(image);
125
126         // The image needs to be moved in normal mode so the traffic light not partly outside the screen
127         const int xoffset( 60);
128         const int yoffset( 19);
129         int cropwidth(pixmap.width() - xoffset);
130         int cropheight(pixmap.height() - yoffset);
131
132         QBrush brush;
133         if ( (pixmap.width() == rect().width()) && (pixmap.height() == rect().height()) )
134         {
135                 // Use the full image in full screen mode
136                 brush.setTexture(pixmap);
137         }
138         else
139         {
140                 // Take part of the image so the traffic lights are moved xoffset poxels to left 
141                 // and yoffset pixels to up
142                 brush.setTexture(pixmap.copy(xoffset, yoffset, cropwidth, cropheight) );
143         }
144
145         QPalette palette;
146         palette.setColor( QPalette::Window, Qt::white );
147         palette.setColor( QPalette::WindowText, Qt::black );
148         palette.setBrush( QPalette::Window, brush );
149         return palette;
150 }
151
152 void RoomStatusIndicatorWidget::setConnectionStatus( QDateTime aCurrentTime, bool aConnected,
153                 QTime aLastUpdated, QString aError )
154 {
155         iTimeDisplay->setText( aCurrentTime.toString( iTimeFormat ) );
156         if ( aLastUpdated.isNull() )
157                 iStatusBar->setText( tr("Disconnected") , BorderedBarWidget::LeftAlign );
158         else
159         {
160                 iDefaultRoomLabel->setHidden( false );
161                 iUntilTextLabel->setHidden( false );
162                 iStatusLabel->setHidden( false );
163
164                 if (!aConnected)
165                 {
166                         iStatusBar->setText( tr("Disconnected").arg(aLastUpdated.toString(iTimeFormat))
167                                         , BorderedBarWidget::LeftAlign );
168                 }
169                 else
170                 {
171                         iStatusBar->setText( tr("Connected - Last update %1").arg(aLastUpdated.toString(iTimeFormat)) ,
172                                         BorderedBarWidget::LeftAlign );
173                 }
174         }
175         showError( aError );
176 }
177
178 void RoomStatusIndicatorWidget::showError( QString aError )
179 {
180         iStatusBar->setText( aError );
181 }
182
183
184 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
185 {
186         iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
187         if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
188         {
189                 iUntilTextLabel->setText(tr("whole day.") );
190         }
191         else
192         {
193                 iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
194         }
195         setPalette(createPalette(aStatus) );
196 }
197
198 void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
199 {
200         iDefaultRoomLabel->setText(aRoom->name() );
201 }
202
203 bool RoomStatusIndicatorWidget::event(QEvent *event)
204 {
205         switch (event->type())
206         {
207                 case QEvent::Paint:
208                         //qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
209                         break;
210                 case QEvent::PaletteChange:
211                         //qDebug()
212                         //              << "[RoomStatusIndicatorWidget::event] <Palette change event>";
213                         break;
214                 default:
215                         break;
216         }
217
218         return ViewBase::event(event);
219 }
220
221 void RoomStatusIndicatorWidget::connectionEstablished()
222 {
223         ViewBase::connectionEstablished();
224 }
225
226 void RoomStatusIndicatorWidget::connectionLost()
227 {
228         ViewBase::connectionLost();
229 }