1 #include "RoomStatusIndicatorWidget.h"
\r
5 #include <QVBoxLayout>
\r
6 #include "DigitalTimeDisplayWidget.h"
\r
13 QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0 );
\r
15 RoomStatusIndicatorWidget::RoomStatusIndicatorWidget( Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent ) :
\r
16 ViewBase( ViewBase::ObservedView, aParent ), iTimeFormat( aTimeFormat )
\r
18 QFont importantTextFont;
\r
19 //importantTextFont.setBold( true );
\r
20 importantTextFont.setPointSize( 20 );
\r
22 QFont regularTextFont;
\r
23 //regularTextFont.setBold( true );
\r
24 regularTextFont.setPointSize( 12 );
\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
33 iDefaultRoomLabel = ToolBox::createLabel( aDefaultRoom->name(), importantTextFont );
\r
34 iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
\r
35 iDefaultRoomLabel->setStyleSheet( "background-color: transparent" );
\r
36 iDefaultRoomLabel->setHidden( true );
\r
39 iStatusLabel = ToolBox::createLabel( tr( "is %1" ).arg( statusToText( aStatus ) ), importantTextFont );
\r
40 iStatusLabel->setAlignment( Qt::AlignHCenter );
\r
41 iStatusLabel->setStyleSheet( "background-color: transparent" );
\r
42 iStatusLabel->setHidden( true );
\r
45 iUntilTextLabel = ToolBox::createLabel( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ), importantTextFont );
\r
46 iUntilTextLabel->setAlignment( Qt::AlignHCenter );
\r
47 iUntilTextLabel->setStyleSheet( "background-color: transparent" );
\r
48 iUntilTextLabel->setHidden( true );
\r
50 // No connection to server note
\r
51 qDebug() << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";
\r
52 QFrame* connectionLabelFrame = new QFrame( this );
\r
53 iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );
\r
54 iConnectionLabel->setFont( importantTextFont );
\r
55 iConnectionLabel->setAlignment( Qt::AlignHCenter );
\r
56 iConnectionLabel->setWordWrap( true );
\r
57 iConnectionLabel->setStyleSheet( "background-color: transparent; color: red; text-decoration:blink; max-width: 250px" );
\r
58 connectionLabelFrame->setFixedSize( iConnectionLabel->sizeHint() );
\r
59 if( connectedOnce && !connectionError ) iConnectionLabel->setHidden( true );
\r
62 QVBoxLayout *topLayout = new QVBoxLayout;
\r
63 topLayout->addStretch();
\r
64 topLayout->addWidget( iTimeDisplay );
\r
65 topLayout->addSpacing( 28 );
\r
66 topLayout->addWidget( iDefaultRoomLabel );
\r
67 topLayout->addWidget( iStatusLabel );
\r
68 topLayout->addWidget( iUntilTextLabel );
\r
69 topLayout->addSpacing( 28 );
\r
70 topLayout->addWidget( connectionLabelFrame );
\r
71 topLayout->addStretch();
\r
73 QHBoxLayout *mainLayout = new QHBoxLayout;
\r
74 mainLayout->addLayout( topLayout );
\r
75 mainLayout->addStretch();
\r
76 //mainLayout->setMargin( 65 );
\r
77 mainLayout->setContentsMargins( 65, 65, 65, 0 );
\r
78 setLayout( mainLayout );
\r
80 statusChanged( aStatus, aUntil );
\r
82 setFocusPolicy( Qt::StrongFocus );
\r
83 setEnabled( true ); // enable mouse & key events
\r
86 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
\r
88 delete iTimeDisplay;
\r
92 QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )
\r
94 return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );
\r
97 QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )
\r
99 // QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );
\r
100 QString image = aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
\r
102 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
\r
103 const int xoffset( 60 );
\r
104 const int yoffset( 19 );
\r
105 // int cropwidth( pixmap.width() - xoffset );
\r
106 // int cropheight( pixmap.height() - yoffset );
\r
109 if ( windowState() == Qt::WindowFullScreen )
\r
111 // Use the full image in full screen mode
\r
112 // brush.setTexture( pixmap );
\r
113 brush.setTexture( QPixmap(image) );
\r
117 // Take part of the image so the traffic lights are moved xoffset poxels to left
\r
118 // and yoffset pixels to up
\r
119 // brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );
\r
120 brush.setTexture( QPixmap(image) );
\r
124 palette.setBrush( QPalette::Window, brush );
\r
128 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )
\r
130 iTimeDisplay->setTime( aCurrentTime );
\r
133 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )
\r
135 qDebug() << "[RoomStatusIndicatorWidget::statusChanged] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
\r
136 iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );
\r
137 if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )
\r
139 iUntilTextLabel->setText( tr( "whole day." ) );
\r
143 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );
\r
145 setPalette( createPalette( aStatus ) );
\r
148 void RoomStatusIndicatorWidget::currentRoomChanged( Room *aRoom )
\r
150 iDefaultRoomLabel->setText( aRoom->name() );
\r
153 bool RoomStatusIndicatorWidget::event(QEvent *event)
\r
155 switch(event->type())
\r
157 case QEvent::Paint:
\r
158 qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
\r
160 case QEvent::PaletteChange:
\r
161 qDebug() << "[RoomStatusIndicatorWidget::event] <Palette change event>";
\r
167 return ViewBase::event( event );
\r
170 void RoomStatusIndicatorWidget::connectionEstablished()
\r
173 if( !connectedOnce )
\r
175 // Just got the required meetings for the first time
\r
176 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";
\r
177 iDefaultRoomLabel->setHidden( false );
\r
178 iUntilTextLabel->setHidden( false );
\r
179 iStatusLabel->setHidden( false );
\r
181 else qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";
\r
182 ViewBase::connectionEstablished();
\r
183 iConnectionLabel->setHidden( true );
\r
186 void RoomStatusIndicatorWidget::connectionLost()
\r
188 ViewBase::connectionLost();
\r
189 iConnectionLabel->setHidden( false );
\r