QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGraphicNode.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskGraphicNode.h"
7#include "QskGraphic.h"
8#include "QskColorFilter.h"
9#include "QskPainterCommand.h"
10
11namespace
12{
13 class GraphicData
14 {
15 public:
16 const QskGraphic& graphic;
17 const QskColorFilter& colorFilter;
18 };
19}
20
21QskGraphicNode::QskGraphicNode()
22{
23}
24
25QskGraphicNode::~QskGraphicNode()
26{
27}
28
29void QskGraphicNode::setGraphic( QQuickWindow* window, const QskGraphic& graphic,
30 const QskColorFilter& colorFilter, const QRectF& rect )
31{
32 QSizeF size;
33
34 if ( graphic.commandTypes() == QskGraphic::RasterData )
35 {
36 /*
37 simple raster data - usually a QImage/QPixmap only.
38 There is no benefit in rescaling it into the target rectangle
39 by the CPU and creating a new texture.
40 */
41 size = graphic.defaultSize();
42 }
43
44 const GraphicData graphicData { graphic, colorFilter };
45 update( window, rect, size, &graphicData );
46}
47
48void QskGraphicNode::paint( QPainter* painter, const QSize& size, const void* nodeData )
49{
50 const auto graphicData = reinterpret_cast< const GraphicData* >( nodeData );
51
52 const auto& graphic = graphicData->graphic;
53 const auto& colorFilter = graphicData->colorFilter;
54
55 const QRectF rect( 0, 0, size.width(), size.height() );
56 graphic.render( painter, rect, colorFilter, Qt::IgnoreAspectRatio );
57}
58
59QskHashValue QskGraphicNode::hash( const void* nodeData ) const
60{
61 const auto graphicData = reinterpret_cast< const GraphicData* >( nodeData );
62
63 const auto& graphic = graphicData->graphic;
64
65 QskHashValue hash = 12000;
66
67 const auto& substitutions = graphicData->colorFilter.substitutions();
68 if ( substitutions.size() > 0 )
69 {
70 hash = qHashBits( substitutions.constData(),
71 substitutions.size() * sizeof( substitutions[ 0 ] ), hash );
72 }
73
74 return graphic.hash( hash );
75}
A paint device for scalable graphics.
Definition QskGraphic.h:28