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