Commit 4b5b9631 authored by Lasse Holmstedt's avatar Lasse Holmstedt

QML Observer: Update selection rects when item's geometry changes

parent 514ec10c
......@@ -81,13 +81,18 @@ QPolygonF SelectionIndicator::addBoundingRectToPolygon(QGraphicsItem *item, QPol
return polygon;
}
void SelectionIndicator::setItems(const QList<QGraphicsObject*> &itemList)
void SelectionIndicator::setItems(const QList<QWeakPointer<QGraphicsObject> > &itemList)
{
clear();
// set selections to also all children if they are not editor items
foreach (QGraphicsItem *item, itemList) {
foreach (QWeakPointer<QGraphicsObject> obj, itemList) {
if (obj.isNull())
continue;
QGraphicsItem *item = obj.data();
QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem = new QGraphicsPolygonItem(m_layerItem.data());
m_indicatorShapeHash.insert(item, newSelectionIndicatorGraphicsItem);
......@@ -106,17 +111,5 @@ void SelectionIndicator::setItems(const QList<QGraphicsObject*> &itemList)
}
}
void SelectionIndicator::updateItems(const QList<QGraphicsObject*> &itemList)
{
foreach (QGraphicsItem *item, itemList) {
if (m_indicatorShapeHash.contains(item)) {
QGraphicsPolygonItem *indicatorGraphicsItem = m_indicatorShapeHash.value(item);
QPolygonF boundingRectInSceneSpace(item->mapToScene(item->boundingRect()));
QPolygonF boundingRectInLayerItemSpace = m_layerItem->mapFromScene(boundingRectInSceneSpace);
indicatorGraphicsItem->setPolygon(boundingRectInLayerItemSpace);
}
}
}
} //namespace QmlViewer
......@@ -49,8 +49,7 @@ public:
void clear();
void setItems(const QList<QGraphicsObject*> &itemList);
void updateItems(const QList<QGraphicsObject*> &itemList);
void setItems(const QList<QWeakPointer<QGraphicsObject> > &itemList);
private:
QPolygonF addBoundingRectToPolygon(QGraphicsItem *item, QPolygonF &polygon);
......
......@@ -407,10 +407,36 @@ void SelectionTool::clear()
void SelectionTool::selectedItemsChanged(const QList<QGraphicsItem*> &itemList)
{
m_selectionIndicator.setItems(toGraphicsObjectList(itemList));
foreach(QWeakPointer<QGraphicsObject> obj, m_selectedItemList) {
if (!obj.isNull()) {
disconnect(obj.data(), SIGNAL(xChanged()), this, SLOT(repaintBoundingRects()));
disconnect(obj.data(), SIGNAL(yChanged()), this, SLOT(repaintBoundingRects()));
disconnect(obj.data(), SIGNAL(widthChanged()), this, SLOT(repaintBoundingRects()));
disconnect(obj.data(), SIGNAL(heightChanged()), this, SLOT(repaintBoundingRects()));
disconnect(obj.data(), SIGNAL(rotationChanged()), this, SLOT(repaintBoundingRects()));
}
}
QList<QGraphicsObject*> objects = toGraphicsObjectList(itemList);
m_selectedItemList.clear();
foreach(QGraphicsObject *obj, objects) {
m_selectedItemList.append(obj);
connect(obj, SIGNAL(xChanged()), this, SLOT(repaintBoundingRects()));
connect(obj, SIGNAL(yChanged()), this, SLOT(repaintBoundingRects()));
connect(obj, SIGNAL(widthChanged()), this, SLOT(repaintBoundingRects()));
connect(obj, SIGNAL(heightChanged()), this, SLOT(repaintBoundingRects()));
connect(obj, SIGNAL(rotationChanged()), this, SLOT(repaintBoundingRects()));
}
m_selectionIndicator.setItems(m_selectedItemList);
//m_resizeIndicator.setItems(toGraphicsObjectList(itemList));
}
void SelectionTool::repaintBoundingRects()
{
m_selectionIndicator.setItems(m_selectedItemList);
}
void SelectionTool::selectUnderPoint(QMouseEvent *event)
{
m_singleSelectionManipulator.begin(event->pos());
......
......@@ -85,6 +85,7 @@ public:
private slots:
void contextMenuElementSelected();
void contextMenuElementHovered(QAction *action);
void repaintBoundingRects();
private:
void createContextMenu(QList<QGraphicsItem*> itemList, QPoint globalPos);
......@@ -100,6 +101,8 @@ private:
QTime m_mousePressTimer;
bool m_selectOnlyContentItems;
QList<QWeakPointer<QGraphicsObject> > m_selectedItemList;
QList<QGraphicsItem*> m_contextMenuItemList;
};
......
......@@ -30,7 +30,6 @@
#ifndef SINGLESELECTIONMANIPULATOR_H
#define SINGLESELECTIONMANIPULATOR_H
#include "selectionrectangle.h"
#include <QPointF>
#include <QList>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment