Skip to content

Commit

Permalink
QskTextFieldSkinlet::sizeHint added
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Dec 4, 2024
1 parent f0d5332 commit b6f2003
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
32 changes: 5 additions & 27 deletions src/controls/QskTextField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ namespace

void TextInput::updateMetrics()
{
auto input = static_cast< const QskTextField* >( parentItem() );
auto textField = static_cast< const QskTextField* >( parentItem() );

setAlignment( input->alignment() );
setFont( input->font() );
setAlignment( textField->alignment() );
setFont( textField->font() );
}

void TextInput::updateColors()
Expand Down Expand Up @@ -490,32 +490,10 @@ void QskTextField::focusOutEvent( QFocusEvent* event )
Inherited::focusOutEvent( event );
}

QSizeF QskTextField::layoutSizeHint( Qt::SizeHint which, const QSizeF& ) const
{
if ( which != Qt::PreferredSize )
return QSizeF();

auto input = m_data->textInput;

input->updateMetrics();

QSizeF hint( input->implicitWidth(), input->implicitHeight() );

if ( m_data->hasPanel )
{
hint = outerBoxSize( Panel, hint );
hint = hint.expandedTo( strutSizeHint( Panel ) );
}

return hint;
}

void QskTextField::updateLayout()
{
auto input = m_data->textInput;

input->updateMetrics();
qskSetItemGeometry( input, subControlRect( Text ) );
m_data->textInput->updateMetrics();
qskSetItemGeometry( m_data->textInput, subControlRect( Text ) );
}

void QskTextField::updateNode( QSGNode* node )
Expand Down
2 changes: 0 additions & 2 deletions src/controls/QskTextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ class QSK_EXPORT QskTextField : public QskControl
void keyPressEvent( QKeyEvent* ) override;
void keyReleaseEvent( QKeyEvent* ) override;

QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;

void updateLayout() override;
void updateNode( QSGNode* ) override;

Expand Down
23 changes: 23 additions & 0 deletions src/controls/QskTextFieldSkinlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "QskTextFieldSkinlet.h"
#include "QskTextField.h"

#include <qfontmetrics.h>

using Q = QskTextField;

QSK_SYSTEM_STATE( QskTextFieldSkinlet, Selected, QskAspect::FirstUserState >> 1 )
Expand Down Expand Up @@ -67,4 +69,25 @@ QSGNode* QskTextFieldSkinlet::updateSubNode(
return Inherited::updateSubNode( skinnable, nodeRole, node );
}

QSizeF QskTextFieldSkinlet::sizeHint( const QskSkinnable* skinnable,
Qt::SizeHint which, const QSizeF& ) const
{
if ( which != Qt::PreferredSize )
return QSizeF();

const auto textField = static_cast< const QskTextField* >( skinnable );

const QFontMetricsF fm( textField->effectiveFont( Q::Text ) );

auto hint = fm.size( Qt::TextSingleLine | Qt::TextExpandTabs, textField->text() );

if ( textField->hasPanel() )
{
hint = textField->outerBoxSize( Q::Panel, hint );
hint = hint.expandedTo( textField->strutSizeHint( Q::Panel ) );
}

return hint;
}

#include "moc_QskTextFieldSkinlet.cpp"
3 changes: 3 additions & 0 deletions src/controls/QskTextFieldSkinlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class QSK_EXPORT QskTextFieldSkinlet : public QskSkinlet
QRectF subControlRect( const QskSkinnable*,
const QRectF& rect, QskAspect::Subcontrol ) const override;

QSizeF sizeHint( const QskSkinnable*,
Qt::SizeHint, const QSizeF& ) const override;

protected:
QSGNode* updateSubNode( const QskSkinnable*,
quint8 nodeRole, QSGNode* ) const override;
Expand Down

0 comments on commit b6f2003

Please sign in to comment.