#include <QtGui>
+#include "globals.hpp"
#include "mainwidget.hpp"
#include "settingsDialog.hpp"
#include "connection.hpp"
#include "devstate.hpp"
#include "settings.hpp"
#include "log.hpp"
+#include "menudialog.hpp"
// --------------------------------------------------
setAttribute(Qt::WA_TranslucentBackground);
#endif
_light = new TrafficLight (this);
- _label = new QLabel (this);
+ _label = new QLabel (tr ("No data"), this);
_timer = new QTimer (this);
_label->setAlignment (Qt::AlignHCenter | Qt::AlignVCenter);
void MainWidget::trafficUpdated ()
{
- ExtendedTrafficInfo info = _traffic->lookup_ext (_settings->regionID ());
+ CityTrafficInfo info = _traffic->lookup_ext (_settings->regionID ());
if (info.valid ()) {
QString data;
bool first = true;
+ Log::instance ()->add ("trafficUpdated, info valid");
+ info.dump ();
_light->setColor (info.color ());
if (_settings->check (Settings::C_ShowRank)) {
if (_settings->check (Settings::C_ShowTime)) {
if (!first)
data.append (", ");
- data.append (info.localtime ());
+ data.append (info.ts ().toString ("h:mm"));
first = false;
}
_label->setText (data);
}
else {
- _light->setColor (ExtendedTrafficInfo::Unknown);
+ Log::instance ()->add ("trafficUpdated, but info not valid");
+ _light->setColor (CityTrafficInfo::Unknown);
_label->setText (tr ("No data"));
}
}
}
-void MainWidget::mousePressEvent (QMouseEvent *event)
+bool MainWidget::event (QEvent *event)
{
- QMenu menu;
- QAction *settingsAction, *updateAction, *todo;
+ if (event->type () != QEvent::WindowActivate)
+ return QWidget::event (event);
- Log::instance ()->add (QString ("mousePressEvent at %1,%2").arg (event->pos ().x ()).arg (event->pos ().y ()));
+ MenuDialog menu (tr ("Yandex.Traffic"));
- settingsAction = menu.addAction (tr ("Settings"));
- updateAction = menu.addAction (tr ("Update"));
+ menu.addEntry (tr ("Settings")).addEntry (tr ("Update"));
- todo = menu.exec (event->pos ());
- if (!todo)
- return;
+ switch (menu.run ()) {
+ case 0:
+ settingsDialog ();
+ break;
+ case 1:
+ _traffic->update ();
+ break;
+ }
- if (todo == settingsAction)
- settingsDialog ();
- if (todo == updateAction)
- _traffic->update ();
+ return QWidget::event (event);
}