给minigui增加了对鼠标中键滚轮的支持后,发现使用IAL的qvfb又不支持中键滚轮的事件,所以就修改qvfb的代码,以增加对中键滚轮的支持。
首先修改minigui中IAL的qvfb.c中
static int mouse_delta = 0;//增加的
static int mouse_update (void)
{
int ret1, ret2;
POINT l_mouse_pt;
int l_mouse_buttons;
ret1 = read (mouse_fd, &l_mouse_pt, sizeof (POINT));
ret2 = read (mouse_fd, &l_mouse_buttons, sizeof (int));
read (mouse_fd, &mouse_delta, sizeof (int));//增加的
if (ret1 == sizeof (POINT) && ret2 && sizeof (int)
&& l_mouse_buttons < 0x08) {
mouse_pt = l_mouse_pt;
mouse_buttons = l_mouse_buttons;
}
else
return 0;
return 1;
}
static void mouse_getxy (int *x, int* y, int *z)
{
*x = mouse_pt.x;
*y = mouse_pt.y;
*z = mouse_delta;//增加的
}
然后修改qvfb的源代码中QVFbView类,我使用的qvfb1.1
修改QVFbView::sendMouseData函数,增加一个参数delta
void QVFbView::sendMouseData( const QPoint &pos, int buttons, int delta )
{
write( mouseFd, &pos, sizeof( QPoint ) );
write( mouseFd, &buttons, sizeof( int ) );
write( mouseFd, &delta, sizeof( int ) );//add,发送鼠标中键滚轮值
}
函数contentsMousePressEvent、contentsMouseDoubleClickEvent、contentsMouseReleaseEvent、contentsMouseMoveEvent中调用
sendMouseData时,最后一个参数delta都置0
再增加一个函数,用于接收鼠标中键滚动时所产生的值
#ifndef QT_NO_WHEELEVENT
void QVFbView::contentsWheelEvent( QWheelEvent *e )
{
sendMouseData( e->pos()/zm, e->state(), e->delta());
}
#endif
记得qvfbview.h头文件中也要相应根据修改和增加的函数进行修改即可,然后重新编译qvfb
需要注意的是QT必须支持WHEELEVENT,,否则不行。
就是如果没有定义宏QT_NO_WHEELEVENT,就说明QT是支持