qskinny/src/nodes/QskTextNode.cpp

70 lines
1.9 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2017-07-21 18:21:34 +02:00
*****************************************************************************/
#include "QskTextNode.h"
2017-10-20 20:26:39 +02:00
#include "QskTextColors.h"
2018-08-03 08:15:28 +02:00
#include "QskTextOptions.h"
2017-10-20 20:26:39 +02:00
#include "QskTextRenderer.h"
2017-07-21 18:21:34 +02:00
2018-07-19 14:10:48 +02:00
#include <qfont.h>
#include <qstring.h>
2017-07-21 18:21:34 +02:00
static inline QskHashValue qskHash(
2017-10-20 20:26:39 +02:00
const QString& text, const QSizeF& size, const QFont& font,
const QskTextOptions& options, const QskTextColors& colors,
Qt::Alignment alignment, Qsk::TextStyle textStyle )
{
QskHashValue hash = 11000;
2018-08-03 08:15:28 +02:00
2017-10-20 20:26:39 +02:00
hash = qHash( text, hash );
hash = qHash( font, hash );
2022-03-25 11:21:32 +01:00
hash = options.hash( hash );
2017-10-20 20:26:39 +02:00
hash = qHash( alignment, hash );
2018-08-03 08:15:28 +02:00
hash = qHash( textStyle, hash );
hash = colors.hash( hash );
2017-10-20 20:26:39 +02:00
hash = qHashBits( &size, sizeof( QSizeF ), hash );
return hash;
}
2018-08-03 08:15:28 +02:00
QskTextNode::QskTextNode()
: m_hash( 0 )
2017-07-21 18:21:34 +02:00
{
}
QskTextNode::~QskTextNode()
{
}
2018-08-03 08:15:28 +02:00
void QskTextNode::setTextData(
const QQuickItem* item, const QString& text, const QRectF& rect,
const QFont& font, const QskTextOptions& options, const QskTextColors& colors,
2017-10-20 20:26:39 +02:00
Qt::Alignment alignment, Qsk::TextStyle textStyle )
2017-07-21 18:21:34 +02:00
{
2018-01-03 17:23:40 +01:00
QMatrix4x4 matrix;
matrix.translate( rect.left(), rect.top() );
2017-07-21 18:21:34 +02:00
2018-01-03 17:23:40 +01:00
if ( matrix != this->matrix() ) // avoid setting DirtyMatrix accidently
setMatrix( matrix );
2017-10-20 20:26:39 +02:00
const auto hash = qskHash( text, rect.size(), font,
2017-10-20 20:26:39 +02:00
options, colors, alignment, textStyle );
2017-07-21 18:21:34 +02:00
2018-01-03 17:23:40 +01:00
if ( hash != m_hash )
{
m_hash = hash;
2017-10-20 20:26:39 +02:00
2018-01-03 17:23:40 +01:00
const QRectF textRect( 0, 0, rect.width(), rect.height() );
2017-10-20 20:26:39 +02:00
2018-01-03 17:23:40 +01:00
/*
In case of having color changes only we would could
go a faster update path: see QskPlainTextRenderer::updateNodeColor.
TODO ...
*/
QskTextRenderer::updateNode( text, font, options, textStyle,
colors, alignment, textRect, item, this );
}
2017-07-21 18:21:34 +02:00
}