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 if ( !colors.styleColor().isValid() )
47 textStyle = Qsk::Normal;
48
49 QMatrix4x4 matrix;
50 matrix.translate( rect.left(), rect.top() );
51
52 if ( matrix != this->matrix() ) // avoid setting DirtyMatrix accidently
53 setMatrix( matrix );
54
55 const auto hash = qskHash( text, rect.size(), font,
56 options, colors, alignment, textStyle );
57
58 if ( hash != m_hash )
59 {
60 m_hash = hash;
61
62 const QRectF textRect( 0, 0, rect.width(), rect.height() );
63
64 /*
65 In case of having color changes only we would could
66 go a faster update path: see QskPlainTextRenderer::updateNodeColor.
67 TODO ...
68 */
69 QskTextRenderer::updateNode( text, font, options, textStyle,
70 colors, alignment, textRect, item, this );
71 }
72}