ca53b9d770fb83dfd81c99c58bd1abdfaae0262f
[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 (windowState() == Qt::WindowFullScreen)
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::setCurrentTime(QTime aCurrentTime)
155 {
156         iTimeDisplay->setText( aCurrentTime.toString( iTimeFormat ) );
157 }
158
159 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
160 {
161         iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
162         if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
163         {
164                 iUntilTextLabel->setText(tr("whole day.") );
165         }
166         else
167         {
168                 iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
169         }
170         setPalette(createPalette(aStatus) );
171 }
172
173 void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
174 {
175         iDefaultRoomLabel->setText(aRoom->name() );
176 }
177
178 bool RoomStatusIndicatorWidget::event(QEvent *event)
179 {
180         switch (event->type())
181         {
182                 case QEvent::Paint:
183                         //qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
184                         break;
185                 case QEvent::PaletteChange:
186                         //qDebug()
187                         //              << "[RoomStatusIndicatorWidget::event] <Palette change event>";
188                         break;
189                 default:
190                         break;
191         }
192
193         return ViewBase::event(event);
194 }
195
196 void RoomStatusIndicatorWidget::connectionEstablished()
197 {
198         if ( !connectedOnce)
199         { 
200                 // Just got the required meetings for the first time              
201                 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";
202                 iDefaultRoomLabel->setHidden( false);
203                 iUntilTextLabel->setHidden( false);
204                 iStatusLabel->setHidden( false);
205         }
206         else
207         {
208                 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";
209         }
210         ViewBase::connectionEstablished();
211         iStatusBar->setText( tr("Connected"), BorderedBarWidget::LeftAlign );
212 }
213
214 void RoomStatusIndicatorWidget::connectionLost()
215 {
216         ViewBase::connectionLost();
217         iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );
218 }