3 #include "mainwidget.hpp"
4 #include "settingsDialog.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 _traffic = new Traffic;
21 _regions = new RegionsTable;
22 _settings = new Settings;
24 QHBoxLayout *layout = new QHBoxLayout;
25 layout->addWidget (_light);
26 layout->addWidget (_label);
29 _light->setVisible (_settings->check (Settings::C_Light));
31 connect (_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ()));
33 // every 5 minutes (TODO, make option)
34 startTimer (5*60*1000);
40 MainWidget::~MainWidget ()
51 void MainWidget::paintEvent(QPaintEvent *event)
54 p.setBrush (QColor(0, 0, 0, 128));
56 p.drawRoundedRect (rect(), 10, 10);
59 QWidget::paintEvent (event);
63 void MainWidget::timerEvent (QTimerEvent *)
70 void MainWidget::trafficUpdated ()
72 ExtendedTrafficInfo info = _traffic->lookup_ext ("1");
77 _light->setColor (info.color ());
79 if (_settings->check (Settings::C_Rank)) {
80 data.append (QString::number (info.level ()));
81 data.append (info.level () > 1 ? tr (" points") : tr (" point"));
85 if (_settings->check (Settings::C_Time)) {
88 data.append (info.localtime ());
92 if (_settings->check (Settings::C_Hint)) {
94 data.append (info.hint ());
97 _label->setText (data);
100 _light->setColor (ExtendedTrafficInfo::Unknown);
104 void MainWidget::updateData ()
106 // Here we need to check for internet connection
111 void MainWidget::settingsDialog ()
113 SettingsDialog dlg (_settings);
118 _light->setVisible (_settings->check (Settings::C_Light));