--- /dev/null
+#include <QtGui>
+#include "light.hpp"
+#include "traffic.hpp"
+
+
+// --------------------------------------------------
+// TrafficLight
+// --------------------------------------------------
+TrafficLight::TrafficLight (QWidget *parent)
+ : QWidget (parent)
+{
+ _color = ExtendedTrafficInfo::Green;
+}
+
+
+void TrafficLight::paintEvent (QPaintEvent *)
+{
+ QPainter painter (this);
+ QColor color;
+ int side = qMin (width (), height ());
+
+ switch (_color) {
+ case ExtendedTrafficInfo::Green:
+ color = Qt::green;
+ break;
+ case ExtendedTrafficInfo::Yellow:
+ color = Qt::yellow;
+ break;
+ case ExtendedTrafficInfo::Red:
+ color = Qt::red;
+ break;
+ }
+
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setPen (color);
+ painter.setBrush (color);
+ painter.drawEllipse ((width ()-side)/2, (height ()-side)/2, side, side);
+}
+
--- /dev/null
+#ifndef __LIGHT_H__
+#define __LIGHT_H__
+
+#include <QtGui>
+
+#include "traffic.hpp"
+
+class TrafficLight : public QWidget
+{
+ Q_OBJECT
+
+private:
+ ExtendedTrafficInfo::light_color _color;
+
+protected:
+ void paintEvent (QPaintEvent *event);
+
+public:
+ TrafficLight (QWidget *parent);
+
+ ExtendedTrafficInfo::light_color color () const
+ { return _color; };
+
+ void setColor (ExtendedTrafficInfo::light_color color)
+ {
+ _color = color;
+ update ();
+ }
+};
+
+#endif // __LIGHT_H__
--- /dev/null
+#include <QtGui>
+
+#include "mainwidget.hpp"
+
+
+
+// --------------------------------------------------
+// MainWidget
+// --------------------------------------------------
+MainWidget::MainWidget ()
+ : QWidget ()
+{
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_TranslucentBackground);
+#endif
+ _light = new TrafficLight (this);
+ _label = new QLabel (this);
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget (_light);
+ layout->addWidget (_label);
+ setLayout (layout);
+
+ _label->setText ("Bla-bla");
+}
+
+
+QSize MainWidget::sizeHint() const
+{
+ return QWidget::sizeHint () + QSize (20, 0);
+}
#include <QtGui>
-#include <settings.hpp>
-#include <regions.hpp>
+#include "settings.hpp"
+#include "regions.hpp"
+#include "light.hpp"
-class MainWidget : public QLabel
+class MainWidget : public QWidget
{
Q_OBJECT
private:
RegionsTable _regions;
Settings _settings;
-public:
- MainWidget ()
- : QLabel ()
- {
- const RegionInfo *ri;
-
- setAlignment(Qt::AlignCenter);
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_TranslucentBackground);
-#endif
- ri = _regions.lookup (_settings.regions ()[0]);
-
- setText (_settings.regions ().join (", ") + ", " + QString (ri ? ri->name () : ""));
- }
+ // Widgets
+ TrafficLight *_light;
+ QLabel *_label;
- QSize sizeHint() const
- {
- return QLabel::sizeHint() + QSize (20, 0);
- }
+public:
+ MainWidget ();
+ QSize sizeHint () const;
protected:
void paintEvent(QPaintEvent *event)
p.drawRoundedRect(rect(), 10, 10);
p.end();
- QLabel::paintEvent(event);
+ QWidget::paintEvent(event);
}
};
-HEADERS += $$PWD/mainwidget.hpp
-SOURCES +=
+HEADERS += $$PWD/mainwidget.hpp $$PWD/light.hpp
+SOURCES += $$PWD/mainwidget.cpp $$PWD/light.cpp
QT += network xml