Fixed errors caused by auto merge that did not work correctly
[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         // QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );\r
80         QString image = aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";\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                 brush.setTexture( QPixmap(image) );\r
94         }\r
95         else\r
96         {\r
97                 // Take part of the image so the traffic lights are moved xoffset poxels to left \r
98                 // and yoffset pixels to up\r
99 //              brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );\r
100                 brush.setTexture( QPixmap(image) );\r
101         }\r
102 \r
103         QPalette palette;\r
104         palette.setBrush( QPalette::Window, brush );\r
105         return palette;\r
106 }\r
107 \r
108 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )\r
109 {\r
110         iTimeDisplay->setTime( aCurrentTime );\r
111 }\r
112 \r
113 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )\r
114 {\r
115         qDebug() << "[RoomStatusIndicatorWidget::statusChanged] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";\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 }
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