1 #include "RoomStatusIndicatorWidget.h"
6 #include "BorderedBarWidget.h"
14 QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0);
16 RoomStatusIndicatorWidget::RoomStatusIndicatorWidget(Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent) :
17 ViewBase(ViewBase::ObservedView, aParent), iTimeFormat(aTimeFormat)
20 clockFont.setStyleHint( QFont::Helvetica );
21 clockFont.setBold( true );
22 clockFont.setPixelSize( 36 );
25 textFont.setStyleHint( QFont::Helvetica );
26 textFont.setBold( true );
27 textFont.setPixelSize( 48 );
30 statusBarFont.setStyleHint( QFont::Helvetica );
31 statusBarFont.setPixelSize( 18 );
33 // display for current time
34 // Note: the time display receives current time info from Engine::clock()
35 iTimeDisplay = new BorderedBarWidget( this );
36 iTimeDisplay->setFaceColor( Qt::darkGray );
37 iTimeDisplay->setBackgroundColor( Qt::white );
38 iTimeDisplay->setBorderWidth( 6 );
39 iTimeDisplay->setFixedWidth( 170 );
40 iTimeDisplay->setFixedHeight( 50 );
41 iTimeDisplay->setFont( clockFont );
43 iStatusBar = new BorderedBarWidget( this );
44 iStatusBar->setFaceColor( Qt::darkGray );
45 iStatusBar->setBackgroundColor( Qt::white );
46 iStatusBar->setBorderWidth( 4 );
47 iStatusBar->setFont(statusBarFont);
48 iStatusBar->setFixedHeight( 36 );
49 iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );
53 = ToolBox::createLabel(aDefaultRoom->name(), textFont);
54 iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
55 iDefaultRoomLabel->setHidden( true );
58 iStatusLabel = ToolBox::createLabel(tr( "is %1" ).arg(statusToText(aStatus) ), textFont);
59 iStatusLabel->setAlignment( Qt::AlignHCenter );
60 iStatusLabel->setHidden( true );
64 = ToolBox::createLabel(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ), textFont);
65 iUntilTextLabel->setAlignment( Qt::AlignHCenter );
66 iUntilTextLabel->setHidden( true );
68 QHBoxLayout *topLayout = new QHBoxLayout;
69 topLayout->addWidget(iTimeDisplay);
71 QVBoxLayout *textLayout = new QVBoxLayout;
72 textLayout->addWidget(iDefaultRoomLabel);
73 textLayout->addWidget(iStatusLabel);
74 textLayout->addWidget(iUntilTextLabel);
75 textLayout->addSpacing( 250 );
77 QHBoxLayout *centerLayout = new QHBoxLayout;
78 centerLayout->addLayout( textLayout );
79 centerLayout->addSpacing( 250 );
81 QHBoxLayout *bottomLayout = new QHBoxLayout;
82 bottomLayout->addSpacing( 56 );
83 bottomLayout->addWidget( iStatusBar );
84 bottomLayout->addSpacing( 56 );
86 QVBoxLayout *mainLayout = new QVBoxLayout;
87 mainLayout->addLayout( topLayout );
88 mainLayout->addSpacing( 50 );
89 mainLayout->addLayout( centerLayout );
90 mainLayout->addLayout( bottomLayout );
91 setLayout(mainLayout);
93 statusChanged(aStatus, aUntil);
96 palette.setColor( QPalette::Window, Qt::white );
97 palette.setColor( QPalette::WindowText, Qt::darkGray );
98 setPalette( palette );
100 setAutoFillBackground( true );
101 setFocusPolicy(Qt::StrongFocus);
102 setEnabled( true); // enable mouse & key events
105 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
114 QString RoomStatusIndicatorWidget::statusToText(const Room::Status aStatus)
116 return (aStatus == Room::BusyStatus ) ? tr("busy") : tr("free");
119 QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
123 aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
124 QPixmap pixmap(image);
126 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
127 const int xoffset( 60);
128 const int yoffset( 19);
129 int cropwidth(pixmap.width() - xoffset);
130 int cropheight(pixmap.height() - yoffset);
133 if ( (pixmap.width() == rect().width()) && (pixmap.height() == rect().height()) )
135 // Use the full image in full screen mode
136 brush.setTexture(pixmap);
140 // Take part of the image so the traffic lights are moved xoffset poxels to left
141 // and yoffset pixels to up
142 brush.setTexture(pixmap.copy(xoffset, yoffset, cropwidth, cropheight) );
146 palette.setColor( QPalette::Window, Qt::white );
147 palette.setColor( QPalette::WindowText, Qt::black );
148 palette.setBrush( QPalette::Window, brush );
152 void RoomStatusIndicatorWidget::setConnectionStatus( QDateTime aCurrentTime, bool aConnected,
153 QTime aLastUpdated, QString aError )
155 iTimeDisplay->setText( aCurrentTime.toString( iTimeFormat ) );
156 if ( aLastUpdated.isNull() )
157 iStatusBar->setText( tr("Disconnected") , BorderedBarWidget::LeftAlign );
160 iDefaultRoomLabel->setHidden( false );
161 iUntilTextLabel->setHidden( false );
162 iStatusLabel->setHidden( false );
166 iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );
170 iStatusBar->setText( tr("Connected - Last update %1").arg(aLastUpdated.toString(iTimeFormat)) ,
171 BorderedBarWidget::LeftAlign );
177 void RoomStatusIndicatorWidget::showError( QString aError )
179 iStatusBar->setText( aError );
183 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
185 iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
186 if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
188 iUntilTextLabel->setText(tr("whole day.") );
192 iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
194 setPalette(createPalette(aStatus) );
197 void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
199 iDefaultRoomLabel->setText(aRoom->name() );
202 bool RoomStatusIndicatorWidget::event(QEvent *event)
204 switch (event->type())
207 //qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
209 case QEvent::PaletteChange:
211 // << "[RoomStatusIndicatorWidget::event] <Palette change event>";
217 return ViewBase::event(event);
220 void RoomStatusIndicatorWidget::connectionEstablished()
222 ViewBase::connectionEstablished();
225 void RoomStatusIndicatorWidget::connectionLost()
227 ViewBase::connectionLost();