text input: Introduce Selected state and rename Text

This commit is contained in:
Peter Hartmann 2024-10-01 12:30:58 +02:00
parent 525ca3bd0e
commit 773ec5dcfe
9 changed files with 47 additions and 53 deletions

View File

@ -1773,8 +1773,8 @@ void Editor::setupTextInputMetrics()
setBoxShape( Q::Panel, 3_px ); setBoxShape( Q::Panel, 3_px );
setAlignment( Q::Text, Qt::AlignLeft | Qt::AlignVCenter ); setAlignment( Q::InputText, Qt::AlignLeft | Qt::AlignVCenter );
setFontRole( Q::Text, Fluent2::Body ); setFontRole( Q::InputText, Fluent2::Body );
} }
void Editor::setupTextInputColors( void Editor::setupTextInputColors(
@ -1785,8 +1785,8 @@ void Editor::setupTextInputColors(
const auto& pal = theme.palette; const auto& pal = theme.palette;
setColor( Q::PanelSelected, pal.fillColor.accent.selectedTextBackground ); setColor( Q::Panel | Q::Selected, pal.fillColor.accent.selectedTextBackground );
setColor( Q::TextSelected, pal.fillColor.textOnAccent.selectedText ); setColor( Q::InputText | Q::Selected, pal.fillColor.textOnAccent.selectedText );
for( const auto state : { A::NoState, Q::Hovered, Q::Focused, Q::Editing, Q::Disabled } ) for( const auto state : { A::NoState, Q::Hovered, Q::Focused, Q::Editing, Q::Disabled } )
{ {
@ -1821,7 +1821,7 @@ void Editor::setupTextInputColors(
} }
const auto panel = Q::Panel | section | state; const auto panel = Q::Panel | section | state;
const auto text = Q::Text | section | state; const auto text = Q::InputText | section | state;
panelColor = rgbSolid( panelColor, pal.background.solid.base ); panelColor = rgbSolid( panelColor, pal.background.solid.base );

View File

@ -386,18 +386,17 @@ void Editor::setupTextInput()
using A = QskAspect; using A = QskAspect;
using P = QPalette; using P = QPalette;
setAlignment( Q::Text, Qt::AlignLeft | Qt::AlignTop ); setAlignment( Q::InputText, Qt::AlignLeft | Qt::AlignTop );
for ( auto state : { A::NoState, Q::Disabled } ) for ( auto state : { A::NoState, Q::Disabled } )
{ {
const auto colorGroup = ( state == A::NoState ) ? P::Active : P::Disabled; const auto colorGroup = ( state == A::NoState ) ? P::Active : P::Disabled;
setGradient( Q::Panel | state, m_pal.color( colorGroup, P::Base ) ); setGradient( Q::Panel | state, m_pal.color( colorGroup, P::Base ) );
setColor( Q::PanelSelected | state, m_pal.color( colorGroup, P::Highlight ) ); setColor( Q::Panel | Q::Selected | state, m_pal.color( colorGroup, P::Highlight ) );
setColor( Q::Text | state, m_pal.color( colorGroup, P::Text ) );
setColor( Q::TextSelected | state, m_pal.color( colorGroup, P::HighlightedText ) );
setColor( Q::InputText | state, m_pal.color( colorGroup, P::Text ) );
setColor( Q::InputText | Q::Selected | state, m_pal.color( colorGroup, P::HighlightedText ) );
} }
setBoxBorderMetrics( Q::Panel, 1_px ); setBoxBorderMetrics( Q::Panel, 1_px );

View File

@ -470,15 +470,15 @@ void Editor::setupTextInput()
// ### Also add a pressed state // ### Also add a pressed state
setColor( Q::Text, m_pal.onSurface ); setColor( Q::InputText, m_pal.onSurface );
setFontRole( Q::Text, BodyMedium ); setFontRole( Q::InputText, BodyMedium );
setAlignment( Q::Text, Qt::AlignLeft | Qt::AlignVCenter ); setAlignment( Q::InputText, Qt::AlignLeft | Qt::AlignVCenter );
const auto disabledPanelColor = QskRgb::toTransparentF( m_pal.onSurface, 0.04 ); const auto disabledPanelColor = QskRgb::toTransparentF( m_pal.onSurface, 0.04 );
setGradient( Q::Panel | Q::Disabled, disabledPanelColor ); setGradient( Q::Panel | Q::Disabled, disabledPanelColor );
setBoxBorderColors( Q::Panel | Q::Disabled, m_pal.onSurface38 ); setBoxBorderColors( Q::Panel | Q::Disabled, m_pal.onSurface38 );
setColor( Q::Text | Q::Disabled, m_pal.onSurface38 ); setColor( Q::InputText | Q::Disabled, m_pal.onSurface38 );
} }
void Editor::setupProgressBar() void Editor::setupProgressBar()

View File

@ -52,7 +52,7 @@ namespace
m_input = new QskTextInput( this ); m_input = new QskTextInput( this );
m_input->setValidator( new InputValidator( m_input ) ); m_input->setValidator( new InputValidator( m_input ) );
m_input->setText( QString::number( value ) ); m_input->setInputText( QString::number( value ) );
const QFontMetricsF fm( m_input->font() ); const QFontMetricsF fm( m_input->font() );
m_input->setFixedWidth( fm.horizontalAdvance( "-0.000" ) ); m_input->setFixedWidth( fm.horizontalAdvance( "-0.000" ) );
@ -65,7 +65,7 @@ namespace
qreal value() const qreal value() const
{ {
return m_input->text().toDouble(); return m_input->inputText().toDouble();
} }
Q_SIGNALS: Q_SIGNALS:

View File

@ -202,24 +202,24 @@ class InputBox : public QskLinearBox
setSpacing( 10 ); setSpacing( 10 );
auto* textInput1 = new QskTextInput( this ); auto* textInput1 = new QskTextInput( this );
textInput1->setText( "Press and edit Me." ); textInput1->setInputText( "Press and edit Me." );
textInput1->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred ); textInput1->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred );
auto* textInput2 = new QskTextInput( this ); auto* textInput2 = new QskTextInput( this );
textInput2->setText( "Press and edit Me." ); textInput2->setInputText( "Press and edit Me." );
textInput2->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred ); textInput2->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred );
textInput2->setActivationModes( QskTextInput::ActivationOnAll ); textInput2->setActivationModes( QskTextInput::ActivationOnAll );
auto* textInput3 = new QskTextInput( this ); auto* textInput3 = new QskTextInput( this );
textInput3->setReadOnly( true ); textInput3->setReadOnly( true );
textInput3->setText( "Read Only information." ); textInput3->setInputText( "Read Only information." );
textInput3->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred ); textInput3->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred );
auto* textInput4 = new QskTextInput( this ); auto* textInput4 = new QskTextInput( this );
textInput4->setEchoMode( QskTextInput::Password ); textInput4->setEchoMode( QskTextInput::Password );
textInput4->setPasswordMaskDelay( 1000 ); textInput4->setPasswordMaskDelay( 1000 );
textInput4->setMaxLength( 8 ); textInput4->setMaxLength( 8 );
textInput4->setText( "12345678" ); textInput4->setInputText( "12345678" );
textInput4->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred ); textInput4->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred );
} }
}; };

View File

@ -13,16 +13,11 @@ QSK_QT_PRIVATE_BEGIN
QSK_QT_PRIVATE_END QSK_QT_PRIVATE_END
QSK_SUBCONTROL( QskTextInput, Panel ) QSK_SUBCONTROL( QskTextInput, Panel )
QSK_SUBCONTROL( QskTextInput, Text ) QSK_SUBCONTROL( QskTextInput, InputText )
#if 1
// shouldn't this be a Selected state, TODO ...
QSK_SUBCONTROL( QskTextInput, PanelSelected )
QSK_SUBCONTROL( QskTextInput, TextSelected )
#endif
QSK_SYSTEM_STATE( QskTextInput, ReadOnly, QskAspect::FirstSystemState << 1 ) QSK_SYSTEM_STATE( QskTextInput, ReadOnly, QskAspect::FirstSystemState << 1 )
QSK_SYSTEM_STATE( QskTextInput, Editing, QskAspect::FirstSystemState << 2 ) QSK_SYSTEM_STATE( QskTextInput, Editing, QskAspect::FirstSystemState << 2 )
QSK_SYSTEM_STATE( QskTextInput, Selected, QskAspect::FirstSystemState << 3 )
static inline void qskPropagateReadOnly( QskTextInput* input ) static inline void qskPropagateReadOnly( QskTextInput* input )
{ {
@ -36,13 +31,13 @@ static inline void qskBindSignals(
const QQuickTextInput* wrappedInput, QskTextInput* input ) const QQuickTextInput* wrappedInput, QskTextInput* input )
{ {
QObject::connect( wrappedInput, &QQuickTextInput::textChanged, QObject::connect( wrappedInput, &QQuickTextInput::textChanged,
input, [ input ] { Q_EMIT input->textChanged( input->text() ); } ); input, [ input ] { Q_EMIT input->inputTextChanged( input->inputText() ); } );
QObject::connect( wrappedInput, &QQuickTextInput::displayTextChanged, QObject::connect( wrappedInput, &QQuickTextInput::displayTextChanged,
input, [ input ] { Q_EMIT input->displayTextChanged( input->displayText() ); } ); input, [ input ] { Q_EMIT input->displayTextChanged( input->displayText() ); } );
QObject::connect( wrappedInput, &QQuickTextInput::textEdited, QObject::connect( wrappedInput, &QQuickTextInput::textEdited,
input, [ input ] { Q_EMIT input->textEdited( input->text() ); } ); input, [ input ] { Q_EMIT input->textEdited( input->inputText() ); } );
QObject::connect( wrappedInput, &QQuickTextInput::validatorChanged, QObject::connect( wrappedInput, &QQuickTextInput::validatorChanged,
input, &QskTextInput::validatorChanged ); input, &QskTextInput::validatorChanged );
@ -252,7 +247,7 @@ namespace
QColor color; QColor color;
color = input->color( QskTextInput::Text ); color = input->color( QskTextInput::InputText );
if ( d->color != color ) if ( d->color != color )
{ {
d->color = color; d->color = color;
@ -261,14 +256,14 @@ namespace
if ( d->hasSelectedText() ) if ( d->hasSelectedText() )
{ {
color = input->color( QskTextInput::PanelSelected ); color = input->color( QskTextInput::Panel | QskTextInput::Selected );
if ( d->selectionColor != color ) if ( d->selectionColor != color )
{ {
d->selectionColor = color; d->selectionColor = color;
isDirty = true; isDirty = true;
} }
color = input->color( QskTextInput::TextSelected ); color = input->color( QskTextInput::InputText | QskTextInput::Selected );
if ( d->selectedTextColor != color ) if ( d->selectedTextColor != color )
{ {
d->selectedTextColor = color; d->selectedTextColor = color;
@ -519,7 +514,7 @@ void QskTextInput::updateLayout()
auto input = m_data->textInput; auto input = m_data->textInput;
input->updateMetrics(); input->updateMetrics();
qskSetItemGeometry( input, subControlRect( Text ) ); qskSetItemGeometry( input, subControlRect( InputText ) );
} }
void QskTextInput::updateNode( QSGNode* node ) void QskTextInput::updateNode( QSGNode* node )
@ -528,12 +523,12 @@ void QskTextInput::updateNode( QSGNode* node )
Inherited::updateNode( node ); Inherited::updateNode( node );
} }
QString QskTextInput::text() const QString QskTextInput::inputText() const
{ {
return m_data->textInput->text(); return m_data->textInput->text();
} }
void QskTextInput::setText( const QString& text ) void QskTextInput::setInputText( const QString& text )
{ {
m_data->textInput->setText( text ); m_data->textInput->setText( text );
} }
@ -574,7 +569,7 @@ static inline void qskUpdateInputMethodFont( const QskTextInput* input )
void QskTextInput::setFontRole( const QskFontRole& role ) void QskTextInput::setFontRole( const QskFontRole& role )
{ {
if ( setFontRoleHint( Text, role ) ) if ( setFontRoleHint( InputText, role ) )
{ {
qskUpdateInputMethodFont( this ); qskUpdateInputMethodFont( this );
Q_EMIT fontRoleChanged(); Q_EMIT fontRoleChanged();
@ -583,7 +578,7 @@ void QskTextInput::setFontRole( const QskFontRole& role )
void QskTextInput::resetFontRole() void QskTextInput::resetFontRole()
{ {
if ( resetFontRoleHint( Text ) ) if ( resetFontRoleHint( InputText ) )
{ {
qskUpdateInputMethodFont( this ); qskUpdateInputMethodFont( this );
Q_EMIT fontRoleChanged(); Q_EMIT fontRoleChanged();
@ -592,12 +587,12 @@ void QskTextInput::resetFontRole()
QskFontRole QskTextInput::fontRole() const QskFontRole QskTextInput::fontRole() const
{ {
return fontRoleHint( Text ); return fontRoleHint( InputText );
} }
void QskTextInput::setAlignment( Qt::Alignment alignment ) void QskTextInput::setAlignment( Qt::Alignment alignment )
{ {
if ( setAlignmentHint( Text, alignment ) ) if ( setAlignmentHint( InputText, alignment ) )
{ {
m_data->textInput->setAlignment( alignment ); m_data->textInput->setAlignment( alignment );
Q_EMIT alignmentChanged(); Q_EMIT alignmentChanged();
@ -606,7 +601,7 @@ void QskTextInput::setAlignment( Qt::Alignment alignment )
void QskTextInput::resetAlignment() void QskTextInput::resetAlignment()
{ {
if ( resetAlignmentHint( Text ) ) if ( resetAlignmentHint( InputText ) )
{ {
m_data->textInput->setAlignment( alignment() ); m_data->textInput->setAlignment( alignment() );
Q_EMIT alignmentChanged(); Q_EMIT alignmentChanged();
@ -615,7 +610,7 @@ void QskTextInput::resetAlignment()
Qt::Alignment QskTextInput::alignment() const Qt::Alignment QskTextInput::alignment() const
{ {
return alignmentHint( Text, Qt::AlignLeft | Qt::AlignTop ); return alignmentHint( InputText, Qt::AlignLeft | Qt::AlignTop );
} }
void QskTextInput::setWrapMode( QskTextOptions::WrapMode wrapMode ) void QskTextInput::setWrapMode( QskTextOptions::WrapMode wrapMode )
@ -632,7 +627,7 @@ QskTextOptions::WrapMode QskTextInput::wrapMode() const
QFont QskTextInput::font() const QFont QskTextInput::font() const
{ {
return effectiveFont( QskTextInput::Text ); return effectiveFont( QskTextInput::InputText );
} }
bool QskTextInput::isReadOnly() const bool QskTextInput::isReadOnly() const
@ -922,7 +917,7 @@ void QskTextInput::setupFrom( const QQuickItem* item )
if ( event.queries() & Qt::ImSurroundingText ) if ( event.queries() & Qt::ImSurroundingText )
{ {
const auto text = event.value( Qt::ImSurroundingText ).toString(); const auto text = event.value( Qt::ImSurroundingText ).toString();
setText( text ); setInputText( text );
} }
if ( event.queries() & Qt::ImCursorPosition ) if ( event.queries() & Qt::ImCursorPosition )

View File

@ -16,7 +16,7 @@ class QSK_EXPORT QskTextInput : public QskControl
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged USER true) Q_PROPERTY( QString inputText READ inputText WRITE setInputText NOTIFY inputTextChanged USER true )
Q_PROPERTY( QString description READ description Q_PROPERTY( QString description READ description
WRITE setDescription NOTIFY descriptionChanged ) WRITE setDescription NOTIFY descriptionChanged )
@ -55,8 +55,8 @@ class QSK_EXPORT QskTextInput : public QskControl
using Inherited = QskControl; using Inherited = QskControl;
public: public:
QSK_SUBCONTROLS( Panel, Text, PanelSelected, TextSelected ) QSK_SUBCONTROLS( Panel, InputText )
QSK_STATES( ReadOnly, Editing ) QSK_STATES( ReadOnly, Editing, Selected )
enum ActivationMode enum ActivationMode
{ {
@ -84,13 +84,13 @@ class QSK_EXPORT QskTextInput : public QskControl
Q_ENUM( EchoMode ) Q_ENUM( EchoMode )
QskTextInput( QQuickItem* parent = nullptr ); QskTextInput( QQuickItem* parent = nullptr );
QskTextInput( const QString& text, QQuickItem* parent = nullptr ); QskTextInput( const QString&, QQuickItem* parent = nullptr );
~QskTextInput() override; ~QskTextInput() override;
void setupFrom( const QQuickItem* ); void setupFrom( const QQuickItem* );
QString text() const; QString inputText() const;
void setDescription( const QString& ); void setDescription( const QString& );
QString description() const; QString description() const;
@ -163,7 +163,7 @@ class QSK_EXPORT QskTextInput : public QskControl
void ensureVisible( int position ); void ensureVisible( int position );
public Q_SLOTS: public Q_SLOTS:
void setText( const QString& ); void setInputText( const QString& );
void setEditing( bool ); void setEditing( bool );
Q_SIGNALS: Q_SIGNALS:
@ -173,7 +173,7 @@ class QSK_EXPORT QskTextInput : public QskControl
void readOnlyChanged( bool ); void readOnlyChanged( bool );
void panelChanged( bool ); void panelChanged( bool );
void textChanged( const QString& ); void inputTextChanged( const QString& );
void displayTextChanged( const QString& ); void displayTextChanged( const QString& );
void textEdited( const QString& ); void textEdited( const QString& );

View File

@ -23,7 +23,7 @@ QRectF QskTextInputSkinlet::subControlRect( const QskSkinnable* skinnable,
{ {
return contentsRect; return contentsRect;
} }
else if ( subControl == QskTextInput::Text ) else if ( subControl == QskTextInput::InputText )
{ {
return skinnable->subControlContentsRect( contentsRect, QskTextInput::Panel ); return skinnable->subControlContentsRect( contentsRect, QskTextInput::Panel );
} }

View File

@ -35,7 +35,7 @@ namespace
if ( subControl == QskTextInput::Panel ) if ( subControl == QskTextInput::Panel )
return m_panelBox->effectiveSubcontrol( QskInputPanelBox::ProxyPanel ); return m_panelBox->effectiveSubcontrol( QskInputPanelBox::ProxyPanel );
if ( subControl == QskTextInput::Text ) if ( subControl == QskTextInput::InputText )
return m_panelBox->effectiveSubcontrol( QskInputPanelBox::ProxyText ); return m_panelBox->effectiveSubcontrol( QskInputPanelBox::ProxyText );
return subControl; return subControl;
@ -187,7 +187,7 @@ QskAspect::Subcontrol QskInputPanelBox::substitutedSubcontrol(
return QskTextInput::Panel; return QskTextInput::Panel;
if ( subControl == QskInputPanelBox::ProxyText ) if ( subControl == QskInputPanelBox::ProxyText )
return QskTextInput::Text; return QskTextInput::InputText;
#endif #endif
return subControl; return subControl;