QskTextFieldSkinlet::sizeHint added
This commit is contained in:
parent
f0d53322aa
commit
b6f2003826
@ -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()
|
||||
@ -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 )
|
||||
|
@ -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;
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "QskTextFieldSkinlet.h"
|
||||
#include "QskTextField.h"
|
||||
|
||||
#include <qfontmetrics.h>
|
||||
|
||||
using Q = QskTextField;
|
||||
|
||||
QSK_SYSTEM_STATE( QskTextFieldSkinlet, Selected, QskAspect::FirstUserState >> 1 )
|
||||
@ -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"
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user