diff --git a/src/libs/qmljsdebugger/editor/boundingrecthighlighter.cpp b/src/libs/qmljsdebugger/editor/boundingrecthighlighter.cpp index 736549681135e6ce779e8d491e530e3f737c7997..90fb9446ebb9135aaf51b8e5a9612b3aa9b99324 100644 --- a/src/libs/qmljsdebugger/editor/boundingrecthighlighter.cpp +++ b/src/libs/qmljsdebugger/editor/boundingrecthighlighter.cpp @@ -99,14 +99,18 @@ void BoundingRectHighlighter::clear() if (m_boxes.length()) { m_animTimer->stop(); + foreach(BoundingBox *box, m_boxes) { + if (!box->highlightedObject.isNull()) { + disconnect(box->highlightedObject.data(), SIGNAL(xChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(yChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(widthChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(heightChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(rotationChanged()), this, SLOT(refresh())); + } + } + qDeleteAll(m_boxes); m_boxes.clear(); - -// disconnect(m_highlightedObject.data(), SIGNAL(xChanged()), this, SLOT(refresh())); -// disconnect(m_highlightedObject.data(), SIGNAL(yChanged()), this, SLOT(refresh())); -// disconnect(m_highlightedObject.data(), SIGNAL(widthChanged()), this, SLOT(refresh())); -// disconnect(m_highlightedObject.data(), SIGNAL(heightChanged()), this, SLOT(refresh())); -// disconnect(m_highlightedObject.data(), SIGNAL(rotationChanged()), this, SLOT(refresh())); } } @@ -132,7 +136,7 @@ void BoundingRectHighlighter::highlight(QList<QGraphicsObject*> items) foreach(QGraphicsObject *itemToHighlight, items) { BoundingBox *box = boxFor(itemToHighlight); if (!box) { - box = new BoundingBox(itemToHighlight, this); + box = createBoundingBox(itemToHighlight); animate = true; } @@ -157,7 +161,7 @@ void BoundingRectHighlighter::highlight(QGraphicsObject* itemToHighlight) BoundingBox *box = boxFor(itemToHighlight); if (!box) { - box = new BoundingBox(itemToHighlight, this); + box = createBoundingBox(itemToHighlight); m_boxes << box; animate = true; qSort(m_boxes); @@ -166,11 +170,24 @@ void BoundingRectHighlighter::highlight(QGraphicsObject* itemToHighlight) highlightAll(animate); } +BoundingBox *BoundingRectHighlighter::createBoundingBox(QGraphicsObject *itemToHighlight) +{ + BoundingBox *box = new BoundingBox(itemToHighlight, this); + + connect(itemToHighlight, SIGNAL(xChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(yChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(widthChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(heightChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(rotationChanged()), this, SLOT(refresh())); + + return box; +} + void BoundingRectHighlighter::highlightAll(bool animate) { foreach(BoundingBox *box, m_boxes) { QGraphicsObject *item = box->highlightedObject.data(); - if (!item) { + if (box->highlightedObject.isNull()) { m_boxes.removeOne(box); continue; } @@ -186,14 +203,6 @@ void BoundingRectHighlighter::highlightAll(bool animate) box->highlightPolygon->setPolygon(QPolygonF(bboxRect)); box->highlightPolygonEdge->setPolygon(QPolygonF(edgeRect)); -// if (XXX) { -// connect(item, SIGNAL(xChanged()), this, SLOT(refresh())); -// connect(item, SIGNAL(yChanged()), this, SLOT(refresh())); -// connect(item, SIGNAL(widthChanged()), this, SLOT(refresh())); -// connect(item, SIGNAL(heightChanged()), this, SLOT(refresh())); -// connect(item, SIGNAL(rotationChanged()), this, SLOT(refresh())); -// } - if (animate) box->highlightPolygonEdge->setOpacity(0); } diff --git a/src/libs/qmljsdebugger/editor/boundingrecthighlighter.h b/src/libs/qmljsdebugger/editor/boundingrecthighlighter.h index 2e8e52226f2337dab49de34a8c150e90d8bf6d18..948de90b13b22724cf838471309b6d8776268a7a 100644 --- a/src/libs/qmljsdebugger/editor/boundingrecthighlighter.h +++ b/src/libs/qmljsdebugger/editor/boundingrecthighlighter.h @@ -34,6 +34,7 @@ private slots: private: BoundingBox *boxFor(QGraphicsObject *item) const; void highlightAll(bool animate); + BoundingBox *createBoundingBox(QGraphicsObject *itemToHighlight); private: Q_DISABLE_COPY(BoundingRectHighlighter); diff --git a/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp b/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp index d61afbcf99acfd8cdddc196ee7f5f594141bd389..2bd96c80efd08eca61ee8d9d32cde4fe242a72a7 100644 --- a/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp +++ b/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp @@ -143,12 +143,6 @@ void SubcomponentEditorTool::setCurrentItem(QGraphicsItem* contextItem) if (!gfxObject) return; - connect(gfxObject, SIGNAL(xChanged()), SLOT(refresh())); - connect(gfxObject, SIGNAL(yChanged()), SLOT(refresh())); - connect(gfxObject, SIGNAL(scaleChanged()), SLOT(refresh())); - connect(gfxObject, SIGNAL(widthChanged()), SLOT(refresh())); - connect(gfxObject, SIGNAL(heightChanged()), SLOT(refresh())); - //QString parentClassName = gfxObject->metaObject()->className(); //if (parentClassName.contains(QRegExp("_QMLTYPE_\\d+"))) @@ -223,7 +217,13 @@ bool SubcomponentEditorTool::itemIsChildOfQmlSubComponent(QGraphicsItem *item) c void SubcomponentEditorTool::pushContext(QGraphicsObject *contextItem) { - connect(contextItem, SIGNAL(destroyed(QObject*)), SLOT(contextDestroyed(QObject*))); + connect(contextItem, SIGNAL(destroyed(QObject*)), this, SLOT(contextDestroyed(QObject*))); + connect(contextItem, SIGNAL(xChanged()), this, SLOT(resizeMask())); + connect(contextItem, SIGNAL(yChanged()), this, SLOT(resizeMask())); + connect(contextItem, SIGNAL(widthChanged()), this, SLOT(resizeMask())); + connect(contextItem, SIGNAL(heightChanged()), this, SLOT(resizeMask())); + connect(contextItem, SIGNAL(rotationChanged()), this, SLOT(resizeMask())); + m_currentContext.push(contextItem); QString title = titleForItem(contextItem); emit contextPushed(title); @@ -250,14 +250,15 @@ QGraphicsObject *SubcomponentEditorTool::popContext() emit contextPopped(); - disconnect(popped, SIGNAL(xChanged()), this, SLOT(refresh())); - disconnect(popped, SIGNAL(yChanged()), this, SLOT(refresh())); - disconnect(popped, SIGNAL(scaleChanged()), this, SLOT(refresh())); - disconnect(popped, SIGNAL(widthChanged()), this, SLOT(refresh())); - disconnect(popped, SIGNAL(heightChanged()), this, SLOT(refresh())); + disconnect(popped, SIGNAL(xChanged()), this, SLOT(resizeMask())); + disconnect(popped, SIGNAL(yChanged()), this, SLOT(resizeMask())); + disconnect(popped, SIGNAL(scaleChanged()), this, SLOT(resizeMask())); + disconnect(popped, SIGNAL(widthChanged()), this, SLOT(resizeMask())); + disconnect(popped, SIGNAL(heightChanged()), this, SLOT(resizeMask())); if (m_currentContext.size() > 1) { - m_mask->setCurrentItem(m_currentContext.top()); + QGraphicsObject *item = m_currentContext.top(); + m_mask->setCurrentItem(item); m_mask->setOpacity(MaxOpacity); m_mask->setVisible(true); } else { @@ -267,9 +268,10 @@ QGraphicsObject *SubcomponentEditorTool::popContext() return popped; } -void SubcomponentEditorTool::refresh() +void SubcomponentEditorTool::resizeMask() { - m_mask->setCurrentItem(m_currentContext.top()); + QGraphicsObject *item = m_currentContext.top(); + m_mask->setCurrentItem(item); } QGraphicsObject *SubcomponentEditorTool::currentRootItem() const diff --git a/src/libs/qmljsdebugger/editor/subcomponenteditortool.h b/src/libs/qmljsdebugger/editor/subcomponenteditortool.h index 3a3f50bddc37e787a9a34b4e1c907691fe656a71..d54b6a71dc0a248794c536d4f91f1050a466cce0 100644 --- a/src/libs/qmljsdebugger/editor/subcomponenteditortool.h +++ b/src/libs/qmljsdebugger/editor/subcomponenteditortool.h @@ -63,7 +63,7 @@ protected: private slots: void animate(); void contextDestroyed(QObject *context); - void refresh(); + void resizeMask(); private: QGraphicsObject *popContext(); diff --git a/src/libs/qmljsdebugger/editor/subcomponentmasklayeritem.cpp b/src/libs/qmljsdebugger/editor/subcomponentmasklayeritem.cpp index 32297771441d0990d0b774f52e8d63af83fa67f3..ce1b43713196833d2563ac8d60e6a29f715354b6 100644 --- a/src/libs/qmljsdebugger/editor/subcomponentmasklayeritem.cpp +++ b/src/libs/qmljsdebugger/editor/subcomponentmasklayeritem.cpp @@ -24,8 +24,28 @@ int SubcomponentMaskLayerItem::type() const return Constants::EditorItemType; } +static QRectF resizeRect(const QRectF &newRect, const QRectF &oldRect) +{ + QRectF result = newRect; + if (oldRect.left() < newRect.left()) + result.setLeft(oldRect.left()); + + if (oldRect.top() < newRect.top()) + result.setTop(oldRect.top()); + + if (oldRect.right() > newRect.right()) + result.setRight(oldRect.right()); + + if (oldRect.bottom() > newRect.bottom()) + result.setBottom(oldRect.bottom()); + + return result; +} + + void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) { + QGraphicsItem *prevItem = m_currentItem; m_currentItem = item; if (!m_currentItem) @@ -38,11 +58,17 @@ void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) QPolygonF itemPoly(itemRect); itemPoly = item->mapToScene(itemPoly); - QRectF borderRect = itemPoly.boundingRect(); + // if updating the same item as before, resize the rectangle only bigger, not smaller. + if (prevItem == item && prevItem != 0) { + m_itemPolyRect = resizeRect(itemPoly.boundingRect(), m_itemPolyRect); + } else { + m_itemPolyRect = itemPoly.boundingRect(); + } + QRectF borderRect = m_itemPolyRect; borderRect.adjust(-1, -1, 1, 1); m_borderRect->setRect(borderRect); - itemPoly = viewPoly.subtracted(QPolygonF(itemPoly.boundingRect())); + itemPoly = viewPoly.subtracted(QPolygonF(m_itemPolyRect)); setPolygon(itemPoly); } diff --git a/src/libs/qmljsdebugger/editor/subcomponentmasklayeritem.h b/src/libs/qmljsdebugger/editor/subcomponentmasklayeritem.h index 1cbc9e6abf0e0fbf1b37f50b785216b91e3b74ca..9a6463646121119904a9850157d34786d29d587c 100644 --- a/src/libs/qmljsdebugger/editor/subcomponentmasklayeritem.h +++ b/src/libs/qmljsdebugger/editor/subcomponentmasklayeritem.h @@ -13,12 +13,15 @@ public: explicit SubcomponentMaskLayerItem(QDeclarativeDesignView *view, QGraphicsItem *parentItem = 0); int type() const; void setCurrentItem(QGraphicsItem *item); + void setBoundingBox(const QRectF &boundingBox); QGraphicsItem *currentItem() const; + QRectF itemRect() const; + private: QDeclarativeDesignView *m_view; QGraphicsItem *m_currentItem; QGraphicsRectItem *m_borderRect; - + QRectF m_itemPolyRect; }; } // namespace QmlViewer