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
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
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
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
54 QHBoxLayout *mainLayout = new QHBoxLayout;
\r
55 mainLayout->addLayout( topLayout );
\r
56 mainLayout->addStretch();
\r
57 mainLayout->setMargin( 65 );
\r
58 setLayout( mainLayout );
\r
60 statusChanged( aStatus, aUntil );
\r
62 setFocusPolicy( Qt::StrongFocus );
\r
63 setEnabled( true ); // enable mouse & key events
\r
66 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
\r
68 delete iTimeDisplay;
\r
72 QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )
\r
74 return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );
\r
77 QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )
\r
79 // QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );
\r
80 QString image = aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
\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
89 if ( windowState() == Qt::WindowFullScreen )
\r
91 // Use the full image in full screen mode
\r
92 // brush.setTexture( pixmap );
\r
93 brush.setTexture( QPixmap(image) );
\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
104 palette.setBrush( QPalette::Window, brush );
\r
108 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )
\r
110 iTimeDisplay->setTime( aCurrentTime );
\r
113 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )
\r
115 iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );
\r
116 if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )
\r
118 iUntilTextLabel->setText( tr( "whole day." ) );
\r
122 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );
\r
124 setPalette( createPalette( aStatus ) );
\r
127 void RoomStatusIndicatorWidget::currentRoomChanged( Room *aRoom )
\r
129 iDefaultRoomLabel->setText( aRoom->name() );
\r
132 bool RoomStatusIndicatorWidget::event(QEvent *event)
\r
134 switch(event->type())
\r
136 case QEvent::Paint:
\r
137 qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
\r
139 case QEvent::PaletteChange:
\r
140 qDebug() << "[RoomStatusIndicatorWidget::event] <Palette change event>";
\r
146 return ViewBase::event( event );
\r