| CMakeLists.txt |
|
6444 |
- |
| doc |
|
|
- |
| engine |
|
|
- |
| qcanvasboxgradient.cpp |
!
\class QCanvasBoxGradient
\since 6.11
\brief QCanvasBoxGradient is a brush for box gradient painting.
\inmodule QtCanvasPainter
Box gradient interpolate colors between start and end points, creating
a rounded rectangle shaped gradient. With the \l setRadius() and
\l setFeather() the roundness and softness of the gradient can be
controlled.
\image qcboxgradient-gallery.webp
{Four squares with rounded-rectangle box gradients of varying
color, corner radius, and edge softness}
Here is a simple example:
\table
\row
\li \inlineimage qcboxgradient-example.webp
{Dark blue rounded square with a soft yellow glow along its edges}
\li
\code
QRectF rect(20, 20, 160, 160);
QCanvasBoxGradient bg(rect);
bg.setFeather(20);
bg.setRadius(50);
bg.setColorAt(0.0, "#1a2a6c");
bg.setColorAt(0.2, "#fdbb2d");
bg.setColorAt(1.0, QColorConstants::Transparent);
p->setFillStyle(bg);
p->fillRect(rect);
\endcode
\endtable
\note When QCanvasBoxGradient is used to paint round rectangle, it is usually
better to use \l QCanvasPainter::rect() than \l QCanvasPainter::roundRect() as the
rounding comes from the brush rather than the path. This avoids creating
extra vertices and thus performs better.
|
6922 |
- |
| qcanvasboxgradient.h |
|
1954 |
- |
| qcanvasboxshadow.cpp |
!
\class QCanvasBoxShadow
\since 6.11
\brief QCanvasBoxShadow is a brush for painting rectangle shadows / glows.
\inmodule QtCanvasPainter
QCanvasBoxShadow is a rounded rectangle brush with blur applied.
The performance of QCanvasBoxShadow is much better than a general shadow that
creates blurred shadow/glow of any shaped item, as it uses SDF approach.
The features of QCanvasBoxShadow are similar to CSS box-shadow, with radius,
spread, blur and color values.
The rendering output also matches the CSS box-shadow, with few notable
differences to make the QCanvasBoxShadow as high-performance as possible.
Blurring is calculated mathematically in the shader rather than using
Gaussian blur, which CSS box-shadow implementations often use. This makes
the shadow look slightly different, especially when the blur amount
grows bigger than half of the shadow width / height.
Here are screenshots to compare the rendering output of QCanvasBoxShadow and
CSS box-shadow in the Chrome browser. These show how blur radius of
0, 10, 20 and 40 pixels affect smaller shadows.
CSS box-shadow:
\image examples_css_box_shadow.png
{Rows of a black bar and a black dot with CSS box-shadow blur of 0,
10, 20, and 40 pixels}
QCanvasBoxShadow:
\image examples_qcpainter_box_shadow.png
{Rows of a black bar and a black dot with QCanvasBoxShadow blur of
0, 10, 20, and 40 pixels}
|
16311 |
- |
| qcanvasboxshadow.h |
|
3667 |
- |
| qcanvasboxshadow_p.h |
|
2545 |
- |
| qcanvasbrush.cpp |
!
\class QCanvasBrush
\since 6.11
\brief QCanvasBrush is the base class for all QCanvasPainter fill / stroke brushes.
\inmodule QtCanvasPainter
QCanvasBrush is the base class for all styles used for \l QCanvasPainter::fill()
and \l QCanvasPainter::stroke().
|
3949 |
- |
| qcanvasbrush.h |
|
2088 |
- |
| qcanvasbrush_p.h |
|
1484 |
- |
| qcanvasconicalgradient.cpp |
!
\class QCanvasConicalGradient
\since 6.11
\brief QCanvasConicalGradient is a brush for conical gradient painting.
\inmodule QtCanvasPainter
Conical gradient interpolate colors between start and end points
around a point with given coordinates. The angle starts from a line
going horizontally right from the center, and proceeds clockwise.
\image qcconicalgradient-gallery.webp
{Four squares with conical gradients sweeping around a center
point, varying in color}
Here is a simple example:
\table
\row
\li \inlineimage qcconicalgradient-example.webp
{Circle with a conical gradient sweeping from yellow through blue
and back to yellow}
\li
\code
QRectF rect(20, 20, 160, 160);
QCanvasConicalGradient cg(rect.center(), 1.75 * M_PI);
cg.setColorAt(0.0, "#fdbb2d");
cg.setColorAt(0.5, "#1a2a6c");
cg.setColorAt(1.0, "#fdbb2d");
p->setFillStyle(cg);
p->beginPath();
p->ellipse(rect);
p->fill();
\endcode
\endtable
|
5957 |
- |
| qcanvasconicalgradient.h |
|
1828 |
- |
| qcanvascustombrush.cpp |
|
17239 |
- |
| qcanvascustombrush.h |
|
2844 |
- |
| qcanvascustombrush_p.h |
|
2757 |
- |
| qcanvasdebugcountervisualizer.cpp |
|
4771 |
- |
| qcanvasdebugcountervisualizer_p.h |
|
1117 |
- |
| qcanvasgradient.cpp |
!
\class QCanvasGradient
\since 6.11
\brief QCanvasGradient is the base class for all QCanvasPainter gradient brushes.
\inmodule QtCanvasPainter
QCanvasGradient is the base class for all QCanvasPainter gradient brushes.
Currently there are four type of gradients: \l QCanvasLinearGradient,
\l QCanvasRadialGradient, \l QCanvasConicalGradient and \l QCanvasBoxGradient.
If no stops are provided with \l setStartColor, \l setEndColor, \l setColorAt or \l setStops,
the gradient is rendered as transparent black (0,0,0,0).
If only a single stop is provided, the gradient is filled with this color.
QCanvasPainter uses two different approaches for painting gradients.
\list
\li With maximum of 2 stops, the colors are passed into shader as 2 vec4 uniforms.
This makes animating 2 stop gradients very performant, with no extra steps in between.
\li With more than 2 stops, the colors are passed into shader as a one dimensional texture.
By default the texture size is 1x256 pixels, optimized for quality and performance.
The textures are cached, so when gradient stops or colors don't change, previous texture
can be reused even when other gradient properties (like position, angle etc.) change.
Although animating multi-stop gradients is fast, it will cause texture uploads, so
consider if it is worth it.
\endlist
There are few environment variables to control the gradients texture usage:
\list
\li QCPAINTER_DISABLE_TEXTURE_USAGE_TRACKING - By default, gradient texture usage is
tracked and kept under the max amount. Set this environment variable to disable
the tracking and keep all gradient textures in memory.
\li QCPAINTER_MAX_TEXTURES - By default, the maximum amount of textures is \c 1024.
Set this environt variable to contain number of desired maximum texture amount.
The currently unused temporary gradient textures are automatically removed when
the maximum amount is reached. \note This does not have an effect when the
texture usage tracking has been disabled.
\endlist
|
21491 |
- |
| qcanvasgradient.h |
|
3773 |
- |
| qcanvasgradient_p.h |
|
6408 |
- |
| qcanvasgridpattern.cpp |
!
\class QCanvasGridPattern
\since 6.11
\brief QCanvasGridPattern is a brush for painting grid patterns.
\inmodule QtCanvasPainter
QCanvasGridPattern is a brush for painting grid and bar patterns.
Here is a simple example:
\code
// Rotated grid into background
QRectF rect(20, 20, 180, 180);
QCanvasGridPattern gp1(rect.topLeft(), QSizeF(16, 16));
gp1.setLineColor("#DBEB00");
gp1.setBackgroundColor("#373F26");
gp1.setLineWidth(2.0);
gp1.setRotation(M_PI / 4);
gp1.setFeather(5.0);
painter.setFillStyle(gp1);
painter.fillRect(rect);
// Rounded rectangle, stroked with
// grid pattern for dashes.
qreal strokeW = 10;
QRectF rect2(40, 40, 140, 140);
QCanvasGridPattern gp2;
gp2.setLineColor(Qt::transparent);
gp2.setBackgroundColor(Qt::white);
gp2.setStartPosition(rect2.x() - strokeW,
rect2.y() - strokeW);
gp2.setCellSize(40, 40);
gp2.setLineWidth(strokeW);
painter.setLineWidth(8);
painter.setStrokeStyle(gp2);
painter.beginPath();
painter.roundRect(rect2, 10);
painter.stroke();
\endcode
\image gridpattern_example_1.png
{Rounded square filled with a yellow diagonal grid and bordered by
a dashed white stroke}
|
11488 |
- |
| qcanvasgridpattern.h |
|
3623 |
- |
| qcanvasgridpattern_p.h |
|
2247 |
- |
| qcanvasimage.cpp |
!
\class QCanvasImage
\since 6.11
\brief QCanvasImage is the image class for QCanvasPainter.
\inmodule QtCanvasPainter
QCanvasImage is the image class used by QCanvasPainter.
To be able to paint images, they fist need to be made available
with e.g. \l QCanvasPainter::addImage(). Then images can be painted
as-is using \l QCanvasPainter::drawImage() or used with
\l QCanvasImagePattern brush to fill / stroke.
Here is a simple example:
\code
static QImage logoImage(":/qtlogo.png");
// Paint an image pattern.
QCanvasImage bg = painter.addImage(logoImage,
QCanvasPainter::ImageFlag::Repeat |
QCanvasPainter::ImageFlag::GenerateMipmaps);
QCanvasImagePattern ip(bg, 0, 0, 44, 32);
painter.setFillStyle(ip);
painter.fillRect(50, 50, 320, 230);
// Paint a single image, with tint color.
QCanvasImage logo = painter.addImage(logoImage);
logo.setTintColor("#2cde85");
painter.drawImage(logo, 100, 80);
\endcode
\image image_example_1.png
{Green-tinted Qt logo drawn over a tiled background of small Qt
logos}
In the above example the QImage is static and addImage() is called
on every repaint. This is not a problem as when the image and flags
remain the same, addImage() fetches the image from cache instead of
uploads it again as a texture. But a more common approac is having
QCanvasImage variables as class members and calling \l QCanvasPainter::addImage()
e.g. in \l QCanvasPainterItemRenderer::initializeResources().
Similarly to QCanvasBrush and QCanvasOffscreenCanvas, QCanvasImage is explicitly shared.
See \l{Implicit Data Sharing} and \l QSharedDataPointer for details.
\note A QCanvasImage object contains only a handle to a graphics resource, such
as a texture. Even when a detach occurs, the actual resource, i.e. the
underlying texture and the image data in it, is never actually copied or
duplicated. The actual owner of the real graphics resource (e.g., a
QRhiTexture) is the QCanvasPainter that handed out the QCanvasImage via
\l{QCanvasPainter::}{addImage()}.
A QCanvasImage always belongs to the QCanvasPainter that created it. Manually
removing images is done by calling \l{QCanvasPainter::}{removeImage()}. In
most cases this will not be necessary, however, since the painter will
automatically destroy any images during its own destruction.
|
8296 |
- |
| qcanvasimage.h |
|
2110 |
- |
| qcanvasimage_p.h |
|
1120 |
- |
| qcanvasimagepattern.cpp |
!
\class QCanvasImagePattern
\since 6.11
\brief QCanvasImagePattern is a brush for painting image patterns.
\inmodule QtCanvasPainter
QCanvasImagePattern is a brush for painting image patterns.
To use QCanvasImage as a pattern, it should have some repeat
flags turned on like \l QCanvasPainter::ImageFlag::Repeat.
Here is a simple example:
\code
// Setup 2 image patterns
static QImage image1(":/pattern2.png");
static QImage image2(":/pattern3.png");
auto flags = QCanvasPainter::ImageFlag::Repeat |
QCanvasPainter::ImageFlag::GenerateMipmaps;
QCanvasImage bg1 = painter.addImage(image1, flags);
QCanvasImage bg2 = painter.addImage(image2, flags);
QCanvasImagePattern ip1(bg1, 0, 0, 64, 64);
QCanvasImagePattern ip2(bg2, 0, 0, 32, 32);
// Fill and stroke round rectangle with
// these image pattern brushes.
painter.beginPath();
painter.roundRect(50, 50, 180, 180, 40);
painter.setFillStyle(ip1);
painter.setStrokeStyle(ip2);
painter.fill();
painter.setLineWidth(20);
painter.stroke();
\endcode
\image imagepattern_example_1.png
{Rounded square tiled with concentric-circle pattern and a green
diagonal-stripe border}
\note When using image patterns, images are often scaled to smaller
and it can be useful to set \l QCanvasPainter::ImageFlag::GenerateMipmaps
for the used QCanvasImage to have smooth patterns.
|
11665 |
- |
| qcanvasimagepattern.h |
|
3727 |
- |
| qcanvasimagepattern_p.h |
|
2445 |
- |
| qcanvaslineargradient.cpp |
!
\class QCanvasLinearGradient
\since 6.11
\brief QCanvasLinearGradient is a brush for linear gradient painting.
\inmodule QtCanvasPainter
Liner gradient interpolate colors between start and end points
along a linear pattern, so horizontally, vertically or diagonally.
The gradient starts from \a startPosition() and ends to \a endPosition().
Outside this area, the colors are the starting and the ending color.
\image qclineargradient-gallery.webp
{Four squares with linear gradients running vertically,
horizontally, diagonally, and as horizontal color bands}
Here is a simple example:
\table
\row
\li \inlineimage qclineargradient-example.webp
{Square with a diagonal linear gradient from blue to red to yellow}
\li
\code
QRectF rect1(0, 0, 200, 200);
QCanvasLinearGradient lg(rect1.topLeft(),
rect1.bottomRight());
lg.setColorAt(0.0, "#1a2a6c");
lg.setColorAt(0.5, "#b21f1f");
lg.setColorAt(1.0, "#fdbb2d");
p->setFillStyle(lg);
p->fillRect(rect1);
\endcode
\endtable
|
6379 |
- |
| qcanvaslineargradient.h |
|
2005 |
- |
| qcanvasoffscreencanvas.cpp |
!
\class QCanvasOffscreenCanvas
\since 6.11
\brief QCanvasOffscreenCanvas represents an offscreen canvas that QCanvasPainter can target.
\inmodule QtCanvasPainter
An offscreen canvas is essentially a color buffer (a QRhiTexture), and
possibly other associated graphics resources. After content has been
rendered into the canvas's color buffer, the canvas can be
\l{QCanvasPainter::addImage()}{registered} to the painter to retrieve a QCanvasImage
that can then be used in \l{QCanvasPainter::drawImage()}{drawImage()} calls or as
an \l{QCanvasImagePattern}{image pattern}.
To create an offscreen canvas, call \l QCanvasPainter::createCanvas(). To target
an offscreen canvas with with draw commands, call the appropriate \l
QCanvasRhiPaintDriver::beginPaint() overload when working with the lower level
API, or \l QCanvasPainterWidget::beginCanvasPainting() or \l
QCanvasPainterItemRenderer::beginCanvasPainting() when using the convenience
widget or Qt Quick item classes.
Similarly to QCanvasImage and QCanvasBrush, QCanvasOffscreenCanvas is explicitly shared.
See \l{Implicit Data Sharing} and \l QSharedDataPointer for details.
\note As with QCanvasImage, a QCanvasOffscreenCanvas can be seen as an object merely
containing handles. Even when a detach occurs, the actual resources, e.g.
the underlying texture and the image data in it, are never actually copied
or duplicated. The actual owner of any real graphics resources (e.g., a
QRhiTexture) is the QCanvasPainter that handed out the QCanvasOffscreenCanvas via
\l{QCanvasPainter::}{createCanvas()}.
A canvas always belongs to the QCanvasPainter that created it. Manually
destroying canvases is done by calling \l{QCanvasPainter::}{destroyCanvas()}. In
most cases this will not be necessary, however, since the painter will
automatically destroy any canvases during its own destruction.
|
7498 |
- |
| qcanvasoffscreencanvas.h |
|
2246 |
- |
| qcanvasoffscreencanvas_p.h |
|
1051 |
- |
| qcanvaspainter.cpp |
|
98468 |
- |
| qcanvaspainter.h |
|
14597 |
- |
| qcanvaspainter_p.h |
|
4211 |
- |
| qcanvaspainterfactory.cpp |
!
\class QCanvasPainterFactory
\since 6.11
\brief QCanvasPainterFactory manages instances of QCanvasPainter and the associated rendering engine.
\inmodule QtCanvasPainter
Applications rendering via QCanvasPainter do not create instances of the painter
class themselves, but rather are expected to use a QCanvasPainterFactory.
\note This class is relevant only when working with QCanvasPainter \b without a
convenience class such as QCanvasPainterWidget or QCanvasPainterItem, because
those provide a QCanvasPainter instance to the application.
The following is an example code snippet of getting a QCanvasPainter for use with
an existing, successfully initialized QRhi:
\code
std::unique_ptr<QCanvasPainterFactory> factory(new QCanvasPainterFactory);
QCanvasPainter *painter = factory->create(rhi);
QCanvasRhiPaintDriver *paintDriver = factory->paintDriver();
\endcode
All drawing code that operates on the same thread with the same QRhi is
recommended to share and reuse the same QCanvasPainter, instead of having a
dedicated painter (and so factory) in each component. This can be achieved
by calling sharedInstance(), instead of constructing a new QCanvasPainterFactory:
\code
QCanvasPainterFactory *factory = QCanvasPainterFactory::sharedInstance(rhi);
QCanvasPainter *painter = factory->painter();
QCanvasRhiPaintDriver *paintDriver = factory->paintDriver();
\endcode
|
6510 |
- |
| qcanvaspainterfactory.h |
|
1240 |
- |
| qcanvaspainterfactory_p.h |
|
1058 |
- |
| qcanvaspainteritem.cpp |
!
\class QCanvasPainterItem
\since 6.11
\brief The QCanvasPainterItem class provides a way to use the Qt Canvas Painter API in the
QML Scene Graph.
\inmodule QtCanvasPainter
To write your own painted item, you first create a subclass of
QCanvasPainterItem, and then start by implementing its only pure virtual
public function: createItemRenderer(), which returns an object that performs
the actual painting.
The below code snippet shows the typical structure of a QCanvasPainterItem
subclass. See QCanvasPainterItemRenderer for an example of the \c MyRenderer
class.
\snippet item-ex-1.cpp 0
Using the \l QtQuick::Item::antialiasing property, it is possible to disable
antialiasing. The default value is \c true. When this is set to \c false,
it disables antialiasing even if the painting code calls
\l QCanvasPainter::setAntialias() with a value bigger than \c 0.
Disabling antialiasing potentially increases the performance.
\sa QCanvasPainterItemRenderer
|
6471 |
- |
| qcanvaspainteritem.h |
|
1529 |
- |
| qcanvaspainteritem_p.h |
|
1064 |
- |
| qcanvaspainteritemrenderer.cpp |
!
\class QCanvasPainterItemRenderer
\since 6.11
\brief The QCanvasPainterItemRenderer handles all painting for a QCanvasPainterItem.
\inmodule QtCanvasPainter
Implement the paint() method to perform the rendering.
To expose data from the item to the renderer in a thread-safe manner,
implement synchronizeData().
The renderer object lives and operates on the \l {Scene Graph and
Rendering}{Qt Quick scene graph render thread}, if there is one, since that
is the thread on which \l{QCanvasPainterItem::}{createItemRenderer()} and
all the functions in this class are invoked.
If the QCanvasPainterItem is moved to a different \l{QQuickWindow}{window},
it will get associated with a new \l QRhi. Therefore, the renderer object is
automatically destroyed, and a new one is created by invoking
\l{QCanvasPainterItem::}{createItemRenderer()} again. This allows simple
management of QCanvasImage and QCanvasOffscreenCanvas objects, because they can be
member variables in renderer, set up either in initializeResources() or in
paint(), without having to reset them when the graphics resources are lost
due to the window and QRhi change, since it all happens implicitly by the
destruction of the whole renderer object.
The below code snippet shows the typical structure of a
QCanvasPainterItemRenderer subclass. See QCanvasPainterItem for an example of
the \c MyItem class.
\snippet renderer-ex-1.cpp 0
\sa QCanvasPainterItem
|
15856 |
- |
| qcanvaspainteritemrenderer.h |
|
2542 |
- |
| qcanvaspainteritemrenderer_p.h |
|
1810 |
- |
| qcanvaspainterwidget.cpp |
!
\class QCanvasPainterWidget
\since 6.11
\brief QCanvasPainterWidget is a widget for rendering using QCanvasPainter.
\inmodule QtCanvasPainter
Implement the \l paint virtual function in a subclass to perform rendering
using a QCanvasPainter.
The below code snippet shows the typical structure of a QCanvasPainterWidget
subclass:
\snippet widget-ex-1.cpp 0
|
11231 |
- |
| qcanvaspainterwidget.h |
|
2305 |
- |
| qcanvaspainterwidget_p.h |
|
1165 |
- |
| qcanvaspath.cpp |
QCanvasPath is native path format of QCanvasPainter.
It has some similarities to QPainterPath, but prioritizes performance and simplicity over features.
Some differences:
- Elements format is private so it can be more optimal.
- No setElementPositionAt() method. No ability to adjust existing path elements makes
it simpler to detect when the path has changed (commandsCount or pathIterations has changed).
- No length(), percentAtLength() or pointAtPercent() methods. The length of the path is not calculated.
- No contains(), intersects() or subtracted() methods. The path area is not calculated.
- No translate() or translated() methods. Instead of translating all path elements one-by-one,
they can be translated (and rotatated & scaled) when renderered.
- No addText() method. Text is not supported natively as a path element.
So in terms of functionality, QCanvasPath is closer to HTML Canvas API Path2D object:
https://developer.mozilla.org/en-US/docs/Web/API/Path2D
|
44659 |
- |
| qcanvaspath.h |
|
7567 |
- |
| qcanvaspath_p.h |
|
1819 |
- |
| qcanvasradialgradient.cpp |
!
\class QCanvasRadialGradient
\since 6.11
\brief QCanvasRadialGradient is a brush for radial gradient painting.
\inmodule QtCanvasPainter
Radial gradient interpolate colors between start and end points, creating
a circle shaped gradient. The gradient is controlled with \l centerPosition(),
\l outerRadius() and \l innerRadius().
\image qcradialgradient-gallery.webp
{Four squares with radial gradients radiating from a center point,
varying in color and center offset}
Here is a simple example:
\table
\row
\li \inlineimage qcradialgradient-example.webp
{Square with a radial gradient from a yellow center through red to a
blue edge}
\li
\code
QRectF rect1(0, 0, 200, 200);
QCanvasRadialGradient rg(rect1.center(), 0, 100);
rg.setColorAt(0.0, "#fdbb2d");
rg.setColorAt(0.6, "#b21f1f");
rg.setColorAt(1.0, "#1a2a6c");
p->setFillStyle(rg);
p->fillRect(rect1);
\endcode
\endtable
|
10782 |
- |
| qcanvasradialgradient.h |
|
3177 |
- |
| qcanvasrhipaintdriver.cpp |
!
\class QCanvasRhiPaintDriver
\since 6.11
\brief The QCanvasRhiPaintDriver class manages the lower level aspects of QCanvasPainter-based rendering for QRhi render targets and offscreen canvases.
\inmodule QtCanvasPainter
Applications wishing to render with QCanvasPainter onto a QRhi-based render
target, such as into a QRhiTexture, or to the color buffer of a
QRhiSwapChain, use QCanvasPainterFactory to initialize and retrieve a QCanvasPainter
and QCanvasRhiPaintDriver associated with the QRhi. The drawing API is provided
by QCanvasPainter, while the low-level aspects of rendering (what is the render
target, what is the command buffer, etc.) are controlled by
QCanvasRhiPaintDriver.
\note This class is relevant only when working with QCanvasPainter \b without a
convenience class such as QCanvasPainterWidget or QCanvasPainterItem, because
those provide a QCanvasPainter instance to the application and manage its
rendering implicitly.
Applications do not create instances of QCanvasRhiPaintDriver themselves. Rather,
retrieve it from a successfully \l{QCanvasPainterFactory::create()}{initialized}
QCanvasPainterFactory by calling
\l{QCanvasPainterFactory::paintDriver()}{paintDriver()}.
The following is an almost complete, standalone console application that
draws a circle into a QRhiTexture, reads back the result, and saves it into
a PNG file:
\snippet paintdriver-ex-1.cpp 0
|
13892 |
- |
| qcanvasrhipaintdriver.h |
|
3075 |
- |
| qcanvasrhipaintdriver_p.h |
|
1269 |
- |
| qcpaint_p.h |
|
1111 |
- |
| QtCanvasPainterBuildInternals.cmake |
|
596 |
- |
| qtcanvaspainterglobal.h |
|
367 |
- |
| qtcanvaspainterglobal_p.h |
|
569 |
- |