qskinny/src/graphic/QskPainterCommand.h

175 lines
4.1 KiB
C
Raw Normal View History

2017-07-21 16:21:34 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef QSK_PAINTER_COMMAND_H
#define QSK_PAINTER_COMMAND_H
#include "QskGlobal.h"
2018-08-03 06:15:28 +00:00
2018-07-19 12:10:48 +00:00
#include <qimage.h>
2018-08-03 06:15:28 +00:00
#include <qpaintengine.h>
2018-07-19 12:10:48 +00:00
#include <qpainterpath.h>
2018-08-03 06:15:28 +00:00
#include <qpixmap.h>
2017-07-21 16:21:34 +00:00
class QSK_EXPORT QskPainterCommand
{
2018-08-03 06:15:28 +00:00
public:
2017-07-21 16:21:34 +00:00
//! Type of the paint command
enum Type
{
//! Invalid command
Invalid = -1,
//! Draw a QPainterPath
Path,
//! Draw a QPixmap
Pixmap,
//! Draw a QImage
Image,
//! QPainter state change
State
};
//! Attributes how to paint a QPixmap
struct PixmapData
{
QRectF rect;
QPixmap pixmap;
QRectF subRect;
};
//! Attributes how to paint a QImage
struct ImageData
{
QRectF rect;
QImage image;
QRectF subRect;
Qt::ImageConversionFlags flags;
};
//! Attributes of a state change
2020-05-03 12:01:41 +00:00
struct StateData
2017-07-21 16:21:34 +00:00
{
QPaintEngine::DirtyFlags flags;
QPen pen;
QBrush brush;
QPointF brushOrigin;
QBrush backgroundBrush;
2020-05-03 12:01:41 +00:00
Qt::BGMode backgroundMode = Qt::TransparentMode;
2017-07-21 16:21:34 +00:00
QFont font;
QMatrix matrix;
QTransform transform;
2020-05-03 12:01:41 +00:00
Qt::ClipOperation clipOperation = Qt::NoClip;
2017-07-21 16:21:34 +00:00
QRegion clipRegion;
QPainterPath clipPath;
2020-05-03 12:01:41 +00:00
bool isClipEnabled = false;
2017-07-21 16:21:34 +00:00
QPainter::RenderHints renderHints;
2020-05-03 12:01:41 +00:00
QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver;
2017-07-21 16:21:34 +00:00
qreal opacity;
};
2020-05-03 12:01:41 +00:00
constexpr QskPainterCommand() noexcept;
2017-07-21 16:21:34 +00:00
QskPainterCommand( const QskPainterCommand& );
explicit QskPainterCommand( const QPainterPath& );
QskPainterCommand( const QRectF& rect,
const QPixmap&, const QRectF& subRect );
QskPainterCommand( const QRectF& rect,
const QImage&, const QRectF& subRect,
Qt::ImageConversionFlags );
explicit QskPainterCommand( const QskPainterCommand::StateData& data );
explicit QskPainterCommand( const QPaintEngineState& );
~QskPainterCommand();
QskPainterCommand& operator=( const QskPainterCommand& );
2020-05-03 12:01:41 +00:00
bool operator==( const QskPainterCommand& other ) const noexcept;
bool operator!=( const QskPainterCommand& other ) const noexcept;
2017-07-21 16:21:34 +00:00
2020-05-03 12:01:41 +00:00
Type type() const noexcept;
2017-07-21 16:21:34 +00:00
2020-05-03 12:01:41 +00:00
QPainterPath* path() noexcept;
const QPainterPath* path() const noexcept;
2017-07-21 16:21:34 +00:00
2020-05-03 12:01:41 +00:00
PixmapData* pixmapData() noexcept;
const PixmapData* pixmapData() const noexcept;
2017-07-21 16:21:34 +00:00
2020-05-03 12:01:41 +00:00
ImageData* imageData() noexcept;
const ImageData* imageData() const noexcept;
2017-07-21 16:21:34 +00:00
2020-05-03 12:01:41 +00:00
StateData* stateData() noexcept;
const StateData* stateData() const noexcept;
2017-07-21 16:21:34 +00:00
2018-08-03 06:15:28 +00:00
private:
2017-07-21 16:21:34 +00:00
void copy( const QskPainterCommand& );
void reset();
Type m_type;
union
{
QPainterPath* m_path;
PixmapData* m_pixmapData;
ImageData* m_imageData;
StateData* m_stateData;
};
};
2020-05-03 12:01:41 +00:00
constexpr inline QskPainterCommand::QskPainterCommand() noexcept
: m_type( Invalid )
, m_path( nullptr )
{
}
inline bool QskPainterCommand::operator!=( const QskPainterCommand& other ) const noexcept
2017-07-21 16:21:34 +00:00
{
return !( *this == other );
}
//! \return Type of the command
2020-05-03 12:01:41 +00:00
inline QskPainterCommand::Type QskPainterCommand::type() const noexcept
2017-07-21 16:21:34 +00:00
{
return m_type;
}
//! \return Painter path to be painted
2020-05-03 12:01:41 +00:00
inline const QPainterPath* QskPainterCommand::path() const noexcept
2017-07-21 16:21:34 +00:00
{
return m_path;
}
//! \return Attributes how to paint a QPixmap
inline const QskPainterCommand::PixmapData*
2020-05-03 12:01:41 +00:00
QskPainterCommand::pixmapData() const noexcept
2017-07-21 16:21:34 +00:00
{
return m_pixmapData;
}
//! \return Attributes how to paint a QImage
inline const QskPainterCommand::ImageData*
2020-05-03 12:01:41 +00:00
QskPainterCommand::imageData() const noexcept
2017-07-21 16:21:34 +00:00
{
return m_imageData;
}
//! \return Attributes of a state change
inline const QskPainterCommand::StateData*
2020-05-03 12:01:41 +00:00
QskPainterCommand::stateData() const noexcept
2017-07-21 16:21:34 +00:00
{
return m_stateData;
}
#endif