QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskPainterCommand.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_PAINTER_COMMAND_H
7#define QSK_PAINTER_COMMAND_H
8
9#include "QskGlobal.h"
10
11#include <qimage.h>
12#include <qpaintengine.h>
13#include <qpainterpath.h>
14#include <qpixmap.h>
15
16class QSK_EXPORT QskPainterCommand
17{
18 public:
19 enum Type : qint8
20 {
21 Invalid = -1,
22
23 Path,
24 Pixmap,
25 Image,
26
27 State
28 };
29
30 struct PixmapData
31 {
32 QRectF rect;
33 QPixmap pixmap;
34 QRectF subRect;
35 };
36
37 struct ImageData
38 {
39 QRectF rect;
40 QImage image;
41 QRectF subRect;
42 Qt::ImageConversionFlags flags;
43 };
44
45 struct StateData
46 {
47 QPaintEngine::DirtyFlags flags;
48
49 QPen pen;
50 QBrush brush;
51 QPointF brushOrigin;
52 QBrush backgroundBrush;
53 Qt::BGMode backgroundMode = Qt::TransparentMode;
54 QFont font;
55 QTransform transform;
56
57 Qt::ClipOperation clipOperation = Qt::NoClip;
58 QRegion clipRegion;
59 QPainterPath clipPath;
60 bool isClipEnabled = false;
61
62 QPainter::RenderHints renderHints;
63 QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver;
64 qreal opacity;
65 };
66
67 constexpr QskPainterCommand() noexcept;
69
70 explicit QskPainterCommand( const QPainterPath& );
71
72 QskPainterCommand( const QRectF& rect,
73 const QPixmap&, const QRectF& subRect );
74
75 QskPainterCommand( const QRectF& rect,
76 const QImage&, const QRectF& subRect,
77 Qt::ImageConversionFlags );
78
79 explicit QskPainterCommand( const QskPainterCommand::StateData& data );
80 explicit QskPainterCommand( const QPaintEngineState& );
81
83
84 QskPainterCommand& operator=( const QskPainterCommand& );
85
86 bool operator==( const QskPainterCommand& other ) const noexcept;
87 bool operator!=( const QskPainterCommand& other ) const noexcept;
88
89 Type type() const noexcept;
90
91 QPainterPath* path() noexcept;
92 const QPainterPath* path() const noexcept;
93
94 PixmapData* pixmapData() noexcept;
95 const PixmapData* pixmapData() const noexcept;
96
97 ImageData* imageData() noexcept;
98 const ImageData* imageData() const noexcept;
99
100 StateData* stateData() noexcept;
101 const StateData* stateData() const noexcept;
102
103 private:
104 void copy( const QskPainterCommand& );
105 void reset();
106
107 Type m_type;
108
109 union
110 {
111 QPainterPath* m_path;
112 PixmapData* m_pixmapData;
113 ImageData* m_imageData;
114 StateData* m_stateData;
115 };
116};
117
118constexpr inline QskPainterCommand::QskPainterCommand() noexcept
119 : m_type( Invalid )
120 , m_path( nullptr )
121{
122}
123
124inline bool QskPainterCommand::operator!=( const QskPainterCommand& other ) const noexcept
125{
126 return !( *this == other );
127}
128
129inline QskPainterCommand::Type QskPainterCommand::type() const noexcept
130{
131 return m_type;
132}
133
134inline const QPainterPath* QskPainterCommand::path() const noexcept
135{
136 return m_path;
137}
138
139inline const QskPainterCommand::PixmapData*
140QskPainterCommand::pixmapData() const noexcept
141{
142 return m_pixmapData;
143}
144
145inline const QskPainterCommand::ImageData*
146QskPainterCommand::imageData() const noexcept
147{
148 return m_imageData;
149}
150
151inline const QskPainterCommand::StateData*
152QskPainterCommand::stateData() const noexcept
153{
154 return m_stateData;
155}
156
157#endif