Settings dialog started. It is empty so far.
[yandex-traffic] / mainwidget.cpp
1 #include <QtGui>
2
3 #include "mainwidget.hpp"
4 #include "settingsDialog.hpp"
5
6
7 // --------------------------------------------------
8 // MainWidget
9 // --------------------------------------------------
10 MainWidget::MainWidget ()
11     : QWidget ()
12 {
13     setMinimumSize (300, 80);
14 #ifdef Q_WS_MAEMO_5
15     setAttribute(Qt::WA_TranslucentBackground);
16 #endif
17     _light = new TrafficLight (this);
18     _label = new QLabel (this);
19
20     _traffic = new Traffic;
21     _regions = new RegionsTable;
22     _settings = new Settings;
23
24     QHBoxLayout *layout = new QHBoxLayout;
25     layout->addWidget (_light);
26     layout->addWidget (_label);
27     setLayout (layout);
28
29     connect (_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ()));
30
31     // every 5 minutes (TODO, make option)
32     startTimer (5*60*1000);
33
34     updateData ();
35 }
36
37
38 MainWidget::~MainWidget ()
39 {
40     delete _traffic;
41     delete _regions;
42     delete _settings;
43
44     delete _light;
45     delete _label;
46 }
47
48
49 void MainWidget::paintEvent(QPaintEvent *event)
50 {
51     QPainter p(this);
52     p.setBrush (QColor(0, 0, 0, 128));
53     p.setPen (Qt::NoPen);
54     p.drawRoundedRect (rect(), 10, 10);
55     p.end ();
56
57     QWidget::paintEvent (event);
58 }
59
60
61 void MainWidget::timerEvent (QTimerEvent *)
62 {
63     updateData ();
64 }
65
66
67
68 void MainWidget::trafficUpdated ()
69 {
70     ExtendedTrafficInfo info = _traffic->lookup_ext ("1");
71
72     if (info.valid ()) {
73         _light->setColor (info.color ());
74         _label->setText (QString ("%1, %2\n%3")
75                          .arg (QString::number (info.level ()))
76                          .arg (info.localtime ())
77                          .arg (info.hint ()));
78     }
79     else
80         _light->setColor (ExtendedTrafficInfo::Unknown);
81 }
82
83
84 void MainWidget::updateData ()
85 {
86     // Here we need to check for internet connection
87     _traffic->update ();
88 }
89
90
91 void MainWidget::settingsDialog ()
92 {
93     SettingsDialog dlg (this, _settings);
94
95     dlg.exec ();
96 }