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