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->setStyleSheet("background-color: transparent");
37 iDefaultRoomLabel->setHidden( true);
40 iStatusLabel = ToolBox::createLabel(tr( "is %1" ).arg(statusToText(aStatus) ), importantTextFont);
41 iStatusLabel->setAlignment(Qt::AlignHCenter);
42 iStatusLabel->setStyleSheet("background-color: transparent");
43 iStatusLabel->setHidden( true);
47 = ToolBox::createLabel(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ), importantTextFont);
48 iUntilTextLabel->setAlignment(Qt::AlignHCenter);
49 iUntilTextLabel->setStyleSheet("background-color: transparent");
50 iUntilTextLabel->setHidden( true);
52 // No connection to server note
54 << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";
55 QFrame* connectionLabelFrame = new QFrame( this );
56 iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );
57 iConnectionLabel->setFont(importantTextFont);
58 iConnectionLabel->setAlignment(Qt::AlignHCenter);
59 iConnectionLabel->setWordWrap( true);
60 iConnectionLabel->setStyleSheet("background-color: transparent; color: red; text-decoration:blink; max-width: 250px");
61 connectionLabelFrame->setFixedSize(iConnectionLabel->sizeHint() );
62 if (connectedOnce && !connectionError)
63 iConnectionLabel->setHidden( true);
65 QVBoxLayout *topLayout = new QVBoxLayout;
66 topLayout->addStretch();
67 topLayout->addWidget(iTimeDisplay);
68 topLayout->addSpacing( 28);
69 topLayout->addWidget(iDefaultRoomLabel);
70 topLayout->addWidget(iStatusLabel);
71 topLayout->addWidget(iUntilTextLabel);
72 topLayout->addSpacing( 28);
73 topLayout->addWidget(connectionLabelFrame);
74 topLayout->addStretch();
76 QHBoxLayout *mainLayout = new QHBoxLayout;
77 mainLayout->addLayout(topLayout);
78 mainLayout->addStretch();
79 //mainLayout->setMargin( 65 );
80 mainLayout->setContentsMargins( 65, 65, 65, 0);
81 setLayout(mainLayout);
83 statusChanged(aStatus, aUntil);
85 setFocusPolicy(Qt::StrongFocus);
86 setEnabled( true); // enable mouse & key events
89 RoomStatusIndicatorWidget::~RoomStatusIndicatorWidget()
95 QString RoomStatusIndicatorWidget::statusToText(const Room::Status aStatus)
97 return (aStatus == Room::BusyStatus ) ? tr("busy") : tr("free");
100 QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
104 aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";
105 QPixmap pixmap(image);
107 // The image needs to be moved in normal mode so the traffic light not partly outside the screen
108 const int xoffset( 60);
109 const int yoffset( 19);
110 int cropwidth(pixmap.width() - xoffset);
111 int cropheight(pixmap.height() - yoffset);
114 if (windowState() == Qt::WindowFullScreen)
116 // Use the full image in full screen mode
117 brush.setTexture(pixmap);
121 // Take part of the image so the traffic lights are moved xoffset poxels to left
122 // and yoffset pixels to up
123 brush.setTexture(pixmap.copy(xoffset, yoffset, cropwidth, cropheight) );
127 palette.setBrush(QPalette::Window, brush);
131 void RoomStatusIndicatorWidget::setCurrentTime(QTime aCurrentTime)
133 iTimeDisplay->setTime(aCurrentTime);
136 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
138 iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
139 if (aUntil == RoomStatusIndicatorWidget::endOfTheDay)
141 iUntilTextLabel->setText(tr("whole day.") );
145 iUntilTextLabel->setText(tr( "until %1" ).arg(aUntil.toString(iTimeFormat) ) );
147 setPalette(createPalette(aStatus) );
150 void RoomStatusIndicatorWidget::currentRoomChanged(Room *aRoom)
152 iDefaultRoomLabel->setText(aRoom->name() );
155 bool RoomStatusIndicatorWidget::event(QEvent *event)
157 switch (event->type())
160 qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";
162 case QEvent::PaletteChange:
164 << "[RoomStatusIndicatorWidget::event] <Palette change event>";
170 return ViewBase::event(event);
173 void RoomStatusIndicatorWidget::connectionEstablished()
177 // Just got the required meetings for the first time
178 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";
179 iDefaultRoomLabel->setHidden( false);
180 iUntilTextLabel->setHidden( false);
181 iStatusLabel->setHidden( false);
185 qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";
187 ViewBase::connectionEstablished();
188 iConnectionLabel->setHidden( true);
191 void RoomStatusIndicatorWidget::connectionLost()
193 ViewBase::connectionLost();
194 iConnectionLabel->setHidden( false);