Gui: add method NavigationStyle::processClickEvent() to reduce code duplication in sub-classes

This commit is contained in:
wmayer
2021-11-05 14:37:18 +01:00
parent f664c02b92
commit ef598dd1e3
10 changed files with 51 additions and 210 deletions

View File

@@ -146,30 +146,8 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev)
else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
processed = true;
}
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
else if (press) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(ev->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
inherited::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
else {
processed = processClickEvent(event);
}
break;
case SoMouseButtonEvent::BUTTON2:

View File

@@ -158,30 +158,8 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev)
else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
processed = true;
}
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
else if (press) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(ev->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
inherited::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
else {
processed = processClickEvent(event);
}
break;
case SoMouseButtonEvent::BUTTON2:

View File

@@ -179,30 +179,8 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev)
processed = true;
this->lockrecenter = true;
}
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
else if (press) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(ev->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
inherited::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
else {
processed = processClickEvent(event);
}
break;
case SoMouseButtonEvent::BUTTON2:

View File

@@ -1670,6 +1670,39 @@ SbBool NavigationStyle::processKeyboardEvent(const SoKeyboardEvent * const event
return processed;
}
SbBool NavigationStyle::processClickEvent(const SoMouseButtonEvent * const event)
{
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
SbBool processed = false;
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
if (press) {
SbTime tmp = (event->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(event->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(event->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
NavigationStyle::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
return processed;
}
void NavigationStyle::setPopupMenuEnabled(const SbBool on)
{
this->menuenabled = on;

View File

@@ -153,6 +153,7 @@ public:
virtual SbBool processEvent(const SoEvent * const ev);
virtual SbBool processMotionEvent(const SoMotion3Event * const ev);
virtual SbBool processKeyboardEvent(const SoKeyboardEvent * const event);
virtual SbBool processClickEvent(const SoMouseButtonEvent * const event);
void setPopupMenuEnabled(const SbBool on);
SbBool isPopupMenuEnabled(void) const;
@@ -227,6 +228,7 @@ protected:
View3DInventorViewer* viewer;
ViewerMode currentmode;
SoMouseButtonEvent mouseDownConsumedEvent;
SbVec2f lastmouseposition;
SbVec2s globalPos;
SbVec2s localPos;
@@ -296,9 +298,6 @@ public:
protected:
SbBool processSoEvent(const SoEvent * const ev);
private:
SoMouseButtonEvent mouseDownConsumedEvent;
};
class GuiExport CADNavigationStyle : public UserNavigationStyle {
@@ -316,7 +315,6 @@ protected:
private:
SbBool lockButton1;
SoMouseButtonEvent mouseDownConsumedEvent;
};
class GuiExport RevitNavigationStyle : public UserNavigationStyle {
@@ -334,7 +332,6 @@ protected:
private:
SbBool lockButton1;
SoMouseButtonEvent mouseDownConsumedEvent;
};
class GuiExport BlenderNavigationStyle : public UserNavigationStyle {
@@ -352,7 +349,6 @@ protected:
private:
SbBool lockButton1;
SoMouseButtonEvent mouseDownConsumedEvent;
};
class GuiExport MayaGestureNavigationStyle : public UserNavigationStyle {
@@ -391,9 +387,6 @@ public:
protected:
SbBool processSoEvent(const SoEvent * const ev);
private:
SoMouseButtonEvent mouseDownConsumedEvent;
};
class GuiExport OpenCascadeNavigationStyle : public UserNavigationStyle {
@@ -408,9 +401,6 @@ public:
protected:
SbBool processSoEvent(const SoEvent * const ev);
private:
SoMouseButtonEvent mouseDownConsumedEvent;
};
class GuiExport OpenSCADNavigationStyle : public UserNavigationStyle {
@@ -425,9 +415,6 @@ public:
protected:
SbBool processSoEvent(const SoEvent * const ev);
private:
SoMouseButtonEvent mouseDownConsumedEvent;
};
class GuiExport TinkerCADNavigationStyle : public UserNavigationStyle {
@@ -442,9 +429,6 @@ public:
protected:
SbBool processSoEvent(const SoEvent * const ev);
private:
SoMouseButtonEvent mouseDownConsumedEvent;
};
} // namespace Gui

View File

@@ -146,30 +146,8 @@ SbBool OpenCascadeNavigationStyle::processSoEvent(const SoEvent * const ev)
else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
processed = true;
}
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
else if (press) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(ev->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
inherited::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
else {
processed = processClickEvent(event);
}
break;
case SoMouseButtonEvent::BUTTON2:

View File

@@ -146,30 +146,8 @@ SbBool OpenSCADNavigationStyle::processSoEvent(const SoEvent * const ev)
else if (viewer->isEditing() && (curmode == NavigationStyle::SPINNING)) {
processed = true;
}
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
else if (press) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(ev->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
inherited::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
else {
processed = processClickEvent(event);
}
break;
case SoMouseButtonEvent::BUTTON2:

View File

@@ -146,30 +146,8 @@ SbBool RevitNavigationStyle::processSoEvent(const SoEvent * const ev)
else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
processed = true;
}
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
else if (press) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(ev->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
inherited::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
else {
processed = processClickEvent(event);
}
break;
case SoMouseButtonEvent::BUTTON2:

View File

@@ -138,30 +138,8 @@ SbBool TinkerCADNavigationStyle::processSoEvent(const SoEvent * const ev)
else if (viewer->isEditing() && (curmode == NavigationStyle::SPINNING)) {
processed = true;
}
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
else if (press) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(ev->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
inherited::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
else {
processed = processClickEvent(event);
}
break;
case SoMouseButtonEvent::BUTTON2:

View File

@@ -146,30 +146,8 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev)
else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
processed = true;
}
// issue #0002433: avoid to swallow the UP event if down the
// scene graph somewhere a dialog gets opened
else if (press) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
// a double-click?
if (tmp.getValue() < dci) {
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
processed = true;
}
else {
mouseDownConsumedEvent.setTime(ev->getTime());
// 'ANY' is used to mark that we don't know yet if it will
// be a double-click event.
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
}
else if (!press) {
if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) {
// now handle the postponed event
inherited::processSoEvent(&mouseDownConsumedEvent);
mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY);
}
else {
processed = processClickEvent(event);
}
break;
case SoMouseButtonEvent::BUTTON2: