Resolve issue with configuration button incorrectly placed.
[yandex-traffic] / mainwidget.cpp
1 #include <QtGui>
2
3 #include "mainwidget.hpp"
4
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     QHBoxLayout *layout = new QHBoxLayout;
21     layout->addWidget (_light);
22     layout->addWidget (_label);
23     setLayout (layout);
24
25     connect (&_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ()));
26
27     // every 5 minutes (TODO, make option)
28     startTimer (5*60*1000);
29
30     // perform update just after creation
31     _traffic.update ();
32 }
33
34
35
36 void MainWidget::paintEvent(QPaintEvent *event)
37 {
38     QPainter p(this);
39     p.setBrush(QColor(0, 0, 0, 128));
40     p.setPen(Qt::NoPen);
41     p.drawRoundedRect(rect(), 10, 10);
42     p.end();
43
44     QWidget::paintEvent(event);
45 }
46
47
48 void MainWidget::timerEvent (QTimerEvent *)
49 {
50     // Perform traffic information refresh
51     // TODO: only if internet connection is available
52     _traffic.update ();
53 }
54
55
56
57 void MainWidget::trafficUpdated ()
58 {
59     ExtendedTrafficInfo info = _traffic.lookup_ext ("1");
60
61     if (info.valid ()) {
62         _light->setColor (info.color ());
63         _label->setText (QString ("%1, %2\n%3")
64                          .arg (QString::number (info.level ()))
65                          .arg (info.localtime ())
66                          .arg (info.hint ()));
67     }
68     else
69         _light->setColor (ExtendedTrafficInfo::Unknown);
70 }