1 #include "RoomStatusIndicatorWidget.h"
6 #include "DigitalTimeDisplayWidget.h"
13 QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0);
15 RoomStatusIndicatorWidget::RoomStatusIndicatorWidget(Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent) :
16 ViewBase(ViewBase::ObservedView, aParent), iTimeFormat(aTimeFormat)
18 QFont importantTextFont;
19 //importantTextFont.setBold( true );
20 importantTextFont.setPointSize( 20);
22 QFont regularTextFont;
23 //regularTextFont.setBold( true );
24 regularTextFont.setPointSize( 12);
26 // display for current time
27 // Note: the time display receives current time info from Engine::clock()
28 iTimeDisplay = new DigitalTimeDisplayWidget( QTime::currentTime(), iTimeFormat, this );
29 iTimeDisplay->setFrameVisible( false);
30 iTimeDisplay->setSize( 250, 120);
34 = ToolBox::createLabel(aDefaultRoom->name(), importantTextFont);
35 iDefaultRoomLabel->setAlignment(Qt::AlignHCenter);
36 iDefaultRoomLabel->setHidden( true);
39 iStatusLabel = ToolBox::createLabel(tr( "is %1" ).arg(statusToText(aStatus) ), importantTextFont);
40 iStatusLabel->setAlignment(Qt::AlignHCenter);
41 iStatusLabel->setStyleSheet("background-color: transparent");
42 iStatusLabel->setHidden( true);
46 = ToolBox::createLabel(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ), importantTextFont);
47 iUntilTextLabel->setAlignment(Qt::AlignHCenter);
48 iUntilTextLabel->setStyleSheet("background-color: transparent");
49 iUntilTextLabel->setHidden( true);
51 // No connection to server note
53 << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";
54 QFrame* connectionLabelFrame = new QFrame( this );
55 iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );
56 iConnectionLabel->setFont(importantTextFont);
57 iConnectionLabel->setAlignment(Qt::AlignHCenter);
58 iConnectionLabel->setWordWrap( true);
59 iConnectionLabel->setStyleSheet("background-color: transparent; color: red; text-decoration:blink; max-width: 250px");
60 connectionLabelFrame->setFixedSize(iConnectionLabel->sizeHint() );
61 if (connectedOnce && !connectionError)
62 iConnectionLabel->setHidden( true);
64 QVBoxLayout *topLayout = new QVBoxLayout;
65 topLayout->addStretch();
66 topLayout->addWidget(iTimeDisplay);
67 topLayout->addSpacing( 28);
68 topLayout->addWidget(iDefaultRoomLabel);
69 topLayout->addWidget(iStatusLabel);
70 topLayout->addWidget(iUntilTextLabel);
71 topLayout->addSpacing( 28);
72 topLayout->addWidget(connectionLabelFrame);
73 topLayout->addStretch();
75 QHBoxLayout *mainLayout = new QHBoxLayout;
76 mainLayout->addLayout(topLayout);
77 mainLayout->addStretch();
78 //mainLayout->setMargin( 65 );
79 mainLayout->setContentsMargins( 65, 65, 65, 0);
80 setLayout(mainLayout);
82 statusChanged(aStatus, aUntil);
85 palette.setColor( QPalette::Window, Qt::white );
86 palette.setColor( QPalette::WindowText, Qt::darkGray );
87 setPalette( palette );
89 setAutoFillBackground( true );
90 setFocusPolicy(Qt::StrongFocus);
91 setEnabled( true); // enable mouse & key events
94 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
100 QString RoomStatusIndicatorWidget::statusToText(const Room::Status aStatus)
102 return (aStatus == Room::BusyStatus ) ? tr("busy") : tr("free");
105 QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
109 aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
110 QPixmap pixmap(image);
112 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
113 const int xoffset( 60);
114 const int yoffset( 19);
115 int cropwidth(pixmap.width() - xoffset);
116 int cropheight(pixmap.height() - yoffset);
119 if (windowState() == Qt::WindowFullScreen)
121 // Use the full image in full screen mode
122 brush.setTexture(pixmap);
126 // Take part of the image so the traffic lights are moved xoffset poxels to left
127 // and yoffset pixels to up
128 brush.setTexture(pixmap.copy(xoffset, yoffset, cropwidth, cropheight) );
132 palette.setColor( QPalette::Window, Qt::white );
133 palette.setColor( QPalette::WindowText, Qt::darkGray );
134 palette.setBrush( QPalette::Window, brush );
138 void RoomStatusIndicatorWidget::setCurrentTime(QTime aCurrentTime)
140 iTimeDisplay->setTime(aCurrentTime);
143 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
145 iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
146 if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
148 iUntilTextLabel->setText(tr("whole day.") );
152 iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
154 setPalette(createPalette(aStatus) );
157 void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
159 iDefaultRoomLabel->setText(aRoom->name() );
162 bool RoomStatusIndicatorWidget::event(QEvent *event)
164 switch (event->type())
167 qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
169 case QEvent::PaletteChange:
171 << "[RoomStatusIndicatorWidget::event] <Palette change event>";
177 return ViewBase::event(event);
180 void RoomStatusIndicatorWidget::connectionEstablished()
184 // Just got the required meetings for the first time
185 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";
186 iDefaultRoomLabel->setHidden( false);
187 iUntilTextLabel->setHidden( false);
188 iStatusLabel->setHidden( false);
192 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";
194 ViewBase::connectionEstablished();
195 iConnectionLabel->setHidden( true);
198 void RoomStatusIndicatorWidget::connectionLost()
200 ViewBase::connectionLost();
201 iConnectionLabel->setHidden( false);