Status bar fixed
[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( 12 );
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( 28 );
49         QPixmap pixmap(":ixonos_logo");
50         iStatusBar->setPixmap( pixmap );
51         iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );
52
53         // Pegasus
54         iDefaultRoomLabel
55                         = ToolBox::createLabel(aDefaultRoom->name(), textFont);
56         iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
57         iDefaultRoomLabel->setHidden( true );
58
59         // is busy
60         iStatusLabel = ToolBox::createLabel(tr( "is %1" ).arg(statusToText(aStatus) ), textFont);
61         iStatusLabel->setAlignment( Qt::AlignHCenter );
62         iStatusLabel->setHidden( true );
63
64         // until 13:22
65         iUntilTextLabel
66                         = ToolBox::createLabel(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ), textFont);
67         iUntilTextLabel->setAlignment( Qt::AlignHCenter );
68         iUntilTextLabel->setHidden( true );
69
70         QHBoxLayout *topLayout = new QHBoxLayout;
71         topLayout->addWidget(iTimeDisplay);
72
73         QVBoxLayout *textLayout = new QVBoxLayout;
74         textLayout->addWidget(iDefaultRoomLabel);
75         textLayout->addWidget(iStatusLabel);
76         textLayout->addWidget(iUntilTextLabel);
77         textLayout->addSpacing( 250 );
78
79         QHBoxLayout *centerLayout = new QHBoxLayout;
80         centerLayout->addLayout( textLayout );
81         centerLayout->addSpacing( 250 );
82
83         QHBoxLayout *bottomLayout = new QHBoxLayout;
84         bottomLayout->addSpacing( 56 );
85         bottomLayout->addWidget( iStatusBar );
86         bottomLayout->addSpacing( 56 );
87
88         QVBoxLayout *mainLayout = new QVBoxLayout;
89         mainLayout->addLayout( topLayout );
90         mainLayout->addSpacing( 50 );
91         mainLayout->addLayout( centerLayout );
92         mainLayout->addLayout( bottomLayout );
93         setLayout(mainLayout);
94
95         statusChanged(aStatus, aUntil);
96
97         QPalette palette;
98         palette.setColor( QPalette::Window, Qt::white );
99         palette.setColor( QPalette::WindowText, Qt::darkGray );
100         setPalette( palette );
101
102         setAutoFillBackground( true );
103         setFocusPolicy(Qt::StrongFocus);
104         setEnabled( true); // enable mouse & key events
105 }
106
107 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
108 {
109         delete iTimeDisplay;
110         iTimeDisplay = 0;
111
112         delete iStatusBar;
113         iStatusBar = 0;
114 }
115
116 QString RoomStatusIndicatorWidget::statusToText(const Room::Status aStatus)
117 {
118         return (aStatus == Room::BusyStatus ) ? tr("busy") : tr("free");
119 }
120
121 QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
122 {
123         QString
124                         image =
125                                         aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
126         QPixmap pixmap(image);
127
128         // The image needs to be moved in normal mode so the traffic light not partly outside the screen
129         const int xoffset( 60);
130         const int yoffset( 19);
131         int cropwidth(pixmap.width() - xoffset);
132         int cropheight(pixmap.height() - yoffset);
133
134         QBrush brush;
135         if ( (pixmap.width() == rect().width()) && (pixmap.height() == rect().height()) )
136         {
137                 // Use the full image in full screen mode
138                 brush.setTexture(pixmap);
139         }
140         else
141         {
142                 // Take part of the image so the traffic lights are moved xoffset poxels to left 
143                 // and yoffset pixels to up
144                 brush.setTexture(pixmap.copy(xoffset, yoffset, cropwidth, cropheight) );
145         }
146
147         QPalette palette;
148         palette.setColor( QPalette::Window, Qt::white );
149         palette.setColor( QPalette::WindowText, Qt::black );
150         palette.setBrush( QPalette::Window, brush );
151         return palette;
152 }
153
154 void RoomStatusIndicatorWidget::setConnectionStatus( QDateTime aCurrentTime, bool aConnected,
155                 QTime aLastUpdated, QString aError )
156 {
157         iTimeDisplay->setText( aCurrentTime.toString( iTimeFormat ) );
158         if ( aLastUpdated.isNull() )
159                 iStatusBar->setText( tr("Disconnected") , BorderedBarWidget::LeftAlign );
160         else
161         {
162                 iDefaultRoomLabel->setHidden( false );
163                 iUntilTextLabel->setHidden( false );
164                 iStatusLabel->setHidden( false );
165
166                 if (!aConnected)
167                 {
168                         iStatusBar->setText( tr("Disconnected").arg(aLastUpdated.toString(iTimeFormat))
169                                         , BorderedBarWidget::LeftAlign );
170                 }
171                 else
172                 {
173                         iStatusBar->setText( tr("Connected - Last update %1").arg(aLastUpdated.toString(iTimeFormat)) ,
174                                         BorderedBarWidget::LeftAlign );
175                 }
176         }
177         showError( aError );
178 }
179
180 void RoomStatusIndicatorWidget::showError( QString aError )
181 {
182         iStatusBar->setText( aError );
183 }
184
185
186 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
187 {
188         iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
189         if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
190         {
191                 iUntilTextLabel->setText(tr("whole day.") );
192         }
193         else
194         {
195                 iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
196         }
197         setPalette(createPalette(aStatus) );
198 }
199
200 void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
201 {
202         iDefaultRoomLabel->setText(aRoom->name() );
203 }
204
205 bool RoomStatusIndicatorWidget::event(QEvent *event)
206 {
207         switch (event->type())
208         {
209                 case QEvent::Paint:
210                         //qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
211                         break;
212                 case QEvent::PaletteChange:
213                         //qDebug()
214                         //              << "[RoomStatusIndicatorWidget::event] <Palette change event>";
215                         break;
216                 default:
217                         break;
218         }
219
220         return ViewBase::event(event);
221 }
222
223 void RoomStatusIndicatorWidget::connectionEstablished()
224 {
225         ViewBase::connectionEstablished();
226 }
227
228 void RoomStatusIndicatorWidget::connectionLost()
229 {
230         ViewBase::connectionLost();
231 }