code moved to QskInputPanelBox
This commit is contained in:
parent
301b8b0250
commit
925016bbc0
|
@ -157,51 +157,5 @@ void QskTextEdit::setTabStopDistance( qreal distance )
|
||||||
m_data->wrappedEdit->setTabStopDistance( 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 "QskTextEdit.moc"
|
||||||
#include "moc_QskTextEdit.cpp"
|
#include "moc_QskTextEdit.cpp"
|
||||||
|
|
|
@ -29,8 +29,6 @@ class QSK_EXPORT QskTextEdit : public QskAbstractTextInput
|
||||||
QskTextEdit( QQuickItem* parent = nullptr );
|
QskTextEdit( QQuickItem* parent = nullptr );
|
||||||
~QskTextEdit() override;
|
~QskTextEdit() override;
|
||||||
|
|
||||||
void setupFrom( const QQuickItem* );
|
|
||||||
|
|
||||||
void setTextFormat( QskTextOptions::TextFormat );
|
void setTextFormat( QskTextOptions::TextFormat );
|
||||||
QskTextOptions::TextFormat textFormat() const;
|
QskTextOptions::TextFormat textFormat() const;
|
||||||
|
|
||||||
|
@ -40,12 +38,9 @@ class QSK_EXPORT QskTextEdit : public QskAbstractTextInput
|
||||||
void setTabStopDistance( qreal );
|
void setTabStopDistance( qreal );
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void panelChanged( bool );
|
|
||||||
void placeholderTextChanged( const QString& );
|
|
||||||
|
|
||||||
void lineCountChanged( int );
|
void lineCountChanged( int );
|
||||||
void textFormatChanged( QskTextOptions::TextFormat );
|
|
||||||
|
|
||||||
|
void textFormatChanged( QskTextOptions::TextFormat );
|
||||||
void tabStopDistanceChanged( qreal );
|
void tabStopDistanceChanged( qreal );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -252,106 +252,5 @@ bool QskTextInput::acceptInput()
|
||||||
return hasAcceptableInput() || fixup();
|
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 "QskTextInput.moc"
|
||||||
#include "moc_QskTextInput.cpp"
|
#include "moc_QskTextInput.cpp"
|
||||||
|
|
|
@ -46,8 +46,6 @@ class QSK_EXPORT QskTextInput : public QskAbstractTextInput
|
||||||
QskTextInput( QQuickItem* parent = nullptr );
|
QskTextInput( QQuickItem* parent = nullptr );
|
||||||
~QskTextInput() override;
|
~QskTextInput() override;
|
||||||
|
|
||||||
void setupFrom( const QQuickItem* );
|
|
||||||
|
|
||||||
int maxLength() const;
|
int maxLength() const;
|
||||||
void setMaxLength( int );
|
void setMaxLength( int );
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,108 @@
|
||||||
#include <qpointer.h>
|
#include <qpointer.h>
|
||||||
#include <qstring.h>
|
#include <qstring.h>
|
||||||
|
|
||||||
|
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
|
namespace
|
||||||
{
|
{
|
||||||
class TextFieldProxy final : public QskTextField
|
class TextFieldProxy final : public QskTextField
|
||||||
|
@ -156,7 +258,7 @@ void QskInputPanelBox::attachInputItem( QQuickItem* item )
|
||||||
{
|
{
|
||||||
if ( m_data->panelHints & QskInputPanelBox::InputProxy )
|
if ( m_data->panelHints & QskInputPanelBox::InputProxy )
|
||||||
{
|
{
|
||||||
m_data->inputProxy->setupFrom( item );
|
qskSetupInput( item, m_data->inputProxy );
|
||||||
m_data->inputProxy->setEditing( true );
|
m_data->inputProxy->setEditing( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue