2018-04-03 08:47:21 +00:00
|
|
|
/******************************************************************************
|
2024-01-17 13:31:45 +00:00
|
|
|
* QSkinny - Copyright (C) The authors
|
2023-04-06 07:23:37 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-04-03 08:47:21 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2024-12-02 11:54:31 +00:00
|
|
|
#include "QskTextFieldSkinlet.h"
|
|
|
|
#include "QskTextField.h"
|
2018-04-03 08:47:21 +00:00
|
|
|
|
2024-12-03 08:32:39 +00:00
|
|
|
using Q = QskTextField;
|
|
|
|
|
2024-12-02 11:54:31 +00:00
|
|
|
QskTextFieldSkinlet::QskTextFieldSkinlet( QskSkin* skin )
|
2018-08-03 06:15:28 +00:00
|
|
|
: Inherited( skin )
|
2018-04-03 08:47:21 +00:00
|
|
|
{
|
2024-12-18 11:37:18 +00:00
|
|
|
setNodeRoles( { PanelRole, TextPanelRole, PlaceholderTextRole } );
|
2018-04-03 08:47:21 +00:00
|
|
|
}
|
|
|
|
|
2024-12-02 11:54:31 +00:00
|
|
|
QskTextFieldSkinlet::~QskTextFieldSkinlet()
|
2018-04-03 08:47:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-12-02 11:54:31 +00:00
|
|
|
QRectF QskTextFieldSkinlet::subControlRect( const QskSkinnable* skinnable,
|
2019-04-25 12:23:39 +00:00
|
|
|
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
2018-04-03 08:47:21 +00:00
|
|
|
{
|
2024-12-03 08:32:39 +00:00
|
|
|
if ( subControl == Q::Panel )
|
2019-04-25 12:23:39 +00:00
|
|
|
return contentsRect;
|
2024-12-18 11:37:18 +00:00
|
|
|
|
|
|
|
if ( subControl == Q::TextPanel )
|
2024-12-03 08:32:39 +00:00
|
|
|
return skinnable->subControlContentsRect( contentsRect, Q::Panel );
|
2024-12-18 11:37:18 +00:00
|
|
|
|
|
|
|
if ( subControl == Q::PlaceholderText )
|
2018-04-03 08:47:21 +00:00
|
|
|
{
|
2024-12-03 08:32:39 +00:00
|
|
|
const auto textField = static_cast< const QskTextField* >( skinnable );
|
|
|
|
if( textField->text().isEmpty() )
|
|
|
|
return subControlRect( skinnable, contentsRect, Q::Text );
|
|
|
|
|
|
|
|
return QRectF();
|
2018-04-03 08:47:21 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 12:23:39 +00:00
|
|
|
return Inherited::subControlRect( skinnable, contentsRect, subControl );
|
2018-04-03 08:47:21 +00:00
|
|
|
}
|
|
|
|
|
2024-12-02 11:54:31 +00:00
|
|
|
QSGNode* QskTextFieldSkinlet::updateSubNode(
|
2018-04-03 08:47:21 +00:00
|
|
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
|
|
|
{
|
2024-12-03 08:32:39 +00:00
|
|
|
const auto textField = static_cast< const QskTextField* >( skinnable );
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
switch ( nodeRole )
|
2018-04-03 08:47:21 +00:00
|
|
|
{
|
|
|
|
case PanelRole:
|
|
|
|
{
|
2024-12-03 08:32:39 +00:00
|
|
|
return updateBoxNode( skinnable, node, Q::Panel );
|
|
|
|
}
|
2024-12-18 11:37:18 +00:00
|
|
|
|
2024-12-03 08:32:39 +00:00
|
|
|
case PlaceholderTextRole:
|
|
|
|
{
|
2024-12-18 11:37:18 +00:00
|
|
|
const auto text = effectivePlaceholderText( textField );
|
2024-12-10 14:08:49 +00:00
|
|
|
if ( text.isEmpty() )
|
|
|
|
return nullptr;
|
2024-12-10 10:27:16 +00:00
|
|
|
|
2024-12-10 14:08:49 +00:00
|
|
|
const auto subControl = Q::PlaceholderText;
|
2024-12-10 10:27:16 +00:00
|
|
|
|
2024-12-10 14:08:49 +00:00
|
|
|
QskSkinHintStatus status;
|
2024-12-10 10:27:16 +00:00
|
|
|
|
2024-12-10 14:08:49 +00:00
|
|
|
auto options = skinnable->textOptionsHint( subControl, &status );
|
|
|
|
if ( !status.isValid() )
|
|
|
|
options.setElideMode( Qt::ElideRight );
|
2024-12-09 09:04:33 +00:00
|
|
|
|
2024-12-10 14:08:49 +00:00
|
|
|
return updateTextNode( skinnable, node,
|
|
|
|
textField->subControlRect( subControl ),
|
|
|
|
textField->alignmentHint( subControl, Qt::AlignLeft ),
|
|
|
|
options, text, subControl );
|
2018-04-03 08:47:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
|
|
|
}
|
|
|
|
|
2024-12-04 09:08:39 +00:00
|
|
|
QSizeF QskTextFieldSkinlet::sizeHint( const QskSkinnable* skinnable,
|
2024-12-18 11:37:18 +00:00
|
|
|
Qt::SizeHint which, const QSizeF& constraint ) const
|
2024-12-04 09:08:39 +00:00
|
|
|
{
|
|
|
|
if ( which != Qt::PreferredSize )
|
|
|
|
return QSizeF();
|
|
|
|
|
2024-12-18 11:37:18 +00:00
|
|
|
auto hint = Inherited::sizeHint( skinnable, which, constraint );
|
|
|
|
hint = skinnable->outerBoxSize( Q::Panel, hint );
|
|
|
|
hint = hint.expandedTo( skinnable->strutSizeHint( Q::Panel ) );
|
2024-12-04 09:08:39 +00:00
|
|
|
|
2024-12-18 11:37:18 +00:00
|
|
|
return hint;
|
|
|
|
}
|
2024-12-04 09:08:39 +00:00
|
|
|
|
2024-12-18 11:37:18 +00:00
|
|
|
QString QskTextFieldSkinlet::effectivePlaceholderText(
|
|
|
|
const QskTextField* textField ) const
|
|
|
|
{
|
|
|
|
if ( textField->text().isEmpty() &&
|
|
|
|
!( textField->isReadOnly() || textField->isEditing() ) )
|
2024-12-04 09:08:39 +00:00
|
|
|
{
|
2024-12-18 11:37:18 +00:00
|
|
|
return textField->placeholderText();
|
2024-12-04 09:08:39 +00:00
|
|
|
}
|
|
|
|
|
2024-12-18 11:37:18 +00:00
|
|
|
return QString();
|
2024-12-04 09:08:39 +00:00
|
|
|
}
|
|
|
|
|
2024-12-02 11:54:31 +00:00
|
|
|
#include "moc_QskTextFieldSkinlet.cpp"
|