|
2 | 2 |
|
3 | 3 | #include "OcctQtTools.h" |
4 | 4 |
|
| 5 | +#include <Aspect_ScrollDelta.hxx> |
5 | 6 | #include <OpenGl_Caps.hxx> |
6 | 7 | #include <OSD_Environment.hxx> |
7 | 8 | #include <Standard_Version.hxx> |
| 9 | +#include <V3d_View.hxx> |
8 | 10 |
|
9 | 11 | #include <QCoreApplication> |
10 | 12 | #include <QGuiApplication> |
@@ -71,12 +73,14 @@ void OcctQtTools::qtGlPlatformSetup() |
71 | 73 | aQsgLoop.Build(); |
72 | 74 | }*/ |
73 | 75 |
|
74 | | - // enable auto-scaling for high-density screens |
| 76 | + // enable auto-scaling for high-density screens and fractional scale factors |
| 77 | + // (this is default since Qt6) |
| 78 | +#if (QT_VERSION_MAJOR == 5) |
75 | 79 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
76 | | -#if (QT_VERSION_MAJOR == 5 && QT_VERSION_MINOR >= 14) |
77 | | - // this is default since Qt6 (for fractional scale factors) |
| 80 | +#if (QT_VERSION_MINOR >= 14) |
78 | 81 | QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); |
79 | 82 | #endif |
| 83 | +#endif |
80 | 84 | } |
81 | 85 |
|
82 | 86 | // ================================================================ |
@@ -136,6 +140,88 @@ void OcctQtTools::qtGlCapsFromSurfaceFormat(OpenGl_Caps& theCaps, const QSurface |
136 | 140 | #endif |
137 | 141 | } |
138 | 142 |
|
| 143 | +// ================================================================ |
| 144 | +// Function : qtHandleHoverEvent |
| 145 | +// ================================================================ |
| 146 | +bool OcctQtTools::qtHandleHoverEvent(Aspect_WindowInputListener& theListener, |
| 147 | + const Handle(V3d_View)& theView, |
| 148 | + const QHoverEvent* theEvent) |
| 149 | +{ |
| 150 | + const Graphic3d_Vec2d aPnt2d(theEvent->pos().x(), theEvent->pos().y()); |
| 151 | + const Graphic3d_Vec2i aPnt2i(theView->Window()->ConvertPointToBacking(aPnt2d) + Graphic3d_Vec2d(0.5)); |
| 152 | + const Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE; |
| 153 | + const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys(theEvent->modifiers()); |
| 154 | + return theListener.UpdateMousePosition(aPnt2i, aButtons, aFlags, false); |
| 155 | +} |
| 156 | + |
| 157 | +// ================================================================ |
| 158 | +// Function : qtHandleMouseEvent |
| 159 | +// ================================================================ |
| 160 | +bool OcctQtTools::qtHandleMouseEvent(Aspect_WindowInputListener& theListener, |
| 161 | + const Handle(V3d_View)& theView, |
| 162 | + const QMouseEvent* theEvent) |
| 163 | +{ |
| 164 | + const Graphic3d_Vec2d aPnt2d(theEvent->pos().x(), theEvent->pos().y()); |
| 165 | + const Graphic3d_Vec2i aPnt2i(theView->Window()->ConvertPointToBacking(aPnt2d) + Graphic3d_Vec2d(0.5)); |
| 166 | + const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys(theEvent->buttons()); |
| 167 | + const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys(theEvent->modifiers()); |
| 168 | + if (theEvent->type() == QEvent::MouseMove) |
| 169 | + return theListener.UpdateMousePosition(aPnt2i, aButtons, aFlags, false); |
| 170 | + |
| 171 | + return theListener.UpdateMouseButtons(aPnt2i, aButtons, aFlags, false); |
| 172 | +} |
| 173 | + |
| 174 | +// ================================================================ |
| 175 | +// Function : qtHandleWheelEvent |
| 176 | +// ================================================================ |
| 177 | +bool OcctQtTools::qtHandleWheelEvent(Aspect_WindowInputListener& theListener, |
| 178 | + const Handle(V3d_View)& theView, |
| 179 | + const QWheelEvent* theEvent) |
| 180 | +{ |
| 181 | +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) |
| 182 | + const Graphic3d_Vec2d aPnt2d(theEvent->position().x(), theEvent->position().y()); |
| 183 | +#else |
| 184 | + const Graphic3d_Vec2d aPnt2d(theEvent->pos().x(), theEvent->pos().y()); |
| 185 | +#endif |
| 186 | + const Graphic3d_Vec2i aPnt2i(theView->Window()->ConvertPointToBacking(aPnt2d) + Graphic3d_Vec2d(0.5)); |
| 187 | + return theListener.UpdateMouseScroll(Aspect_ScrollDelta(aPnt2i, double(theEvent->angleDelta().y()) / 120.0)); |
| 188 | +} |
| 189 | + |
| 190 | +// ================================================================ |
| 191 | +// Function : qtHandleTouchEvent |
| 192 | +// ================================================================ |
| 193 | +bool OcctQtTools::qtHandleTouchEvent(Aspect_WindowInputListener& theListener, |
| 194 | + const Handle(V3d_View)& theView, |
| 195 | + const QTouchEvent* theEvent) |
| 196 | +{ |
| 197 | + bool hasUpdates = false; |
| 198 | + for (const QTouchEvent::TouchPoint& aQTouch : theEvent->touchPoints()) |
| 199 | + { |
| 200 | + const Standard_Size aTouchId = aQTouch.id(); |
| 201 | + const Graphic3d_Vec2d aNewPos2d = |
| 202 | + theView->Window()->ConvertPointToBacking(Graphic3d_Vec2d(aQTouch.pos().x(), aQTouch.pos().y())); |
| 203 | + const Graphic3d_Vec2i aNewPos2i = Graphic3d_Vec2i(aNewPos2d + Graphic3d_Vec2d(0.5)); |
| 204 | + if (aQTouch.state() == Qt::TouchPointPressed |
| 205 | + && aNewPos2i.minComp() >= 0) |
| 206 | + { |
| 207 | + hasUpdates = true; |
| 208 | + theListener.AddTouchPoint(aTouchId, aNewPos2d); |
| 209 | + } |
| 210 | + else if (aQTouch.state() == Qt::TouchPointMoved |
| 211 | + && theListener.TouchPoints().Contains(aTouchId)) |
| 212 | + { |
| 213 | + hasUpdates = true; |
| 214 | + theListener.UpdateTouchPoint(aTouchId, aNewPos2d); |
| 215 | + } |
| 216 | + else if (aQTouch.state() == Qt::TouchPointReleased |
| 217 | + && theListener.RemoveTouchPoint(aTouchId)) |
| 218 | + { |
| 219 | + hasUpdates = true; |
| 220 | + } |
| 221 | + } |
| 222 | + return hasUpdates; |
| 223 | +} |
| 224 | + |
139 | 225 | // ================================================================ |
140 | 226 | // Function : qtMouseButtons2VKeys |
141 | 227 | // ================================================================ |
|
0 commit comments