Merge branch 'master' of https://git.maemo.org/projects/qtmeetings
[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         QString image = aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";\r
100         QPixmap pixmap( image );\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         }\r
114         else\r
115         {\r
116                 // Take part of the image so the traffic lights are moved xoffset poxels to left \r
117                 // and yoffset pixels to up\r
118                 brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );\r
119         }\r
120 \r
121         QPalette palette;\r
122         palette.setBrush( QPalette::Window, brush );\r
123         return palette;\r
124 }\r
125 \r
126 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )\r
127 {\r
128         iTimeDisplay->setTime( aCurrentTime );\r
129 }\r
130 \r
131 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )\r
132 {\r
133         iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );\r
134         if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )\r
135         {\r
136                 iUntilTextLabel->setText( tr( "whole day." ) );\r
137         }\r
138         else\r
139         {\r
140                 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );\r
141         }\r
142         setPalette( createPalette( aStatus ) );\r
143 }
144 \r
145 void RoomStatusIndicatorWidget::currentRoomChanged( Room *aRoom )\r
146 {\r
147         iDefaultRoomLabel->setText( aRoom->name() );\r
148 }\r
149 \r
150 bool RoomStatusIndicatorWidget::event(QEvent *event)\r
151 {\r
152         switch(event->type())\r
153         {\r
154                 case QEvent::Paint:\r
155                         qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";\r
156                         break;\r
157                 case QEvent::PaletteChange:\r
158                         qDebug() << "[RoomStatusIndicatorWidget::event] <Palette change event>";\r
159                         break;\r
160                 default:\r
161                         break;\r
162         }\r
163         \r
164         return ViewBase::event( event );\r
165 }\r
166 \r
167 void RoomStatusIndicatorWidget::connectionEstablished()\r
168 {\r
169         \r
170         if( !connectedOnce )\r
171         {\r
172                 // Just got the required meetings for the first time\r
173                 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";\r
174                 iDefaultRoomLabel->setHidden( false );\r
175                 iUntilTextLabel->setHidden( false );\r
176                 iStatusLabel->setHidden( false );\r
177         }\r
178         else qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";\r
179         ViewBase::connectionEstablished();\r
180         iConnectionLabel->setHidden( true );\r
181 }\r
182 \r
183 void RoomStatusIndicatorWidget::connectionLost()\r
184 {\r
185         ViewBase::connectionLost();\r
186         iConnectionLabel->setHidden( false );\r
187 }\r
188 \r