1 #include "RoomStatusIndicatorWidget.h"
6 #include "DigitalTimeDisplayWidget.h"
13 QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0 );
15 RoomStatusIndicatorWidget::RoomStatusIndicatorWidget( Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent ) :
16 ViewBase( ViewBase::ObservedView, aParent ), iTimeFormat( aTimeFormat )
18 QFont importantTextFont;
19 //importantTextFont.setBold( true );
20 importantTextFont.setPointSize( 20 );
22 QFont regularTextFont;
23 //regularTextFont.setBold( true );
24 regularTextFont.setPointSize( 12 );
26 // display for current time
27 // Note: the time display receives current time info from Engine::clock()
28 iTimeDisplay = new DigitalTimeDisplayWidget( QTime::currentTime(), iTimeFormat, this );
29 iTimeDisplay->setFrameVisible( false );
30 iTimeDisplay->setSize( 250, 120 );
33 iDefaultRoomLabel = ToolBox::createLabel( aDefaultRoom->name(), importantTextFont );
34 iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
35 iDefaultRoomLabel->setStyleSheet( "background-color: transparent" );
36 iDefaultRoomLabel->setHidden( true );
39 iStatusLabel = ToolBox::createLabel( tr( "is %1" ).arg( statusToText( aStatus ) ), importantTextFont );
40 iStatusLabel->setAlignment( Qt::AlignHCenter );
41 iStatusLabel->setStyleSheet( "background-color: transparent" );
42 iStatusLabel->setHidden( true );
45 iUntilTextLabel = ToolBox::createLabel( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ), importantTextFont );
46 iUntilTextLabel->setAlignment( Qt::AlignHCenter );
47 iUntilTextLabel->setStyleSheet( "background-color: transparent" );
48 iUntilTextLabel->setHidden( true );
50 // No connection to server note
51 qDebug() << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";
52 QFrame* connectionLabelFrame = new QFrame( this );
53 iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );
54 iConnectionLabel->setFont( importantTextFont );
55 iConnectionLabel->setAlignment( Qt::AlignHCenter );
56 iConnectionLabel->setWordWrap( true );
57 iConnectionLabel->setStyleSheet( "background-color: transparent; color: red; text-decoration:blink; max-width: 250px" );
58 connectionLabelFrame->setFixedSize( iConnectionLabel->sizeHint() );
59 if( connectedOnce && !connectionError ) iConnectionLabel->setHidden( true );
62 QVBoxLayout *topLayout = new QVBoxLayout;
63 topLayout->addStretch();
64 topLayout->addWidget( iTimeDisplay );
65 topLayout->addSpacing( 28 );
66 topLayout->addWidget( iDefaultRoomLabel );
67 topLayout->addWidget( iStatusLabel );
68 topLayout->addWidget( iUntilTextLabel );
69 topLayout->addSpacing( 28 );
70 topLayout->addWidget( connectionLabelFrame );
71 topLayout->addStretch();
73 QHBoxLayout *mainLayout = new QHBoxLayout;
74 mainLayout->addLayout( topLayout );
75 mainLayout->addStretch();
76 //mainLayout->setMargin( 65 );
77 mainLayout->setContentsMargins( 65, 65, 65, 0 );
78 setLayout( mainLayout );
80 statusChanged( aStatus, aUntil );
82 setFocusPolicy( Qt::StrongFocus );
83 setEnabled( true ); // enable mouse & key events
86 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
92 QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )
94 return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );
97 QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )
99 QString image = aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
100 QPixmap pixmap( image );
102 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
103 const int xoffset( 60 );
104 const int yoffset( 19 );
105 int cropwidth( pixmap.width() - xoffset );
106 int cropheight( pixmap.height() - yoffset );
109 if ( windowState() == Qt::WindowFullScreen )
111 // Use the full image in full screen mode
112 brush.setTexture( pixmap );
116 // Take part of the image so the traffic lights are moved xoffset poxels to left
117 // and yoffset pixels to up
118 brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );
122 palette.setBrush( QPalette::Window, brush );
126 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )
128 iTimeDisplay->setTime( aCurrentTime );
131 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )
133 iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );
134 if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )
136 iUntilTextLabel->setText( tr( "whole day." ) );
140 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );
142 setPalette( createPalette( aStatus ) );
145 void RoomStatusIndicatorWidget::currentRoomChanged( Room *aRoom )
147 iDefaultRoomLabel->setText( aRoom->name() );
150 bool RoomStatusIndicatorWidget::event(QEvent *event)
152 switch(event->type())
155 qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
157 case QEvent::PaletteChange:
158 qDebug() << "[RoomStatusIndicatorWidget::event] <Palette change event>";
164 return ViewBase::event( event );