QskTextFieldSkinlet::sizeHint added
This commit is contained in:
parent
f0d53322aa
commit
b6f2003826
@ -233,10 +233,10 @@ namespace
|
|||||||
|
|
||||||
void TextInput::updateMetrics()
|
void TextInput::updateMetrics()
|
||||||
{
|
{
|
||||||
auto input = static_cast< const QskTextField* >( parentItem() );
|
auto textField = static_cast< const QskTextField* >( parentItem() );
|
||||||
|
|
||||||
setAlignment( input->alignment() );
|
setAlignment( textField->alignment() );
|
||||||
setFont( input->font() );
|
setFont( textField->font() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextInput::updateColors()
|
void TextInput::updateColors()
|
||||||
@ -490,32 +490,10 @@ void QskTextField::focusOutEvent( QFocusEvent* event )
|
|||||||
Inherited::focusOutEvent( 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()
|
void QskTextField::updateLayout()
|
||||||
{
|
{
|
||||||
auto input = m_data->textInput;
|
m_data->textInput->updateMetrics();
|
||||||
|
qskSetItemGeometry( m_data->textInput, subControlRect( Text ) );
|
||||||
input->updateMetrics();
|
|
||||||
qskSetItemGeometry( input, subControlRect( Text ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskTextField::updateNode( QSGNode* node )
|
void QskTextField::updateNode( QSGNode* node )
|
||||||
|
@ -209,8 +209,6 @@ class QSK_EXPORT QskTextField : public QskControl
|
|||||||
void keyPressEvent( QKeyEvent* ) override;
|
void keyPressEvent( QKeyEvent* ) override;
|
||||||
void keyReleaseEvent( QKeyEvent* ) override;
|
void keyReleaseEvent( QKeyEvent* ) override;
|
||||||
|
|
||||||
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
|
|
||||||
|
|
||||||
void updateLayout() override;
|
void updateLayout() override;
|
||||||
void updateNode( QSGNode* ) override;
|
void updateNode( QSGNode* ) override;
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "QskTextFieldSkinlet.h"
|
#include "QskTextFieldSkinlet.h"
|
||||||
#include "QskTextField.h"
|
#include "QskTextField.h"
|
||||||
|
|
||||||
|
#include <qfontmetrics.h>
|
||||||
|
|
||||||
using Q = QskTextField;
|
using Q = QskTextField;
|
||||||
|
|
||||||
QSK_SYSTEM_STATE( QskTextFieldSkinlet, Selected, QskAspect::FirstUserState >> 1 )
|
QSK_SYSTEM_STATE( QskTextFieldSkinlet, Selected, QskAspect::FirstUserState >> 1 )
|
||||||
@ -67,4 +69,25 @@ QSGNode* QskTextFieldSkinlet::updateSubNode(
|
|||||||
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
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"
|
#include "moc_QskTextFieldSkinlet.cpp"
|
||||||
|
@ -30,6 +30,9 @@ class QSK_EXPORT QskTextFieldSkinlet : public QskSkinlet
|
|||||||
QRectF subControlRect( const QskSkinnable*,
|
QRectF subControlRect( const QskSkinnable*,
|
||||||
const QRectF& rect, QskAspect::Subcontrol ) const override;
|
const QRectF& rect, QskAspect::Subcontrol ) const override;
|
||||||
|
|
||||||
|
QSizeF sizeHint( const QskSkinnable*,
|
||||||
|
Qt::SizeHint, const QSizeF& ) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSGNode* updateSubNode( const QskSkinnable*,
|
QSGNode* updateSubNode( const QskSkinnable*,
|
||||||
quint8 nodeRole, QSGNode* ) const override;
|
quint8 nodeRole, QSGNode* ) const override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user