ce5c8ebda926da644d8decdc05051a52f75575fe
[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         // No connection to server note\r
45         qDebug() << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";\r
46         QFrame* connectionLabelFrame = new QFrame( this );\r
47         iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );\r
48         iConnectionLabel->setFont( importantTextFont ); \r
49         iConnectionLabel->setAlignment( Qt::AlignHCenter );\r
50         iConnectionLabel->setWordWrap( true );\r
51         iConnectionLabel->setStyleSheet( "background-color: transparent; color: red; text-decoration:blink; max-width: 250px" );\r
52         connectionLabelFrame->setFixedSize( iConnectionLabel->sizeHint() );\r
53         //iConnectionLabel->setHidden( true );\r
54 \r
55         QVBoxLayout *topLayout = new QVBoxLayout;\r
56         topLayout->addStretch();\r
57         topLayout->addWidget( iTimeDisplay );\r
58         topLayout->addSpacing( 28 );\r
59         topLayout->addWidget( iDefaultRoomLabel );\r
60         topLayout->addWidget( iStatusLabel );\r
61         topLayout->addWidget( iUntilTextLabel );\r
62         topLayout->addSpacing( 28 );\r
63         topLayout->addWidget( connectionLabelFrame );\r
64         topLayout->addStretch();\r
65 \r
66         QHBoxLayout *mainLayout = new QHBoxLayout;\r
67         mainLayout->addLayout( topLayout );\r
68         mainLayout->addStretch();\r
69         //mainLayout->setMargin( 65 );\r
70         mainLayout->setContentsMargins( 65, 65, 65, 0 );\r
71         setLayout( mainLayout );\r
72 \r
73         statusChanged( aStatus, aUntil );\r
74 \r
75         setFocusPolicy( Qt::StrongFocus );\r
76         setEnabled( true ); // enable mouse & key events\r
77 }\r
78 \r
79 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()\r
80 {\r
81         delete iTimeDisplay;\r
82         iTimeDisplay = 0;\r
83 }\r
84 \r
85 QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )\r
86 {\r
87         return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );\r
88 }\r
89 \r
90 QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )\r
91 {\r
92         QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );\r
93 \r
94         // The image needs to be moved in normal mode so the traffic light not partly outside the screen\r
95         const int xoffset( 60 );\r
96         const int yoffset( 19 );\r
97         int cropwidth( pixmap.width() - xoffset );\r
98         int cropheight( pixmap.height() - yoffset );\r
99         \r
100         QBrush brush;\r
101         if ( windowState() == Qt::WindowFullScreen )\r
102         {\r
103                 // Use the full image in full screen mode\r
104                 brush.setTexture( pixmap );\r
105         }\r
106         else\r
107         {\r
108                 // Take part of the image so the traffic lights are moved xoffset poxels to left \r
109                 // and yoffset pixels to up\r
110                 brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );\r
111         }\r
112 \r
113         QPalette palette;\r
114         palette.setBrush( QPalette::Window, brush );\r
115         return palette;\r
116 }\r
117 \r
118 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )\r
119 {\r
120         iTimeDisplay->setTime( aCurrentTime );\r
121 }\r
122 \r
123 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )\r
124 {\r
125         iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );\r
126         if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )\r
127         {\r
128                 iUntilTextLabel->setText( tr( "whole day." ) );\r
129         }\r
130         else\r
131         {\r
132                 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );\r
133         }\r
134         setPalette( createPalette( aStatus ) );\r
135 }\r