From 36bea5747767d942535da48a50944fac80dfc901 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 14 Mar 2025 14:06:38 +0100 Subject: [PATCH] Outlined/Filled moved to gallery code --- designsystems/material3/QskMaterial3Skin.cpp | 4 +- .../QskMaterial3TextFieldSkinlet.cpp | 13 ++-- examples/gallery/inputs/InputPage.cpp | 63 ++++++++++++++++--- src/controls/QskTextField.cpp | 25 -------- src/controls/QskTextField.h | 16 ----- 5 files changed, 64 insertions(+), 57 deletions(-) diff --git a/designsystems/material3/QskMaterial3Skin.cpp b/designsystems/material3/QskMaterial3Skin.cpp index c0f77ea1..f7642ec6 100644 --- a/designsystems/material3/QskMaterial3Skin.cpp +++ b/designsystems/material3/QskMaterial3Skin.cpp @@ -483,8 +483,8 @@ void Editor::setupTextField() setFontRole( Q::Text, BodyLarge ); setColor( Q::Text | Q::Disabled, m_pal.onSurface38 ); - const auto Outlined = static_cast< A::Variation >( Q::OutlinedStyle ); - const auto Filled = static_cast< A::Variation >( Q::FilledStyle ); + const auto Outlined = A::NoVariation; + const auto Filled = static_cast< A::Variation >( 1 ); const auto activeStates = Q::Focused | Q::Editing; diff --git a/designsystems/material3/QskMaterial3TextFieldSkinlet.cpp b/designsystems/material3/QskMaterial3TextFieldSkinlet.cpp index 696a4b5b..03d292f2 100644 --- a/designsystems/material3/QskMaterial3TextFieldSkinlet.cpp +++ b/designsystems/material3/QskMaterial3TextFieldSkinlet.cpp @@ -15,6 +15,11 @@ using Q = QskTextField; +static inline bool isOutlined( const QskTextField* textField ) +{ + return textField->effectiveVariation() == QskAspect::NoVariation; +} + namespace { const int spacingV = 0; // skin hint ! @@ -87,7 +92,7 @@ QRectF QskMaterial3TextFieldSkinlet::subControlRect( const QskSkinnable* skinnab const QFontMetrics fm( textField->effectiveFont( Q::Header ) ); const auto textSize = fm.size( Qt::TextSingleLine | Qt::TextExpandTabs, text ); - if ( textField->style() == QskTextField::OutlinedStyle ) + if ( isOutlined( textField ) ) { const auto r = subControlRect( skinnable, contentsRect, Q::TextPanel ); @@ -109,7 +114,7 @@ QRectF QskMaterial3TextFieldSkinlet::subControlRect( const QskSkinnable* skinnab { auto rect = skinnable->subControlRect( contentsRect, Q::Panel ); - if ( textField->style() == QskTextField::OutlinedStyle ) + if ( isOutlined( textField ) ) { const QFontMetrics fm( textField->effectiveFont( Q::Header ) ); rect.setTop( rect.top() + 0.5 * fm.height() ); @@ -160,7 +165,7 @@ QSGNode* QskMaterial3TextFieldSkinlet::updateSubNode( auto hints = textField->boxHints( Q::TextPanel ); - if( textField->style() == QskTextField::OutlinedStyle ) + if ( isOutlined( textField ) ) { const auto clipRect = textField->subControlRect( Q::Header ); if ( !clipRect.isEmpty() ) @@ -196,7 +201,7 @@ QSizeF QskMaterial3TextFieldSkinlet::sizeHint( const QskSkinnable* skinnable, auto hint = textField->unwrappedTextSize(); hint = hint.expandedTo( skinnable->strutSizeHint( Q::TextPanel ) ); - if ( textField->style() == QskTextField::OutlinedStyle ) + if ( isOutlined( textField ) ) { const QFontMetrics fm( textField->effectiveFont( Q::Header ) ); hint.rheight() += 0.5 * fm.height(); diff --git a/examples/gallery/inputs/InputPage.cpp b/examples/gallery/inputs/InputPage.cpp index 20c88360..6b90e668 100644 --- a/examples/gallery/inputs/InputPage.cpp +++ b/examples/gallery/inputs/InputPage.cpp @@ -68,6 +68,46 @@ namespace } }; + class TextField : public QskTextField + { + public: + enum Style + { + OutlinedStyle, + FilledStyle + }; + + TextField( QQuickItem* parent = nullptr ) + : QskTextField( parent ) + { + } + + void setStyle( Style style ) + { + if ( style != m_style ) + { + m_style = style; + + resetImplicitSize(); + polish(); + update(); + } + } + + Style style() const + { + return m_style; + } + + QskAspect::Variation effectiveVariation() const override + { + return static_cast< QskAspect::Variation >( m_style ); + } + + private: + Style m_style = OutlinedStyle; + }; + class TextInputBox : public QskLinearBox { public: @@ -78,7 +118,7 @@ namespace setDefaultAlignment( Qt::AlignHCenter | Qt::AlignTop ); { - auto field = new QskTextField( this ); + auto field = new TextField( this ); field->setHeaderText( "Name" ); field->setText( "John Doe" ); field->setPlaceholderText( "" ); @@ -86,19 +126,19 @@ namespace } { - auto field = new QskTextField( this ); + auto field = new TextField( this ); field->setHeaderText( "Nickname" ); field->setPlaceholderText( "" ); field->setFooterText( "Optional" ); } { - auto field = new QskTextField( this ); + auto field = new TextField( this ); field->setIcon( {} ); field->setPlaceholderText( "" ); } { - auto field = new QskTextField( this ); + auto field = new TextField( this ); field->setSkinStateFlag( QskTextField::Error ); field->setText( "Error Text" ); field->setHeaderText( "error" ); @@ -107,7 +147,7 @@ namespace } { - auto field = new QskTextField( this ); + auto field = new TextField( this ); field->setReadOnly( true ); field->setText( "Read Only" ); field->setHeaderText( "read only" ); @@ -115,7 +155,7 @@ namespace } { - auto field = new QskTextField( this ); + auto field = new TextField( this ); field->setMaxLength( 15 ); field->setHeaderText( "password" ); field->setEchoMode( QskTextField::Password ); @@ -123,11 +163,14 @@ namespace } } - void setStyle( int style ) + void setStyle( int value ) { auto textFields = findChildren< QskTextField* >(); for ( auto field : textFields ) - field->setStyle( static_cast< QskTextField::Style >( style ) ); + { + const auto style = static_cast< TextField::Style >( value ); + dynamic_cast< TextField* >(field)->setStyle( style ); + } } }; @@ -158,8 +201,8 @@ namespace StyleComboBox( QQuickItem* parent = nullptr ) : QskComboBox( parent ) { - addOption( QString(), "Filled" ); addOption( QString(), "Outlined" ); + addOption( QString(), "Filled" ); } }; } @@ -240,7 +283,7 @@ InputPage::InputPage( QQuickItem* parent ) connect( styleBox, &QskComboBox::currentIndexChanged, textInputBox, &TextInputBox::setStyle ); - styleBox->setCurrentIndex( QskTextField::OutlinedStyle ); + styleBox->setCurrentIndex( TextField::OutlinedStyle ); } void InputPage::syncValues( qreal value ) diff --git a/src/controls/QskTextField.cpp b/src/controls/QskTextField.cpp index ddc08d1a..f1700285 100644 --- a/src/controls/QskTextField.cpp +++ b/src/controls/QskTextField.cpp @@ -29,7 +29,6 @@ class QskTextField::PrivateData QString footerText; QString placeholderText; - Style style = FilledStyle; QskAspect::States buttonStates; }; @@ -53,25 +52,6 @@ QskTextField::~QskTextField() { } -void QskTextField::setStyle( Style style ) -{ - if ( style != m_data->style ) - { - m_data->style = style; - - resetImplicitSize(); - polish(); - update(); - - Q_EMIT styleChanged( style ); - } -} - -QskTextField::Style QskTextField::style() const -{ - return m_data->style; -} - QString QskTextField::headerText() const { return m_data->headerText; @@ -136,11 +116,6 @@ QString QskTextField::placeholderText() const return m_data->placeholderText; } -QskAspect::Variation QskTextField::effectiveVariation() const -{ - return static_cast< QskAspect::Variation >( m_data->style ); -} - void QskTextField::handleButtonClick() { clear(); diff --git a/src/controls/QskTextField.h b/src/controls/QskTextField.h index 67968817..a2aacdce 100644 --- a/src/controls/QskTextField.h +++ b/src/controls/QskTextField.h @@ -22,9 +22,6 @@ class QSK_EXPORT QskTextField : public QskTextInput Q_PROPERTY( QString placeholderText READ placeholderText WRITE setPlaceholderText NOTIFY placeholderTextChanged ) - Q_PROPERTY( Style style READ style - WRITE setStyle NOTIFY styleChanged ) - using Inherited = QskTextInput; public: @@ -33,21 +30,11 @@ class QSK_EXPORT QskTextField : public QskTextInput QSK_SUBCONTROLS( Panel, Header, Footer, Placeholder, Icon, Button, ButtonPanel, CharacterCount ) - enum Style : quint8 - { - FilledStyle, - OutlinedStyle - }; - Q_ENUM( Style ) - QskTextField( QQuickItem* parent = nullptr ); QskTextField( const QString& text, QQuickItem* parent = nullptr ); ~QskTextField() override; - void setStyle( Style ); - Style style() const; - void setHeaderText( const QString& ); QString headerText() const; @@ -60,8 +47,6 @@ class QSK_EXPORT QskTextField : public QskTextInput void setPlaceholderText( const QString& ); QString placeholderText() const; - QskAspect::Variation effectiveVariation() const override; - #if 1 QskAspect::States buttonStates() const; #endif @@ -70,7 +55,6 @@ class QSK_EXPORT QskTextField : public QskTextInput void headerTextChanged( const QString& ); void footerTextChanged( const QString& ); void placeholderTextChanged( const QString& ); - void styleChanged( Style ); protected: void hoverEnterEvent( QHoverEvent* ) override;