Skip to content

Commit

Permalink
[Simulator] Improve middle mouse button handling over radio navigatio…
Browse files Browse the repository at this point in the history
…n 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)
  • Loading branch information
mpaperno committed Mar 12, 2017
1 parent 2144bb7 commit f103c88
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions companion/src/simulation/widgets/buttonswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ class Area : public QObject
action(action)
{
if (action)
connect(action, &RadioUiAction::triggered, this, &Area::onActionTriggered);
connect(action, &RadioUiAction::toggled, this, &Area::onActionToggled);
}

bool contains(int x, int y)
{
return polygon.containsPoint(QPoint(x, y), Qt::OddEvenFill);
}

void onActionTriggered(int, bool active)
void onActionToggled(int, bool active)
{
if (active)
emit imageChanged(imgFile);
Expand Down Expand Up @@ -108,20 +108,24 @@ class ButtonsWidget : public QWidget

void onMouseButtonEvent(bool press, QMouseEvent * event)
{
bool anyTriggered = false;
int x = event->x();
int y = event->y();
if (!(event->button() & (Qt::LeftButton | Qt::MidButton))) {
event->ignore();
return;
}

foreach(Area * area, areas) {
if (event->button() == Qt::LeftButton && area->contains(x, y)) {
if (area->action)
area->action->trigger(press);
anyTriggered = true;
break;
if (!area->action)
continue;
if (area->contains(event->x(), event->y())) {
area->action->trigger(press);
event->accept();
return;
}
else if (area->action->isActive()) {
area->action->trigger(false);
}
}
if (!anyTriggered)
setBitmap("");
event->ignore();
}

virtual void mousePressEvent(QMouseEvent * event)
Expand All @@ -132,10 +136,6 @@ class ButtonsWidget : public QWidget
{
onMouseButtonEvent(false, event);
}
virtual void mouseLeaveEvent(QMouseEvent * event)
{
onMouseButtonEvent(false, event);
}

void paintEvent(QPaintEvent *)
{
Expand Down

0 comments on commit f103c88

Please sign in to comment.