Skip to content

Commit

Permalink
workaround/hacks removed, that are not needed anymore ( QQuickTxtInput
Browse files Browse the repository at this point in the history
has enhanced its public API in the meantime )
  • Loading branch information
uwerat committed Dec 19, 2024
1 parent a6f91ea commit eb31ef6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 98 deletions.
115 changes: 17 additions & 98 deletions src/controls/QskTextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -248,6 +188,7 @@ namespace
setActiveFocusOnTab( false );
setFlag( ItemAcceptsInputMethod, false );
setFocusOnPress( false );
setSelectByMouse( true );

componentComplete();

Expand Down Expand Up @@ -285,48 +226,16 @@ namespace

void QuickTextInput::updateColors()
{
auto textInput = static_cast< const QskTextInput* >( parentItem() );
auto d = QQuickTextInputPrivate::get( this );

bool isDirty = false;
using Q = QskTextInput;

QColor color;

color = textInput->color( QskTextInput::Text );
if ( d->color != color )
{
d->color = color;
isDirty = true;
}
auto input = static_cast< const QskTextInput* >( parentItem() );

if ( d->hasSelectedText() )
{
QskAspect::States states = QskTextInputSkinlet::Selected;
#if 0
states |= textInput->skinStates();
#endif
setColor( input->color( Q::Text ) );

color = textInput->color( QskTextInput::TextPanel | states );
if ( d->selectionColor != color )
{
d->selectionColor = color;
isDirty = true;
}
const auto state = QskTextInputSkinlet::Selected;

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 ) );
}
}

Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/controls/QskTextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eb31ef6

Please sign in to comment.