From eb31ef673844fa79269a91ea2acd46655ecfb5f8 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 19 Dec 2024 16:26:34 +0100 Subject: [PATCH] workaround/hacks removed, that are not needed anymore ( QQuickTxtInput has enhanced its public API in the meantime ) --- src/controls/QskTextInput.cpp | 115 +++++----------------------------- src/controls/QskTextInput.h | 6 ++ 2 files changed, 23 insertions(+), 98 deletions(-) diff --git a/src/controls/QskTextInput.cpp b/src/controls/QskTextInput.cpp index c3e397616..28c0b74f5 100644 --- a/src/controls/QskTextInput.cpp +++ b/src/controls/QskTextInput.cpp @@ -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 ); - - 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 ) ); } } @@ -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 ); diff --git a/src/controls/QskTextInput.h b/src/controls/QskTextInput.h index c3da9ae61..c2ef09f30 100644 --- a/src/controls/QskTextInput.h +++ b/src/controls/QskTextInput.h @@ -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;