PedestrianLightWidget.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * Copyright (c) 2012 committers of YAKINDU and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. * Contributors:
  8. * m.muehlbrandt - initial API and implementation
  9. *
  10. */
  11. #include "PedestrianLightWidget.h"
  12. PedestrianLightWidget::PedestrianLightWidget(QWidget *parent) :
  13. QWidget(parent) {
  14. white = false;
  15. red = false;
  16. green = false;
  17. }
  18. void PedestrianLightWidget::setSignals(bool white, bool red, bool green) {
  19. this->white = white;
  20. this->red = red;
  21. this->green = green;
  22. }
  23. void PedestrianLightWidget::paintEvent(QPaintEvent *event) {
  24. QWidget::paintEvent(event);
  25. QPainter painter(this);
  26. painter.setBrush(Qt::darkGray);
  27. painter.drawRect(this->rect());
  28. QRect rect = this->rect().translated(0, 0);
  29. painter.setBrush(white ? Qt::white : Qt::black);
  30. int size = rect.width() / 5;
  31. painter.drawRect(rect.width() / 5 - size / 2, (rect.height() - size) / 2,
  32. size, size);
  33. painter.setBrush(red ? Qt::red : Qt::black);
  34. painter.drawEllipse(QPoint(rect.width() / 2, rect.height() / 2),
  35. rect.width() / 8, rect.width() / 8);
  36. painter.setBrush(green ? Qt::green : Qt::black);
  37. painter.drawEllipse(QPoint(rect.width() * 4 / 5, rect.height() / 2),
  38. rect.width() / 8, rect.width() / 8);
  39. }
  40. PedestrianLightWidget::~PedestrianLightWidget() {
  41. }