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