started to remove QskSkinRenderer
This commit is contained in:
parent
958196db19
commit
f21bed63c7
@ -5,7 +5,10 @@
|
||||
|
||||
#include "Frame.h"
|
||||
|
||||
#include <QskBoxOptions.h>
|
||||
#include <QskBoxShapeMetrics.h>
|
||||
#include <QskBoxBorderMetrics.h>
|
||||
#include <QskBoxBorderColors.h>
|
||||
#include <QskGradient.h>
|
||||
#include <QskBoxNode.h>
|
||||
#include <QskSkinlet.h>
|
||||
|
||||
@ -145,18 +148,10 @@ void Frame::updateFrameNode( const QRectF& rect, QskBoxNode* node )
|
||||
}
|
||||
}
|
||||
|
||||
QskBoxOptions options;
|
||||
|
||||
options.border.setWidths( m_frameWidth );
|
||||
options.borderColors.setColor( Qsk::Left, c1 );
|
||||
options.borderColors.setColor( Qsk::Top, c1 );
|
||||
options.borderColors.setColor( Qsk::Right, c2 );
|
||||
options.borderColors.setColor( Qsk::Bottom, c2 );
|
||||
|
||||
options.fillGradient.setColor( m_color );
|
||||
options.shape.setRadius( effectiveRadius( rect, m_radius ) );
|
||||
const QskBoxBorderColors borderColors( c1, c1, c2, c2 );
|
||||
const qreal radius = effectiveRadius( rect, m_radius );
|
||||
|
||||
node->setBoxData( rect, options );
|
||||
node->setBoxData( rect, radius, m_frameWidth, borderColors, m_color );
|
||||
}
|
||||
|
||||
#include "moc_Frame.cpp"
|
||||
|
@ -109,15 +109,15 @@ bool QskTextOptions::operator==( const QskTextOptions& other ) const
|
||||
&& ( m_maximumLineCount == other.m_maximumLineCount );
|
||||
}
|
||||
|
||||
bool QskTextOptions::isRichText( const QString& text ) const
|
||||
bool QskTextOptions::isPlainText( const QString& text ) const
|
||||
{
|
||||
if ( text.isEmpty() )
|
||||
return false;
|
||||
return true;
|
||||
|
||||
if ( m_format == QskTextOptions::AutoText )
|
||||
return Qt::mightBeRichText( text );
|
||||
return !Qt::mightBeRichText( text );
|
||||
|
||||
return m_format == QskTextOptions::RichText;
|
||||
return m_format == QskTextOptions::PlainText;
|
||||
}
|
||||
|
||||
uint qHash( const QskTextOptions &options, uint seed ) noexcept
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
bool operator==( const QskTextOptions& other ) const;
|
||||
bool operator!=( const QskTextOptions& other ) const;
|
||||
|
||||
bool isRichText( const QString& text ) const;
|
||||
bool isPlainText( const QString& text ) const;
|
||||
|
||||
int textFlags() const;
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "QskScrollViewSkinlet.h"
|
||||
#include "QskScrollView.h"
|
||||
#include "QskAspect.h"
|
||||
#include "QskSkinRenderer.h"
|
||||
#include "QskFunctions.h"
|
||||
|
||||
#include <QTransform>
|
||||
|
@ -6,52 +6,13 @@
|
||||
#include "QskSkinRenderer.h"
|
||||
#include "QskSkinnable.h"
|
||||
#include "QskControl.h"
|
||||
#include "QskRgbValue.h"
|
||||
|
||||
#include "QskTextRenderer.h"
|
||||
#include "QskPlainTextRenderer.h"
|
||||
#include "QskBoxOptions.h"
|
||||
#include "QskTextNode.h"
|
||||
|
||||
#include <QMatrix4x4>
|
||||
|
||||
static inline qreal qskRadiusAt( const QskBoxShapeMetrics& shape, Qt::Edge edge )
|
||||
{
|
||||
switch( edge )
|
||||
{
|
||||
case Qt::LeftEdge:
|
||||
{
|
||||
return qMax(
|
||||
shape.radius( Qt::TopLeftCorner ).width(),
|
||||
shape.radius( Qt::BottomLeftCorner ).width()
|
||||
);
|
||||
}
|
||||
case Qt::TopEdge:
|
||||
{
|
||||
return qMax(
|
||||
shape.radius( Qt::TopLeftCorner ).height(),
|
||||
shape.radius( Qt::TopRightCorner ).height()
|
||||
);
|
||||
}
|
||||
case Qt::RightEdge:
|
||||
{
|
||||
return qMax(
|
||||
shape.radius( Qt::TopRightCorner ).width(),
|
||||
shape.radius( Qt::BottomRightCorner ).width()
|
||||
);
|
||||
}
|
||||
case Qt::BottomEdge:
|
||||
{
|
||||
return qMax(
|
||||
shape.radius( Qt::BottomLeftCorner ).height(),
|
||||
shape.radius( Qt::BottomRightCorner ).height()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
QSizeF QskSkinRenderer::textSize( const QskSkinnable* skinnable,
|
||||
const QString& text, const QskTextOptions& options,
|
||||
QskAspect::Subcontrol subControl )
|
||||
@ -60,9 +21,9 @@ QSizeF QskSkinRenderer::textSize( const QskSkinnable* skinnable,
|
||||
|
||||
auto font = skinnable->effectiveFont( subControl );
|
||||
|
||||
if ( options.isRichText( text ) )
|
||||
if ( options.isPlainText( text ) )
|
||||
{
|
||||
QskTextRenderer renderer;
|
||||
QskPlainTextRenderer renderer;
|
||||
renderer.setFont( font );
|
||||
renderer.setOptions( options );
|
||||
|
||||
@ -70,7 +31,7 @@ QSizeF QskSkinRenderer::textSize( const QskSkinnable* skinnable,
|
||||
}
|
||||
else
|
||||
{
|
||||
QskPlainTextRenderer renderer;
|
||||
QskTextRenderer renderer;
|
||||
renderer.setFont( font );
|
||||
renderer.setOptions( options );
|
||||
|
||||
@ -84,15 +45,7 @@ QSizeF QskSkinRenderer::textSize( const QskSkinnable* skinnable,
|
||||
{
|
||||
const auto font = skinnable->effectiveFont( subControl );
|
||||
|
||||
if ( options.isRichText( text ) )
|
||||
{
|
||||
QskTextRenderer renderer;
|
||||
renderer.setFont( font );
|
||||
renderer.setOptions( options );
|
||||
|
||||
return renderer.textRect( boundingSize, text ).size();
|
||||
}
|
||||
else
|
||||
if ( options.isPlainText( text ) )
|
||||
{
|
||||
QskPlainTextRenderer renderer;
|
||||
renderer.setFont( font );
|
||||
@ -100,14 +53,14 @@ QSizeF QskSkinRenderer::textSize( const QskSkinnable* skinnable,
|
||||
|
||||
return renderer.textRect( boundingSize, text ).size();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QskTextRenderer renderer;
|
||||
renderer.setFont( font );
|
||||
renderer.setOptions( options );
|
||||
|
||||
void QskSkinRenderer::updateTextAt( const QskSkinnable* skinnable,
|
||||
const QPointF& pos, const QString& text, const QskTextOptions& options,
|
||||
QskTextNode* textNode, QskAspect::Subcontrol subControl )
|
||||
{
|
||||
const QRectF r( pos.x(), pos.y(), 0.0, 0.0 );
|
||||
updateText( skinnable, r, Qt::AlignLeft, text, options, textNode, subControl );
|
||||
return renderer.textRect( boundingSize, text ).size();
|
||||
}
|
||||
}
|
||||
|
||||
void QskSkinRenderer::updateText( const QskSkinnable* skinnable,
|
||||
@ -137,13 +90,12 @@ void QskSkinRenderer::updateText( const QskSkinnable* skinnable,
|
||||
subControl | Style, Qsk::Normal );
|
||||
}
|
||||
|
||||
const auto isRichText = options.isRichText( text ) ||
|
||||
options.format() == QskTextOptions::StyledText;
|
||||
const auto isPlainText = options.isPlainText( text );
|
||||
|
||||
// doesn't work - we end up with a black rectangle TODO ...
|
||||
#if 0
|
||||
// Optimization: only update the color if that is all that has changed
|
||||
if ( !isRichText && ( ( skinnable->dirtyAspects() & TypeMask ) == Color ) )
|
||||
if ( isPlainText && color_is_dirty )
|
||||
{
|
||||
QskPlainTextRenderer::updateNodeColor( parentNode, textRgb,
|
||||
fontOptions.textStyle, styleRgb );
|
||||
@ -155,35 +107,28 @@ void QskSkinRenderer::updateText( const QskSkinnable* skinnable,
|
||||
{
|
||||
case QskTextOptions::FixedSize:
|
||||
break;
|
||||
|
||||
case QskTextOptions::HorizontalFit:
|
||||
Q_UNIMPLEMENTED();
|
||||
break;
|
||||
|
||||
case QskTextOptions::VerticalFit:
|
||||
font.setPixelSize( bounds.height() * 0.5 );
|
||||
break;
|
||||
|
||||
case QskTextOptions::Fit:
|
||||
Q_UNIMPLEMENTED();
|
||||
break;
|
||||
}
|
||||
|
||||
QColor linkColor;
|
||||
if ( isRichText )
|
||||
if ( !isPlainText )
|
||||
linkColor = skinnable->color( subControl | LinkColor );
|
||||
|
||||
if ( textNode->setTextData( text, bounds.size(), font,
|
||||
options, alignment, textStyle, textColor, styleColor, linkColor ) )
|
||||
{
|
||||
if ( isRichText )
|
||||
{
|
||||
QskTextRenderer renderer;
|
||||
renderer.setFont( font );
|
||||
renderer.setOptions( options );
|
||||
renderer.setAlignment( alignment );
|
||||
|
||||
renderer.updateNode( skinnable->owningControl(), bounds.size(),
|
||||
text, textNode, textColor, textStyle, styleColor, linkColor );
|
||||
}
|
||||
else
|
||||
if ( isPlainText )
|
||||
{
|
||||
QskPlainTextRenderer renderer;
|
||||
renderer.setFont( font );
|
||||
@ -193,52 +138,15 @@ void QskSkinRenderer::updateText( const QskSkinnable* skinnable,
|
||||
renderer.updateNode( skinnable->owningControl(), bounds.size(),
|
||||
text, textNode, textColor, textStyle, styleColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
QskTextRenderer renderer;
|
||||
renderer.setFont( font );
|
||||
renderer.setOptions( options );
|
||||
renderer.setAlignment( alignment );
|
||||
|
||||
renderer.updateNode( skinnable->owningControl(), bounds.size(),
|
||||
text, textNode, textColor, textStyle, styleColor, linkColor );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QskBoxOptions QskSkinRenderer::boxOptions( const QskSkinnable* skinnable,
|
||||
const QSizeF& size, QskAspect::Subcontrol subControl )
|
||||
{
|
||||
using namespace QskAspect;
|
||||
|
||||
QskBoxOptions options;
|
||||
|
||||
options.shape = skinnable->boxShapeHint( subControl ).toAbsolute( size );
|
||||
options.border = skinnable->boxBorderMetricsHint( subControl ).toAbsolute( size );
|
||||
options.borderColors = skinnable->boxBorderColorsHint( subControl );
|
||||
options.fillGradient = skinnable->gradientHint( subControl );
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
QMarginsF QskSkinRenderer::paddingHint(
|
||||
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border,
|
||||
const QSizeF& size, bool inner )
|
||||
{
|
||||
const auto shapeAbsolute = shape.toAbsolute( size );
|
||||
const auto borderAbsolute = border.toAbsolute( size );
|
||||
|
||||
QMarginsF padding(
|
||||
qskRadiusAt( shapeAbsolute, Qt::LeftEdge ),
|
||||
qskRadiusAt( shapeAbsolute, Qt::TopEdge ),
|
||||
qskRadiusAt( shapeAbsolute, Qt::RightEdge ),
|
||||
qskRadiusAt( shapeAbsolute, Qt::BottomEdge )
|
||||
);
|
||||
|
||||
// half of the border goes to the inner side
|
||||
const QMarginsF b = borderAbsolute.widths() * 0.5;
|
||||
|
||||
/*
|
||||
not correct for calculating the outer padding,
|
||||
but to get things started. TODO ...
|
||||
*/
|
||||
|
||||
if ( inner )
|
||||
padding -= b;
|
||||
else
|
||||
padding += b;
|
||||
|
||||
// sin 45° ceiled : 0.70710678;
|
||||
constexpr double f = 1.0 - 0.70710678;
|
||||
return f * padding;
|
||||
}
|
||||
|
@ -13,15 +13,11 @@
|
||||
|
||||
class QskSkinnable;
|
||||
class QskTextOptions;
|
||||
class QskBoxOptions;
|
||||
class QskBoxShapeMetrics;
|
||||
class QskBoxBorderMetrics;
|
||||
class QskTextNode;
|
||||
|
||||
class QPointF;
|
||||
class QRectF;
|
||||
class QSizeF;
|
||||
class QMarginsF;
|
||||
class QString;
|
||||
|
||||
namespace QskSkinRenderer
|
||||
@ -34,22 +30,12 @@ namespace QskSkinRenderer
|
||||
const QString&, const QskTextOptions&,
|
||||
QskTextNode*, QskAspect::Subcontrol );
|
||||
|
||||
QSK_EXPORT void updateTextAt( const QskSkinnable*,
|
||||
const QPointF&, const QString&, const QskTextOptions&,
|
||||
QskTextNode*, QskAspect::Subcontrol );
|
||||
|
||||
QSK_EXPORT QSizeF textSize( const QskSkinnable*,
|
||||
const QString&, const QskTextOptions&, QskAspect::Subcontrol );
|
||||
|
||||
QSK_EXPORT QSizeF textSize( const QskSkinnable*,
|
||||
const QSizeF& boundingSize, const QString&,
|
||||
const QskTextOptions&, QskAspect::Subcontrol );
|
||||
|
||||
QSK_EXPORT QskBoxOptions boxOptions( const QskSkinnable*,
|
||||
const QSizeF&, QskAspect::Subcontrol );
|
||||
|
||||
QSK_EXPORT QMarginsF paddingHint(
|
||||
const QskBoxShapeMetrics&, const QskBoxBorderMetrics&, const QSizeF&, bool inner );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -9,6 +9,9 @@
|
||||
#include "QskSetup.h"
|
||||
#include "QskSkin.h"
|
||||
#include "QskControl.h"
|
||||
#include "QskBoxShapeMetrics.h"
|
||||
#include "QskBoxBorderMetrics.h"
|
||||
#include "QskBoxBorderColors.h"
|
||||
#include "QskGradient.h"
|
||||
#include "QskSkinRenderer.h"
|
||||
#include "QskBoxNode.h"
|
||||
@ -16,7 +19,6 @@
|
||||
#include "QskTextNode.h"
|
||||
#include "QskGraphicNode.h"
|
||||
#include "QskGraphicTextureFactory.h"
|
||||
#include "QskBoxOptions.h"
|
||||
#include "QskFunctions.h"
|
||||
|
||||
#include <QSGSimpleRectNode>
|
||||
@ -78,6 +80,15 @@ static inline QSGNode* qskUpdateGraphicNode(
|
||||
return graphicNode;
|
||||
}
|
||||
|
||||
static inline bool qskIsBoxVisible( const QskBoxBorderMetrics& borderMetrics,
|
||||
const QskBoxBorderColors& borderColors, const QskGradient& gradient )
|
||||
{
|
||||
if ( gradient.isVisible() )
|
||||
return true;
|
||||
|
||||
return !borderMetrics.isNull() && borderColors.isVisible();
|
||||
}
|
||||
|
||||
class QskSkinlet::PrivateData
|
||||
{
|
||||
public:
|
||||
@ -188,10 +199,7 @@ QSGNode* QskSkinlet::updateBackgroundNode(
|
||||
if ( boxNode == nullptr )
|
||||
boxNode = new QskBoxNode();
|
||||
|
||||
QskBoxOptions options;
|
||||
options.fillGradient = gradient;
|
||||
|
||||
boxNode->setBoxData( rect, options );
|
||||
boxNode->setBoxData( rect, gradient );
|
||||
return boxNode;
|
||||
}
|
||||
|
||||
@ -342,21 +350,29 @@ QSGNode* QskSkinlet::updateBoxNode( const QskSkinnable* skinnable,
|
||||
{
|
||||
using namespace QskAspect;
|
||||
|
||||
if ( rect.isEmpty() )
|
||||
const QMarginsF margins = skinnable->marginsHint( subControl | Margin );
|
||||
|
||||
const QRectF boxRect = rect.marginsRemoved( margins );
|
||||
if ( boxRect.isEmpty() )
|
||||
return nullptr;
|
||||
|
||||
const auto options = QskSkinRenderer::boxOptions( skinnable, rect.size(), subControl );
|
||||
if ( !options.isVisible() )
|
||||
auto borderMetrics = skinnable->boxBorderMetricsHint( subControl );
|
||||
borderMetrics = borderMetrics.toAbsolute( boxRect.size() );
|
||||
|
||||
const auto borderColors = skinnable->boxBorderColorsHint( subControl );
|
||||
const auto fillGradient = skinnable->gradientHint( subControl );
|
||||
|
||||
if ( !qskIsBoxVisible( borderMetrics, borderColors, fillGradient ) )
|
||||
return nullptr;
|
||||
|
||||
auto shape = skinnable->boxShapeHint( subControl );
|
||||
shape = shape.toAbsolute( boxRect.size() );
|
||||
|
||||
auto boxNode = static_cast< QskBoxNode* >( node );
|
||||
if ( boxNode == nullptr )
|
||||
boxNode = new QskBoxNode();
|
||||
|
||||
const QMarginsF margins = skinnable->marginsHint( subControl | Margin );
|
||||
const QRectF boxRect = rect.marginsRemoved( margins );
|
||||
|
||||
boxNode->setBoxData( boxRect, options );
|
||||
boxNode->setBoxData( boxRect, shape, borderMetrics, borderColors, fillGradient );
|
||||
|
||||
return boxNode;
|
||||
}
|
||||
@ -373,21 +389,28 @@ QSGNode* QskSkinlet::updateBoxClipNode( const QskSkinnable* skinnable,
|
||||
{
|
||||
using namespace QskAspect;
|
||||
|
||||
if ( rect.isEmpty() )
|
||||
return nullptr;
|
||||
|
||||
const auto options = QskSkinRenderer::boxOptions( skinnable, rect.size(), subControl );
|
||||
if ( !options.isVisible() )
|
||||
return nullptr;
|
||||
|
||||
auto clipNode = static_cast< QskBoxClipNode* >( node );
|
||||
if ( clipNode == nullptr )
|
||||
clipNode = new QskBoxClipNode();
|
||||
|
||||
const QRectF clipRect = rect.marginsRemoved(
|
||||
skinnable->marginsHint( subControl | Margin ) );
|
||||
const QMarginsF margins = skinnable->marginsHint( subControl | Margin );
|
||||
|
||||
clipNode->setBox( clipRect, options.shape, options.border );
|
||||
const QRectF clipRect = rect.marginsRemoved( margins );
|
||||
if ( clipRect.isEmpty() )
|
||||
{
|
||||
clipNode->setIsRectangular( true );
|
||||
clipNode->setClipRect( clipRect );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto borderMetrics = skinnable->boxBorderMetricsHint( subControl );
|
||||
borderMetrics = borderMetrics.toAbsolute( clipRect.size() );
|
||||
|
||||
auto shape = skinnable->boxShapeHint( subControl );
|
||||
shape = shape.toAbsolute( clipRect.size() );
|
||||
|
||||
clipNode->setBox( clipRect, shape, borderMetrics );
|
||||
}
|
||||
|
||||
return clipNode;
|
||||
}
|
||||
|
@ -604,30 +604,60 @@ const char* QskSkinnable::skinStateAsPrintable( QskAspect::State state ) const
|
||||
return bytes[counter].constData();
|
||||
}
|
||||
|
||||
static inline QMarginsF qskMargins( const QskSkinnable* skinnable,
|
||||
static inline QMarginsF qskEffectivePadding( const QskSkinnable* skinnable,
|
||||
QskAspect::Aspect aspect, const QSizeF& size, bool inner )
|
||||
{
|
||||
using namespace QskAspect;
|
||||
using namespace Qt;
|
||||
|
||||
const QMarginsF padding1 = QskSkinRenderer::paddingHint(
|
||||
skinnable->boxShapeHint( aspect | Shape),
|
||||
skinnable->boxBorderMetricsHint( aspect | Border ),
|
||||
size, inner );
|
||||
const auto shape = skinnable->boxShapeHint( aspect | Shape ).toAbsolute( size );
|
||||
const auto borderMetrics = skinnable->boxBorderMetricsHint( aspect | Border );
|
||||
|
||||
const QMarginsF padding2 = skinnable->marginsHint( aspect | Padding );
|
||||
|
||||
const qreal left = qMax( shape.radius( TopLeftCorner ).width(),
|
||||
shape.radius( BottomLeftCorner ).width() );
|
||||
|
||||
const qreal top = qMax( shape.radius( TopLeftCorner ).height(),
|
||||
shape.radius( TopRightCorner ).height() );
|
||||
|
||||
const qreal right = qMax( shape.radius( TopRightCorner ).width(),
|
||||
shape.radius( BottomRightCorner ).width() );
|
||||
|
||||
const qreal bottom = qMax( shape.radius( Qt::BottomLeftCorner ).height(),
|
||||
shape.radius( Qt::BottomRightCorner ).height() );
|
||||
|
||||
QMarginsF padding( left, top, right, bottom );
|
||||
|
||||
// half of the border goes to the inner side
|
||||
const auto borderMargins = borderMetrics.toAbsolute( size ).widths() * 0.5;
|
||||
|
||||
if ( inner )
|
||||
{
|
||||
padding -= borderMargins;
|
||||
}
|
||||
else
|
||||
{
|
||||
// not correct, but to get things started. TODO ...
|
||||
padding += borderMargins;
|
||||
}
|
||||
|
||||
// sin 45° ceiled : 0.70710678;
|
||||
padding *= 1.0 - 0.70710678;
|
||||
|
||||
const QMarginsF paddingHint = skinnable->marginsHint( aspect | Padding );
|
||||
|
||||
return QMarginsF(
|
||||
qMax( padding1.left(), padding2.left() ),
|
||||
qMax( padding1.top(), padding2.top() ),
|
||||
qMax( padding1.right(), padding2.right() ),
|
||||
qMax( padding1.bottom(), padding2.bottom() )
|
||||
qMax( padding.left(), paddingHint.left() ),
|
||||
qMax( padding.top(), paddingHint.top() ),
|
||||
qMax( padding.right(), paddingHint.right() ),
|
||||
qMax( padding.bottom(), paddingHint.bottom() )
|
||||
);
|
||||
}
|
||||
|
||||
QSizeF QskSkinnable::innerBoxSize(
|
||||
QskAspect::Aspect aspect, const QSizeF& outerBoxSize ) const
|
||||
{
|
||||
const QMarginsF m = qskMargins( this, aspect, outerBoxSize, true );
|
||||
const QMarginsF m = qskEffectivePadding( this, aspect, outerBoxSize, true );
|
||||
|
||||
return QSizeF( outerBoxSize.width() - m.left() - m.right(),
|
||||
outerBoxSize.height() - m.top() - m.bottom() );
|
||||
@ -636,14 +666,14 @@ QSizeF QskSkinnable::innerBoxSize(
|
||||
QRectF QskSkinnable::innerBox(
|
||||
QskAspect::Aspect aspect, const QRectF& outerBox ) const
|
||||
{
|
||||
const QMarginsF m = qskMargins( this, aspect, outerBox.size(), true );
|
||||
const QMarginsF m = qskEffectivePadding( this, aspect, outerBox.size(), true );
|
||||
return outerBox.marginsRemoved( m );
|
||||
}
|
||||
|
||||
QSizeF QskSkinnable::outerBoxSize(
|
||||
QskAspect::Aspect aspect, const QSizeF& innerBoxSize ) const
|
||||
{
|
||||
const QMarginsF m = qskMargins( this, aspect, innerBoxSize, false );
|
||||
const QMarginsF m = qskEffectivePadding( this, aspect, innerBoxSize, false );
|
||||
|
||||
return QSizeF( innerBoxSize.width() + m.left() + m.right(),
|
||||
innerBoxSize.height() + m.top() + m.bottom() );
|
||||
@ -652,7 +682,7 @@ QSizeF QskSkinnable::outerBoxSize(
|
||||
QRectF QskSkinnable::outerBox(
|
||||
QskAspect::Aspect aspect, const QRectF& innerBox ) const
|
||||
{
|
||||
const QMarginsF m = qskMargins( this, aspect, innerBox.size(), false );
|
||||
const QMarginsF m = qskEffectivePadding( this, aspect, innerBox.size(), false );
|
||||
return innerBox.marginsAdded( m );
|
||||
}
|
||||
|
||||
|
@ -17,15 +17,32 @@ class QskTextLabel::PrivateData
|
||||
{
|
||||
public:
|
||||
PrivateData( const QString& txt ):
|
||||
effectiveTextFormat( QskTextOptions::AutoText ),
|
||||
text( txt )
|
||||
{
|
||||
effectiveTextFormat = textOptions.format();
|
||||
}
|
||||
|
||||
QskTextOptions textOptions;
|
||||
QskTextOptions effectiveOptions() const
|
||||
{
|
||||
if ( textOptions.format() != QskTextOptions::AutoText )
|
||||
return textOptions;
|
||||
|
||||
if ( effectiveTextFormat == QskTextOptions::AutoText )
|
||||
{
|
||||
effectiveTextFormat = textOptions.isPlainText( text )
|
||||
? QskTextOptions::PlainText : QskTextOptions::RichText;
|
||||
}
|
||||
|
||||
QskTextOptions options = textOptions;
|
||||
options.setFormat( effectiveTextFormat );
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
QskTextOptions::TextFormat effectiveTextFormat;
|
||||
QString text;
|
||||
|
||||
QskTextOptions textOptions;
|
||||
mutable QskTextOptions::TextFormat effectiveTextFormat;
|
||||
};
|
||||
|
||||
QskTextLabel::QskTextLabel( QQuickItem* parent ):
|
||||
@ -50,7 +67,7 @@ void QskTextLabel::setText( const QString& text )
|
||||
return;
|
||||
|
||||
m_data->text = text;
|
||||
m_data->effectiveTextFormat = QskTextOptions::AutoText;
|
||||
m_data->effectiveTextFormat = m_data->textOptions.format();
|
||||
|
||||
resetImplicitSize();
|
||||
update();
|
||||
@ -68,9 +85,6 @@ void QskTextLabel::setTextOptions( const QskTextOptions& options )
|
||||
if ( options == m_data->textOptions )
|
||||
return;
|
||||
|
||||
if ( options.format() != m_data->textOptions.format() )
|
||||
m_data->effectiveTextFormat = QskTextOptions::AutoText;
|
||||
|
||||
#if 0
|
||||
// we are killing user settings of the policy this way ??
|
||||
|
||||
@ -80,6 +94,7 @@ void QskTextLabel::setTextOptions( const QskTextOptions& options )
|
||||
setSizePolicy( policy, sizePolicy().verticalPolicy() );
|
||||
#endif
|
||||
|
||||
m_data->effectiveTextFormat = options.format();
|
||||
m_data->textOptions = options;
|
||||
|
||||
resetImplicitSize();
|
||||
@ -156,27 +171,12 @@ QFont QskTextLabel::font() const
|
||||
return effectiveFont( QskTextLabel::Text );
|
||||
}
|
||||
|
||||
bool QskTextLabel::isRichText() const
|
||||
{
|
||||
if ( m_data->effectiveTextFormat == QskTextOptions::AutoText )
|
||||
{
|
||||
// caching the rich text evaluation
|
||||
const bool isRichRext = m_data->textOptions.isRichText( m_data->text );
|
||||
m_data->effectiveTextFormat = isRichRext ? QskTextOptions::RichText : QskTextOptions::PlainText;
|
||||
}
|
||||
|
||||
return m_data->effectiveTextFormat;
|
||||
}
|
||||
|
||||
QSizeF QskTextLabel::contentsSizeHint() const
|
||||
{
|
||||
if ( !m_data->text.isEmpty() )
|
||||
{
|
||||
QskTextOptions options = textOptions();
|
||||
options.setFormat( isRichText() ? QskTextOptions::RichText : QskTextOptions::PlainText );
|
||||
|
||||
return QskSkinRenderer::textSize(
|
||||
this, m_data->text, options, QskTextLabel::Text );
|
||||
return QskSkinRenderer::textSize( this, m_data->text,
|
||||
m_data->effectiveOptions(), QskTextLabel::Text );
|
||||
}
|
||||
|
||||
return QSizeF( 0, 0 );
|
||||
@ -199,11 +199,9 @@ qreal QskTextLabel::heightForWidth( qreal width ) const
|
||||
maxHeight = m_data->textOptions.maximumLineCount() * lineHeight;
|
||||
}
|
||||
|
||||
QskTextOptions options = textOptions();
|
||||
options.setFormat( isRichText() ? QskTextOptions::RichText : QskTextOptions::PlainText );
|
||||
|
||||
const QSizeF size = QskSkinRenderer::textSize( this,
|
||||
QSizeF( width, maxHeight ), m_data->text, options, QskTextLabel::Text );
|
||||
QSizeF( width, maxHeight ), m_data->text,
|
||||
m_data->effectiveOptions(), QskTextLabel::Text );
|
||||
|
||||
return qCeil( size.height() );
|
||||
}
|
||||
@ -218,11 +216,9 @@ qreal QskTextLabel::widthForHeight( qreal height ) const
|
||||
|
||||
const qreal maxWidth = std::numeric_limits< qreal >::max();
|
||||
|
||||
QskTextOptions options = textOptions();
|
||||
options.setFormat( isRichText() ? QskTextOptions::RichText : QskTextOptions::PlainText );
|
||||
|
||||
const QSizeF size = QskSkinRenderer::textSize( this,
|
||||
QSizeF( maxWidth, height ), m_data->text, options, QskTextLabel::Text );
|
||||
QSizeF( maxWidth, height ), m_data->text,
|
||||
m_data->effectiveOptions(), QskTextLabel::Text );
|
||||
|
||||
return qCeil( size.width() );
|
||||
}
|
||||
|
@ -57,8 +57,6 @@ public:
|
||||
virtual qreal heightForWidth( qreal width ) const override;
|
||||
virtual qreal widthForHeight( qreal height ) const override;
|
||||
|
||||
bool isRichText() const;
|
||||
|
||||
QFont font() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -4,8 +4,12 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "QskBoxNode.h"
|
||||
#include "QskBoxOptions.h"
|
||||
#include "QskBoxRenderer.h"
|
||||
#include "QskBoxShapeMetrics.h"
|
||||
#include "QskBoxBorderMetrics.h"
|
||||
#include "QskBoxBorderColors.h"
|
||||
#include "QskGradient.h"
|
||||
|
||||
|
||||
#include <QSGVertexColorMaterial>
|
||||
#include <QSGFlatColorMaterial>
|
||||
@ -25,19 +29,21 @@ static inline bool qskIsMonochrome( const QRgb* rgbValues )
|
||||
&& ( rgbValues[2] == rgbValues[3] );
|
||||
}
|
||||
|
||||
static inline uint qskMetricsHash( const QskBoxOptions& options )
|
||||
static inline uint qskMetricsHash( const QskBoxShapeMetrics& shape,
|
||||
const QskBoxBorderMetrics& borderMetrics )
|
||||
{
|
||||
uint hash = 13000;
|
||||
|
||||
hash = options.shape.hash( hash );
|
||||
return options.border.hash( hash );
|
||||
hash = shape.hash( hash );
|
||||
return borderMetrics.hash( hash );
|
||||
}
|
||||
|
||||
static inline uint qskColorsHash( const QskBoxOptions& options )
|
||||
static inline uint qskColorsHash( const QskBoxBorderColors& borderColors,
|
||||
const QskGradient& fillGradient )
|
||||
{
|
||||
uint hash = 13000;
|
||||
hash = options.borderColors.hash( hash );
|
||||
return options.fillGradient.hash( hash );
|
||||
hash = borderColors.hash( hash );
|
||||
return fillGradient.hash( hash );
|
||||
}
|
||||
|
||||
QskBoxNode::QskBoxNode():
|
||||
@ -55,11 +61,19 @@ QskBoxNode::~QskBoxNode()
|
||||
delete material();
|
||||
}
|
||||
|
||||
void QskBoxNode::setBoxData( const QRectF& rect, const QskBoxOptions& options )
|
||||
void QskBoxNode::setBoxData( const QRectF& rect, const QskGradient& fillGradient )
|
||||
{
|
||||
setBoxData( rect, QskBoxShapeMetrics(), QskBoxBorderMetrics(),
|
||||
QskBoxBorderColors(), fillGradient );
|
||||
}
|
||||
|
||||
void QskBoxNode::setBoxData( const QRectF& rect,
|
||||
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics,
|
||||
const QskBoxBorderColors& borderColors, const QskGradient& fillGradient )
|
||||
{
|
||||
#if 1
|
||||
const uint metricsHash = qskMetricsHash( options );
|
||||
const uint colorsHash = qskColorsHash( options );
|
||||
const uint metricsHash = qskMetricsHash( shape, borderMetrics );
|
||||
const uint colorsHash = qskColorsHash( borderColors, fillGradient );
|
||||
|
||||
if ( ( metricsHash == m_metricsHash ) &&
|
||||
( colorsHash == m_colorsHash ) && ( rect == m_rect ) )
|
||||
@ -81,11 +95,7 @@ void QskBoxNode::setBoxData( const QRectF& rect, const QskBoxOptions& options )
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& gradient = options.fillGradient;
|
||||
const auto& borderMetrics = options.border;
|
||||
const auto& borderColors = options.borderColors;
|
||||
|
||||
bool hasFill = options.fillGradient.isValid();
|
||||
bool hasFill = fillGradient.isValid();
|
||||
|
||||
bool hasBorder = !borderMetrics.isNull();
|
||||
if ( hasBorder )
|
||||
@ -104,14 +114,14 @@ void QskBoxNode::setBoxData( const QRectF& rect, const QskBoxOptions& options )
|
||||
return;
|
||||
}
|
||||
|
||||
const bool isFillMonochrome = hasFill ? gradient.isMonochrome() : true;
|
||||
const bool isFillMonochrome = hasFill ? fillGradient.isMonochrome() : true;
|
||||
const bool isBorderMonochrome = hasBorder ? borderColors.isMonochrome() : true;
|
||||
|
||||
if ( hasFill && hasBorder )
|
||||
{
|
||||
if ( isFillMonochrome && isBorderMonochrome )
|
||||
{
|
||||
if ( borderColors.color( Qsk::Left ) == gradient.startColor() )
|
||||
if ( borderColors.color( Qsk::Left ) == fillGradient.startColor() )
|
||||
{
|
||||
// we can draw border and background in one
|
||||
hasBorder = false;
|
||||
@ -143,8 +153,8 @@ void QskBoxNode::setBoxData( const QRectF& rect, const QskBoxOptions& options )
|
||||
{
|
||||
setMonochrome( false );
|
||||
|
||||
renderer.renderBox( m_rect, options.shape, options.border,
|
||||
options.borderColors, options.fillGradient, *geometry() );
|
||||
renderer.renderBox( m_rect, shape, borderMetrics,
|
||||
borderColors, fillGradient, *geometry() );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -155,15 +165,13 @@ void QskBoxNode::setBoxData( const QRectF& rect, const QskBoxOptions& options )
|
||||
|
||||
if ( hasFill )
|
||||
{
|
||||
flatMaterial->setColor( gradient.startColor() );
|
||||
renderer.renderFill( m_rect, options.shape,
|
||||
QskBoxBorderMetrics(), *geometry() );
|
||||
flatMaterial->setColor( fillGradient.startColor() );
|
||||
renderer.renderFill( m_rect, shape, QskBoxBorderMetrics(), *geometry() );
|
||||
}
|
||||
else
|
||||
{
|
||||
flatMaterial->setColor( borderColors.color( Qsk::Left ).rgba() );
|
||||
renderer.renderBorder( m_rect, options.shape,
|
||||
options.border, *geometry() );
|
||||
renderer.renderBorder( m_rect, shape, borderMetrics, *geometry() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,10 @@
|
||||
|
||||
#include "QskGlobal.h"
|
||||
|
||||
class QskBoxOptions;
|
||||
class QskBoxShapeMetrics;
|
||||
class QskBoxBorderMetrics;
|
||||
class QskBoxBorderColors;
|
||||
class QskGradient;
|
||||
class QRectF;
|
||||
|
||||
#include <QSGNode>
|
||||
@ -19,7 +22,11 @@ public:
|
||||
QskBoxNode();
|
||||
virtual ~QskBoxNode();
|
||||
|
||||
void setBoxData( const QRectF& rect, const QskBoxOptions& );
|
||||
void setBoxData( const QRectF& rect,
|
||||
const QskBoxShapeMetrics&, const QskBoxBorderMetrics&,
|
||||
const QskBoxBorderColors&, const QskGradient& );
|
||||
|
||||
void setBoxData( const QRectF& rect, const QskGradient& );
|
||||
|
||||
private:
|
||||
void setMonochrome( bool on );
|
||||
|
@ -31,7 +31,6 @@ DEPENDPATH *= $${QSK_SUBDIRS}
|
||||
|
||||
HEADERS += \
|
||||
common/QskAspect.h \
|
||||
common/QskBoxOptions.h \
|
||||
common/QskBoxBorderColors.h \
|
||||
common/QskBoxBorderMetrics.h \
|
||||
common/QskBoxShapeMetrics.h \
|
||||
@ -49,7 +48,6 @@ HEADERS += \
|
||||
|
||||
SOURCES += \
|
||||
common/QskAspect.cpp \
|
||||
common/QskBoxOptions.cpp \
|
||||
common/QskBoxBorderColors.cpp \
|
||||
common/QskBoxBorderMetrics.cpp \
|
||||
common/QskBoxShapeMetrics.cpp \
|
||||
|
Loading…
x
Reference in New Issue
Block a user