CloseOnPressOutside enabled for the vitual keyboard to commits and close
the edited text. This allows to finish inputs, when Qt::ImhMultiLine is enabled.
This commit is contained in:
parent
e4823304f0
commit
237cb4ab7e
|
@ -121,7 +121,6 @@ static inline void qskForwardEvent( QQuickItem* item, QEvent* event )
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
class PropertyBinder : public QObject
|
class PropertyBinder : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "QskTextPredictor.h"
|
#include "QskTextPredictor.h"
|
||||||
#include "QskWindow.h"
|
#include "QskWindow.h"
|
||||||
#include "QskPlatform.h"
|
#include "QskPlatform.h"
|
||||||
|
#include "QskInputGrabber.h"
|
||||||
|
|
||||||
#include <qguiapplication.h>
|
#include <qguiapplication.h>
|
||||||
#include <qmap.h>
|
#include <qmap.h>
|
||||||
|
@ -31,20 +32,53 @@ namespace
|
||||||
{
|
{
|
||||||
class Popup : public QskPopup
|
class Popup : public QskPopup
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
using Inherited = QskPopup;
|
using Inherited = QskPopup;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Popup()
|
Popup()
|
||||||
{
|
{
|
||||||
setPolishOnResize( true );
|
setPolishOnResize( true );
|
||||||
setPolishOnParentResize( true );
|
setPolishOnParentResize( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
Q_SIGNALS:
|
||||||
|
void commitRequested();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void aboutToShow() override
|
||||||
|
{
|
||||||
|
Inherited::aboutToShow();
|
||||||
|
|
||||||
|
if ( popupFlags() & QskPopup::CloseOnPressOutside )
|
||||||
|
{
|
||||||
|
if ( auto inputGrabber = findChild< QskInputGrabber* >() )
|
||||||
|
inputGrabber->installEventFilter( this );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool eventFilter( QObject* object, QEvent* event ) override
|
||||||
|
{
|
||||||
|
if ( qobject_cast< QskInputGrabber* >( object ) )
|
||||||
|
{
|
||||||
|
if ( event->type() == QEvent::MouseButtonPress )
|
||||||
|
{
|
||||||
|
if ( popupFlags() & QskPopup::CloseOnPressOutside )
|
||||||
|
{
|
||||||
|
Q_EMIT commitRequested();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Inherited::eventFilter( object, event );
|
||||||
|
}
|
||||||
|
|
||||||
void updateLayout() override
|
void updateLayout() override
|
||||||
{
|
{
|
||||||
const auto m = margins();
|
const auto m = margins();
|
||||||
const auto item = findChild<const QskInputPanel*>();
|
const auto item = findChild< const QskInputPanel* >();
|
||||||
|
|
||||||
auto r = qskItemGeometry( parentItem() );
|
auto r = qskItemGeometry( parentItem() );
|
||||||
r -= m;
|
r -= m;
|
||||||
|
@ -426,6 +460,7 @@ void QskInputContext::showPanel( const QQuickItem* item )
|
||||||
popup->setMargins( 5 );
|
popup->setMargins( 5 );
|
||||||
popup->setModal( true );
|
popup->setModal( true );
|
||||||
|
|
||||||
|
popup->setPopupFlag( QskPopup::CloseOnPressOutside, true );
|
||||||
popup->setPopupFlag( QskPopup::DeleteOnClose, true );
|
popup->setPopupFlag( QskPopup::DeleteOnClose, true );
|
||||||
|
|
||||||
popup->setParentItem( item->window()->contentItem() );
|
popup->setParentItem( item->window()->contentItem() );
|
||||||
|
@ -438,6 +473,9 @@ void QskInputContext::showPanel( const QQuickItem* item )
|
||||||
panel->setParent( popup );
|
panel->setParent( popup );
|
||||||
|
|
||||||
popup->open();
|
popup->open();
|
||||||
|
|
||||||
|
connect( popup, &Popup::commitRequested, panel,
|
||||||
|
[panel]() { panel->commitCurrentText( true ); } );
|
||||||
}
|
}
|
||||||
|
|
||||||
panel->attachInputItem( const_cast< QQuickItem* >( item ) );
|
panel->attachInputItem( const_cast< QQuickItem* >( item ) );
|
||||||
|
@ -580,4 +618,5 @@ QskInputPanel* QskInputContextFactory::createPanel() const
|
||||||
return new Panel();
|
return new Panel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "QskInputContext.moc"
|
||||||
#include "moc_QskInputContext.cpp"
|
#include "moc_QskInputContext.cpp"
|
||||||
|
|
|
@ -311,7 +311,7 @@ class QskInputPanel::PrivateData
|
||||||
|
|
||||||
Qt::InputMethodHints inputHints;
|
Qt::InputMethodHints inputHints;
|
||||||
bool hasPredictorLocale = false;
|
bool hasPredictorLocale = false;
|
||||||
const QskInputPanel* panel;
|
QskInputPanel* panel;
|
||||||
|
|
||||||
void handleKeyProcessingFinished( const Result& result )
|
void handleKeyProcessingFinished( const Result& result )
|
||||||
{
|
{
|
||||||
|
@ -325,16 +325,7 @@ class QskInputPanel::PrivateData
|
||||||
}
|
}
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
{
|
{
|
||||||
if ( auto proxy = panel->inputProxy() )
|
panel->commitCurrentText( false );
|
||||||
{
|
|
||||||
// using input method query instead
|
|
||||||
const auto value = proxy->property( "text" );
|
|
||||||
if ( value.canConvert< QString >() )
|
|
||||||
{
|
|
||||||
qskSendReplaceText( inputItem, value.toString() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qskSendKey( inputItem, result.key );
|
qskSendKey( inputItem, result.key );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -605,5 +596,19 @@ void QskInputPanel::commitKey( int key )
|
||||||
key, m_data->inputHints, this, predictor, spaceLeft );
|
key, m_data->inputHints, this, predictor, spaceLeft );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskInputPanel::commitCurrentText( bool isFinal )
|
||||||
|
{
|
||||||
|
if ( auto proxy = inputProxy() )
|
||||||
|
{
|
||||||
|
// using Qt::ImSurroundingText instead ??
|
||||||
|
const auto value = proxy->property( "text" );
|
||||||
|
if ( value.canConvert< QString >() )
|
||||||
|
qskSendReplaceText( m_data->inputItem, value.toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isFinal )
|
||||||
|
commitKey( Qt::Key_Escape );
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_QskInputPanel.cpp"
|
#include "moc_QskInputPanel.cpp"
|
||||||
#include "QskInputPanel.moc"
|
#include "QskInputPanel.moc"
|
||||||
|
|
|
@ -35,6 +35,7 @@ class QSK_EXPORT QskInputPanel : public QskControl
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void commitKey( int keyCode );
|
void commitKey( int keyCode );
|
||||||
void commitPredictiveText( int index );
|
void commitPredictiveText( int index );
|
||||||
|
void commitCurrentText( bool isFinal );
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void keySelected( int keyCode );
|
void keySelected( int keyCode );
|
||||||
|
|
|
@ -343,7 +343,7 @@ void QskInputPanelBox::keyPressEvent( QKeyEvent* event )
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
case Qt::Key_Escape:
|
case Qt::Key_Escape:
|
||||||
{
|
{
|
||||||
keyCode = event->key();
|
Q_EMIT keySelected( event->key() );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,13 +355,13 @@ void QskInputPanelBox::keyPressEvent( QKeyEvent* event )
|
||||||
keyCode = text[ 0 ].unicode();
|
keyCode = text[ 0 ].unicode();
|
||||||
else
|
else
|
||||||
keyCode = event->key();
|
keyCode = event->key();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_data->keyboard->hasKey( keyCode ) )
|
if ( m_data->keyboard->hasKey( keyCode ) )
|
||||||
{
|
{
|
||||||
// animating the corresponding key button ???
|
// animating the corresponding key button ???
|
||||||
Q_EMIT keySelected( keyCode );
|
Q_EMIT keySelected( keyCode );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue