From 997f958e7ae240a5ca5835dc7db1a7009e53ea08 Mon Sep 17 00:00:00 2001 From: Max Lapan Date: Thu, 18 Mar 2010 13:56:47 +0300 Subject: [PATCH] Use dialog instead of popup menu. --- mainwidget.cpp | 28 ++++++++++++----------- mainwidget.hpp | 2 +- menudialog.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++ menudialog.hpp | 24 ++++++++++++++++++++ yandex-traffic-gui.pri | 4 ++-- yandex-traffic-widget_ru.qm | Bin 3284 -> 3363 bytes yandex-traffic-widget_ru.ts | 4 ++++ 7 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 menudialog.cpp create mode 100644 menudialog.hpp diff --git a/mainwidget.cpp b/mainwidget.cpp index 7e9a455..33d3303 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -6,6 +6,7 @@ #include "devstate.hpp" #include "settings.hpp" #include "log.hpp" +#include "menudialog.hpp" // -------------------------------------------------- @@ -177,24 +178,25 @@ void MainWidget::applySettings () } -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); } diff --git a/mainwidget.hpp b/mainwidget.hpp index eee235f..20e86be 100644 --- a/mainwidget.hpp +++ b/mainwidget.hpp @@ -33,8 +33,8 @@ public slots: void updateData (); protected: + bool event (QEvent *event); void paintEvent (QPaintEvent *event); - void mousePressEvent (QMouseEvent *event); void updateSize (); void applySettings (); diff --git a/menudialog.cpp b/menudialog.cpp new file mode 100644 index 0000000..a7d68c9 --- /dev/null +++ b/menudialog.cpp @@ -0,0 +1,52 @@ +#include + +#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 (sender ()); + + if (!btn) + return; + + index = _buttons.indexOf (btn); + + accept (); +} + + +int MenuDialog::run () +{ + index = -1; + + if (exec () == QDialog::Accepted) + return index; + else + return -1; +} + + diff --git a/menudialog.hpp b/menudialog.hpp new file mode 100644 index 0000000..be9878d --- /dev/null +++ b/menudialog.hpp @@ -0,0 +1,24 @@ +#ifndef __MENUDIALOG_H__ +#define __MENUDIALOG_H__ + +#include + + +class MenuDialog : public QDialog +{ + Q_OBJECT +private: + QList _buttons; + QBoxLayout* _layout; + int index; + +protected slots: + void buttonClicked (); + +public: + MenuDialog (const QString &title); + MenuDialog& addEntry (const QString &text); + int run (); +}; + +#endif // __MENUDIALOG_H__ diff --git a/yandex-traffic-gui.pri b/yandex-traffic-gui.pri index 72bf043..2d919c2 100644 --- a/yandex-traffic-gui.pri +++ b/yandex-traffic-gui.pri @@ -1,5 +1,5 @@ -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 diff --git a/yandex-traffic-widget_ru.qm b/yandex-traffic-widget_ru.qm index 0e10b4145fb6edf0f0c8b8fd0744224eac0e04cb..e3e7c865ae7eba162eb7e1e027fc416f68c4aec8 100644 GIT binary patch delta 410 zcmca2xmap~h-3x>gHJ631Dgf|%ZCsK28M+Utn$Yg7+7p3>dM!5GO&RJId(9xcX%@} zaB48HZ!iVYkqpMg{}>pU9x|AKXl5G*b1*%f!HfG80|RR@L(tzZK*R1cgq%49G;9jP za-Axm_;Y4=usUAmBru)9d{)L7XwEEFu@xT~7#KgXy3I-ls!wHI_f&*|p`Js5b;GK? zK#g{+`@dx}FmNqpJ+@*gP(vz&W}nLXGD8!nv5(E*y)e*WFW6pvC_F4Th7f@bP{Oa za_;HOml-S=7;Jf5#oU2DJj~-~a0953g=aToG0*`z5Sl%LUv1kRpv7JMMmeQG144kV z8_Uc19(17*q`u8^j9lC;j_4E=3 z2DW(|xkfEO{rfmi&DR6U*K%nu1v-$un=AU=S)e#0*U9Otfa(&sxr$B#9hks9o%u4* z;kG=kV(ttE49qn=eg-#yKHJN)o3R+^038U;F37L8?GDglXMUrcQlJ66Kv!~mY;Izl L$Fw<}We*1cP?KCK diff --git a/yandex-traffic-widget_ru.ts b/yandex-traffic-widget_ru.ts index 2faa161..62bdc8e 100644 --- a/yandex-traffic-widget_ru.ts +++ b/yandex-traffic-widget_ru.ts @@ -61,6 +61,10 @@ %n баллов + + Yandex.Traffic + Яндекс.Пробки + Settings -- 1.7.9.5