2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskTextNode.h"
|
|
|
|
#include "QskTextOptions.h"
|
2017-10-20 20:26:39 +02:00
|
|
|
#include "QskTextColors.h"
|
|
|
|
#include "QskTextRenderer.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
#include <QFont>
|
2017-10-20 15:29:50 +02:00
|
|
|
#include <QColor>
|
2017-07-21 18:21:34 +02:00
|
|
|
#include <QString>
|
|
|
|
|
2017-10-20 20:26:39 +02:00
|
|
|
static inline uint qskHash(
|
|
|
|
const QString& text, const QSizeF& size, const QFont& font,
|
|
|
|
const QskTextOptions& options, const QskTextColors& colors,
|
|
|
|
Qt::Alignment alignment, Qsk::TextStyle textStyle )
|
|
|
|
{
|
|
|
|
uint hash = 11000;
|
|
|
|
|
|
|
|
hash = qHash( text, hash );
|
|
|
|
hash = qHash( font, hash );
|
|
|
|
hash = qHash( options, hash );
|
|
|
|
hash = qHash( alignment, hash );
|
|
|
|
hash = qHash( textStyle, hash );
|
|
|
|
hash = colors.hash( hash );
|
|
|
|
hash = qHashBits( &size, sizeof( QSizeF ), hash );
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QskTextNode::QskTextNode():
|
|
|
|
m_hash( 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskTextNode::~QskTextNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-20 20:26:39 +02:00
|
|
|
void QskTextNode::setTextData( const QQuickItem* item,
|
|
|
|
const QString& text, const QRectF& rect, const QFont& font,
|
|
|
|
const QskTextOptions& options, const QskTextColors& colors,
|
|
|
|
Qt::Alignment alignment, Qsk::TextStyle textStyle )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2017-10-20 20:26:39 +02:00
|
|
|
if ( m_rect != rect )
|
|
|
|
{
|
|
|
|
QMatrix4x4 matrix;
|
|
|
|
matrix.translate( rect.left(), rect.top() );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-10-20 20:26:39 +02:00
|
|
|
if ( matrix != this->matrix() ) // avoid setting DirtyMatrix accidently
|
|
|
|
setMatrix( matrix );
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint hash = qskHash( text, rect.size(), font,
|
|
|
|
options, colors, alignment, textStyle );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
if ( hash == m_hash )
|
2017-10-20 20:26:39 +02:00
|
|
|
return;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
m_hash = hash;
|
2017-10-20 20:26:39 +02:00
|
|
|
|
|
|
|
const QRectF textRect( 0, 0, rect.width(), rect.height() );
|
|
|
|
|
2017-10-23 07:46:46 +02: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
|
|
|
}
|