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
34 iDefaultRoomLabel->setHidden( true );
\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
40 iStatusLabel->setHidden( true );
\r
43 iUntilTextLabel = ToolBox::createLabel( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ), importantTextFont );
\r
44 iUntilTextLabel->setAlignment( Qt::AlignHCenter );
\r
45 iUntilTextLabel->setStyleSheet( "background-color: transparent" );
\r
46 iUntilTextLabel->setHidden( true );
\r
48 // No connection to server note
\r
49 qDebug() << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";
\r
50 QFrame* connectionLabelFrame = new QFrame( this );
\r
51 iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );
\r
52 iConnectionLabel->setFont( importantTextFont );
\r
53 iConnectionLabel->setAlignment( Qt::AlignHCenter );
\r
54 iConnectionLabel->setWordWrap( true );
\r
55 iConnectionLabel->setStyleSheet( "background-color: transparent; color: red; text-decoration:blink; max-width: 250px" );
\r
56 connectionLabelFrame->setFixedSize( iConnectionLabel->sizeHint() );
\r
57 if( connectedOnce && !connectionError ) iConnectionLabel->setHidden( true );
\r
60 QVBoxLayout *topLayout = new QVBoxLayout;
\r
61 topLayout->addStretch();
\r
62 topLayout->addWidget( iTimeDisplay );
\r
63 topLayout->addSpacing( 28 );
\r
64 topLayout->addWidget( iDefaultRoomLabel );
\r
65 topLayout->addWidget( iStatusLabel );
\r
66 topLayout->addWidget( iUntilTextLabel );
\r
67 topLayout->addSpacing( 28 );
\r
68 topLayout->addWidget( connectionLabelFrame );
\r
69 topLayout->addStretch();
\r
71 QHBoxLayout *mainLayout = new QHBoxLayout;
\r
72 mainLayout->addLayout( topLayout );
\r
73 mainLayout->addStretch();
\r
74 //mainLayout->setMargin( 65 );
\r
75 mainLayout->setContentsMargins( 65, 65, 65, 0 );
\r
76 setLayout( mainLayout );
\r
78 statusChanged( aStatus, aUntil );
\r
80 setFocusPolicy( Qt::StrongFocus );
\r
81 setEnabled( true ); // enable mouse & key events
\r
84 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
\r
86 delete iTimeDisplay;
\r
90 QString RoomStatusIndicatorWidget::statusToText( const Room::Status aStatus )
\r
92 return ( aStatus == Room::BusyStatus ) ? tr( "busy" ) : tr( "free" );
\r
95 QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )
\r
97 QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );
\r
99 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
\r
100 const int xoffset( 60 );
\r
101 const int yoffset( 19 );
\r
102 int cropwidth( pixmap.width() - xoffset );
\r
103 int cropheight( pixmap.height() - yoffset );
\r
106 if ( windowState() == Qt::WindowFullScreen )
\r
108 // Use the full image in full screen mode
\r
109 brush.setTexture( pixmap );
\r
113 // Take part of the image so the traffic lights are moved xoffset poxels to left
\r
114 // and yoffset pixels to up
\r
115 brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );
\r
119 palette.setBrush( QPalette::Window, brush );
\r
123 void RoomStatusIndicatorWidget::setCurrentTime( QTime aCurrentTime )
\r
125 iTimeDisplay->setTime( aCurrentTime );
\r
128 void RoomStatusIndicatorWidget::statusChanged( const Room::Status aStatus, const QTime aUntil )
\r
130 iStatusLabel->setText( tr( "is %1" ).arg( statusToText( aStatus ) ) );
\r
131 if ( aUntil == RoomStatusIndicatorWidget::endOfTheDay )
\r
133 iUntilTextLabel->setText( tr( "whole day." ) );
\r
137 iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );
\r
139 setPalette( createPalette( aStatus ) );
\r
142 void RoomStatusIndicatorWidget::connectionEstablished()
\r
144 if( !connectedOnce )
\r
146 // Just got the required meetings for the first time
\r
147 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";
\r
148 iDefaultRoomLabel->setHidden( false );
\r
149 iUntilTextLabel->setHidden( false );
\r
150 iStatusLabel->setHidden( false );
\r
152 ViewBase::connectionEstablished();
\r
153 iConnectionLabel->setHidden( true );
\r
156 void RoomStatusIndicatorWidget::connectionLost()
\r
158 ViewBase::connectionLost();
\r
159 iConnectionLabel->setHidden( false );
\r