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
|
||||
{
|
||||
|
||||
class PropertyBinder : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "QskTextPredictor.h"
|
||||
#include "QskWindow.h"
|
||||
#include "QskPlatform.h"
|
||||
#include "QskInputGrabber.h"
|
||||
|
||||
#include <qguiapplication.h>
|
||||
#include <qmap.h>
|
||||
|
@ -31,6 +32,8 @@ namespace
|
|||
{
|
||||
class Popup : public QskPopup
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
using Inherited = QskPopup;
|
||||
|
||||
public:
|
||||
|
@ -40,7 +43,38 @@ namespace
|
|||
setPolishOnParentResize( true );
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
const auto m = margins();
|
||||
|
@ -426,6 +460,7 @@ void QskInputContext::showPanel( const QQuickItem* item )
|
|||
popup->setMargins( 5 );
|
||||
popup->setModal( true );
|
||||
|
||||
popup->setPopupFlag( QskPopup::CloseOnPressOutside, true );
|
||||
popup->setPopupFlag( QskPopup::DeleteOnClose, true );
|
||||
|
||||
popup->setParentItem( item->window()->contentItem() );
|
||||
|
@ -438,6 +473,9 @@ void QskInputContext::showPanel( const QQuickItem* item )
|
|||
panel->setParent( popup );
|
||||
|
||||
popup->open();
|
||||
|
||||
connect( popup, &Popup::commitRequested, panel,
|
||||
[panel]() { panel->commitCurrentText( true ); } );
|
||||
}
|
||||
|
||||
panel->attachInputItem( const_cast< QQuickItem* >( item ) );
|
||||
|
@ -580,4 +618,5 @@ QskInputPanel* QskInputContextFactory::createPanel() const
|
|||
return new Panel();
|
||||
}
|
||||
|
||||
#include "QskInputContext.moc"
|
||||
#include "moc_QskInputContext.cpp"
|
||||
|
|
|
@ -311,7 +311,7 @@ class QskInputPanel::PrivateData
|
|||
|
||||
Qt::InputMethodHints inputHints;
|
||||
bool hasPredictorLocale = false;
|
||||
const QskInputPanel* panel;
|
||||
QskInputPanel* panel;
|
||||
|
||||
void handleKeyProcessingFinished( const Result& result )
|
||||
{
|
||||
|
@ -325,16 +325,7 @@ class QskInputPanel::PrivateData
|
|||
}
|
||||
case Qt::Key_Return:
|
||||
{
|
||||
if ( auto proxy = panel->inputProxy() )
|
||||
{
|
||||
// using input method query instead
|
||||
const auto value = proxy->property( "text" );
|
||||
if ( value.canConvert< QString >() )
|
||||
{
|
||||
qskSendReplaceText( inputItem, value.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
panel->commitCurrentText( false );
|
||||
qskSendKey( inputItem, result.key );
|
||||
break;
|
||||
}
|
||||
|
@ -605,5 +596,19 @@ void QskInputPanel::commitKey( int key )
|
|||
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 "QskInputPanel.moc"
|
||||
|
|
|
@ -35,6 +35,7 @@ class QSK_EXPORT QskInputPanel : public QskControl
|
|||
public Q_SLOTS:
|
||||
void commitKey( int keyCode );
|
||||
void commitPredictiveText( int index );
|
||||
void commitCurrentText( bool isFinal );
|
||||
|
||||
Q_SIGNALS:
|
||||
void keySelected( int keyCode );
|
||||
|
|
|
@ -343,7 +343,7 @@ void QskInputPanelBox::keyPressEvent( QKeyEvent* event )
|
|||
case Qt::Key_Return:
|
||||
case Qt::Key_Escape:
|
||||
{
|
||||
keyCode = event->key();
|
||||
Q_EMIT keySelected( event->key() );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -355,8 +355,6 @@ void QskInputPanelBox::keyPressEvent( QKeyEvent* event )
|
|||
keyCode = text[ 0 ].unicode();
|
||||
else
|
||||
keyCode = event->key();
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_data->keyboard->hasKey( keyCode ) )
|
||||
{
|
||||
|
@ -364,5 +362,7 @@ void QskInputPanelBox::keyPressEvent( QKeyEvent* event )
|
|||
Q_EMIT keySelected( keyCode );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_QskInputPanelBox.cpp"
|
||||
|
|
Loading…
Reference in New Issue