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