QT5 implement some mouse handling
Scrollwheel handling seems to work with mouse, but not correct when using a touchpad - at least for me. Change-Id: I4f1b32205516912e31f9c52605ba2bf4ec6059a8
This commit is contained in:
committed by
Thorsten Behrens
parent
843ec5e37f
commit
1426437be0
@@ -30,6 +30,8 @@
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtGui/QScreen>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
#include <saldatabasic.hxx>
|
||||
#include <vcl/layout.hxx>
|
||||
@@ -490,7 +492,12 @@ const SystemEnvData* Qt5Frame::GetSystemData() const
|
||||
|
||||
SalFrame::SalPointerState Qt5Frame::GetPointerState()
|
||||
{
|
||||
return SalPointerState();
|
||||
SalPointerState aState;
|
||||
QPoint pos = QCursor::pos();
|
||||
aState.maPos = Point( pos.x(), pos.y() );
|
||||
aState.mnState = GetMouseModCode( qApp->mouseButtons() ) |
|
||||
GetKeyModCode( qApp->keyboardModifiers() );
|
||||
return aState;
|
||||
}
|
||||
|
||||
KeyIndicatorState Qt5Frame::GetIndicatorState()
|
||||
|
@@ -21,8 +21,37 @@
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
#include <vcl/event.hxx>
|
||||
|
||||
void CairoDeleter::operator()(cairo_surface_t *pSurface) const
|
||||
{
|
||||
cairo_surface_destroy( pSurface );
|
||||
}
|
||||
|
||||
sal_uInt16 GetKeyModCode( Qt::KeyboardModifiers eKeyModifiers )
|
||||
{
|
||||
sal_uInt16 nCode = 0;
|
||||
if( eKeyModifiers & Qt::ShiftModifier )
|
||||
nCode |= KEY_SHIFT;
|
||||
if( eKeyModifiers & Qt::ControlModifier )
|
||||
nCode |= KEY_MOD1;
|
||||
if( eKeyModifiers & Qt::AltModifier )
|
||||
nCode |= KEY_MOD2;
|
||||
if( eKeyModifiers & Qt::MetaModifier )
|
||||
nCode |= KEY_MOD3;
|
||||
return nCode;
|
||||
}
|
||||
|
||||
sal_uInt16 GetMouseModCode( Qt::MouseButtons eButtons )
|
||||
{
|
||||
sal_uInt16 nCode = 0;
|
||||
if( eButtons & Qt::LeftButton )
|
||||
nCode |= MOUSE_LEFT;
|
||||
if( eButtons & Qt::MidButton )
|
||||
nCode |= MOUSE_MIDDLE;
|
||||
if( eButtons & Qt::RightButton )
|
||||
nCode |= MOUSE_RIGHT;
|
||||
return nCode;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@@ -99,4 +99,7 @@ struct CairoDeleter
|
||||
|
||||
typedef std::unique_ptr<cairo_surface_t, CairoDeleter> UniqueCairoSurface;
|
||||
|
||||
sal_uInt16 GetKeyModCode( Qt::KeyboardModifiers eKeyModifiers );
|
||||
sal_uInt16 GetMouseModCode( Qt::MouseButtons eButtons );
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@@ -25,8 +25,10 @@
|
||||
#include "Qt5Tools.hxx"
|
||||
|
||||
#include <QtGui/QImage>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QPaintEvent>
|
||||
#include <QtGui/QWheelEvent>
|
||||
|
||||
#include <cairo.h>
|
||||
#include <headless/svpgdi.hxx>
|
||||
@@ -36,6 +38,7 @@ Qt5Widget::Qt5Widget( Qt5Frame &rFrame, QWidget *parent, Qt::WindowFlags f )
|
||||
, m_pFrame( &rFrame )
|
||||
{
|
||||
create();
|
||||
setMouseTracking( true );
|
||||
}
|
||||
|
||||
Qt5Widget::~Qt5Widget()
|
||||
@@ -82,4 +85,88 @@ void Qt5Widget::resizeEvent( QResizeEvent* )
|
||||
m_pFrame->CallCallback( SalEvent::Resize, nullptr );
|
||||
}
|
||||
|
||||
void Qt5Widget::mouseButtonEvent( QMouseEvent *pEvent, bool bReleased )
|
||||
{
|
||||
SalMouseEvent aEvent;
|
||||
switch( pEvent->button() )
|
||||
{
|
||||
case Qt::LeftButton: aEvent.mnButton = MOUSE_LEFT; break;
|
||||
case Qt::MidButton: aEvent.mnButton = MOUSE_MIDDLE; break;
|
||||
case Qt::RightButton: aEvent.mnButton = MOUSE_RIGHT; break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
aEvent.mnTime = pEvent->timestamp();
|
||||
aEvent.mnX = (long) pEvent->pos().x();
|
||||
aEvent.mnY = (long) pEvent->pos().y();
|
||||
aEvent.mnCode = GetKeyModCode( pEvent->modifiers() ) |
|
||||
GetMouseModCode( pEvent->buttons() );
|
||||
|
||||
SalEvent nEventType;
|
||||
if ( bReleased )
|
||||
nEventType = SalEvent::MouseButtonUp;
|
||||
else
|
||||
nEventType = SalEvent::MouseButtonDown;
|
||||
m_pFrame->CallCallback( nEventType, &aEvent );
|
||||
}
|
||||
|
||||
void Qt5Widget::mousePressEvent( QMouseEvent *pEvent )
|
||||
{
|
||||
mouseButtonEvent( pEvent, false );
|
||||
}
|
||||
|
||||
void Qt5Widget::mouseReleaseEvent( QMouseEvent *pEvent )
|
||||
{
|
||||
mouseButtonEvent( pEvent, true );
|
||||
}
|
||||
|
||||
void Qt5Widget::mouseMoveEvent( QMouseEvent *pEvent )
|
||||
{
|
||||
SalMouseEvent aEvent;
|
||||
aEvent.mnTime = pEvent->timestamp();
|
||||
aEvent.mnX = pEvent->pos().x();
|
||||
aEvent.mnY = pEvent->pos().y();
|
||||
aEvent.mnCode = GetKeyModCode( pEvent->modifiers() ) |
|
||||
GetMouseModCode( pEvent->buttons() );
|
||||
aEvent.mnButton = 0;
|
||||
|
||||
m_pFrame->CallCallback( SalEvent::MouseMove, &aEvent );
|
||||
pEvent->accept();
|
||||
}
|
||||
|
||||
void Qt5Widget::wheelEvent( QWheelEvent *pEvent )
|
||||
{
|
||||
SalWheelMouseEvent aEvent;
|
||||
|
||||
aEvent.mnTime = pEvent->timestamp();
|
||||
aEvent.mnX = pEvent->pos().x();
|
||||
aEvent.mnY = pEvent->pos().y();
|
||||
aEvent.mnCode = GetKeyModCode( pEvent->modifiers() ) |
|
||||
GetMouseModCode( pEvent->buttons() );
|
||||
|
||||
int nDelta = pEvent->angleDelta().x();
|
||||
aEvent.mbHorz = true;
|
||||
if ( !nDelta )
|
||||
{
|
||||
nDelta = pEvent->angleDelta().y();
|
||||
aEvent.mbHorz = false;
|
||||
}
|
||||
if ( !nDelta )
|
||||
return;
|
||||
nDelta /= 8;
|
||||
|
||||
aEvent.mnDelta = nDelta;
|
||||
aEvent.mnNotchDelta = nDelta > 0 ? 1 : -1;
|
||||
aEvent.mnScrollLines = 3;
|
||||
|
||||
m_pFrame->CallCallback( SalEvent::WheelMouse, &aEvent );
|
||||
pEvent->accept();
|
||||
}
|
||||
|
||||
void Qt5Widget::moveEvent( QMoveEvent* )
|
||||
{
|
||||
m_pFrame->CallCallback( SalEvent::Move, nullptr );
|
||||
}
|
||||
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@@ -23,8 +23,11 @@
|
||||
|
||||
class Qt5Frame;
|
||||
class Qt5Object;
|
||||
class QMouseEvent;
|
||||
class QMoveEvent;
|
||||
class QPaintEvent;
|
||||
class QResizeEvent;
|
||||
class QWheelEvent;
|
||||
|
||||
class Qt5Widget
|
||||
: public QWidget
|
||||
@@ -33,8 +36,15 @@ class Qt5Widget
|
||||
|
||||
Qt5Frame *m_pFrame;
|
||||
|
||||
void mouseButtonEvent( QMouseEvent*, bool );
|
||||
|
||||
void paintEvent( QPaintEvent* ) override;
|
||||
void resizeEvent( QResizeEvent* ) override;
|
||||
void moveEvent( QMoveEvent* ) override;
|
||||
void mouseMoveEvent( QMouseEvent*) override;
|
||||
void mousePressEvent( QMouseEvent*) override;
|
||||
void mouseReleaseEvent( QMouseEvent*) override;
|
||||
void wheelEvent( QWheelEvent* ) override;
|
||||
|
||||
public:
|
||||
Qt5Widget( Qt5Frame &rFrame,
|
||||
|
Reference in New Issue
Block a user