workaround/hacks removed, that are not needed anymore ( QQuickTxtInput

has enhanced its public API in the meantime )
This commit is contained in:
Uwe Rathmann 2024-12-19 16:26:34 +01:00
parent a6f91ea863
commit eb31ef6738
2 changed files with 23 additions and 98 deletions

View File

@ -114,66 +114,6 @@ namespace
return QQuickTextInputPrivate::get( this )->fixup();
}
bool hasAcceptableInput() const
{
/*
we would like to call QQuickTextInputPrivate::hasAcceptableInput
but unfortunately it is private, so we need to hack somthing
together
*/
auto that = const_cast< QuickTextInput* >( this );
auto d = QQuickTextInputPrivate::get( that );
if ( d->m_validator )
{
QString text = displayText();
int pos = d->m_cursor;
const auto state = d->m_validator->validate( text, pos );
if ( state != QValidator::Acceptable )
return false;
}
if ( d->m_maskData )
{
/*
We only want to do the check for the maskData here
and have to disable d->m_validator temporarily
*/
class Validator final : public QValidator
{
public:
State validate( QString&, int& ) const override
{
return QValidator::Acceptable;
}
};
const auto validator = d->m_validator;
const auto validInput = d->m_validInput;
const auto acceptableInput = d->m_acceptableInput;
d->m_acceptableInput = true;
static Validator noValidator;
that->setValidator( &noValidator ); // implicitly checking maskData
that->setValidator( d->m_validator );
const bool isAcceptable = d->m_acceptableInput;
// restoring old values
d->m_validInput = validInput;
d->m_acceptableInput = acceptableInput;
return isAcceptable;
}
return true;
}
void updateColors();
void updateMetrics();
@ -248,6 +188,7 @@ namespace
setActiveFocusOnTab( false );
setFlag( ItemAcceptsInputMethod, false );
setFocusOnPress( false );
setSelectByMouse( true );
componentComplete();
@ -285,48 +226,16 @@ namespace
void QuickTextInput::updateColors()
{
auto textInput = static_cast< const QskTextInput* >( parentItem() );
auto d = QQuickTextInputPrivate::get( this );
using Q = QskTextInput;
bool isDirty = false;
auto input = static_cast< const QskTextInput* >( parentItem() );
QColor color;
setColor( input->color( Q::Text ) );
color = textInput->color( QskTextInput::Text );
if ( d->color != color )
{
d->color = color;
isDirty = true;
}
const auto state = QskTextInputSkinlet::Selected;
if ( d->hasSelectedText() )
{
QskAspect::States states = QskTextInputSkinlet::Selected;
#if 0
states |= textInput->skinStates();
#endif
color = textInput->color( QskTextInput::TextPanel | states );
if ( d->selectionColor != color )
{
d->selectionColor = color;
isDirty = true;
}
color = textInput->color( QskTextInput::Text | states );
if ( d->selectedTextColor != color )
{
d->selectedTextColor = color;
isDirty = true;
}
}
if ( isDirty )
{
d->textLayoutDirty = true;
d->updateType = QQuickTextInputPrivate::UpdatePaintNode;
update();
}
setSelectionColor( input->color( Q::TextPanel | state ) );
setSelectedTextColor( input->color( QskTextInput::Text | state ) );
}
}
@ -623,6 +532,16 @@ QskTextOptions::WrapMode QskTextInput::wrapMode() const
m_data->wrappedInput->wrapMode() );
}
void QskTextInput::setSelectByMouse( bool on )
{
m_data->wrappedInput->setSelectByMouse( on );
}
bool QskTextInput::selectByMouse() const
{
return m_data->wrappedInput->selectByMouse();
}
QFont QskTextInput::font() const
{
return effectiveFont( QskTextInput::Text );

View File

@ -47,6 +47,9 @@ class QSK_EXPORT QskTextInput : public QskControl
WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay
NOTIFY passwordMaskDelayChanged )
Q_PROPERTY( bool selectByMouse READ selectByMouse
WRITE setSelectByMouse )
using Inherited = QskControl;
public:
@ -99,6 +102,9 @@ class QSK_EXPORT QskTextInput : public QskControl
void setActivationModes( ActivationModes );
ActivationModes activationModes() const;
void setSelectByMouse( bool );
bool selectByMouse() const;
bool isEditing() const;
QFont font() const;