#include "devstate.hpp"
#include "settings.hpp"
#include "log.hpp"
+#include "menudialog.hpp"
// --------------------------------------------------
}
-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);
}
void updateData ();
protected:
+ bool event (QEvent *event);
void paintEvent (QPaintEvent *event);
- void mousePressEvent (QMouseEvent *event);
void updateSize ();
void applySettings ();
--- /dev/null
+#include <QtGui>
+
+#include "menudialog.hpp"
+
+
+// --------------------------------------------------
+// MenuDialog
+// --------------------------------------------------
+MenuDialog::MenuDialog (const QString &title)
+ : QDialog ()
+{
+ setWindowTitle (title);
+ _layout = new QVBoxLayout (this);
+}
+
+
+MenuDialog& MenuDialog::addEntry (const QString &text)
+{
+ QPushButton* btn = new QPushButton (text, this);
+
+ connect (btn, SIGNAL (clicked ()), SLOT (buttonClicked ()));
+ _layout->addWidget (btn);
+ _buttons.append (btn);
+
+ return *this;
+}
+
+
+void MenuDialog::buttonClicked ()
+{
+ QPushButton *btn = static_cast<QPushButton*> (sender ());
+
+ if (!btn)
+ return;
+
+ index = _buttons.indexOf (btn);
+
+ accept ();
+}
+
+
+int MenuDialog::run ()
+{
+ index = -1;
+
+ if (exec () == QDialog::Accepted)
+ return index;
+ else
+ return -1;
+}
+
+
--- /dev/null
+#ifndef __MENUDIALOG_H__
+#define __MENUDIALOG_H__
+
+#include <QtGui>
+
+
+class MenuDialog : public QDialog
+{
+ Q_OBJECT
+private:
+ QList<QPushButton*> _buttons;
+ QBoxLayout* _layout;
+ int index;
+
+protected slots:
+ void buttonClicked ();
+
+public:
+ MenuDialog (const QString &title);
+ MenuDialog& addEntry (const QString &text);
+ int run ();
+};
+
+#endif // __MENUDIALOG_H__
-HEADERS += $$PWD/mainwidget.hpp $$PWD/light.hpp $$PWD/settingsDialog.hpp
-SOURCES += $$PWD/mainwidget.cpp $$PWD/light.cpp $$PWD/settingsDialog.cpp
+HEADERS += $$PWD/mainwidget.hpp $$PWD/light.hpp $$PWD/settingsDialog.hpp $$PWD/menudialog.hpp
+SOURCES += $$PWD/mainwidget.cpp $$PWD/light.cpp $$PWD/settingsDialog.cpp $$PWD/menudialog.cpp
!maemo5 {
HEADERS += $$PWD/QtMaemo5Adapters.hpp
<numerusform>%n баллов</numerusform>
</translation>
</message>
+ <message>
+ <source>Yandex.Traffic</source>
+ <translation>Яндекс.Пробки</translation>
+ </message>
</context>
<context>
<name>Settings</name>