5#ifndef QGRAPHICSITEM_P_H
6#define QGRAPHICSITEM_P_H
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
23#include <private/qgraphicsview_p.h>
25#include <private/qgraphicstransform_p.h>
27#include <QtCore/qpoint.h>
33class QGraphicsItemPrivate;
64 Q_DECLARE_PUBLIC(QGraphicsItem)
70 ExtraMaxDeviceCoordCacheSize,
71 ExtraBoundingRegionGranularity
83 QGraphicsItemPrivate();
86 static const QGraphicsItemPrivate *
get(
const QGraphicsItem *item)
88 return item->d_ptr.data();
90 static QGraphicsItemPrivate *
get(QGraphicsItem *item)
92 return item->d_ptr.data();
101 QTransform genericMapFromSceneTransform(
const QWidget *viewport =
nullptr)
const;
105 return (flags & QGraphicsItem::ItemIgnoresTransformations)
106 || (ancestorFlags & AncestorIgnoresTransformations);
120 bool hiddenByPanel =
false);
121 void setEnabledHelper(
bool newEnabled,
bool explicitly,
bool update =
true);
123 bool ignoreDirtyBit =
false,
bool ignoreOpacity =
false)
const;
126#if QT_CONFIG(graphicseffect)
127 enum InvalidateReason {
130 void invalidateParentGraphicsEffectsRecursively();
131 void invalidateChildGraphicsEffectsRecursively(InvalidateReason reason);
135 void addChild(QGraphicsItem *child);
137 void setParentItemHelper(QGraphicsItem *parent,
const QVariant *newParentVariant,
138 const QVariant *thisPointerVariant);
140 void initStyleOption(QStyleOptionGraphicsItem *option,
const QTransform &worldTransform,
141 const QRegion &exposedRegion,
bool allItems =
false)
const;
149 for (
int i = 0; i < children.size(); ++i)
150 children.at(i)->d_ptr->resolveFont(inheritedMask);
155 for (
int i = 0; i < children.size(); ++i)
156 children.at(i)->d_ptr->resolvePalette(inheritedMask);
163 for (
int i = 0; i < extras.size(); ++i) {
164 const ExtraStruct &extra = extras.at(i);
165 if (extra.type == type)
171 inline void setExtra(Extra type,
const QVariant &value)
174 for (
int i = 0; i < extras.size(); ++i) {
175 if (extras.at(i).type == type) {
182 extras << ExtraStruct(type, value);
184 extras[index].value = value;
190 for (
int i = 0; i < extras.size(); ++i) {
191 if (extras.at(i).type == type) {
200 ExtraStruct(Extra type,
const QVariant &value)
201 : type(type), value(value)
208 {
return type < extra; }
221 QGraphicsItem *that = q_func();
228 return sceneTransformTranslateOnly;
233 for (
int i = 0; i < children.size(); ++i)
234 children.at(i)->d_ptr->dirtySceneTransform = 1;
240 QGraphicsItem *p = parent;
243 int parentFlags = p->d_ptr->flags;
248 if ((myFlags & QGraphicsItem::ItemIgnoresParentOpacity)
249 || (parentFlags & QGraphicsItem::ItemDoesntPropagateOpacityToChildren)) {
253 o *= p->d_ptr->opacity;
254 p = p->d_ptr->parent;
255 myFlags = parentFlags;
261 {
return (opacity < qreal(0.001)); }
264 {
return (opacity < qreal(0.001)); }
273 return isOpacityNull(calcEffectiveOpacity());
277 if (!parent || !opacity)
280 return calcEffectiveOpacity();
285 if (parent && !(flags & QGraphicsItem::ItemIgnoresParentOpacity)
286 && !(parent->d_ptr->flags & QGraphicsItem::ItemDoesntPropagateOpacityToChildren)) {
287 return parentOpacity * opacity;
294 if (!children.size())
296 if (flags & QGraphicsItem::ItemDoesntPropagateOpacityToChildren)
299 for (
int i = 0; i < children.size(); ++i) {
300 if (children.at(i)->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity)
307 {
return (flags & QGraphicsItem::ItemClipsChildrenToShape) || children.isEmpty(); }
311 return !visible || (childrenCombineOpacity() && isFullyTransparent());
316 void setFocusHelper(Qt::FocusReason focusReason,
bool climb,
bool focusFromHide);
318 void setSubFocus(QGraphicsItem *rootItem =
nullptr, QGraphicsItem *stopItem =
nullptr);
319 void clearSubFocus(QGraphicsItem *rootItem =
nullptr, QGraphicsItem *stopItem =
nullptr);
326 static inline bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b);
349 struct TransformData;
362#ifndef QT_NO_GESTURES
429struct QGraphicsItemPrivate::TransformData
431 QTransform transform;
436 QList<QGraphicsTransform *> graphicsTransforms;
440 scale(1.0), rotation(0.0),
441 xOrigin(0.0), yOrigin(0.0),
445 QTransform computedFullTransform(QTransform *postmultiplyTransform =
nullptr)
const
448 if (!postmultiplyTransform || postmultiplyTransform->isIdentity())
450 if (transform.isIdentity())
451 return *postmultiplyTransform;
452 return transform * *postmultiplyTransform;
455 QTransform x(transform);
456 if (!graphicsTransforms.isEmpty()) {
458 for (
int i = 0; i < graphicsTransforms.size(); ++i)
459 graphicsTransforms.at(i)->applyTo(&m);
460 x *= m.toTransform();
462 x.translate(xOrigin, yOrigin);
464 x.scale(scale, scale);
465 x.translate(-xOrigin, -yOrigin);
466 if (postmultiplyTransform)
467 x *= *postmultiplyTransform;
474 inline QGraphicsItemPaintInfo(
const QTransform *
const xform1,
const QTransform *
const xform2,
475 const QTransform *
const xform3,
476 QRegion *r,
QWidget *w, QStyleOptionGraphicsItem *opt,
477 QPainter *p, qreal o,
bool b1,
bool b2)
478 : viewTransform(xform1), transformPtr(xform2), effectTransform(xform3), exposedRegion(r),
widget(w),
479 option(opt),
painter(p), opacity(o), wasDirtySceneTransform(b1), drawItem(b2)
494#if QT_CONFIG(graphicseffect)
495class QGraphicsItemEffectSourcePrivate :
public QGraphicsEffectSourcePrivate
498 QGraphicsItemEffectSourcePrivate(QGraphicsItem *i)
499 : QGraphicsEffectSourcePrivate(), item(i), info(
nullptr)
502 void detach() override
504 item->d_ptr->graphicsEffect =
nullptr;
505 item->prepareGeometryChange();
508 const QGraphicsItem *graphicsItem()
const override
511 const QWidget *widget()
const override
514 void update() override {
515 item->d_ptr->updateDueToGraphicsEffect =
true;
517 item->d_ptr->updateDueToGraphicsEffect =
false;
520 void effectBoundingRectChanged() override
521 { item->prepareGeometryChange(); }
523 bool isPixmap()
const override
525 return item->type() == QGraphicsPixmapItem::Type
526 && !(item->flags() & QGraphicsItem::ItemIsSelectable)
527 && item->d_ptr->children.size() == 0;
530 const QStyleOption *styleOption()
const override
531 {
return info ? info->option :
nullptr; }
533 QRect deviceRect()
const override
535 if (!info || !info->widget) {
536 qWarning(
"QGraphicsEffectSource::deviceRect: Not yet implemented, lacking device context");
539 return info->widget->rect();
542 QRectF boundingRect(Qt::CoordinateSystem system)
const override;
543 void draw(QPainter *) override;
544 QPixmap pixmap(Qt::CoordinateSystem system,
546 QGraphicsEffect::PixmapPadMode mode)
const override;
547 QRectF paddedEffectRect(Qt::CoordinateSystem system, QGraphicsEffect::PixmapPadMode mode,
const QRectF &sourceRect,
bool *unpadded =
nullptr)
const;
550 QGraphicsItemPaintInfo *info;
551 QTransform lastEffectTransform;
556
557
558
559
560
564 const QGraphicsItemPrivate *d1 = item1->d_ptr.data();
565 const QGraphicsItemPrivate *d2 = item2->d_ptr.data();
566 if (d1->parent == d2->parent)
567 return qt_closestLeaf(item1, item2);
571 int item1Depth = d1->depth();
572 int item2Depth = d2->depth();
573 const QGraphicsItem *p = item1;
574 const QGraphicsItem *t1 = item1;
575 while (item1Depth > item2Depth && (p = p->d_ptr->parent)) {
578 return !(t1->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent);
584 const QGraphicsItem *t2 = item2;
585 while (item2Depth > item1Depth && (p = p->d_ptr->parent)) {
588 return (t2->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent);
595 const QGraphicsItem *p1 = t1;
596 const QGraphicsItem *p2 = t2;
597 while (t1 && t1 != t2) {
600 t1 = t1->d_ptr->parent;
601 t2 = t2->d_ptr->parent;
606 return qt_closestLeaf(p1, p2);
610
611
612
613
614
621
622
623inline bool qt_closestLeaf(
const QGraphicsItem *item1,
const QGraphicsItem *item2)
626 const QGraphicsItemPrivate *d1 = item1->d_ptr.data();
627 const QGraphicsItemPrivate *d2 = item2->d_ptr.data();
628 bool f1 = d1->flags & QGraphicsItem::ItemStacksBehindParent;
629 bool f2 = d2->flags & QGraphicsItem::ItemStacksBehindParent;
633 return d1->z > d2->z;
634 return d1->siblingIndex > d2->siblingIndex;
638
639
644
645
646inline QTransform QGraphicsItemPrivate::transformToParent()
const
649 combineTransformToParent(&matrix);
654
655
656inline void QGraphicsItemPrivate::ensureSortedChildren()
658 if (needSortChildren) {
659 needSortChildren = 0;
660 sequentialOrdering = 1;
661 if (children.isEmpty())
663 std::sort(children.begin(), children.end(), qt_notclosestLeaf);
664 for (
int i = 0; i < children.size(); ++i) {
665 if (children.at(i)->d_ptr->siblingIndex != i) {
666 sequentialOrdering = 0;
674
675
676inline bool QGraphicsItemPrivate::insertionOrder(QGraphicsItem *a, QGraphicsItem *b)
678 return a->d_ptr->siblingIndex < b->d_ptr->siblingIndex;
682
683
684inline void QGraphicsItemPrivate::markParentDirty(
bool updateBoundingRect)
686 QGraphicsItemPrivate *parentp =
this;
687#if QT_CONFIG(graphicseffect)
688 if (updateBoundingRect && parentp->graphicsEffect && !parentp->inSetPosHelper) {
689 parentp->notifyInvalidated = 1;
690 static_cast<QGraphicsItemEffectSourcePrivate *>(parentp->graphicsEffect->d_func()
691 ->source->d_func())->invalidateCache();
694 while (parentp->parent) {
695 parentp = parentp->parent->d_ptr.data();
696 parentp->dirtyChildren = 1;
698 if (updateBoundingRect) {
699 parentp->dirtyChildrenBoundingRect = 1;
701 parentp->notifyBoundingRectChanged = 1;
703#if QT_CONFIG(graphicseffect)
704 if (parentp->graphicsEffect) {
705 if (updateBoundingRect) {
706 static_cast<QGraphicsItemEffectSourcePrivate *>(parentp->graphicsEffect->d_func()
707 ->source->d_func())->invalidateCache();
708 parentp->notifyInvalidated = 1;
710 if (parentp->scene && parentp->graphicsEffect->isEnabled()) {
712 parentp->fullUpdatePending = 1;
The QAbstractGraphicsShapeItem class provides a common base for all path items.
The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.
QHash< QPaintDevice *, DeviceData > deviceData
QHash< const QGraphicsItem *, QMap< int, QVariant > > data
The QGraphicsItemGroup class provides a container that treats a group of items as a single item.
quint32 localCollisionHack
virtual ~QGraphicsItemPrivate()
bool isOpacityNull() const
void updateChildWithGraphicsEffectFlagRecursively()
Returns a pointer to this item's effect if it has one; otherwise \nullptr.
void sendScenePosChange()
QGraphicsItem * subFocusItem
void setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromHide)
void invalidateChildrenSceneTransform()
virtual void setPosHelper(const QPointF &pos)
QVariant extra(Extra type) const
quint32 dirtySceneTransform
static bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b)
Qt::InputMethodHints imHints
void invalidateDepthRecursively()
QList< QGraphicsItem ** > focusProxyRefs
QTransform transformToParent() const
virtual void focusScopeItemChange(bool isSubFocusItem)
void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, const QRegion &exposedRegion, bool allItems=false) const
QGraphicsEffect * graphicsEffect
QGraphicsItem * focusProxy
void markParentDirty(bool updateBoundingRect=false)
QGraphicsItem * focusScopeItem
void setEnabledHelper(bool newEnabled, bool explicitly, bool update=true)
void setSubFocus(QGraphicsItem *rootItem=nullptr, QGraphicsItem *stopItem=nullptr)
quint32 explicitlyDisabled
void combineTransformToParent(QTransform *x, const QTransform *viewTransform=nullptr) const
quint32 notifyInvalidated
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
bool itemIsUntransformable() const
quint32 filtersDescendantEvents
QList< ExtraStruct > extras
quint32 mayHaveChildWithGraphicsEffect
quint32 acceptedMouseButtons
quint32 dirtyChildrenBoundingRect
void updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag, AncestorFlag flag=NoFlag, bool enabled=false, bool root=true)
bool discardUpdateRequest(bool ignoreVisibleBit=false, bool ignoreDirtyBit=false, bool ignoreOpacity=false) const
void combineTransformFromParent(QTransform *x, const QTransform *viewTransform=nullptr) const
static QGraphicsItemPrivate * get(QGraphicsItem *item)
virtual void resetWidth()
QGraphicsItem::PanelModality panelModality
void updateAncestorFlags()
virtual void transformChanged()
bool childrenCombineOpacity() const
void appendGraphicsTransform(QGraphicsTransform *t)
void clearSubFocus(QGraphicsItem *rootItem=nullptr, QGraphicsItem *stopItem=nullptr)
void ensureSceneTransform()
void setTransformHelper(const QTransform &transform)
void ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem)
void ensureSequentialSiblingIndex()
void removeChild(QGraphicsItem *child)
@ AncestorContainsChildren
@ AncestorFiltersChildEvents
@ AncestorHandlesChildEvents
@ AncestorIgnoresTransformations
quint32 updateDueToGraphicsEffect
QRectF sceneEffectiveBoundingRect() const
quint32 hasBoundingRegionGranularity
quint32 acceptedTouchBeginEvent
quint32 sceneTransformTranslateOnly
void remapItemPos(QEvent *event, QGraphicsItem *item)
void clearFocusHelper(bool giveFocusToParent, bool hiddenByParentPanel)
static bool movableAncestorIsSelected(const QGraphicsItem *item)
quint32 sendParentChangeNotification
QRectF effectiveBoundingRect(const QRectF &rect) const
QRectF effectiveBoundingRect(QGraphicsItem *topMostEffectItem=nullptr) const
quint32 scenePosDescendants
void updatePaintedViewBoundingRects(bool updateChildren)
bool isFullyTransparent() const
quint32 acceptTouchEvents
bool childrenClippedToShape() const
quint32 sequentialOrdering
virtual void updateSceneTransformFromParent()
virtual void siblingOrderChange()
quint32 paintedViewBoundingRectsNeedRepaint
void childrenBoundingRectHelper(QTransform *x, QRectF *rect, QGraphicsItem *topMostEffectItem)
bool hasTranslateOnlySceneTransform()
QRectF childrenBoundingRect
quint32 holesInSiblingIndex
void removeExtraItemCache()
virtual void resolvePalette(uint inheritedMask)
virtual void subFocusItemChange()
qreal effectiveOpacity() const
quint32 handlesChildEvents
quint32 notifyBoundingRectChanged
TransformData * transformData
QGraphicsItemCache * maybeExtraItemCache() const
void prependGraphicsTransform(QGraphicsTransform *t)
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
QTransform sceneTransform
virtual void resetHeight()
QHash< QWidget *, QRect > paintedViewBoundingRects
QGraphicsItemCache * extraItemCache() const
virtual void resolveFont(uint inheritedMask)
qreal combineOpacityFromParent(qreal parentOpacity) const
void unsetExtra(Extra type)
qreal calcEffectiveOpacity() const
void addChild(QGraphicsItem *child)
void setIsMemberOfGroup(bool enabled)
virtual bool isProxyWidget() const
void ensureSortedChildren()
void setVisibleHelper(bool newVisible, bool explicitly, bool update=true, bool hiddenByPanel=false)
static bool isOpacityNull(qreal opacity)
virtual void setHeight(qreal)
quint32 fullUpdatePending
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.
The QGraphicsObject class provides a base class for all graphics items that require signals,...
The QGraphicsPathItem class provides a path item that you can add to a QGraphicsScene.
QGraphicsPixmapItem::ShapeMode shapeMode
Qt::TransformationMode transformationMode
The QGraphicsPixmapItem class provides a pixmap item that you can add to a QGraphicsScene.
The QGraphicsPolygonItem class provides a polygon item that you can add to a QGraphicsScene.
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsSceneEvent class provides a base class for all graphics view related events.
The QGraphicsSceneHelpEvent class provides events when a tooltip is requested.
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
The QGraphicsSceneMoveEvent class provides events for widget moving in the graphics view framework.
The QGraphicsSceneResizeEvent class provides events for widget resizing in the graphics view framewor...
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
void updateBoundingRect()
The QGraphicsSimpleTextItem class provides a simple text item that you can add to a QGraphicsScene.
void _q_updateBoundingRect(const QSizeF &)
void _q_ensureVisible(QRectF)
QPointF controlOffset() const
QGraphicsTextItemPrivate()
bool _q_mouseOnEdge(QGraphicsSceneMouseEvent *)
QWidgetTextControl * control
QWidgetTextControl * textControl() const
void sendControlEvent(QEvent *e)
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display form...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
qreal width() const
Returns the width of the generated outlines.
void setWidth(qreal width)
Sets the width of the generated outline painter path to width.
\inmodule QtCore\reentrant
The QPolygonF class provides a list of points using floating point precision.
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(animation)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
static void formatGraphicsItemHelper(QDebug debug, const QGraphicsItem *item)
bool _qt_movableAncestorIsSelected(const QGraphicsItem *item)
static QRectF setupTextLayout(QTextLayout *layout)
QDebug operator<<(QDebug debug, const QGraphicsObject *item)
static QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, const QPen &pen)
QDebug operator<<(QDebug debug, const QGraphicsItem *item)
static bool qt_QGraphicsItem_isObscured(const QGraphicsItem *item, const QGraphicsItem *other, const QRectF &rect)
bool qt_closestItemLast(const QGraphicsItem *item1, const QGraphicsItem *item2)
Returns true if item2 is on top of item1.
bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
bool qt_closestItemFirst(const QGraphicsItem *item1, const QGraphicsItem *item2)
Returns true if item1 is on top of item2.
QT_REQUIRE_CONFIG(graphicsview)
static QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
static QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
static void _q_adjustRect(QRectF *rect)
QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
const QTransform * transformPtr
const QTransform * effectTransform
quint32 wasDirtySceneTransform
QStyleOptionGraphicsItem * option
const QTransform * viewTransform