Added two helper function to correctly translate QT mouse events into coords for our trackball.

You must use QT2VCG_X QT2VCG_Y instead of passing the event coords because on newer machines (mac but also win) with very high res monitor, qt events are no more in physical coords.
This commit is contained in:
Paolo Cignoni 2013-12-13 07:55:43 +00:00
parent 94540d3ca6
commit 276438958f
1 changed files with 43 additions and 16 deletions

View File

@ -30,8 +30,35 @@ $Log: trackball.h,v $
#ifndef QT_TRACKBALL_H
#define QT_TRACKBALL_H
/// Transforms the event coordintates (that are device independent)
/// into the expected framebuffer coordinates (e.g.in opengl pixels)
/// This is necessary because trackball works in the viewport coord systems.
float QT2VCG_X( QWidget *qw, QMouseEvent *e)
{
#if QT_VERSION >= 0x050000
return e->x ()*qw->devicePixelRatio() ;
#else
Q_UNUSED(qw);
return e->x ();
#endif
}
/// Transforms the event coordintates (that are device independent)
/// into the expected framebuffer coordinates (e.g.in opengl pixels)
/// This is necessary because trackball works in the viewport coord systems.
float QT2VCG_Y( QWidget *qw, QMouseEvent *e)
{
#if QT_VERSION >= 0x050000
return (qw->height () - e->y ())*qw->devicePixelRatio() ;
#else
return qw->height () - e->y ();
#endif
}
/// Takes a QT MouseButton, some QT KeyboardModifiers and returns the equivalent Trackball::Button
static vcg::Trackball::Button QT2VCG (Qt::MouseButton qtbt, Qt::KeyboardModifiers modifiers)
vcg::Trackball::Button QT2VCG (Qt::MouseButton qtbt, Qt::KeyboardModifiers modifiers)
{
int vcgbt = vcg::Trackball::BUTTON_NONE;