Fixed the room status changing information flow
[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         // 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 \r
41         // until 13:22\r
42         iUntilTextLabel = ToolBox::createLabel( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ), importantTextFont );\r
43         iUntilTextLabel->setAlignment( Qt::AlignHCenter );\r
44         iUntilTextLabel->setStyleSheet( "background-color: transparent" );\r
45 \r
46         QVBoxLayout *topLayout = new QVBoxLayout;\r
47         topLayout->addStretch();\r
48         topLayout->addWidget( iTimeDisplay );\r
49         topLayout->addWidget( iDefaultRoomLabel );\r
50         topLayout->addWidget( iStatusLabel );\r
51         topLayout->addWidget( iUntilTextLabel );\r
52         topLayout->addStretch();\r
53 \r
54         QHBoxLayout *mainLayout = new QHBoxLayout;\r
55         mainLayout->addLayout( topLayout );\r
56         mainLayout->addStretch();\r
57         mainLayout->setMargin( 65 );\r
58         setLayout( mainLayout );\r
59 \r
60         statusChanged( aStatus, aUntil );\r
61 \r
62         setFocusPolicy( Qt::StrongFocus );\r
63         setEnabled( true ); // enable mouse & key events\r
64 }\r
65 \r
66 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()\r
67 {\r
68         delete iTimeDisplay;\r
69         iTimeDisplay = 0;\r
70 }\r
71 \r
72 QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )\r
73 {\r
74         return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );\r
75 }\r
76 \r
77 QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )\r
78 {\r
79         QString image = aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";\r
80         QPixmap pixmap( image );\r
81 \r
82         // The image needs to be moved in normal mode so the traffic light not partly outside the screen\r
83         const int xoffset( 60 );\r
84         const int yoffset( 19 );\r
85         int cropwidth( pixmap.width() - xoffset );\r
86         int cropheight( pixmap.height() - yoffset );\r
87         \r
88         QBrush brush;\r
89         if ( windowState() == Qt::WindowFullScreen )\r
90         {\r
91                 // Use the full image in full screen mode\r
92                 brush.setTexture( pixmap );\r
93         }\r
94         else\r
95         {\r
96                 // Take part of the image so the traffic lights are moved xoffset poxels to left \r
97                 // and yoffset pixels to up\r
98                 brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );\r
99         }\r
100 \r
101         QPalette palette;\r
102         palette.setBrush( QPalette::Window, brush );\r
103         return palette;\r
104 }\r
105 \r
106 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )\r
107 {\r
108         iTimeDisplay->setTime( aCurrentTime );\r
109 }\r
110 \r
111 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )\r
112 {\r
113         iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );\r
114         if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )\r
115         {\r
116                 iUntilTextLabel->setText( tr( "whole day." ) );\r
117         }\r
118         else\r
119         {\r
120                 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );\r
121         }\r
122         setPalette( createPalette( aStatus ) );\r
123 }
124 \r
125 void RoomStatusIndicatorWidget::currentRoomChanged( Room *aRoom )\r
126 {\r
127         iDefaultRoomLabel->setText( aRoom->name() );\r
128 }\r
129 \r
130 bool RoomStatusIndicatorWidget::event(QEvent *event)\r
131 {\r
132         switch(event->type())\r
133         {\r
134                 case QEvent::Paint:\r
135                         qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";\r
136                         break;\r
137                 case QEvent::PaletteChange:\r
138                         qDebug() << "[RoomStatusIndicatorWidget::event] <Palette change event>";\r
139                         break;\r
140                 default:\r
141                         break;\r
142         }\r
143         \r
144         return ViewBase::event( event );\r
145 }\r