1 #include "RoomStatusIndicatorWidget.h"
\r
5 #include <QVBoxLayout>
\r
6 #include "DigitalTimeDisplayWidget.h"
\r
11 QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0 );
\r
13 RoomStatusIndicatorWidget::RoomStatusIndicatorWidget( Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent ) :
\r
14 ViewBase( ViewBase::ObservedView, aParent ), iTimeFormat( aTimeFormat )
\r
16 QFont importantTextFont;
\r
17 //importantTextFont.setBold( true );
\r
18 importantTextFont.setPointSize( 20 );
\r
20 QFont regularTextFont;
\r
21 //regularTextFont.setBold( true );
\r
22 regularTextFont.setPointSize( 12 );
\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
31 iDefaultRoomLabel = ToolBox::createLabel( aDefaultRoom->name(), importantTextFont );
\r
32 iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
\r
33 iDefaultRoomLabel->setStyleSheet( "background-color: transparent" );
\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
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
44 QVBoxLayout *topLayout = new QVBoxLayout;
\r
45 topLayout->addStretch();
\r
46 topLayout->addWidget( iTimeDisplay );
\r
47 topLayout->addWidget( iDefaultRoomLabel );
\r
48 topLayout->addWidget( iStatusLabel );
\r
49 topLayout->addWidget( iUntilTextLabel );
\r
50 topLayout->addStretch();
\r
52 QHBoxLayout *mainLayout = new QHBoxLayout;
\r
53 mainLayout->addLayout( topLayout );
\r
54 mainLayout->addStretch();
\r
55 mainLayout->setMargin( 65 );
\r
56 setLayout( mainLayout );
\r
58 statusChanged( aStatus, aUntil );
\r
60 setFocusPolicy( Qt::StrongFocus );
\r
61 setEnabled( true ); // enable mouse & key events
\r
64 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
\r
66 delete iTimeDisplay;
\r
70 QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )
\r
72 return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );
\r
75 QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )
\r
77 QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );
\r
79 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
\r
80 const int xoffset( 60 );
\r
81 const int yoffset( 19 );
\r
82 int cropwidth( pixmap.width() - xoffset );
\r
83 int cropheight( pixmap.height() - yoffset );
\r
86 if ( windowState() == Qt::WindowFullScreen )
\r
88 // Use the full image in full screen mode
\r
89 brush.setTexture( pixmap );
\r
93 // Take part of the image so the traffic lights are moved xoffset poxels to left
\r
94 // and yoffset pixels to up
\r
95 brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );
\r
99 palette.setBrush( QPalette::Window, brush );
\r
103 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )
\r
105 iTimeDisplay->setTime( aCurrentTime );
\r
108 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )
\r
110 iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );
\r
111 if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )
\r
113 iUntilTextLabel->setText( tr( "whole day." ) );
\r
117 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );
\r
119 setPalette( createPalette( aStatus ) );
\r