Skip to content

Commit

Permalink
QskTextField::placeholderText introduced, QskTextField::description
Browse files Browse the repository at this point in the history
removed
  • Loading branch information
uwerat committed Dec 3, 2024
1 parent 77739d7 commit 77e556f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
17 changes: 9 additions & 8 deletions src/controls/QskTextField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) );
Expand Down
12 changes: 6 additions & 6 deletions src/controls/QskTextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
30 changes: 23 additions & 7 deletions src/controls/QskTextFieldSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 );
Expand All @@ -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 );
}
}

Expand Down
1 change: 1 addition & 0 deletions src/controls/QskTextFieldSkinlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class QSK_EXPORT QskTextFieldSkinlet : public QskSkinlet
enum NodeRole
{
PanelRole,
PlaceholderTextRole,
RoleCount
};

Expand Down

0 comments on commit 77e556f

Please sign in to comment.