X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=mainwidget.cpp;h=6b7f6be0faaabfe90d65261148a47598eead09f2;hb=7557e186ad03c14c1c7c8960b11f563cce4f0c88;hp=160a8c0644f11a2247a8c879481ff6fb08dccb95;hpb=a678a18b989a0e722ed4333eeff07b2c2494a3e9;p=yandex-traffic diff --git a/mainwidget.cpp b/mainwidget.cpp index 160a8c0..6b7f6be 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -1,7 +1,7 @@ #include #include "mainwidget.hpp" - +#include "settingsDialog.hpp" // -------------------------------------------------- @@ -17,46 +17,57 @@ MainWidget::MainWidget () _light = new TrafficLight (this); _label = new QLabel (this); + _traffic = new Traffic; + _regions = new RegionsTable; + _settings = new Settings; + QHBoxLayout *layout = new QHBoxLayout; layout->addWidget (_light); layout->addWidget (_label); setLayout (layout); - connect (&_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ())); + connect (_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ())); // every 5 minutes (TODO, make option) startTimer (5*60*1000); - // perform update just after creation - _traffic.update (); + updateData (); } +MainWidget::~MainWidget () +{ + delete _traffic; + delete _regions; + delete _settings; + + delete _light; + delete _label; +} + void MainWidget::paintEvent(QPaintEvent *event) { QPainter p(this); - p.setBrush(QColor(0, 0, 0, 128)); - p.setPen(Qt::NoPen); - p.drawRoundedRect(rect(), 10, 10); - p.end(); + p.setBrush (QColor(0, 0, 0, 128)); + p.setPen (Qt::NoPen); + p.drawRoundedRect (rect(), 10, 10); + p.end (); - QWidget::paintEvent(event); + QWidget::paintEvent (event); } void MainWidget::timerEvent (QTimerEvent *) { - // Perform traffic information refresh - // TODO: only if internet connection is available - _traffic.update (); + updateData (); } void MainWidget::trafficUpdated () { - ExtendedTrafficInfo info = _traffic.lookup_ext ("1"); + ExtendedTrafficInfo info = _traffic->lookup_ext ("1"); if (info.valid ()) { _light->setColor (info.color ()); @@ -68,3 +79,18 @@ void MainWidget::trafficUpdated () else _light->setColor (ExtendedTrafficInfo::Unknown); } + + +void MainWidget::updateData () +{ + // Here we need to check for internet connection + _traffic->update (); +} + + +void MainWidget::settingsDialog () +{ + SettingsDialog dlg (_settings); + + dlg.exec (); +}