**
****************************************************************************/
-#include "qsgpainteditem.h"
-#include <private/qsgpainteditem_p.h>
-#include <private/qsgpainternode_p.h>
+#include "qquickpainteditem.h"
+#include <private/qquickpainteditem_p.h>
+#include <private/qsgpainternode_p.h>
#include <private/qsgcontext_p.h>
#include <private/qsgadaptationlayer_p.h>
+
#include <qmath.h>
QT_BEGIN_NAMESPACE
/*!
- \class QSGPaintedItem
- \brief The QSGPaintedItem class provides a way to use the QPainter API in the
+ \class QQuickPaintedItem
+ \brief The QQuickPaintedItem class provides a way to use the QPainter API in the
QML Scene Graph.
\inmodule QtDeclarative
- The QSGPaintedItem makes it possible to use the QPainter API with the QML Scene Graph.
+ The QQuickPaintedItem makes it possible to use the QPainter API with the QML Scene Graph.
It sets up a textured rectangle in the Scene Graph and uses a QPainter to paint
onto the texture. The render target can be either a QImage or a QOpenGLFramebufferObject.
When the render target is a QImage, QPainter first renders into the image then
To enable QPainter to do anti-aliased rendering, use setAntialiasing().
- QSGPaintedItem is meant to make it easier to port old code that is using the
+ QQuickPaintedItem is meant to make it easier to port old code that is using the
QPainter API to the QML Scene Graph API and it should be used only for that purpose.
- To write your own painted item, you first create a subclass of QSGPaintedItem, and then
+ To write your own painted item, you first create a subclass of QQuickPaintedItem, and then
start by implementing its only pure virtual public function: paint(), which implements
the actual painting. To get the size of the area painted by the item, use
contentsBoundingRect().
*/
/*!
- \enum QSGPaintedItem::RenderTarget
+ \enum QQuickPaintedItem::RenderTarget
- This enum describes QSGPaintedItem's render targets. The render target is the
+ This enum describes QQuickPaintedItem's render targets. The render target is the
surface QPainter paints onto before the item is rendered on screen.
\value Image The default; QPainter paints into a QImage using the raster paint engine.
*/
/*!
- \enum QSGPaintedItem::PerformanceHint
+ \enum QQuickPaintedItem::PerformanceHint
This enum describes flags that you can enable to improve rendering
- performance in QSGPaintedItem. By default, none of these flags are set.
+ performance in QQuickPaintedItem. By default, none of these flags are set.
\value FastFBOResizing If your item gets resized often and you are using the
- QSGPaintedItem::FramebufferObject render target, set this flag to true to reduce the
+ QQuickPaintedItem::FramebufferObject render target, set this flag to true to reduce the
item resizing time at the cost of using more graphics memory. Resizing a Framebuffer object
is a costly operation, by enabling this property the Framebuffer Object will use a texture
larger than the actual size of the item to avoid as much as possible resizing it.
/*!
\internal
*/
-QSGPaintedItemPrivate::QSGPaintedItemPrivate()
- : QSGItemPrivate()
+QQuickPaintedItemPrivate::QQuickPaintedItemPrivate()
+ : QQuickItemPrivate()
, contentsScale(1.0)
, fillColor(Qt::transparent)
- , renderTarget(QSGPaintedItem::Image)
+ , renderTarget(QQuickPaintedItem::Image)
, performanceHints(0)
, geometryDirty(false)
, contentsDirty(false)
}
/*!
- Constructs a QSGPaintedItem with the given \a parent item.
+ Constructs a QQuickPaintedItem with the given \a parent item.
*/
-QSGPaintedItem::QSGPaintedItem(QSGItem *parent)
- : QSGItem(*(new QSGPaintedItemPrivate), parent)
+QQuickPaintedItem::QQuickPaintedItem(QQuickItem *parent)
+ : QQuickItem(*(new QQuickPaintedItemPrivate), parent)
{
setFlag(ItemHasContents);
}
/*!
\internal
*/
-QSGPaintedItem::QSGPaintedItem(QSGPaintedItemPrivate &dd, QSGItem *parent)
- : QSGItem(dd, parent)
+QQuickPaintedItem::QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent)
+ : QQuickItem(dd, parent)
{
setFlag(ItemHasContents);
}
/*!
- Destroys the QSGPaintedItem.
+ Destroys the QQuickPaintedItem.
*/
-QSGPaintedItem::~QSGPaintedItem()
+QQuickPaintedItem::~QQuickPaintedItem()
{
}
\sa paint()
*/
-void QSGPaintedItem::update(const QRect &rect)
+void QQuickPaintedItem::update(const QRect &rect)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
d->contentsDirty = true;
if (rect.isNull() && !d->dirtyRect.isNull())
d->dirtyRect = contentsBoundingRect().toAlignedRect();
else
d->dirtyRect |= (contentsBoundingRect() & rect).toAlignedRect();
- QSGItem::update();
+ QQuickItem::update();
}
/*!
\sa setOpaquePainting()
*/
-bool QSGPaintedItem::opaquePainting() const
+bool QQuickPaintedItem::opaquePainting() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
return d->opaquePainting;
}
\sa opaquePainting()
*/
-void QSGPaintedItem::setOpaquePainting(bool opaque)
+void QQuickPaintedItem::setOpaquePainting(bool opaque)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (d->opaquePainting == opaque)
return;
d->opaquePainting = opaque;
- QSGItem::update();
+ QQuickItem::update();
}
/*!
\sa setAntialiasing()
*/
-bool QSGPaintedItem::antialiasing() const
+bool QQuickPaintedItem::antialiasing() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
return d->antialiasing;
}
\sa antialiasing()
*/
-void QSGPaintedItem::setAntialiasing(bool enable)
+void QQuickPaintedItem::setAntialiasing(bool enable)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (d->antialiasing == enable)
return;
\sa setMipmap()
*/
-bool QSGPaintedItem::mipmap() const
+bool QQuickPaintedItem::mipmap() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
return d->mipmap;
}
\sa mipmap()
*/
-void QSGPaintedItem::setMipmap(bool enable)
+void QQuickPaintedItem::setMipmap(bool enable)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (d->mipmap == enable)
return;
\sa setPerformanceHint(), setPerformanceHints()
*/
-QSGPaintedItem::PerformanceHints QSGPaintedItem::performanceHints() const
+QQuickPaintedItem::PerformanceHints QQuickPaintedItem::performanceHints() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
return d->performanceHints;
}
\sa setPerformanceHints(), performanceHints()
*/
-void QSGPaintedItem::setPerformanceHint(QSGPaintedItem::PerformanceHint hint, bool enabled)
+void QQuickPaintedItem::setPerformanceHint(QQuickPaintedItem::PerformanceHint hint, bool enabled)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
PerformanceHints oldHints = d->performanceHints;
if (enabled)
d->performanceHints |= hint;
\sa setPerformanceHint(), performanceHints()
*/
-void QSGPaintedItem::setPerformanceHints(QSGPaintedItem::PerformanceHints hints)
+void QQuickPaintedItem::setPerformanceHints(QQuickPaintedItem::PerformanceHints hints)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (d->performanceHints == hints)
return;
d->performanceHints = hints;
Use this function to know the area painted by the item.
- \sa QSGItem::width(), QSGItem::height(), contentsSize(), contentsScale()
+ \sa QQuickItem::width(), QQuickItem::height(), contentsSize(), contentsScale()
*/
-QRectF QSGPaintedItem::contentsBoundingRect() const
+QRectF QQuickPaintedItem::contentsBoundingRect() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
qreal w = d->width;
QSizeF sz = d->contentsSize * d->contentsScale;
}
/*!
- \property QSGPaintedItem::contentsSize
+ \property QQuickPaintedItem::contentsSize
\brief The size of the contents
The contents size is the size of the item in regards to how it is painted
using the paint() function. This is distinct from the size of the
item in regards to height() and width().
*/
-QSize QSGPaintedItem::contentsSize() const
+QSize QQuickPaintedItem::contentsSize() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
return d->contentsSize;
}
-void QSGPaintedItem::setContentsSize(const QSize &size)
+void QQuickPaintedItem::setContentsSize(const QSize &size)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (d->contentsSize == size)
return;
/*!
This convenience function is equivalent to calling setContentsSize(QSize()).
*/
-void QSGPaintedItem::resetContentsSize()
+void QQuickPaintedItem::resetContentsSize()
{
setContentsSize(QSize());
}
/*!
- \property QSGPaintedItem::contentsScale
+ \property QQuickPaintedItem::contentsScale
\brief The scale of the contents
All painting happening in paint() is scaled by the contents scale. This is distinct
The default value is 1.
*/
-qreal QSGPaintedItem::contentsScale() const
+qreal QQuickPaintedItem::contentsScale() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
return d->contentsScale;
}
-void QSGPaintedItem::setContentsScale(qreal scale)
+void QQuickPaintedItem::setContentsScale(qreal scale)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (d->contentsScale == scale)
return;
}
/*!
- \property QSGPaintedItem::fillColor
+ \property QQuickPaintedItem::fillColor
\brief The item's background fill color.
By default, the fill color is set to Qt::transparent.
*/
-QColor QSGPaintedItem::fillColor() const
+QColor QQuickPaintedItem::fillColor() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
return d->fillColor;
}
-void QSGPaintedItem::setFillColor(const QColor &c)
+void QQuickPaintedItem::setFillColor(const QColor &c)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (d->fillColor == c)
return;
}
/*!
- \property QSGPaintedItem::renderTarget
+ \property QQuickPaintedItem::renderTarget
\brief The item's render target.
This property defines which render target the QPainter renders into, it can be either
- QSGPaintedItem::Image or QSGPaintedItem::FramebufferObject. Both have certains benefits,
+ QQuickPaintedItem::Image or QQuickPaintedItem::FramebufferObject. Both have certains benefits,
typically performance versus quality. Using a framebuffer object avoids a costly upload
of the image contents to the texture in graphics memory, while using an image enables
high quality anti-aliasing.
\warning Resizing a framebuffer object is a costly operation, avoid using
- the QSGPaintedItem::FramebufferObject render target if the item gets resized often.
+ the QQuickPaintedItem::FramebufferObject render target if the item gets resized often.
- By default, the render target is QSGPaintedItem::Image.
+ By default, the render target is QQuickPaintedItem::Image.
*/
-QSGPaintedItem::RenderTarget QSGPaintedItem::renderTarget() const
+QQuickPaintedItem::RenderTarget QQuickPaintedItem::renderTarget() const
{
- Q_D(const QSGPaintedItem);
+ Q_D(const QQuickPaintedItem);
return d->renderTarget;
}
-void QSGPaintedItem::setRenderTarget(RenderTarget target)
+void QQuickPaintedItem::setRenderTarget(RenderTarget target)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (d->renderTarget == target)
return;
}
/*!
- \fn virtual void QSGPaintedItem::paint(QPainter *painter) = 0
+ \fn virtual void QQuickPaintedItem::paint(QPainter *painter) = 0
This function, which is usually called by the QML Scene Graph, paints the
contents of an item in local coordinates.
The function is called after the item has been filled with the fillColor.
- Reimplement this function in a QSGPaintedItem subclass to provide the
+ Reimplement this function in a QQuickPaintedItem subclass to provide the
item's painting implementation, using \a painter.
\note The QML Scene Graph uses two separate threads, the main thread does things such as
/*!
This function is called after the item's geometry has changed.
*/
-void QSGPaintedItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+void QQuickPaintedItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
d->geometryDirty = true;
- QSGItem::geometryChanged(newGeometry, oldGeometry);
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
}
This function is called when the Scene Graph node associated to the item needs to
be updated.
*/
-QSGNode *QSGPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
+QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
{
Q_UNUSED(data);
- Q_D(QSGPaintedItem);
+ Q_D(QQuickPaintedItem);
if (width() <= 0 || height() <= 0) {
delete oldNode;