Gui: implement SoMouseWheelEvent

and sythesize it instead of fake buttons 4 and 5
This commit is contained in:
DeepSOIC
2020-08-09 23:38:39 +03:00
committed by wwmayer
parent 666682d4e7
commit 68848ea9f8
6 changed files with 106 additions and 9 deletions

View File

@@ -1095,6 +1095,7 @@ SET(Inventor_CPP_SRCS
SoAxisCrossKit.cpp
SoTextLabel.cpp
SoTouchEvents.cpp
SoMouseWheelEvent.cpp
SoFCCSysDragger.cpp
)
SET(Inventor_SRCS
@@ -1121,6 +1122,7 @@ SET(Inventor_SRCS
SoAxisCrossKit.h
SoTextLabel.h
SoTouchEvents.h
SoMouseWheelEvent.h
SoFCCSysDragger.h
)
SOURCE_GROUP("View3D\\Inventor" FILES ${Inventor_SRCS})

View File

@@ -37,11 +37,14 @@
QuarterWidget.
*/
#include "PreCompiled.h"
#ifdef _MSC_VER
#pragma warning(disable : 4267)
#endif
#include <Quarter/devices/Mouse.h>
#include <Gui/SoMouseWheelEvent.h>
#include <QtCore/QEvent>
#include <QtCore/QSize>
@@ -67,11 +70,13 @@ public:
this->publ = publ;
this->location2 = new SoLocation2Event;
this->mousebutton = new SoMouseButtonEvent;
this->wheel = new SoMouseWheelEvent;
}
~MouseP() {
delete this->location2;
delete this->mousebutton;
delete this->wheel;
}
const SoEvent * mouseMoveEvent(QMouseEvent * event);
@@ -82,6 +87,7 @@ public:
class SoLocation2Event * location2;
class SoMouseButtonEvent * mousebutton;
class SoMouseWheelEvent * wheel;
SbVec2s windowsize;
Mouse * publ;
};
@@ -161,26 +167,24 @@ MouseP::mouseMoveEvent(QMouseEvent * event)
const SoEvent *
MouseP::mouseWheelEvent(QWheelEvent * event)
{
PUBLIC(this)->setModifiers(this->mousebutton, event);
PUBLIC(this)->setModifiers(this->wheel, event);
SbVec2s pos(event->pos().x(), PUBLIC(this)->windowsize[1] - event->pos().y() - 1);
// the following corrects for high-dpi displays (e.g. mac retina)
#if QT_VERSION >= 0x050000
pos *= publ->quarter->devicePixelRatio();
#endif
this->location2->setPosition(pos);
this->mousebutton->setPosition(pos);
this->location2->setPosition(pos); //I don't know why location2 is assigned here, I assumend it important --DeepSOIC
this->wheel->setPosition(pos);
// QWheelEvent::delta() returns the distance that the wheel is
// rotated, in eights of a degree. A positive value indicates that
// the wheel was rotated forwards away from the user; a negative
// value indicates that the wheel was rotated backwards toward the
// user.
(event->delta() > 0) ?
this->mousebutton->setButton(SoMouseButtonEvent::BUTTON4) :
this->mousebutton->setButton(SoMouseButtonEvent::BUTTON5);
// user. A typical wheel click is 120, but values coming from touchpad
// can be a lot lower
this->wheel->setDelta(event->delta());
this->mousebutton->setState(SoButtonEvent::DOWN);
return this->mousebutton;
return this->wheel;
}
const SoEvent *

View File

@@ -56,6 +56,7 @@
#include "Inventor/MarkerBitmaps.h"
#include "Inventor/SmSwitchboard.h"
#include "SoFCCSysDragger.h"
#include "SoMouseWheelEvent.h"
#include "propertyeditor/PropertyItem.h"
#include "NavigationStyle.h"
@@ -125,6 +126,7 @@ void Gui::SoFCDB::init()
SoFCSeparator ::initClass();
SoFCSelectionRoot ::initClass();
SoFCPathAnnotation ::initClass();
SoMouseWheelEvent ::initClass();
PropertyItem ::init();
PropertySeparatorItem ::init();

View File

@@ -0,0 +1,28 @@
/***************************************************************************
* Copyright (c) Victor Titov (DeepSOIC) *
* (vv.titov@gmail.com) 2020 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#include "SoMouseWheelEvent.h"
SO_EVENT_SOURCE(SoMouseWheelEvent);

View File

@@ -0,0 +1,56 @@
/***************************************************************************
* Copyright (c) Victor Titov (DeepSOIC) *
* (vv.titov@gmail.com) 2020 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef SOMOUSEWHEELEVENT_H_FC
#define SOMOUSEWHEELEVENT_H_FC
//#ifndef GuiExport
//#define GuiExport
//#endif
#include <Inventor/events/SoEvent.h>
/**
* @brief The SoMouseWheelEvent class is a temporary replacement for
* SoMouseWheelEvent from Coin, for until freecad stops using Coin version that
* doesn't have one (coin v 4.0.0a doesn't have SoMouseWheelEvent).
*/
class GuiExport SoMouseWheelEvent : public SoEvent {
SO_EVENT_HEADER();
public: //methods
static void initClass(){
SO_EVENT_INIT_CLASS(SoMouseWheelEvent, SoEvent);
}
SoMouseWheelEvent () : delta(0) {}
SoMouseWheelEvent (int delta) : delta(delta) {}
///returns wheel position change. One click is usually 120 units,
/// smaller values come from high-resolution devices like touchpads
int getDelta() const {return delta;}
void setDelta(int delta) {this->delta = delta;}
~SoMouseWheelEvent(){}
private: //data
int delta;
};
#endif

View File

@@ -41,6 +41,7 @@
#include "Application.h"
#include "Document.h"
#include "NavigationStyle.h"
#include "SoMouseWheelEvent.h"
#include "SoFCSelectionAction.h"
#include "SoFCOffscreenRenderer.h"
#include "SoFCVectorizeSVGAction.h"
@@ -1992,6 +1993,10 @@ void View3DInventorPy::eventCallback(void * ud, SoEventCallback * n)
dict.setItem("Button", Py::String(button));
}
if (e->isOfType(SoMouseWheelEvent::getClassTypeId())){
const SoMouseWheelEvent* mwe = static_cast<const SoMouseWheelEvent*>(e);
dict.setItem("Delta", Py::Long(mwe->getDelta()));
}
if (e->isOfType(SoSpaceballButtonEvent::getClassTypeId())) {
const SoSpaceballButtonEvent* sbe = static_cast<const SoSpaceballButtonEvent*>(e);
std::string button;