missing methods added.
[qtmeetings] / src / UserInterface / Views / RoomStatusIndicatorWidget.cpp
1 #include "RoomStatusIndicatorWidget.h"
2
3 #include <QLabel>
4 #include <QFont>
5 #include <QVBoxLayout>
6 #include "DigitalTimeDisplayWidget.h"
7 #include "ToolBox.h"
8
9 #include <QEvent>
10
11 #include <QtDebug>
12
13 QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0);
14
15 RoomStatusIndicatorWidget::RoomStatusIndicatorWidget(Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent) :
16         ViewBase(ViewBase::ObservedView, aParent), iTimeFormat(aTimeFormat)
17 {
18         QFont importantTextFont;
19         //importantTextFont.setBold( true );
20         importantTextFont.setPointSize( 20);
21
22         QFont regularTextFont;
23         //regularTextFont.setBold( true );
24         regularTextFont.setPointSize( 12);
25
26         // display for current time
27         // Note: the time display receives current time info from Engine::clock()
28         iTimeDisplay = new DigitalTimeDisplayWidget( QTime::currentTime(), iTimeFormat, this );
29         iTimeDisplay->setFrameVisible( false);
30         iTimeDisplay->setSize( 250, 120);
31
32         // Pegasus
33         iDefaultRoomLabel
34                         = ToolBox::createLabel(aDefaultRoom->name(), importantTextFont);
35         iDefaultRoomLabel->setAlignment(Qt::AlignHCenter);
36         iDefaultRoomLabel->setStyleSheet("background-color: transparent");
37         iDefaultRoomLabel->setHidden( true);
38
39         // is busy
40         iStatusLabel = ToolBox::createLabel(tr( "is %1" ).arg(statusToText(aStatus) ), importantTextFont);
41         iStatusLabel->setAlignment(Qt::AlignHCenter);
42         iStatusLabel->setStyleSheet("background-color: transparent");
43         iStatusLabel->setHidden( true);
44
45         // until 13:22
46         iUntilTextLabel
47                         = ToolBox::createLabel(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ), importantTextFont);
48         iUntilTextLabel->setAlignment(Qt::AlignHCenter);
49         iUntilTextLabel->setStyleSheet("background-color: transparent");
50         iUntilTextLabel->setHidden( true);
51
52         // No connection to server note
53         qDebug()
54                         << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";
55         QFrame* connectionLabelFrame = new QFrame( this );
56         iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );
57         iConnectionLabel->setFont(importantTextFont);
58         iConnectionLabel->setAlignment(Qt::AlignHCenter);
59         iConnectionLabel->setWordWrap( true);
60         iConnectionLabel->setStyleSheet("background-color: transparent; color: red; text-decoration:blink; max-width: 250px");
61         connectionLabelFrame->setFixedSize(iConnectionLabel->sizeHint() );
62         if (connectedOnce && !connectionError)
63                 iConnectionLabel->setHidden( true);
64
65         QVBoxLayout *topLayout = new QVBoxLayout;
66         topLayout->addStretch();
67         topLayout->addWidget(iTimeDisplay);
68         topLayout->addSpacing( 28);
69         topLayout->addWidget(iDefaultRoomLabel);
70         topLayout->addWidget(iStatusLabel);
71         topLayout->addWidget(iUntilTextLabel);
72         topLayout->addSpacing( 28);
73         topLayout->addWidget(connectionLabelFrame);
74         topLayout->addStretch();
75
76         QHBoxLayout *mainLayout = new QHBoxLayout;
77         mainLayout->addLayout(topLayout);
78         mainLayout->addStretch();
79         //mainLayout->setMargin( 65 );
80         mainLayout->setContentsMargins( 65, 65, 65, 0);
81         setLayout(mainLayout);
82
83         statusChanged(aStatus, aUntil);
84
85         setFocusPolicy(Qt::StrongFocus);
86         setEnabled( true); // enable mouse & key events
87 }
88
89 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
90 {
91         delete iTimeDisplay;
92         iTimeDisplay = 0;
93 }
94
95 QString RoomStatusIndicatorWidget::statusToText(const Room::Status aStatus)
96 {
97         return (aStatus == Room::BusyStatus ) ? tr("busy") : tr("free");
98 }
99
100 QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
101 {
102         QString
103                         image =
104                                         aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
105         QPixmap pixmap(image);
106
107         // The image needs to be moved in normal mode so the traffic light not partly outside the screen
108         const int xoffset( 60);
109         const int yoffset( 19);
110         int cropwidth(pixmap.width() - xoffset);
111         int cropheight(pixmap.height() - yoffset);
112
113         QBrush brush;
114         if (windowState() == Qt::WindowFullScreen)
115         {
116                 // Use the full image in full screen mode
117                 brush.setTexture(pixmap);
118         }
119         else
120         {
121                 // Take part of the image so the traffic lights are moved xoffset poxels to left 
122                 // and yoffset pixels to up
123                 brush.setTexture(pixmap.copy(xoffset, yoffset, cropwidth, cropheight) );
124         }
125
126         QPalette palette;
127         palette.setBrush(QPalette::Window, brush);
128         return palette;
129 }
130
131 void RoomStatusIndicatorWidget::setCurrentTime(QTime aCurrentTime)
132 {
133         iTimeDisplay->setTime(aCurrentTime);
134 }
135
136 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
137 {
138         iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
139         if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
140         {
141                 iUntilTextLabel->setText(tr("whole day.") );
142         }
143         else
144         {
145                 iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
146         }
147         setPalette(createPalette(aStatus) );
148 }
149
150 void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
151 {
152         iDefaultRoomLabel->setText(aRoom->name() );
153 }
154
155 bool RoomStatusIndicatorWidget::event(QEvent *event)
156 {
157         switch (event->type())
158         {
159                 case QEvent::Paint:
160                         qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
161                         break;
162                 case QEvent::PaletteChange:
163                         qDebug()
164                                         << "[RoomStatusIndicatorWidget::event] <Palette change event>";
165                         break;
166                 default:
167                         break;
168         }
169
170         return ViewBase::event(event);
171 }
172
173 void RoomStatusIndicatorWidget::connectionEstablished()
174 {
175         if ( !connectedOnce)
176         { 
177                 // Just got the required meetings for the first time              
178                 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";
179                 iDefaultRoomLabel->setHidden( false);
180                 iUntilTextLabel->setHidden( false);
181                 iStatusLabel->setHidden( false);
182         }
183         else
184         {
185                 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";
186         }
187         ViewBase::connectionEstablished();
188         iConnectionLabel->setHidden( true);
189 }
190
191 void RoomStatusIndicatorWidget::connectionLost()
192 {
193         ViewBase::connectionLost();
194         iConnectionLabel->setHidden( false);
195 }