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