From 77e556fad27cd133c40103205a8b3ac35b273cb7 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 3 Dec 2024 09:32:39 +0100 Subject: [PATCH] QskTextField::placeholderText introduced, QskTextField::description removed --- src/controls/QskTextField.cpp | 17 ++++++++-------- src/controls/QskTextField.h | 12 +++++------ src/controls/QskTextFieldSkinlet.cpp | 30 +++++++++++++++++++++------- src/controls/QskTextFieldSkinlet.h | 1 + 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/controls/QskTextField.cpp b/src/controls/QskTextField.cpp index 5f8080f6f..9540d4768 100644 --- a/src/controls/QskTextField.cpp +++ b/src/controls/QskTextField.cpp @@ -14,6 +14,7 @@ QSK_QT_PRIVATE_END QSK_SUBCONTROL( QskTextField, Panel ) QSK_SUBCONTROL( QskTextField, Text ) +QSK_SUBCONTROL( QskTextField, PlaceholderText ) #if 1 // shouldn't this be a Selected state, TODO ... @@ -289,7 +290,7 @@ class QskTextField::PrivateData { public: TextInput* textInput; - QString description; // f.e. used as prompt in QskInputPanel + QString placeholderText; unsigned int activationModes : 3; bool hasPanel : 1; @@ -538,18 +539,18 @@ void QskTextField::setText( const QString& text ) m_data->textInput->setText( text ); } -void QskTextField::setDescription( const QString& text ) +void QskTextField::setPlaceholderText( const QString& text ) { - if ( m_data->description != text ) + if ( m_data->placeholderText != text ) { - m_data->description = text; - Q_EMIT descriptionChanged( text ); + m_data->placeholderText = text; + Q_EMIT placeholderTextChanged( text ); } } -QString QskTextField::description() const +QString QskTextField::placeholderText() const { - return m_data->description; + return m_data->placeholderText; } QskTextField::ActivationModes QskTextField::activationModes() const @@ -618,7 +619,7 @@ Qt::Alignment QskTextField::alignment() const return alignmentHint( Text, Qt::AlignLeft | Qt::AlignTop ); } -void QskTextField::setWrapMode( QskTextOptions::WrapMode wrapMode ) +void QskTextField::setWrapMode( QskTextOptions::WrapMode wrapMode ) { m_data->textInput->setWrapMode( static_cast< QQuickTextInput::WrapMode >( wrapMode ) ); diff --git a/src/controls/QskTextField.h b/src/controls/QskTextField.h index cc0c13da5..73e88f2ed 100644 --- a/src/controls/QskTextField.h +++ b/src/controls/QskTextField.h @@ -18,8 +18,8 @@ class QSK_EXPORT QskTextField : public QskControl Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged USER true) - Q_PROPERTY( QString description READ description - WRITE setDescription NOTIFY descriptionChanged ) + Q_PROPERTY( QString placeholderText READ placeholderText + WRITE setPlaceholderText NOTIFY placeholderTextChanged ) Q_PROPERTY( QskFontRole fontRole READ fontRole WRITE setFontRole RESET resetFontRole NOTIFY fontRoleChanged ) @@ -55,7 +55,7 @@ class QSK_EXPORT QskTextField : public QskControl using Inherited = QskControl; public: - QSK_SUBCONTROLS( Panel, Text, PanelSelected, TextSelected ) + QSK_SUBCONTROLS( Panel, Text, PlaceholderText, PanelSelected, TextSelected ) QSK_STATES( ReadOnly, Editing ) enum ActivationMode @@ -92,8 +92,8 @@ class QSK_EXPORT QskTextField : public QskControl QString text() const; - void setDescription( const QString& ); - QString description() const; + void setPlaceholderText( const QString& ); + QString placeholderText() const; void setPanel( bool ); bool hasPanel() const; @@ -177,7 +177,7 @@ class QSK_EXPORT QskTextField : public QskControl void displayTextChanged( const QString& ); void textEdited( const QString& ); - void descriptionChanged( const QString& ); + void placeholderTextChanged( const QString& ); void fontRoleChanged(); void alignmentChanged(); diff --git a/src/controls/QskTextFieldSkinlet.cpp b/src/controls/QskTextFieldSkinlet.cpp index ca1f67231..6635d6634 100644 --- a/src/controls/QskTextFieldSkinlet.cpp +++ b/src/controls/QskTextFieldSkinlet.cpp @@ -6,10 +6,12 @@ #include "QskTextFieldSkinlet.h" #include "QskTextField.h" +using Q = QskTextField; + QskTextFieldSkinlet::QskTextFieldSkinlet( QskSkin* skin ) : Inherited( skin ) { - setNodeRoles( { PanelRole } ); + setNodeRoles( { PanelRole, PlaceholderTextRole, } ); } QskTextFieldSkinlet::~QskTextFieldSkinlet() @@ -19,13 +21,21 @@ QskTextFieldSkinlet::~QskTextFieldSkinlet() QRectF QskTextFieldSkinlet::subControlRect( const QskSkinnable* skinnable, const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const { - if ( subControl == QskTextField::Panel ) + if ( subControl == Q::Panel ) { return contentsRect; } - else if ( subControl == QskTextField::Text ) + else if ( subControl == Q::Text ) + { + return skinnable->subControlContentsRect( contentsRect, Q::Panel ); + } + else if ( subControl == Q::PlaceholderText ) { - return skinnable->subControlContentsRect( contentsRect, QskTextField::Panel ); + const auto textField = static_cast< const QskTextField* >( skinnable ); + if( textField->text().isEmpty() ) + return subControlRect( skinnable, contentsRect, Q::Text ); + + return QRectF(); } return Inherited::subControlRect( skinnable, contentsRect, subControl ); @@ -34,15 +44,21 @@ QRectF QskTextFieldSkinlet::subControlRect( const QskSkinnable* skinnable, QSGNode* QskTextFieldSkinlet::updateSubNode( const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const { + const auto textField = static_cast< const QskTextField* >( skinnable ); + switch ( nodeRole ) { case PanelRole: { - const auto input = static_cast< const QskTextField* >( skinnable ); - if ( !input->hasPanel() ) + if ( !textField->hasPanel() ) return nullptr; - return updateBoxNode( skinnable, node, QskTextField::Panel ); + return updateBoxNode( skinnable, node, Q::Panel ); + } + case PlaceholderTextRole: + { + return updateTextNode( skinnable, node, + textField->placeholderText(), Q::PlaceholderText ); } } diff --git a/src/controls/QskTextFieldSkinlet.h b/src/controls/QskTextFieldSkinlet.h index 37ba5a4a6..b7205d270 100644 --- a/src/controls/QskTextFieldSkinlet.h +++ b/src/controls/QskTextFieldSkinlet.h @@ -18,6 +18,7 @@ class QSK_EXPORT QskTextFieldSkinlet : public QskSkinlet enum NodeRole { PanelRole, + PlaceholderTextRole, RoleCount };