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( 12 );
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( 28 );
49 QPixmap pixmap(":ixonos_logo");
50 iStatusBar->setPixmap( pixmap );
51 iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );
55 = ToolBox::createLabel(aDefaultRoom->name(), textFont);
56 iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );
57 iDefaultRoomLabel->setHidden( true );
60 iStatusLabel = ToolBox::createLabel(tr( "is %1" ).arg(statusToText(aStatus) ), textFont);
61 iStatusLabel->setAlignment( Qt::AlignHCenter );
62 iStatusLabel->setHidden( true );
66 = ToolBox::createLabel(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ), textFont);
67 iUntilTextLabel->setAlignment( Qt::AlignHCenter );
68 iUntilTextLabel->setHidden( true );
70 QHBoxLayout *topLayout = new QHBoxLayout;
71 topLayout->addWidget(iTimeDisplay);
73 QVBoxLayout *textLayout = new QVBoxLayout;
74 textLayout->addWidget(iDefaultRoomLabel);
75 textLayout->addWidget(iStatusLabel);
76 textLayout->addWidget(iUntilTextLabel);
77 textLayout->addSpacing( 250 );
79 QHBoxLayout *centerLayout = new QHBoxLayout;
80 centerLayout->addLayout( textLayout );
81 centerLayout->addSpacing( 250 );
83 QHBoxLayout *bottomLayout = new QHBoxLayout;
84 bottomLayout->addSpacing( 56 );
85 bottomLayout->addWidget( iStatusBar );
86 bottomLayout->addSpacing( 56 );
88 QVBoxLayout *mainLayout = new QVBoxLayout;
89 mainLayout->addLayout( topLayout );
90 mainLayout->addSpacing( 50 );
91 mainLayout->addLayout( centerLayout );
92 mainLayout->addLayout( bottomLayout );
93 setLayout(mainLayout);
95 statusChanged(aStatus, aUntil);
98 palette.setColor( QPalette::Window, Qt::white );
99 palette.setColor( QPalette::WindowText, Qt::darkGray );
100 setPalette( palette );
102 setAutoFillBackground( true );
103 setFocusPolicy(Qt::StrongFocus);
104 setEnabled( true); // enable mouse & key events
107 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
116 QString RoomStatusIndicatorWidget::statusToText(const Room::Status aStatus)
118 return (aStatus == Room::BusyStatus ) ? tr("busy") : tr("free");
121 QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
125 aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
126 QPixmap pixmap(image);
128 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
129 const int xoffset( 60);
130 const int yoffset( 19);
131 int cropwidth(pixmap.width() - xoffset);
132 int cropheight(pixmap.height() - yoffset);
135 if (windowState() == Qt::WindowFullScreen)
137 // Use the full image in full screen mode
138 brush.setTexture(pixmap);
142 // Take part of the image so the traffic lights are moved xoffset poxels to left
143 // and yoffset pixels to up
144 brush.setTexture(pixmap.copy(xoffset, yoffset, cropwidth, cropheight) );
148 palette.setColor( QPalette::Window, Qt::white );
149 palette.setColor( QPalette::WindowText, Qt::black );
150 palette.setBrush( QPalette::Window, brush );
154 void RoomStatusIndicatorWidget::setCurrentTime(QTime aCurrentTime)
156 iTimeDisplay->setText( aCurrentTime.toString( iTimeFormat ) );
159 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
161 iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
162 if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
164 iUntilTextLabel->setText(tr("whole day.") );
168 iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
170 setPalette(createPalette(aStatus) );
173 void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
175 iDefaultRoomLabel->setText(aRoom->name() );
178 bool RoomStatusIndicatorWidget::event(QEvent *event)
180 switch (event->type())
183 //qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
185 case QEvent::PaletteChange:
187 // << "[RoomStatusIndicatorWidget::event] <Palette change event>";
193 return ViewBase::event(event);
196 void RoomStatusIndicatorWidget::connectionEstablished()
200 // Just got the required meetings for the first time
201 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";
202 iDefaultRoomLabel->setHidden( false);
203 iUntilTextLabel->setHidden( false);
204 iStatusLabel->setHidden( false);
208 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";
210 ViewBase::connectionEstablished();
211 iStatusBar->setText( tr("Connected"), BorderedBarWidget::LeftAlign );
214 void RoomStatusIndicatorWidget::connectionLost()
216 ViewBase::connectionLost();
217 iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );