diff options
Diffstat (limited to 'src/widgets/graphicsview')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsanchorlayout.h | 1 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | 6 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsanchorlayout_p.h | 7 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsitem.cpp | 2 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsscene.cpp | 33 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicssceneevent.cpp | 98 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicssceneevent.h | 4 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.cpp | 16 |
8 files changed, 145 insertions, 22 deletions
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout.h b/src/widgets/graphicsview/qgraphicsanchorlayout.h index e392be1568..9bea43dd8e 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout.h +++ b/src/widgets/graphicsview/qgraphicsanchorlayout.h @@ -70,7 +70,6 @@ private: Q_DECLARE_PRIVATE(QGraphicsAnchor) friend class QGraphicsAnchorLayoutPrivate; - friend struct AnchorData; }; class Q_WIDGETS_EXPORT QGraphicsAnchorLayout : public QGraphicsLayout diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index 71027f00a2..008560d856 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -167,7 +167,7 @@ AnchorData::~AnchorData() if (graphicsAnchor) { // Remove reference to ourself to avoid double removal in // QGraphicsAnchorPrivate dtor. - graphicsAnchor->d_func()->data = 0; + QGraphicsAnchorPrivate::get(graphicsAnchor)->data = nullptr; delete graphicsAnchor; } @@ -215,7 +215,7 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) } else { // It is a user-created anchor, fetch size information from the associated QGraphicsAnchor Q_ASSERT(graphicsAnchor); - QGraphicsAnchorPrivate *anchorPrivate = graphicsAnchor->d_func(); + QGraphicsAnchorPrivate *anchorPrivate = QGraphicsAnchorPrivate::get(graphicsAnchor); // Policy, min and max sizes are straightforward policy = anchorPrivate->sizePolicy; @@ -2526,7 +2526,7 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) // Check if this constraint have some overlap with current // trunk variables... - foreach (QSimplexVariable *ad, trunkVariables) { + for (QSimplexVariable *ad : qAsConst(trunkVariables)) { if (c->variables.contains(ad)) { match = true; break; diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.h b/src/widgets/graphicsview/qgraphicsanchorlayout_p.h index 6b2408b2eb..699ca32bfe 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.h @@ -73,6 +73,7 @@ QT_BEGIN_NAMESPACE respectively. */ +namespace QtGraphicsAnchorLayout { /*! \internal @@ -326,6 +327,9 @@ public: QSet<AnchorData *> positives; QSet<AnchorData *> negatives; }; +} // namespace QtGraphicsAnchorLayout +using namespace QtGraphicsAnchorLayout; + Q_DECLARE_TYPEINFO(GraphPath, Q_MOVABLE_TYPE); class QGraphicsAnchorLayoutPrivate; @@ -346,6 +350,9 @@ public: void setSizePolicy(QSizePolicy::Policy policy); + static QGraphicsAnchorPrivate *get(QGraphicsAnchor *q) + { return q->d_func(); } + QGraphicsAnchorLayoutPrivate *layoutPrivate; AnchorData *data; diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index fdf21fb499..203b879020 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -7310,7 +7310,7 @@ void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) selectedItems = d_ptr->scene->selectedItems(); initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions; if (initialPositions.isEmpty()) { - foreach (QGraphicsItem *item, selectedItems) + for (QGraphicsItem *item : qAsConst(selectedItems)) initialPositions[item] = item->pos(); initialPositions[this] = pos(); } diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index 37c631483a..7cc694a613 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -4331,7 +4331,8 @@ static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion & pix->fill(Qt::transparent); pixmapPainter.begin(pix); } else { - subPix = QPixmap(br.size()); + subPix = QPixmap(br.size() * pix->devicePixelRatio()); + subPix.setDevicePixelRatio(pix->devicePixelRatio()); subPix.fill(Qt::transparent); pixmapPainter.begin(&subPix); pixmapPainter.translate(-br.topLeft()); @@ -4409,6 +4410,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte return; } + const qreal devicePixelRatio = painter->device()->devicePixelRatio(); const qreal oldPainterOpacity = painter->opacity(); qreal newPainterOpacity = oldPainterOpacity; QGraphicsProxyWidget *proxy = item->isWidget() ? qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(item)) : 0; @@ -4428,6 +4430,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte // Fetch the off-screen transparent buffer and exposed area info. QPixmapCache::Key pixmapKey; QPixmap pix; + bool pixmapFound; QGraphicsItemCache *itemCache = itemd->extraItemCache(); if (cacheMode == QGraphicsItem::ItemCoordinateCache) { @@ -4442,18 +4445,20 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte // Render using item coordinate cache mode. if (cacheMode == QGraphicsItem::ItemCoordinateCache) { QSize pixmapSize; - bool fixedCacheSize = false; + bool fixedCacheSize = itemCache->fixedSize.isValid(); QRect br = brect.toAlignedRect(); - if ((fixedCacheSize = itemCache->fixedSize.isValid())) { + if (fixedCacheSize) { pixmapSize = itemCache->fixedSize; } else { pixmapSize = br.size(); } + pixmapSize *= devicePixelRatio; + // Create or recreate the pixmap. int adjust = itemCache->fixedSize.isValid() ? 0 : 2; QSize adjustSize(adjust*2, adjust*2); - br.adjust(-adjust, -adjust, adjust, adjust); + br.adjust(-adjust / devicePixelRatio, -adjust / devicePixelRatio, adjust / devicePixelRatio, adjust / devicePixelRatio); if (pix.isNull() || (!fixedCacheSize && (pixmapSize + adjustSize) != pix.size())) { pix = QPixmap(pixmapSize + adjustSize); itemCache->boundingRect = br; @@ -4476,7 +4481,8 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte // Fit the item's bounding rect into the pixmap's coordinates. QTransform itemToPixmap; if (fixedCacheSize) { - const QPointF scale(pixmapSize.width() / brect.width(), pixmapSize.height() / brect.height()); + const QPointF scale((pixmapSize.width() / devicePixelRatio) / brect.width(), + (pixmapSize.height() / devicePixelRatio) / brect.height()); itemToPixmap.scale(scale.x(), scale.y()); } itemToPixmap.translate(-br.x(), -br.y()); @@ -4498,6 +4504,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte styleOptionTmp.exposedRect = exposedRect; // Render. + pix.setDevicePixelRatio(devicePixelRatio); _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), &styleOptionTmp, painterStateProtection); @@ -4595,21 +4602,22 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte // Copy / "scroll" the old pixmap onto the new ole and calculate // scrolled exposure. - if (newCacheIndent != deviceData->cacheIndent || deviceRect.size() != pix.size()) { + if (newCacheIndent != deviceData->cacheIndent || deviceRect.size() != pix.size() / devicePixelRatio) { QPoint diff = newCacheIndent - deviceData->cacheIndent; - QPixmap newPix(deviceRect.size()); + QPixmap newPix(deviceRect.size() * devicePixelRatio); // ### Investigate removing this fill (test with Plasma and // graphicssystem raster). newPix.fill(Qt::transparent); if (!pix.isNull()) { + newPix.setDevicePixelRatio(devicePixelRatio); QPainter newPixPainter(&newPix); newPixPainter.drawPixmap(-diff, pix); newPixPainter.end(); } QRegion exposed; - exposed += newPix.rect(); + exposed += QRect(QPoint(0,0), newPix.size() / devicePixelRatio); if (!pix.isNull()) - exposed -= QRect(-diff, pix.size()); + exposed -= QRect(-diff, pix.size() / devicePixelRatio); scrollExposure = exposed; pix = newPix; @@ -4621,9 +4629,9 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte deviceData->cacheIndent = QPoint(); // Auto-adjust the pixmap size. - if (deviceRect.size() != pix.size()) { + if (deviceRect.size() != pix.size() / devicePixelRatio) { // exposed needs to cover the whole pixmap - pix = QPixmap(deviceRect.size()); + pix = QPixmap(deviceRect.size() * devicePixelRatio); pixModified = true; itemCache->allExposed = true; itemCache->exposed.clear(); @@ -4667,6 +4675,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte styleOptionTmp.exposedRect = br.adjusted(-1, -1, 1, 1); // Render the exposed areas. + pix.setDevicePixelRatio(devicePixelRatio); _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), &styleOptionTmp, painterStateProtection); @@ -6391,7 +6400,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) ev.setWidget(event->widget()); sendEvent(receiver.data(), &ev); QSet<QGesture *> ignoredGestures; - foreach (QGesture *g, gestures) { + for (QGesture *g : qAsConst(gestures)) { if (!ev.isAccepted() && !ev.isAccepted(g)) { // if the gesture was ignored by its target, we will update the // targetItems list with a possible target items (items that diff --git a/src/widgets/graphicsview/qgraphicssceneevent.cpp b/src/widgets/graphicsview/qgraphicssceneevent.cpp index f7f09486e9..398ef1aaf5 100644 --- a/src/widgets/graphicsview/qgraphicssceneevent.cpp +++ b/src/widgets/graphicsview/qgraphicssceneevent.cpp @@ -259,8 +259,9 @@ #include "qgraphicssceneevent.h" -#ifndef QT_NO_DEBUG +#ifndef QT_NO_DEBUG_STREAM #include <QtCore/qdebug.h> +#include <private/qdebug_p.h> #endif #include <QtCore/qmap.h> #include <QtCore/qpoint.h> @@ -1730,4 +1731,99 @@ void QGraphicsSceneMoveEvent::setNewPos(const QPointF &pos) d->newPos = pos; } +#ifndef QT_NO_DEBUG_STREAM +template <class Event> +static inline void formatPositions(QDebug &debug, const Event *event) +{ + debug << ", pos="; + QtDebugUtils::formatQPoint(debug, event->pos()); + debug << ", scenePos="; + QtDebugUtils::formatQPoint(debug, event->scenePos()); + debug << ", screenPos="; + QtDebugUtils::formatQPoint(debug, event->screenPos()); +} + +QDebug operator<<(QDebug debug, const QGraphicsSceneEvent *event) +{ + QDebugStateSaver saver(debug); + debug.nospace(); + if (!event) { + debug << "QGraphicsSceneEvent(0)"; + return debug; + } + + const QEvent::Type type = event->type(); + switch (type) { + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseRelease: + case QEvent::GraphicsSceneMouseDoubleClick: { + const QGraphicsSceneMouseEvent *me = static_cast<const QGraphicsSceneMouseEvent *>(event); + const Qt::MouseButton button = me->button(); + const Qt::MouseButtons buttons = me->buttons(); + debug << "QGraphicsSceneMouseEvent("; + QtDebugUtils::formatQEnum(debug, type); + if (type != QEvent::GraphicsSceneMouseMove) { + debug << ", "; + QtDebugUtils::formatQEnum(debug, button); + } + if (buttons && button != buttons) { + debug << ", buttons="; + QtDebugUtils::formatQFlags(debug, buttons); + } + QtDebugUtils::formatNonNullQFlags(debug, ", ", me->modifiers()); + formatPositions(debug, me); + QtDebugUtils::formatNonNullQEnum(debug, ", ", me->source()); + QtDebugUtils::formatNonNullQFlags(debug, ", flags=", me->flags()); + debug << ')'; + } + break; + case QEvent::GraphicsSceneContextMenu: { + const QGraphicsSceneContextMenuEvent *ce = static_cast<const QGraphicsSceneContextMenuEvent *>(event); + debug << "QGraphicsSceneContextMenuEvent(reason=" << ce->reason(); + QtDebugUtils::formatNonNullQFlags(debug, ", ", ce->modifiers()); + formatPositions(debug, ce); + debug << ')'; + } + break; + case QEvent::GraphicsSceneHoverEnter: + case QEvent::GraphicsSceneHoverMove: + case QEvent::GraphicsSceneHoverLeave: + debug << "QGraphicsSceneHoverEvent("; + formatPositions(debug, static_cast<const QGraphicsSceneHoverEvent *>(event)); + debug << ')'; + break; + case QEvent::GraphicsSceneHelp: + break; + case QEvent::GraphicsSceneDragEnter: + case QEvent::GraphicsSceneDragMove: + case QEvent::GraphicsSceneDragLeave: + case QEvent::GraphicsSceneDrop: { + const QGraphicsSceneDragDropEvent *de = static_cast<const QGraphicsSceneDragDropEvent *>(event); + debug << "QGraphicsSceneDragDropEvent(proposedAction="; + QtDebugUtils::formatQEnum(debug, de->proposedAction()); + debug << ", possibleActions="; + QtDebugUtils::formatQFlags(debug, de->possibleActions()); + debug << ", source=" << de->source(); + QtDebugUtils::formatNonNullQFlags(debug, ", buttons=", de->buttons()); + QtDebugUtils::formatNonNullQFlags(debug, ", ", de->modifiers()); + formatPositions(debug, de); + } + break; + case QEvent::GraphicsSceneWheel: { + const QGraphicsSceneWheelEvent *we = static_cast<const QGraphicsSceneWheelEvent *>(event); + debug << "QGraphicsSceneWheelEvent("; + QtDebugUtils::formatNonNullQFlags(debug, ", buttons=", we->buttons()); + QtDebugUtils::formatNonNullQFlags(debug, ", ", we->modifiers()); + formatPositions(debug, we); + debug << ')'; + } + break; + default: + break; + } + return debug; +} +#endif // !QT_NO_DEBUG_STREAM + QT_END_NAMESPACE diff --git a/src/widgets/graphicsview/qgraphicssceneevent.h b/src/widgets/graphicsview/qgraphicssceneevent.h index 77b53e401d..9d940be2c0 100644 --- a/src/widgets/graphicsview/qgraphicssceneevent.h +++ b/src/widgets/graphicsview/qgraphicssceneevent.h @@ -320,6 +320,10 @@ public: void setNewPos(const QPointF &pos); }; +#ifndef QT_NO_DEBUG_STREAM +Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGraphicsSceneEvent *); +#endif + QT_END_NAMESPACE #endif diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index f79ee41e10..24647dd74c 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -2703,7 +2703,7 @@ void QGraphicsView::updateScene(const QList<QRectF> &rects) dirtyViewportRects << xrect; } - foreach (const QRect &rect, dirtyViewportRects) { + for (const QRect &rect : qAsConst(dirtyViewportRects)) { // Add the exposed rect to the update region. In rect update // mode, we only count the bounding rect of items. if (!boundingRectUpdate) { @@ -3483,7 +3483,9 @@ void QGraphicsView::paintEvent(QPaintEvent *event) // Recreate the background pixmap, and flag the whole background as // exposed. if (d->mustResizeBackgroundPixmap) { - d->backgroundPixmap = QPixmap(viewport()->size()); + const qreal dpr = d->viewport->devicePixelRatioF(); + d->backgroundPixmap = QPixmap(viewport()->size() * dpr); + d->backgroundPixmap.setDevicePixelRatio(dpr); QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole()); if (!bgBrush.isOpaque()) d->backgroundPixmap.fill(Qt::transparent); @@ -3679,14 +3681,20 @@ void QGraphicsView::scrollContentsBy(int dx, int dy) && X11->use_xrender #endif ) { + // Below, QPixmap::scroll() works in device pixels, while the delta values + // and backgroundPixmapExposed are in device independent pixels. + const qreal dpr = d->backgroundPixmap.devicePixelRatio(); + const qreal inverseDpr = qreal(1) / dpr; + // Scroll the background pixmap QRegion exposed; if (!d->backgroundPixmap.isNull()) - d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed); + d->backgroundPixmap.scroll(dx * dpr, dy * dpr, d->backgroundPixmap.rect(), &exposed); // Invalidate the background pixmap d->backgroundPixmapExposed.translate(dx, dy); - d->backgroundPixmapExposed += exposed; + const QRegion exposedScaled = QTransform::fromScale(inverseDpr, inverseDpr).map(exposed); + d->backgroundPixmapExposed += exposedScaled; } // Always replay on scroll. |