QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskTextNode.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskTextNode.h"
7#include "QskTextColors.h"
8#include "QskTextOptions.h"
9#include "QskTextRenderer.h"
10
11#include <qfont.h>
12#include <qstring.h>
13
14static inline QskHashValue qskHash(
15 const QString& text, const QSizeF& size, const QFont& font,
16 const QskTextOptions& options, const QskTextColors& colors,
17 Qt::Alignment alignment, Qsk::TextStyle textStyle )
18{
19 QskHashValue hash = 11000;
20
21 hash = qHash( text, hash );
22 hash = qHash( font, hash );
23 hash = options.hash( hash );
24 hash = qHash( alignment, hash );
25 hash = qHash( textStyle, hash );
26 hash = colors.hash( hash );
27 hash = qHashBits( &size, sizeof( QSizeF ), hash );
28
29 return hash;
30}
31
32QskTextNode::QskTextNode()
33 : m_hash( 0 )
34{
35}
36
37QskTextNode::~QskTextNode()
38{
39}
40
41void QskTextNode::setTextData(
42 const QQuickItem* item, const QString& text, const QRectF& rect,
43 const QFont& font, const QskTextOptions& options, const QskTextColors& colors,
44 Qt::Alignment alignment, Qsk::TextStyle textStyle )
45{
46 QMatrix4x4 matrix;
47 matrix.translate( rect.left(), rect.top() );
48
49 if ( matrix != this->matrix() ) // avoid setting DirtyMatrix accidently
50 setMatrix( matrix );
51
52 const auto hash = qskHash( text, rect.size(), font,
53 options, colors, alignment, textStyle );
54
55 if ( hash != m_hash )
56 {
57 m_hash = hash;
58
59 const QRectF textRect( 0, 0, rect.width(), rect.height() );
60
61 /*
62 In case of having color changes only we would could
63 go a faster update path: see QskPlainTextRenderer::updateNodeColor.
64 TODO ...
65 */
66 QskTextRenderer::updateNode( text, font, options, textStyle,
67 colors, alignment, textRect, item, this );
68 }
69}