[Simulator] Improve middle mouse button handling over radio navigation key areas: clicks were ignored, now either activates the current key under mouse, if any, or triggers default middle-mouse action (enter/menu/rotary press). (closes #4585)

This commit is contained in:
Max Paperno
2017-03-11 20:11:45 -05:00
parent 2144bb77e3
commit f103c8851f
@@ -39,7 +39,7 @@ class Area : public QObject
action(action) action(action)
{ {
if (action) if (action)
connect(action, &RadioUiAction::triggered, this, &Area::onActionTriggered); connect(action, &RadioUiAction::toggled, this, &Area::onActionToggled);
} }
bool contains(int x, int y) bool contains(int x, int y)
@@ -47,7 +47,7 @@ class Area : public QObject
return polygon.containsPoint(QPoint(x, y), Qt::OddEvenFill); return polygon.containsPoint(QPoint(x, y), Qt::OddEvenFill);
} }
void onActionTriggered(int, bool active) void onActionToggled(int, bool active)
{ {
if (active) if (active)
emit imageChanged(imgFile); emit imageChanged(imgFile);
@@ -108,20 +108,24 @@ class ButtonsWidget : public QWidget
void onMouseButtonEvent(bool press, QMouseEvent * event) void onMouseButtonEvent(bool press, QMouseEvent * event)
{ {
bool anyTriggered = false; if (!(event->button() & (Qt::LeftButton | Qt::MidButton))) {
int x = event->x(); event->ignore();
int y = event->y(); return;
}
foreach(Area * area, areas) { foreach(Area * area, areas) {
if (event->button() == Qt::LeftButton && area->contains(x, y)) { if (!area->action)
if (area->action) continue;
area->action->trigger(press); if (area->contains(event->x(), event->y())) {
anyTriggered = true; area->action->trigger(press);
break; event->accept();
return;
}
else if (area->action->isActive()) {
area->action->trigger(false);
} }
} }
if (!anyTriggered) event->ignore();
setBitmap("");
} }
virtual void mousePressEvent(QMouseEvent * event) virtual void mousePressEvent(QMouseEvent * event)
@@ -132,10 +136,6 @@ class ButtonsWidget : public QWidget
{ {
onMouseButtonEvent(false, event); onMouseButtonEvent(false, event);
} }
virtual void mouseLeaveEvent(QMouseEvent * event)
{
onMouseButtonEvent(false, event);
}
void paintEvent(QPaintEvent *) void paintEvent(QPaintEvent *)
{ {