summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2017-10-30 19:55:18 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-11-06 12:05:32 +0100
commit1426437be0530a8ba5749c7e76c5ce0e9053af2f (patch)
treee96d8f9c33fe3f935337cb4324fcdc2a1113bc5e
parent843ec5e37f290dca79f8f1245a18d67112f4427f (diff)
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
-rw-r--r--vcl/qt5/Qt5Frame.cxx9
-rw-r--r--vcl/qt5/Qt5Tools.cxx29
-rw-r--r--vcl/qt5/Qt5Tools.hxx3
-rw-r--r--vcl/qt5/Qt5Widget.cxx87
-rw-r--r--vcl/qt5/Qt5Widget.hxx10
5 files changed, 137 insertions, 1 deletions
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index 683f35146e2e..445029627279 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -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()
diff --git a/vcl/qt5/Qt5Tools.cxx b/vcl/qt5/Qt5Tools.cxx
index 5ce038b2b054..ec090a69dcbd 100644
--- a/vcl/qt5/Qt5Tools.cxx
+++ b/vcl/qt5/Qt5Tools.cxx
@@ -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: */
diff --git a/vcl/qt5/Qt5Tools.hxx b/vcl/qt5/Qt5Tools.hxx
index e429f4d9c56c..b45f3c6c0738 100644
--- a/vcl/qt5/Qt5Tools.hxx
+++ b/vcl/qt5/Qt5Tools.hxx
@@ -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: */
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index 7682a4717ae0..90ef68e9e9a7 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -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: */
diff --git a/vcl/qt5/Qt5Widget.hxx b/vcl/qt5/Qt5Widget.hxx
index 3f6b32dfd613..83375278c738 100644
--- a/vcl/qt5/Qt5Widget.hxx
+++ b/vcl/qt5/Qt5Widget.hxx
@@ -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,