QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskGraphicTextureFactory.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskGraphicTextureFactory.h"
7#include "QskTextureRenderer.h"
8
9#include <qquickwindow.h>
10
11QskGraphicTextureFactory::QskGraphicTextureFactory()
12{
13}
14
15QskGraphicTextureFactory::QskGraphicTextureFactory(
16 const QskGraphic& graphic, const QSize& size )
17 : m_graphic( graphic )
18 , m_size( size )
19{
20}
21
22QskGraphicTextureFactory::~QskGraphicTextureFactory()
23{
24}
25
26void QskGraphicTextureFactory::setGraphic( const QskGraphic& graphic )
27{
28 m_graphic = graphic;
29}
30
31QskGraphic QskGraphicTextureFactory::graphic() const
32{
33 return m_graphic;
34}
35
36void QskGraphicTextureFactory::setColorFilter(
37 const QskColorFilter& colorFilter )
38{
39 m_colorFilter = colorFilter;
40}
41
42const QskColorFilter& QskGraphicTextureFactory::colorFilter() const
43{
44 return m_colorFilter;
45}
46
47void QskGraphicTextureFactory::setSize( const QSize& size )
48{
49 m_size = size;
50}
51
52QSize QskGraphicTextureFactory::size() const
53{
54 return m_size;
55}
56
57QSGTexture* QskGraphicTextureFactory::createTexture( QQuickWindow* window ) const
58{
59 class PaintHelper : public QskTextureRenderer::PaintHelper
60 {
61 public:
62 PaintHelper( const QskGraphic& graphic, const QskColorFilter& filter )
63 : m_graphic( graphic )
64 , m_filter( filter )
65 {
66 }
67
68 void paint( QPainter* painter, const QSize& size ) override
69 {
70 const QRect rect( 0, 0, size.width(), size.height() );
71 m_graphic.render( painter, rect, m_filter );
72 }
73
74 private:
75 const QskGraphic& m_graphic;
76 const QskColorFilter& m_filter;
77 };
78
79 PaintHelper helper( m_graphic, m_colorFilter );
80 return QskTextureRenderer::createPaintedTexture( window, m_size, &helper );
81}
82
83QSize QskGraphicTextureFactory::textureSize() const
84{
85 return m_size;
86}
87
88int QskGraphicTextureFactory::textureByteCount() const
89{
90 return m_size.width() * m_size.height() * 4;
91}
92
93QImage QskGraphicTextureFactory::image() const
94{
95 return m_graphic.toImage( m_size, Qt::KeepAspectRatio );
96}
A paint device for scalable graphics.
Definition QskGraphic.h:28