3 #include "mainwidget.hpp"
7 // --------------------------------------------------
9 // --------------------------------------------------
10 MainWidget::MainWidget ()
14 setAttribute(Qt::WA_TranslucentBackground);
16 _light = new TrafficLight (this);
17 _label = new QLabel (this);
19 QHBoxLayout *layout = new QHBoxLayout;
20 layout->addWidget (_light);
21 layout->addWidget (_label);
24 connect (&_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ()));
26 // every 5 minutes (TODO, make option)
27 startTimer (5*60*1000);
29 // perform update just after creation
34 QSize MainWidget::sizeHint() const
36 return _label->sizeHint () + _light->sizeHint () + QSize (20, 0);
40 void MainWidget::paintEvent(QPaintEvent *event)
43 p.setBrush(QColor(0, 0, 0, 128));
45 p.drawRoundedRect(rect(), 10, 10);
48 QWidget::paintEvent(event);
52 void MainWidget::timerEvent (QTimerEvent *)
54 // Perform traffic information refresh
55 // TODO: only if internet connection is available
60 void MainWidget::trafficUpdated ()
62 ExtendedTrafficInfo info = _traffic.lookup_ext ("1");
65 _light->setColor (info.color ());
66 _label->setText (QString ("%1, %2\n%3")
67 .arg (QString::number (info.level ()))
68 .arg (info.localtime ())
72 _light->setColor (ExtendedTrafficInfo::Unknown);