diff options
Diffstat (limited to 'src/imports/shapes/qquickshape.cpp')
-rw-r--r-- | src/imports/shapes/qquickshape.cpp | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/src/imports/shapes/qquickshape.cpp b/src/imports/shapes/qquickshape.cpp index 518f7a08cf..54a0a3d402 100644 --- a/src/imports/shapes/qquickshape.cpp +++ b/src/imports/shapes/qquickshape.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(QQSHAPE_LOG_TIME_DIRTY_SYNC, "qt.shape.time.sync") /*! - \qmlmodule QtQuick.Shapes 1.0 + \qmlmodule QtQuick.Shapes 1.11 \title Qt Quick Shapes QML Types \ingroup qmlmodules \brief Provides QML types for drawing stroked and filled shapes. @@ -61,7 +61,7 @@ Q_LOGGING_CATEGORY(QQSHAPE_LOG_TIME_DIRTY_SYNC, "qt.shape.time.sync") To use the types in this module, import the module with the following line: \badcode - import QtQuick.Shapes 1.0 + import QtQuick.Shapes 1.11 \endcode */ @@ -778,6 +778,63 @@ QQuickShape::Status QQuickShape::status() const return d->status; } +/*! + \qmlproperty enumeration QtQuick.Shapes::Shape::containsMode + \since QtQuick.Shapes 1.11 + + This property determines the definition of \l {QQuickItem::contains()}{contains()} + for the Shape. It is useful in case you add + \l {Qt Quick Pointer Handlers QML Types}{Pointer Handlers} and you + want to react only when the mouse or touchpoint is fully inside the Shape. + + \value Shape.BoundingRectContains + The default implementation of \l QQuickItem::contains() checks only + whether the given point is inside the rectangular bounding box. This is + the most efficient implementation, which is why it's the default. + + \value Shape.FillContains + Check whether the interior (the part that would be filled if you are + rendering it with fill) of any \l ShapePath that makes up this Shape + contains the given point. The more complex and numerous ShapePaths you + add, the less efficient this is to check, which can potentially slow + down event delivery in your application. So it should be used with care. + + One way to speed up the \c FillContains check is to generate an approximate + outline with as few points as possible, place that in a transparent Shape + on top, and add your Pointer Handlers to that, so that the containment + check is cheaper during event delivery. +*/ +QQuickShape::ContainsMode QQuickShape::containsMode() const +{ + Q_D(const QQuickShape); + return d->containsMode; +} + +void QQuickShape::setContainsMode(QQuickShape::ContainsMode containsMode) +{ + Q_D(QQuickShape); + if (d->containsMode == containsMode) + return; + + d->containsMode = containsMode; + emit containsModeChanged(); +} + +bool QQuickShape::contains(const QPointF &point) const +{ + Q_D(const QQuickShape); + switch (d->containsMode) { + case BoundingRectContains: + return QQuickItem::contains(point); + case FillContains: + for (QQuickShapePath *path : d->sp) { + if (path->path().contains(point)) + return true; + } + } + return false; +} + static void vpe_append(QQmlListProperty<QObject> *property, QObject *obj) { QQuickShape *item = static_cast<QQuickShape *>(property->object); |