#include <QtGui>
#include "mainwidget.hpp"
-
+#include "settingsDialog.hpp"
// --------------------------------------------------
_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 ());
else
_light->setColor (ExtendedTrafficInfo::Unknown);
}
+
+
+void MainWidget::updateData ()
+{
+ // Here we need to check for internet connection
+ _traffic->update ();
+}
+
+
+void MainWidget::settingsDialog ()
+{
+ SettingsDialog dlg (this, _settings);
+
+ dlg.exec ();
+}