From 925016bbc0502c8a248a2037ab09c72ee7cd55c2 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 21 Jan 2025 15:17:32 +0100 Subject: [PATCH] code moved to QskInputPanelBox --- src/controls/QskTextEdit.cpp | 46 ------------ src/controls/QskTextEdit.h | 7 +- src/controls/QskTextInput.cpp | 101 --------------------------- src/controls/QskTextInput.h | 2 - src/inputpanel/QskInputPanelBox.cpp | 104 +++++++++++++++++++++++++++- 5 files changed, 104 insertions(+), 156 deletions(-) diff --git a/src/controls/QskTextEdit.cpp b/src/controls/QskTextEdit.cpp index b26809a4..1dd0d501 100644 --- a/src/controls/QskTextEdit.cpp +++ b/src/controls/QskTextEdit.cpp @@ -157,51 +157,5 @@ void QskTextEdit::setTabStopDistance( qreal distance ) m_data->wrappedEdit->setTabStopDistance( distance ); } -void QskTextEdit::setupFrom( const QQuickItem* item ) -{ - if ( item == nullptr ) - return; - - // finding attributes from the input hints of item - - int maxCharacters = 32767; - - Qt::InputMethodQueries queries = Qt::ImQueryAll; - queries &= ~Qt::ImEnabled; - - QInputMethodQueryEvent event( queries ); - QCoreApplication::sendEvent( const_cast< QQuickItem* >( item ), &event ); - - if ( event.queries() & Qt::ImMaximumTextLength ) - { - // needs to be handled before Qt::ImCursorPosition ! - - const auto max = event.value( Qt::ImMaximumTextLength ).toInt(); - maxCharacters = qBound( 0, max, maxCharacters ); - } - - if ( event.queries() & Qt::ImSurroundingText ) - { - const auto text = event.value( Qt::ImSurroundingText ).toString(); - setText( text ); - } - - if ( event.queries() & Qt::ImCursorPosition ) - { - const auto pos = event.value( Qt::ImCursorPosition ).toInt(); - setCursorPosition( pos ); - } - - if ( event.queries() & Qt::ImCurrentSelection ) - { -#if 0 - const auto text = event.value( Qt::ImCurrentSelection ).toString(); - if ( !text.isEmpty() ) - { - } -#endif - } -} - #include "QskTextEdit.moc" #include "moc_QskTextEdit.cpp" diff --git a/src/controls/QskTextEdit.h b/src/controls/QskTextEdit.h index 6ad2dbd7..91788df8 100644 --- a/src/controls/QskTextEdit.h +++ b/src/controls/QskTextEdit.h @@ -29,8 +29,6 @@ class QSK_EXPORT QskTextEdit : public QskAbstractTextInput QskTextEdit( QQuickItem* parent = nullptr ); ~QskTextEdit() override; - void setupFrom( const QQuickItem* ); - void setTextFormat( QskTextOptions::TextFormat ); QskTextOptions::TextFormat textFormat() const; @@ -40,12 +38,9 @@ class QSK_EXPORT QskTextEdit : public QskAbstractTextInput void setTabStopDistance( qreal ); Q_SIGNALS: - void panelChanged( bool ); - void placeholderTextChanged( const QString& ); - void lineCountChanged( int ); - void textFormatChanged( QskTextOptions::TextFormat ); + void textFormatChanged( QskTextOptions::TextFormat ); void tabStopDistanceChanged( qreal ); private: diff --git a/src/controls/QskTextInput.cpp b/src/controls/QskTextInput.cpp index 030ef80c..f968e863 100644 --- a/src/controls/QskTextInput.cpp +++ b/src/controls/QskTextInput.cpp @@ -252,106 +252,5 @@ bool QskTextInput::acceptInput() return hasAcceptableInput() || fixup(); } -void QskTextInput::setupFrom( const QQuickItem* item ) -{ - if ( item == nullptr ) - return; - - // finding attributes from the input hints of item - - int maxCharacters = 32767; - QskTextInput::EchoMode echoMode = QskTextInput::Normal; - - Qt::InputMethodQueries queries = Qt::ImQueryAll; - queries &= ~Qt::ImEnabled; - - QInputMethodQueryEvent event( queries ); - QCoreApplication::sendEvent( const_cast< QQuickItem* >( item ), &event ); - - if ( event.queries() & Qt::ImHints ) - { - const auto hints = static_cast< Qt::InputMethodHints >( - event.value( Qt::ImHints ).toInt() ); - - if ( hints & Qt::ImhHiddenText ) - echoMode = QskTextInput::NoEcho; - } - - if ( event.queries() & Qt::ImMaximumTextLength ) - { - // needs to be handled before Qt::ImCursorPosition ! - - const auto max = event.value( Qt::ImMaximumTextLength ).toInt(); - maxCharacters = qBound( 0, max, maxCharacters ); - } - - setMaxLength( maxCharacters ); - - if ( event.queries() & Qt::ImSurroundingText ) - { - const auto text = event.value( Qt::ImSurroundingText ).toString(); - setText( text ); - } - - if ( event.queries() & Qt::ImCursorPosition ) - { - const auto pos = event.value( Qt::ImCursorPosition ).toInt(); - setCursorPosition( pos ); - } - - if ( event.queries() & Qt::ImCurrentSelection ) - { -#if 0 - const auto text = event.value( Qt::ImCurrentSelection ).toString(); - if ( !text.isEmpty() ) - { - } -#endif - } - - int passwordMaskDelay = -1; - QString passwordCharacter; - - if ( echoMode == QskTextInput::NoEcho ) - { - /* - Qt::ImhHiddenText does not provide information - to decide between NoEcho/Password, or provides - more details about how to deal with hidden inputs. - So we try to find out more from trying some properties. - */ - - QVariant value; - - value = item->property( "passwordMaskDelay" ); - if ( value.canConvert< int >() ) - passwordMaskDelay = value.toInt(); - - value = item->property( "passwordCharacter" ); - if ( value.canConvert< QString >() ) - passwordCharacter = value.toString(); - - value = item->property( "echoMode" ); - if ( value.canConvert< int >() ) - { - const auto mode = value.toInt(); - if ( mode == QskTextInput::Password ) - echoMode = QskTextInput::Password; - } - } - - if ( passwordMaskDelay >= 0 ) - setPasswordMaskDelay( passwordMaskDelay ); - else - resetPasswordMaskDelay(); - - if ( !passwordCharacter.isEmpty() ) - setPasswordCharacter( passwordCharacter ); - else - resetPasswordCharacter(); - - setEchoMode( echoMode ); -} - #include "QskTextInput.moc" #include "moc_QskTextInput.cpp" diff --git a/src/controls/QskTextInput.h b/src/controls/QskTextInput.h index de8d839b..2cfb7138 100644 --- a/src/controls/QskTextInput.h +++ b/src/controls/QskTextInput.h @@ -46,8 +46,6 @@ class QSK_EXPORT QskTextInput : public QskAbstractTextInput QskTextInput( QQuickItem* parent = nullptr ); ~QskTextInput() override; - void setupFrom( const QQuickItem* ); - int maxLength() const; void setMaxLength( int ); diff --git a/src/inputpanel/QskInputPanelBox.cpp b/src/inputpanel/QskInputPanelBox.cpp index 50ac0314..26af7c31 100644 --- a/src/inputpanel/QskInputPanelBox.cpp +++ b/src/inputpanel/QskInputPanelBox.cpp @@ -13,6 +13,108 @@ #include #include +static void qskSetupInput( const QQuickItem* item, QskTextInput* textInput ) +{ + if ( item == nullptr ) + return; + + // finding attributes from the input hints of item + + int maxCharacters = 32767; + QskTextInput::EchoMode echoMode = QskTextInput::Normal; + + Qt::InputMethodQueries queries = Qt::ImQueryAll; + queries &= ~Qt::ImEnabled; + + QInputMethodQueryEvent event( queries ); + QCoreApplication::sendEvent( const_cast< QQuickItem* >( item ), &event ); + + if ( event.queries() & Qt::ImHints ) + { + const auto hints = static_cast< Qt::InputMethodHints >( + event.value( Qt::ImHints ).toInt() ); + + if ( hints & Qt::ImhHiddenText ) + echoMode = QskTextInput::NoEcho; + } + + if ( event.queries() & Qt::ImMaximumTextLength ) + { + // needs to be handled before Qt::ImCursorPosition ! + + const auto value = event.value( Qt::ImMaximumTextLength ); + if ( value.isValid() ) + maxCharacters = qBound( 0, value.toInt(), maxCharacters ); + } + + textInput->setMaxLength( maxCharacters ); + + if ( event.queries() & Qt::ImSurroundingText ) + { + const auto text = event.value( Qt::ImSurroundingText ).toString(); + textInput->setText( text ); + } + + if ( event.queries() & Qt::ImCursorPosition ) + { + const auto pos = event.value( Qt::ImCursorPosition ).toInt(); + textInput->setCursorPosition( pos ); + } + + if ( event.queries() & Qt::ImCurrentSelection ) + { +#if 0 + const auto text = event.value( Qt::ImCurrentSelection ).toString(); + if ( !text.isEmpty() ) + { + } +#endif + } + + int passwordMaskDelay = -1; + QString passwordCharacter; + + if ( echoMode == QskTextInput::NoEcho ) + { + /* + Qt::ImhHiddenText does not provide information + to decide between NoEcho/Password, or provides + more details about how to deal with hidden inputs. + So we try to find out more from trying some properties. + */ + + QVariant value; + + value = item->property( "passwordMaskDelay" ); + if ( value.canConvert< int >() ) + passwordMaskDelay = value.toInt(); + + value = item->property( "passwordCharacter" ); + if ( value.canConvert< QString >() ) + passwordCharacter = value.toString(); + + value = item->property( "echoMode" ); + if ( value.canConvert< int >() ) + { + const auto mode = value.toInt(); + if ( mode == QskTextInput::Password ) + echoMode = QskTextInput::Password; + } + } + + if ( passwordMaskDelay >= 0 ) + textInput->setPasswordMaskDelay( passwordMaskDelay ); + else + textInput->resetPasswordMaskDelay(); + + if ( !passwordCharacter.isEmpty() ) + textInput->setPasswordCharacter( passwordCharacter ); + else + textInput->resetPasswordCharacter(); + + textInput->setEchoMode( echoMode ); +} + namespace { class TextFieldProxy final : public QskTextField @@ -156,7 +258,7 @@ void QskInputPanelBox::attachInputItem( QQuickItem* item ) { if ( m_data->panelHints & QskInputPanelBox::InputProxy ) { - m_data->inputProxy->setupFrom( item ); + qskSetupInput( item, m_data->inputProxy ); m_data->inputProxy->setEditing( true ); } }