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
17 QFont importantTextFont;
\r
18 //importantTextFont.setBold( true );
\r
19 importantTextFont.setPointSize( 20 );
\r
21 QFont regularTextFont;
\r
22 //regularTextFont.setBold( true );
\r
23 regularTextFont.setPointSize( 12 );
\r
25 // display for current time
\r
26 // Note: the time display receives current time info from Engine::clock()
\r
27 iTimeDisplay = new DigitalTimeDisplayWidget( QTime::currentTime(), iTimeFormat, this );
\r
28 iTimeDisplay->setFrameVisible( false );
\r
29 iTimeDisplay->setSize( 250, 120 );
\r
32 iDefaultRoomLabel = ToolBox::createLabel( aDefaultRoom->name(), importantTextFont );
\r
33 iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
\r
34 iDefaultRoomLabel->setStyleSheet( "background-color: transparent" );
\r
36 iStatusLabel = ToolBox::createLabel( tr( "is %1" ).arg( statusToText( aStatus ) ), importantTextFont );
\r
37 iStatusLabel->setAlignment( Qt::AlignHCenter );
\r
38 iStatusLabel->setStyleSheet( "background-color: transparent" );
\r
41 iUntilTextLabel = ToolBox::createLabel( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ), importantTextFont );
\r
42 iUntilTextLabel->setAlignment( Qt::AlignHCenter );
\r
43 iUntilTextLabel->setStyleSheet( "background-color: transparent" );
\r
45 QVBoxLayout *topLayout = new QVBoxLayout;
\r
46 topLayout->addStretch();
\r
47 topLayout->addWidget( iTimeDisplay );
\r
48 topLayout->addWidget( iDefaultRoomLabel );
\r
49 topLayout->addWidget( iStatusLabel );
\r
50 topLayout->addWidget( iUntilTextLabel );
\r
51 topLayout->addStretch();
\r
53 QHBoxLayout *mainLayout = new QHBoxLayout;
\r
54 mainLayout->addLayout( topLayout );
\r
55 mainLayout->addStretch();
\r
56 mainLayout->setMargin( 65 );
\r
57 setLayout( mainLayout );
\r
59 statusChanged( aStatus, aUntil );
\r
61 setFocusPolicy( Qt::StrongFocus );
\r
62 setEnabled( true ); // enable mouse & key events
\r
65 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
\r
67 delete iTimeDisplay;
\r
71 QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )
\r
73 return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );
\r
76 QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )
\r
78 QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );
\r
80 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
\r
81 const int xoffset( 60 );
\r
82 const int yoffset( 19 );
\r
83 int cropwidth( pixmap.width() - xoffset );
\r
84 int cropheight( pixmap.height() - yoffset );
\r
87 if ( windowState() == Qt::WindowFullScreen )
\r
89 // Use the full image in full screen mode
\r
90 brush.setTexture( pixmap );
\r
94 // Take part of the image so the traffic lights are moved xoffset poxels to left
\r
95 // and yoffset pixels to up
\r
96 brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );
\r
100 palette.setBrush( QPalette::Window, brush );
\r
104 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )
\r
106 iTimeDisplay->setTime( aCurrentTime );
\r
109 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )
\r
111 iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );
\r
112 if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )
\r
114 iUntilTextLabel->setText( tr( "whole day." ) );
\r
118 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );
\r
120 setPalette( createPalette( aStatus ) );
\r
123 void RoomStatusIndicatorWidget::currentRoomChanged( Room *aRoom )
\r
125 iDefaultRoomLabel->setText( aRoom->name() );
\r