Commit 84fe346d authored by CGoGN GIT Supervisor's avatar CGoGN GIT Supervisor

Merge branch 'master' of /home/kraemer/CGoGN

* 'master' of /home/kraemer/CGoGN:
  QTgl -> ajout evenement mouseClick
parents 86d40771 dc1e629f
......@@ -274,10 +274,15 @@ public:
*/
virtual void cb_mouseRelease(int button, int x, int y) {}
/**
* Mouse button has been clicked
*/
virtual void cb_mouseClick(int button, int x, int y) {}
/**
* the mouse has been move (with button still pressed)
*/
virtual void cb_mouseMove(int x, int y) {}
virtual void cb_mouseMove(int button, int x, int y) {}
/**
* key press CB (context is ok)
......
......@@ -70,6 +70,7 @@ protected:
std::stack<glm::mat4> m_stack_mv;
int m_current_button;
QPoint clickPoint;
int beginx;
int beginy;
int newModel;
......@@ -101,17 +102,20 @@ public:
void resizeGL(int width, int height);
void mousePressEvent(QMouseEvent *event);
public:
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseClickEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent* event);
void keyPressEvent(QKeyEvent *event);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent* event);
void wheelEvent ( QWheelEvent * event );
void wheelEvent(QWheelEvent* event);
bool Shift() { return m_state_modifier & Qt::ShiftModifier; }
......
......@@ -152,63 +152,76 @@ void GLWidget::mousePressEvent(QMouseEvent* event)
{
beginx = event->x();
beginy = event->y();
clickPoint = event->pos();
m_current_button = event->button();
if (m_cbs)
m_cbs->cb_mousePress(event->button(), event->x(), event->y());
m_cbs->cb_mousePress(event->button(), event->x(), getHeight() - event->y());
}
void GLWidget::mouseReleaseEvent(QMouseEvent* event)
{
if (m_cbs)
m_cbs->cb_mouseRelease(event->button(), event->x(), event->y());
m_cbs->cb_mouseRelease(event->button(), event->x(), getHeight() - event->y());
if(event->pos() == clickPoint)
mouseClickEvent(event) ;
}
void GLWidget::mouseMoveEvent(QMouseEvent* event)
void GLWidget::mouseClickEvent(QMouseEvent* event)
{
int x = event->x();
int y = event->y();
if (m_cbs)
m_cbs->cb_mouseClick(event->button(), event->x(), getHeight() - event->y());
}
switch (m_current_button)
void GLWidget::mouseMoveEvent(QMouseEvent* event)
{
if(m_state_modifier == Qt::NoModifier)
{
case Qt::RightButton:
{
float wl;
if (m_cbs->trans_z() > -20.0f)
wl = 20.0f/foc;
else
wl = -2.0f * m_cbs->trans_z() / foc;
m_cbs->trans_x() += wl / W * (x - beginx);
m_cbs->trans_y() += wl / H * (beginy - y);
}
break;
case Qt::MidButton:
{
float wl = -0.5f * FAR_PLANE / foc;
m_cbs->trans_z() -= wl / W * (x - beginx);
m_cbs->trans_z() -= wl / H * (y - beginy);
}
break;
case Qt::LeftButton:
int x = event->x();
int y = event->y();
switch (m_current_button)
{
trackball(
m_cbs->lastquat(),
(2.0f * beginx - W) / W,
(H - 2.0f * beginy) / H,
(2.0f * x - W) / W,(H - 2.0f * y) / H
);
add_quats(m_cbs->lastquat(), m_cbs->curquat(), m_cbs->curquat());
case Qt::RightButton:
{
float wl;
if (m_cbs->trans_z() > -20.0f)
wl = 20.0f / foc;
else
wl = -2.0f * m_cbs->trans_z() / foc;
m_cbs->trans_x() += wl / W * (x - beginx);
m_cbs->trans_y() += wl / H * (beginy - y);
}
break;
case Qt::MidButton:
{
float wl = -0.5f * FAR_PLANE / foc;
m_cbs->trans_z() -= wl / W * (x - beginx);
m_cbs->trans_z() -= wl / H * (y - beginy);
}
break;
case Qt::LeftButton:
{
trackball(
m_cbs->lastquat(),
(2.0f * beginx - W) / W,
(H - 2.0f * beginy) / H,
(2.0f * x - W) / W,(H - 2.0f * y) / H
);
add_quats(m_cbs->lastquat(), m_cbs->curquat(), m_cbs->curquat());
}
break;
}
break;
}
beginx = x;
beginy = y;
newModel = 1;
updateGL();
beginx = x;
beginy = y;
newModel = 1;
updateGL();
}
if (m_cbs)
m_cbs->cb_mouseMove(event->x(), event->y());
m_cbs->cb_mouseMove(event->button(), event->x(), getHeight() - event->y());
}
void GLWidget::wheelEvent ( QWheelEvent * event )
......@@ -249,7 +262,7 @@ void GLWidget::keyReleaseEvent(QKeyEvent *event)
int k = event->key();
if ( (k >= 65) && (k <= 91) && (event->modifiers() != Qt::ShiftModifier) )
k+=32;
k += 32;
if (m_cbs)
m_cbs->cb_keyRelease(k);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment