Merge pull request #6966 from theg4sh:linux-window-mouse-wheel-support
This commit is contained in:
commit
80951bd091
@ -2630,17 +2630,17 @@ void DefaultViewPort::resizeEvent(QResizeEvent* evnt)
|
|||||||
void DefaultViewPort::wheelEvent(QWheelEvent* evnt)
|
void DefaultViewPort::wheelEvent(QWheelEvent* evnt)
|
||||||
{
|
{
|
||||||
int delta = evnt->delta();
|
int delta = evnt->delta();
|
||||||
int cv_event = -1;
|
int cv_event = ((evnt->orientation() == Qt::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL);
|
||||||
int flags = ((delta & 0xffff)<<16) | ((evnt->orientation() == Qt::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL);
|
int flags = (delta & 0xffff)<<16;
|
||||||
QPoint pt = evnt->pos();
|
QPoint pt = evnt->pos();
|
||||||
|
|
||||||
icvmouseHandler(evnt, mouse_wheel, cv_event, flags);
|
icvmouseHandler((QMouseEvent*)evnt, mouse_wheel, cv_event, flags);
|
||||||
icvmouseProcessing(QPoingF(pt), cv_event, flags);
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
||||||
|
|
||||||
scaleView(delta / 240.0, pt);
|
scaleView(delta / 240.0, pt);
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
|
|
||||||
QWidget::mouseWheel(evnt);
|
QWidget::wheelEvent(evnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2857,7 +2857,9 @@ void DefaultViewPort::icvmouseHandler(QMouseEvent *evnt, type_mouse_event catego
|
|||||||
Qt::KeyboardModifiers modifiers = evnt->modifiers();
|
Qt::KeyboardModifiers modifiers = evnt->modifiers();
|
||||||
Qt::MouseButtons buttons = evnt->buttons();
|
Qt::MouseButtons buttons = evnt->buttons();
|
||||||
|
|
||||||
flags = 0;
|
// This line gives excess flags flushing, with it you cannot predefine flags value.
|
||||||
|
// icvmouseHandler called with flags == 0 where it really need.
|
||||||
|
//flags = 0;
|
||||||
if(modifiers & Qt::ShiftModifier)
|
if(modifiers & Qt::ShiftModifier)
|
||||||
flags |= CV_EVENT_FLAG_SHIFTKEY;
|
flags |= CV_EVENT_FLAG_SHIFTKEY;
|
||||||
if(modifiers & Qt::ControlModifier)
|
if(modifiers & Qt::ControlModifier)
|
||||||
@ -2872,7 +2874,7 @@ void DefaultViewPort::icvmouseHandler(QMouseEvent *evnt, type_mouse_event catego
|
|||||||
if(buttons & Qt::MidButton)
|
if(buttons & Qt::MidButton)
|
||||||
flags |= CV_EVENT_FLAG_MBUTTON;
|
flags |= CV_EVENT_FLAG_MBUTTON;
|
||||||
|
|
||||||
cv_event = CV_EVENT_MOUSEMOVE;
|
if (cv_event == -1)
|
||||||
switch(evnt->button())
|
switch(evnt->button())
|
||||||
{
|
{
|
||||||
case Qt::LeftButton:
|
case Qt::LeftButton:
|
||||||
@ -2887,7 +2889,8 @@ void DefaultViewPort::icvmouseHandler(QMouseEvent *evnt, type_mouse_event catego
|
|||||||
cv_event = tableMouseButtons[category][2];
|
cv_event = tableMouseButtons[category][2];
|
||||||
flags |= CV_EVENT_FLAG_MBUTTON;
|
flags |= CV_EVENT_FLAG_MBUTTON;
|
||||||
break;
|
break;
|
||||||
default:;
|
default:
|
||||||
|
cv_event = CV_EVENT_MOUSEMOVE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3191,6 +3194,22 @@ void OpenGlViewPort::paintGL()
|
|||||||
glDrawCallback(glDrawData);
|
glDrawCallback(glDrawData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenGlViewPort::wheelEvent(QWheelEvent* evnt)
|
||||||
|
{
|
||||||
|
int delta = evnt->delta();
|
||||||
|
int cv_event = ((evnt->orientation() == Qt::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL);
|
||||||
|
int flags = (delta & 0xffff)<<16;
|
||||||
|
QPoint pt = evnt->pos();
|
||||||
|
|
||||||
|
icvmouseHandler((QMouseEvent*)evnt, mouse_wheel, cv_event, flags);
|
||||||
|
icvmouseProcessing(QPointF(pt), cv_event, flags);
|
||||||
|
|
||||||
|
scaleView(delta / 240.0, pt);
|
||||||
|
viewport()->update();
|
||||||
|
|
||||||
|
QWidget::wheelEvent(evnt);
|
||||||
|
}
|
||||||
|
|
||||||
void OpenGlViewPort::mousePressEvent(QMouseEvent* evnt)
|
void OpenGlViewPort::mousePressEvent(QMouseEvent* evnt)
|
||||||
{
|
{
|
||||||
int cv_event = -1, flags = 0;
|
int cv_event = -1, flags = 0;
|
||||||
@ -3244,7 +3263,9 @@ void OpenGlViewPort::icvmouseHandler(QMouseEvent* evnt, type_mouse_event categor
|
|||||||
Qt::KeyboardModifiers modifiers = evnt->modifiers();
|
Qt::KeyboardModifiers modifiers = evnt->modifiers();
|
||||||
Qt::MouseButtons buttons = evnt->buttons();
|
Qt::MouseButtons buttons = evnt->buttons();
|
||||||
|
|
||||||
flags = 0;
|
// This line gives excess flags flushing, with it you cannot predefine flags value.
|
||||||
|
// icvmouseHandler called with flags == 0 where it really need.
|
||||||
|
//flags = 0;
|
||||||
if(modifiers & Qt::ShiftModifier)
|
if(modifiers & Qt::ShiftModifier)
|
||||||
flags |= CV_EVENT_FLAG_SHIFTKEY;
|
flags |= CV_EVENT_FLAG_SHIFTKEY;
|
||||||
if(modifiers & Qt::ControlModifier)
|
if(modifiers & Qt::ControlModifier)
|
||||||
@ -3259,26 +3280,23 @@ void OpenGlViewPort::icvmouseHandler(QMouseEvent* evnt, type_mouse_event categor
|
|||||||
if(buttons & Qt::MidButton)
|
if(buttons & Qt::MidButton)
|
||||||
flags |= CV_EVENT_FLAG_MBUTTON;
|
flags |= CV_EVENT_FLAG_MBUTTON;
|
||||||
|
|
||||||
cv_event = CV_EVENT_MOUSEMOVE;
|
if (cv_event == -1)
|
||||||
switch(evnt->button())
|
switch(evnt->button())
|
||||||
{
|
{
|
||||||
case Qt::LeftButton:
|
case Qt::LeftButton:
|
||||||
cv_event = tableMouseButtons[category][0];
|
cv_event = tableMouseButtons[category][0];
|
||||||
flags |= CV_EVENT_FLAG_LBUTTON;
|
flags |= CV_EVENT_FLAG_LBUTTON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Qt::RightButton:
|
case Qt::RightButton:
|
||||||
cv_event = tableMouseButtons[category][1];
|
cv_event = tableMouseButtons[category][1];
|
||||||
flags |= CV_EVENT_FLAG_RBUTTON;
|
flags |= CV_EVENT_FLAG_RBUTTON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Qt::MidButton:
|
case Qt::MidButton:
|
||||||
cv_event = tableMouseButtons[category][2];
|
cv_event = tableMouseButtons[category][2];
|
||||||
flags |= CV_EVENT_FLAG_MBUTTON;
|
flags |= CV_EVENT_FLAG_MBUTTON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
;
|
cv_event = CV_EVENT_MOUSEMOVE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,12 +366,13 @@ private slots:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum type_mouse_event { mouse_up = 0, mouse_down = 1, mouse_dbclick = 2, mouse_move = 3 };
|
enum type_mouse_event { mouse_up = 0, mouse_down = 1, mouse_dbclick = 2, mouse_move = 3, mouse_wheel = 4 };
|
||||||
static const int tableMouseButtons[][3]={
|
static const int tableMouseButtons[][3]={
|
||||||
{CV_EVENT_LBUTTONUP, CV_EVENT_RBUTTONUP, CV_EVENT_MBUTTONUP}, //mouse_up
|
{CV_EVENT_LBUTTONUP, CV_EVENT_RBUTTONUP, CV_EVENT_MBUTTONUP}, //mouse_up
|
||||||
{CV_EVENT_LBUTTONDOWN, CV_EVENT_RBUTTONDOWN, CV_EVENT_MBUTTONDOWN}, //mouse_down
|
{CV_EVENT_LBUTTONDOWN, CV_EVENT_RBUTTONDOWN, CV_EVENT_MBUTTONDOWN}, //mouse_down
|
||||||
{CV_EVENT_LBUTTONDBLCLK, CV_EVENT_RBUTTONDBLCLK, CV_EVENT_MBUTTONDBLCLK}, //mouse_dbclick
|
{CV_EVENT_LBUTTONDBLCLK, CV_EVENT_RBUTTONDBLCLK, CV_EVENT_MBUTTONDBLCLK}, //mouse_dbclick
|
||||||
{CV_EVENT_MOUSEMOVE, CV_EVENT_MOUSEMOVE, CV_EVENT_MOUSEMOVE} //mouse_move
|
{CV_EVENT_MOUSEMOVE, CV_EVENT_MOUSEMOVE, CV_EVENT_MOUSEMOVE}, //mouse_move
|
||||||
|
{0, 0, 0} //mouse_wheel, to prevent exceptions in code
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -436,6 +437,7 @@ protected:
|
|||||||
void resizeGL(int w, int h);
|
void resizeGL(int w, int h);
|
||||||
void paintGL();
|
void paintGL();
|
||||||
|
|
||||||
|
void wheelEvent(QWheelEvent* event);
|
||||||
void mouseMoveEvent(QMouseEvent* event);
|
void mouseMoveEvent(QMouseEvent* event);
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
void mouseReleaseEvent(QMouseEvent* event);
|
void mouseReleaseEvent(QMouseEvent* event);
|
||||||
|
@ -1970,9 +1970,9 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da
|
|||||||
#if defined(GTK_VERSION3_4)
|
#if defined(GTK_VERSION3_4)
|
||||||
// NOTE: in current implementation doesn't possible to put into callback function delta_x and delta_y separetely
|
// NOTE: in current implementation doesn't possible to put into callback function delta_x and delta_y separetely
|
||||||
double delta = (event->scroll.delta_x + event->scroll.delta_y);
|
double delta = (event->scroll.delta_x + event->scroll.delta_y);
|
||||||
int orient = (event->scroll.delta_y!=0) ? CV_EVENT_MOUSEHWHEEL : CV_EVENT_MOUSEWHEEL;
|
cv_event = (event->scroll.delta_y!=0) ? CV_EVENT_MOUSEHWHEEL : CV_EVENT_MOUSEWHEEL;
|
||||||
#else
|
#else
|
||||||
int orient = CV_EVENT_MOUSEWHEEL;
|
cv_event = CV_EVENT_MOUSEWHEEL;
|
||||||
#endif //GTK_VERSION3_4
|
#endif //GTK_VERSION3_4
|
||||||
|
|
||||||
state = event->scroll.state;
|
state = event->scroll.state;
|
||||||
@ -1982,15 +1982,14 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da
|
|||||||
case GDK_SCROLL_SMOOTH: flags |= (((int)delta << 16));
|
case GDK_SCROLL_SMOOTH: flags |= (((int)delta << 16));
|
||||||
break;
|
break;
|
||||||
#endif //GTK_VERSION3_4
|
#endif //GTK_VERSION3_4
|
||||||
case GDK_SCROLL_LEFT: orient = CV_EVENT_MOUSEHWHEEL;
|
case GDK_SCROLL_LEFT: cv_event = CV_EVENT_MOUSEHWHEEL;
|
||||||
case GDK_SCROLL_UP: flags |= ((-(int)1 << 16));
|
case GDK_SCROLL_UP: flags |= ((-(int)1 << 16));
|
||||||
break;
|
break;
|
||||||
case GDK_SCROLL_RIGHT: orient = CV_EVENT_MOUSEHWHEEL;
|
case GDK_SCROLL_RIGHT: cv_event = CV_EVENT_MOUSEHWHEEL;
|
||||||
case GDK_SCROLL_DOWN: flags |= (((int)1 << 16));
|
case GDK_SCROLL_DOWN: flags |= (((int)1 << 16));
|
||||||
break;
|
break;
|
||||||
default: ;
|
default: ;
|
||||||
};
|
};
|
||||||
cv_event = orient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( cv_event >= 0 )
|
if( cv_event >= 0 )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user