3 #include "mainwidget.hpp"
7 // --------------------------------------------------
9 // --------------------------------------------------
10 MainWidget::MainWidget ()
13 setMinimumSize (300, 80);
15 setAttribute(Qt::WA_TranslucentBackground);
17 _light = new TrafficLight (this);
18 _label = new QLabel (this);
20 QHBoxLayout *layout = new QHBoxLayout;
21 layout->addWidget (_light);
22 layout->addWidget (_label);
25 connect (&_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ()));
27 // every 5 minutes (TODO, make option)
28 startTimer (5*60*1000);
30 // perform update just after creation
36 void MainWidget::paintEvent(QPaintEvent *event)
39 p.setBrush(QColor(0, 0, 0, 128));
41 p.drawRoundedRect(rect(), 10, 10);
44 QWidget::paintEvent(event);
48 void MainWidget::timerEvent (QTimerEvent *)
50 // Perform traffic information refresh
51 // TODO: only if internet connection is available
57 void MainWidget::trafficUpdated ()
59 ExtendedTrafficInfo info = _traffic.lookup_ext ("1");
62 _light->setColor (info.color ());
63 _label->setText (QString ("%1, %2\n%3")
64 .arg (QString::number (info.level ()))
65 .arg (info.localtime ())
69 _light->setColor (ExtendedTrafficInfo::Unknown);