diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-11-07 13:18:05 +0100 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-11-07 13:39:49 +0100 |
commit | 9858edd6576b03292bccfebb142fc92588df0c42 (patch) | |
tree | 2e3ec454f72cf6401b1d9154eb40ddd4d03e1204 /vcl | |
parent | e379f7ff4229a3c011e3a38ae06ed812c49ab0f8 (diff) |
QT5 initial keyboard support
No idea, if we can / should map those vendor specific keys, like
Gtk+ does.
This also prefixes the non-virtual functions with "handle".
Change-Id: Id8c42651e07d33728ff6deced06a82de29aa3fad
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qt5/Qt5Widget.cxx | 106 | ||||
-rw-r--r-- | vcl/qt5/Qt5Widget.hxx | 9 |
2 files changed, 111 insertions, 4 deletions
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx index e17cd7da1a10..8d55aaa6832b 100644 --- a/vcl/qt5/Qt5Widget.cxx +++ b/vcl/qt5/Qt5Widget.cxx @@ -24,7 +24,9 @@ #include "Qt5Graphics.hxx" #include "Qt5Tools.hxx" +#include <QtGui/QFocusEvent> #include <QtGui/QImage> +#include <QtGui/QKeyEvent> #include <QtGui/QMouseEvent> #include <QtGui/QPainter> #include <QtGui/QPaintEvent> @@ -40,6 +42,7 @@ Qt5Widget::Qt5Widget( Qt5Frame &rFrame, QWidget *parent, Qt::WindowFlags f ) { create(); setMouseTracking( true ); + setFocusPolicy( Qt::StrongFocus ); } Qt5Widget::~Qt5Widget() @@ -85,7 +88,7 @@ void Qt5Widget::resizeEvent( QResizeEvent* ) m_pFrame->CallCallback( SalEvent::Resize, nullptr ); } -void Qt5Widget::mouseButtonEvent( QMouseEvent *pEvent, bool bReleased ) +void Qt5Widget::handleMouseButtonEvent( QMouseEvent *pEvent, bool bReleased ) { SalMouseEvent aEvent; switch( pEvent->button() ) @@ -112,12 +115,12 @@ void Qt5Widget::mouseButtonEvent( QMouseEvent *pEvent, bool bReleased ) void Qt5Widget::mousePressEvent( QMouseEvent *pEvent ) { - mouseButtonEvent( pEvent, false ); + handleMouseButtonEvent( pEvent, false ); } void Qt5Widget::mouseReleaseEvent( QMouseEvent *pEvent ) { - mouseButtonEvent( pEvent, true ); + handleMouseButtonEvent( pEvent, true ); } void Qt5Widget::mouseMoveEvent( QMouseEvent *pEvent ) @@ -175,4 +178,101 @@ void Qt5Widget::showEvent( QShowEvent* ) m_pFrame->CallCallback( SalEvent::Paint, &aPaintEvt ); } +static sal_uInt16 GetKeyCode( int keyval ) +{ + sal_uInt16 nCode = 0; + if( keyval >= Qt::Key_0 && keyval <= Qt::Key_9 ) + nCode = KEY_0 + ( keyval - Qt::Key_0 ); + else if( keyval >= Qt::Key_A && keyval <= Qt::Key_Z ) + nCode = KEY_A + ( keyval - Qt::Key_A ); + else if( keyval >= Qt::Key_F1 && keyval <= Qt::Key_F26 ) + nCode = KEY_F1 + (keyval - Qt::Key_F1); + else + { + switch( keyval ) + { + case Qt::Key_Down: nCode = KEY_DOWN; break; + case Qt::Key_Up: nCode = KEY_UP; break; + case Qt::Key_Left: nCode = KEY_LEFT; break; + case Qt::Key_Right: nCode = KEY_RIGHT; break; + case Qt::Key_Home: nCode = KEY_HOME; break; + case Qt::Key_End: nCode = KEY_END; break; + case Qt::Key_PageUp: nCode = KEY_PAGEUP; break; + case Qt::Key_PageDown: nCode = KEY_PAGEDOWN; break; + case Qt::Key_Return: nCode = KEY_RETURN; break; + case Qt::Key_Escape: nCode = KEY_ESCAPE; break; + case Qt::Key_Tab: nCode = KEY_TAB; break; + case Qt::Key_Backspace: nCode = KEY_BACKSPACE; break; + case Qt::Key_Space: nCode = KEY_SPACE; break; + case Qt::Key_Insert: nCode = KEY_INSERT; break; + case Qt::Key_Delete: nCode = KEY_DELETE; break; + case Qt::Key_Plus: nCode = KEY_ADD; break; + case Qt::Key_Minus: nCode = KEY_SUBTRACT; break; + case Qt::Key_Asterisk: nCode = KEY_MULTIPLY; break; + case Qt::Key_Slash: nCode = KEY_DIVIDE; break; + case Qt::Key_Period: nCode = KEY_POINT; break; + case Qt::Key_Comma: nCode = KEY_COMMA; break; + case Qt::Key_Less: nCode = KEY_LESS; break; + case Qt::Key_Greater: nCode = KEY_GREATER; break; + case Qt::Key_Equal: nCode = KEY_EQUAL; break; + case Qt::Key_Find: nCode = KEY_FIND; break; + case Qt::Key_Menu: nCode = KEY_CONTEXTMENU; break; + case Qt::Key_Help: nCode = KEY_HELP; break; + case Qt::Key_Undo: nCode = KEY_UNDO; break; + case Qt::Key_Redo: nCode = KEY_REPEAT; break; + case Qt::Key_Cancel: nCode = KEY_F11; break; + case Qt::Key_AsciiTilde: nCode = KEY_TILDE; break; + case Qt::Key_QuoteLeft: nCode = KEY_QUOTELEFT; break; + case Qt::Key_BracketLeft: nCode = KEY_BRACKETLEFT; break; + case Qt::Key_BracketRight: nCode = KEY_BRACKETRIGHT; break; + case Qt::Key_Semicolon: nCode = KEY_SEMICOLON; break; + case Qt::Key_Copy: nCode = KEY_COPY; break; + case Qt::Key_Cut: nCode = KEY_CUT; break; + case Qt::Key_Open: nCode = KEY_OPEN; break; + case Qt::Key_Paste: nCode = KEY_PASTE; break; + } + } + + return nCode; +} + +bool Qt5Widget::handleKeyEvent( QKeyEvent *pEvent, bool bDown ) +{ + SalKeyEvent aEvent; + + aEvent.mnCharCode = (pEvent->text().isEmpty() ? 0 : pEvent->text().at( 0 ).unicode()); + aEvent.mnRepeat = 0; + aEvent.mnCode = GetKeyCode( pEvent->key() ); + aEvent.mnCode |= GetKeyModCode( pEvent->modifiers() ); + + bool bStopProcessingKey; + if ( bDown ) + bStopProcessingKey = m_pFrame->CallCallback( SalEvent::KeyInput, &aEvent ); + else + bStopProcessingKey = m_pFrame->CallCallback( SalEvent::KeyUp, &aEvent ); + return bStopProcessingKey; +} + +void Qt5Widget::keyPressEvent( QKeyEvent *pEvent ) +{ + if ( handleKeyEvent( pEvent, true ) ) + pEvent->accept(); +} + +void Qt5Widget::keyReleaseEvent( QKeyEvent *pEvent ) +{ + if ( handleKeyEvent( pEvent, false ) ) + pEvent->accept(); +} + +void Qt5Widget::focusInEvent( QFocusEvent* ) +{ + m_pFrame->CallCallback( SalEvent::GetFocus, nullptr ); +} + +void Qt5Widget::focusOutEvent( QFocusEvent* ) +{ + m_pFrame->CallCallback( SalEvent::LoseFocus, nullptr ); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/Qt5Widget.hxx b/vcl/qt5/Qt5Widget.hxx index bacd6ab403d0..8ba955e8cf69 100644 --- a/vcl/qt5/Qt5Widget.hxx +++ b/vcl/qt5/Qt5Widget.hxx @@ -23,6 +23,8 @@ class Qt5Frame; class Qt5Object; +class QFocusEvent; +class QKeyEvent; class QMouseEvent; class QMoveEvent; class QPaintEvent; @@ -37,8 +39,13 @@ class Qt5Widget Qt5Frame *m_pFrame; - void mouseButtonEvent( QMouseEvent*, bool ); + bool handleKeyEvent( QKeyEvent*, bool ); + void handleMouseButtonEvent( QMouseEvent*, bool ); + virtual void focusInEvent( QFocusEvent* ) override; + virtual void focusOutEvent( QFocusEvent* ) override; + virtual void keyPressEvent( QKeyEvent* ) override; + virtual void keyReleaseEvent( QKeyEvent* ) override; virtual void mouseMoveEvent( QMouseEvent*) override; virtual void mousePressEvent( QMouseEvent*) override; virtual void mouseReleaseEvent( QMouseEvent*) override; |