Commit 45bdff44 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Items in Positioner cannot manipulated anymore

Add a positioner node instance and the concept of resizable and movable
items. Item in a positioner will be not selected anymore. Instead their
positioner will be selected which is not resizable.
parent 48a43475
...@@ -97,11 +97,11 @@ void SelectionIndicator::setItems(const QList<QWeakPointer<QGraphicsObject> > &i ...@@ -97,11 +97,11 @@ void SelectionIndicator::setItems(const QList<QWeakPointer<QGraphicsObject> > &i
// set selections to also all children if they are not editor items // set selections to also all children if they are not editor items
foreach (QWeakPointer<QGraphicsObject> obj, itemList) { foreach (QWeakPointer<QGraphicsObject> object, itemList) {
if (obj.isNull()) if (object.isNull())
continue; continue;
QGraphicsItem *item = obj.data(); QGraphicsItem *item = object.data();
QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem = new QGraphicsPolygonItem(m_layerItem.data()); QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem = new QGraphicsPolygonItem(m_layerItem.data());
if (!m_indicatorShapeHash.contains(item)) { if (!m_indicatorShapeHash.contains(item)) {
......
...@@ -93,7 +93,8 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem* ...@@ -93,7 +93,8 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem if (formEditorItem
&& selectedNodes.contains(formEditorItem->qmlItemNode()) && selectedNodes.contains(formEditorItem->qmlItemNode())
&& !formEditorItem->qmlItemNode().isRootNode() && formEditorItem->qmlItemNode().instanceIsMovable()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner()
&& (formEditorItem->qmlItemNode().hasShowContent())) && (formEditorItem->qmlItemNode().hasShowContent()))
return true; return true;
} }
...@@ -101,7 +102,8 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem* ...@@ -101,7 +102,8 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*
foreach (QGraphicsItem *item, itemList) { foreach (QGraphicsItem *item, itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem if (formEditorItem
&& !formEditorItem->qmlItemNode().isRootNode() && formEditorItem->qmlItemNode().instanceIsMovable()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner()
&& selectedNodes.contains(formEditorItem->qmlItemNode())) && selectedNodes.contains(formEditorItem->qmlItemNode()))
return true; return true;
} }
......
...@@ -200,8 +200,8 @@ FormEditorItem *FormEditorScene::addFormEditorItem(const QmlItemNode &qmlItemNod ...@@ -200,8 +200,8 @@ FormEditorItem *FormEditorScene::addFormEditorItem(const QmlItemNode &qmlItemNod
QRectF sceneRect(qmlItemNode.instanceBoundingRect()); QRectF sceneRect(qmlItemNode.instanceBoundingRect());
setSceneRect(sceneRect); setSceneRect(sceneRect);
formLayerItem()->update(); formLayerItem()->update();
manipulatorLayerItem()->update(); manipulatorLayerItem()->update();
} }
......
...@@ -322,10 +322,25 @@ FormEditorItem* MoveTool::containerFormEditorItem(const QList<QGraphicsItem*> &i ...@@ -322,10 +322,25 @@ FormEditorItem* MoveTool::containerFormEditorItem(const QList<QGraphicsItem*> &i
return 0; return 0;
} }
QList<FormEditorItem*> movalbeItems(const QList<FormEditorItem*> &itemList)
{
QList<FormEditorItem*> filteredItemList(itemList);
QMutableListIterator<FormEditorItem*> listIterator(filteredItemList);
while (listIterator.hasNext()) {
FormEditorItem *item = listIterator.next();
if (!item->qmlItemNode().isValid() || !item->qmlItemNode().instanceIsMovable() || item->qmlItemNode().instanceIsInPositioner())
listIterator.remove();
}
return filteredItemList;
}
QList<FormEditorItem*> MoveTool::movingItems(const QList<FormEditorItem*> &selectedItemList) QList<FormEditorItem*> MoveTool::movingItems(const QList<FormEditorItem*> &selectedItemList)
{ {
FormEditorItem* ancestorItem = ancestorIfOtherItemsAreChild(selectedItemList); QList<FormEditorItem*> filteredItemList = movalbeItems(selectedItemList);
FormEditorItem* ancestorItem = ancestorIfOtherItemsAreChild(filteredItemList);
if (ancestorItem != 0 && ancestorItem->qmlItemNode().isRootNode()) { if (ancestorItem != 0 && ancestorItem->qmlItemNode().isRootNode()) {
// view()->changeToSelectionTool(); // view()->changeToSelectionTool();
...@@ -339,12 +354,12 @@ QList<FormEditorItem*> MoveTool::movingItems(const QList<FormEditorItem*> &selec ...@@ -339,12 +354,12 @@ QList<FormEditorItem*> MoveTool::movingItems(const QList<FormEditorItem*> &selec
return ancestorItemList; return ancestorItemList;
} }
if (!haveSameParent(selectedItemList)) { if (!haveSameParent(filteredItemList)) {
// view()->changeToSelectionTool(); // view()->changeToSelectionTool();
return QList<FormEditorItem*>(); return QList<FormEditorItem*>();
} }
return selectedItemList; return filteredItemList;
} }
void MoveTool::formEditorItemsChanged(const QList<FormEditorItem*> &itemList) void MoveTool::formEditorItemsChanged(const QList<FormEditorItem*> &itemList)
......
...@@ -72,11 +72,12 @@ void ResizeIndicator::setItems(const QList<FormEditorItem*> &itemList) ...@@ -72,11 +72,12 @@ void ResizeIndicator::setItems(const QList<FormEditorItem*> &itemList)
foreach (FormEditorItem* item, itemList) { foreach (FormEditorItem* item, itemList) {
if (item if (item
&& item->qmlItemNode().isValid() && item->qmlItemNode().isValid()
&& item->qmlItemNode().isRootNode()) && item->qmlItemNode().instanceIsResizable()
continue; && !item->qmlItemNode().instanceIsInPositioner()) {
ResizeController controller(m_layerItem, item); ResizeController controller(m_layerItem, item);
m_itemControllerHash.insert(item, controller); m_itemControllerHash.insert(item, controller);
}
} }
} }
......
...@@ -101,18 +101,20 @@ void RubberBandSelectionManipulator::select(SelectionType selectionType) ...@@ -101,18 +101,20 @@ void RubberBandSelectionManipulator::select(SelectionType selectionType)
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem if (formEditorItem
&& formEditorItem->qmlItemNode().isValid() && formEditorItem->qmlItemNode().isValid()
&& m_beginFormEditorItem->childItems().contains(formEditorItem) && m_beginFormEditorItem->childItems().contains(formEditorItem)
&& !formEditorItem->qmlItemNode().isRootNode()) && formEditorItem->qmlItemNode().instanceIsMovable()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner())
{ {
newNodeList.append(formEditorItem->qmlItemNode()); newNodeList.append(formEditorItem->qmlItemNode());
} }
} }
if (newNodeList.isEmpty() if (newNodeList.isEmpty()
&& m_beginFormEditorItem->qmlItemNode().isValid() && m_beginFormEditorItem->qmlItemNode().isValid()
&& !m_beginFormEditorItem->qmlItemNode().isRootNode()) && m_beginFormEditorItem->qmlItemNode().instanceIsMovable()
newNodeList.append(m_beginFormEditorItem->qmlItemNode()); && !m_beginFormEditorItem->qmlItemNode().instanceIsInPositioner())
newNodeList.append(m_beginFormEditorItem->qmlItemNode());
QList<QmlItemNode> nodeList; QList<QmlItemNode> nodeList;
......
...@@ -85,7 +85,7 @@ void SelectionIndicator::setItems(const QList<FormEditorItem*> &itemList) ...@@ -85,7 +85,7 @@ void SelectionIndicator::setItems(const QList<FormEditorItem*> &itemList)
clear(); clear();
foreach (FormEditorItem *item, itemList) { foreach (FormEditorItem *item, itemList) {
if (item->qmlItemNode().isValid()) if (!item->qmlItemNode().isValid())
continue; continue;
QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem = new QGraphicsPolygonItem(m_layerItem.data()); QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem = new QGraphicsPolygonItem(m_layerItem.data());
......
...@@ -145,7 +145,8 @@ void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList, ...@@ -145,7 +145,8 @@ void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
if (formEditorItem if (formEditorItem
&& formEditorItem->qmlItemNode().isValid() && formEditorItem->qmlItemNode().isValid()
&& !formEditorItem->qmlItemNode().isRootNode() && !formEditorItem->qmlItemNode().instanceIsInPositioner()
&& formEditorItem->qmlItemNode().instanceIsMovable()
&& (formEditorItem->qmlItemNode().hasShowContent() || !m_selectOnlyContentItems)) && (formEditorItem->qmlItemNode().hasShowContent() || !m_selectOnlyContentItems))
{ {
topSelectableItem = formEditorItem; topSelectableItem = formEditorItem;
......
...@@ -81,7 +81,8 @@ void SingleSelectionManipulator::select(SelectionType selectionType, bool select ...@@ -81,7 +81,8 @@ void SingleSelectionManipulator::select(SelectionType selectionType, bool select
if (formEditorItem if (formEditorItem
&& formEditorItem->qmlItemNode().isValid() && formEditorItem->qmlItemNode().isValid()
&& !formEditorItem->qmlItemNode().isRootNode() && formEditorItem->qmlItemNode().instanceIsMovable()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner()
&& (formEditorItem->qmlItemNode().hasShowContent() || !selectOnlyContentItems)) && (formEditorItem->qmlItemNode().hasShowContent() || !selectOnlyContentItems))
{ {
selectedNode = formEditorItem->qmlItemNode(); selectedNode = formEditorItem->qmlItemNode();
......
...@@ -94,7 +94,8 @@ SOURCES += $$PWD/model/abstractview.cpp \ ...@@ -94,7 +94,8 @@ SOURCES += $$PWD/model/abstractview.cpp \
$$PWD/exceptions/rewritingexception.cpp \ $$PWD/exceptions/rewritingexception.cpp \
$$PWD/instances/nodeinstancemetaobject.cpp \ $$PWD/instances/nodeinstancemetaobject.cpp \
$$PWD/instances/behaviornodeinstance.cpp \ $$PWD/instances/behaviornodeinstance.cpp \
$$PWD/instances/nodeinstancesignalspy.cpp $$PWD/instances/nodeinstancesignalspy.cpp \
$$PWD/instances/positionernodeinstance.cpp
HEADERS += $$PWD/include/corelib_global.h \ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/abstractview.h \ $$PWD/include/abstractview.h \
...@@ -187,7 +188,8 @@ HEADERS += $$PWD/include/corelib_global.h \ ...@@ -187,7 +188,8 @@ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/rewritingexception.h \ $$PWD/include/rewritingexception.h \
$$PWD/instances/nodeinstancemetaobject.h \ $$PWD/instances/nodeinstancemetaobject.h \
$$PWD/instances/behaviornodeinstance.h \ $$PWD/instances/behaviornodeinstance.h \
$$PWD/instances/nodeinstancesignalspy.h $$PWD/instances/nodeinstancesignalspy.h \
$$PWD/instances/positionernodeinstance.h
contains(CONFIG, plugin) { contains(CONFIG, plugin) {
# If core.pri has been included in the qmldesigner plugin # If core.pri has been included in the qmldesigner plugin
......
...@@ -102,6 +102,7 @@ public: ...@@ -102,6 +102,7 @@ public:
bool isQDeclarativeView() const; bool isQDeclarativeView() const;
bool isGraphicsObject() const; bool isGraphicsObject() const;
bool isTransition() const; bool isTransition() const;
bool isPositioner() const;
bool equalGraphicsItem(QGraphicsItem *item) const; bool equalGraphicsItem(QGraphicsItem *item) const;
...@@ -127,6 +128,9 @@ public: ...@@ -127,6 +128,9 @@ public:
bool isValid() const; bool isValid() const;
void makeInvalid(); void makeInvalid();
bool hasContent() const; bool hasContent() const;
bool isResizable() const;
bool isMovable() const;
bool isInPositioner() const;
bool isWrappingThisObject(QObject *object) const; bool isWrappingThisObject(QObject *object) const;
......
...@@ -68,6 +68,9 @@ public: ...@@ -68,6 +68,9 @@ public:
bool canReparent() const; bool canReparent() const;
bool instanceIsAnchoredBySibling() const; bool instanceIsAnchoredBySibling() const;
bool instanceIsAnchoredByChildren() const; bool instanceIsAnchoredByChildren() const;
bool instanceIsMovable() const;
bool instanceIsResizable() const;
bool instanceIsInPositioner() const;
QRectF instanceBoundingRect() const; QRectF instanceBoundingRect() const;
QTransform instanceTransform() const; QTransform instanceTransform() const;
......
...@@ -40,7 +40,8 @@ namespace Internal { ...@@ -40,7 +40,8 @@ namespace Internal {
GraphicsObjectNodeInstance::GraphicsObjectNodeInstance(QGraphicsObject *graphicsObject, bool hasContent) GraphicsObjectNodeInstance::GraphicsObjectNodeInstance(QGraphicsObject *graphicsObject, bool hasContent)
: ObjectNodeInstance(graphicsObject), : ObjectNodeInstance(graphicsObject),
m_hasContent(hasContent) m_hasContent(hasContent),
m_isMovable(true)
{ {
} }
...@@ -232,5 +233,16 @@ void GraphicsObjectNodeInstance::paintUpdate() ...@@ -232,5 +233,16 @@ void GraphicsObjectNodeInstance::paintUpdate()
{ {
graphicsObject()->update(); graphicsObject()->update();
} }
bool GraphicsObjectNodeInstance::isMovable() const
{
return m_isMovable && graphicsObject() && graphicsObject()->parentItem();
}
void GraphicsObjectNodeInstance::setMovable(bool movable)
{
m_isMovable = movable;
}
} // namespace Internal } // namespace Internal
} // namespace QmlDesigner } // namespace QmlDesigner
...@@ -74,12 +74,16 @@ public: ...@@ -74,12 +74,16 @@ public:
void paintUpdate(); void paintUpdate();
bool isMovable() const;
void setMovable(bool movable);
protected: protected:
QGraphicsObject *graphicsObject() const; QGraphicsObject *graphicsObject() const;
void paintRecursively(QGraphicsItem *graphicsItem, QPainter *painter) const; void paintRecursively(QGraphicsItem *graphicsItem, QPainter *painter) const;
static QPair<QGraphicsObject*, bool> createGraphicsObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context); static QPair<QGraphicsObject*, bool> createGraphicsObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context);
private: // variables private: // variables
bool m_hasContent; bool m_hasContent;
bool m_isMovable;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "componentnodeinstance.h" #include "componentnodeinstance.h"
#include "qmltransitionnodeinstance.h" #include "qmltransitionnodeinstance.h"
#include "qmlpropertychangesnodeinstance.h" #include "qmlpropertychangesnodeinstance.h"
#include "positionernodeinstance.h"
#include "behaviornodeinstance.h" #include "behaviornodeinstance.h"
#include "qmlstatenodeinstance.h" #include "qmlstatenodeinstance.h"
#include "nodeabstractproperty.h" #include "nodeabstractproperty.h"
...@@ -144,6 +145,8 @@ Internal::ObjectNodeInstance::Pointer NodeInstance::createInstance(const NodeMet ...@@ -144,6 +145,8 @@ Internal::ObjectNodeInstance::Pointer NodeInstance::createInstance(const NodeMet
instance = Internal::QDeclarativeViewNodeInstance::create(metaInfo, context, objectToBeWrapped); instance = Internal::QDeclarativeViewNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("Qt/QGraphicsWidget", 4, 7)) else if (metaInfo.isSubclassOf("Qt/QGraphicsWidget", 4, 7))
instance = Internal::GraphicsWidgetNodeInstance::create(metaInfo, context, objectToBeWrapped); instance = Internal::GraphicsWidgetNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("QDeclarativeBasePositioner", 4, 7))
instance = Internal::PositionerNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("Qt/Item", 4, 7)) else if (metaInfo.isSubclassOf("Qt/Item", 4, 7))
instance = Internal::QmlGraphicsItemNodeInstance::create(metaInfo, context, objectToBeWrapped); instance = Internal::QmlGraphicsItemNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("Qt/QGraphicsScene", 4, 7)) else if (metaInfo.isSubclassOf("Qt/QGraphicsScene", 4, 7))
...@@ -341,6 +344,11 @@ bool NodeInstance::isTransition() const ...@@ -341,6 +344,11 @@ bool NodeInstance::isTransition() const
return m_nodeInstance->isTransition(); return m_nodeInstance->isTransition();
} }
bool NodeInstance::isPositioner() const
{
return m_nodeInstance->isPositioner();
}
/*! /*!
\brief Returns if the NodeInstance is a QGraphicsItem. \brief Returns if the NodeInstance is a QGraphicsItem.
\returns true if this NodeInstance is a QGraphicsItem \returns true if this NodeInstance is a QGraphicsItem
...@@ -460,6 +468,21 @@ bool NodeInstance::hasContent() const ...@@ -460,6 +468,21 @@ bool NodeInstance::hasContent() const
return m_nodeInstance->hasContent(); return m_nodeInstance->hasContent();
} }
bool NodeInstance::isResizable() const
{
return m_nodeInstance->isResizable();
}
bool NodeInstance::isMovable() const
{
return m_nodeInstance->isMovable();
}
bool NodeInstance::isInPositioner() const
{
return m_nodeInstance->isInPositioner();
}
bool NodeInstance::hasAnchor(const QString &name) const bool NodeInstance::hasAnchor(const QString &name) const
{ {
return m_nodeInstance->hasAnchor(name); return m_nodeInstance->hasAnchor(name);
......
...@@ -98,7 +98,8 @@ bool ChildrenChangeEventFilter::eventFilter(QObject * /*object*/, QEvent *event) ...@@ -98,7 +98,8 @@ bool ChildrenChangeEventFilter::eventFilter(QObject * /*object*/, QEvent *event)
ObjectNodeInstance::ObjectNodeInstance(QObject *object) ObjectNodeInstance::ObjectNodeInstance(QObject *object)
: m_deleteHeldInstance(true), : m_deleteHeldInstance(true),
m_object(object), m_object(object),
m_metaObject(0) m_metaObject(0),
m_isInPositioner(false)
{ {
} }
...@@ -249,6 +250,11 @@ bool ObjectNodeInstance::isTransition() const ...@@ -249,6 +250,11 @@ bool ObjectNodeInstance::isTransition() const
return false; return false;
} }
bool ObjectNodeInstance::isPositioner() const
{
return false;
}
bool ObjectNodeInstance::equalGraphicsItem(QGraphicsItem * /*item*/) const bool ObjectNodeInstance::equalGraphicsItem(QGraphicsItem * /*item*/) const
{ {
return false; return false;
...@@ -795,6 +801,26 @@ bool ObjectNodeInstance::hasContent() const ...@@ -795,6 +801,26 @@ bool ObjectNodeInstance::hasContent() const
return false; return false;
} }
bool ObjectNodeInstance::isResizable() const
{
return false;
}
bool ObjectNodeInstance::isMovable() const
{
return false;
}
bool ObjectNodeInstance::isInPositioner() const
{
return m_isInPositioner;
}
void ObjectNodeInstance::setInPositioner(bool isInPositioner)
{
m_isInPositioner = isInPositioner;
}
void ObjectNodeInstance::updateAnchors() void ObjectNodeInstance::updateAnchors()
{ {
} }
......
...@@ -117,6 +117,8 @@ public: ...@@ -117,6 +117,8 @@ public:
virtual bool isQDeclarativeView() const; virtual bool isQDeclarativeView() const;
virtual bool isGraphicsObject() const; virtual bool isGraphicsObject() const;
virtual bool isTransition() const; virtual bool isTransition() const;
virtual bool isPositioner() const;
virtual bool equalGraphicsItem(QGraphicsItem *item) const; virtual bool equalGraphicsItem(QGraphicsItem *item) const;
...@@ -165,6 +167,10 @@ public: ...@@ -165,6 +167,10 @@ public:
QObject *object() const; QObject *object() const;
virtual bool hasContent() const; virtual bool hasContent() const;
virtual bool isResizable() const;
virtual bool isMovable() const;
bool isInPositioner() const;
void setInPositioner(bool isInPositioner);
bool hasBindingForProperty(const QString &name) const; bool hasBindingForProperty(const QString &name) const;
...@@ -207,6 +213,7 @@ private: ...@@ -207,6 +213,7 @@ private:
QWeakPointer<QObject> m_object; QWeakPointer<QObject> m_object;
NodeInstanceMetaObject *m_metaObject; NodeInstanceMetaObject *m_metaObject;
NodeInstanceSignalSpy m_signalSpy; NodeInstanceSignalSpy m_signalSpy;
bool m_isInPositioner;
}; };
......
#include "positionernodeinstance.h"
#include <private/qdeclarativepositioners_p.h>
#include <invalidnodeinstanceexception.h>
namespace QmlDesigner {
namespace Internal {
PositionerNodeInstance::PositionerNodeInstance(QDeclarativeBasePositioner *item, bool hasContent)
: QmlGraphicsItemNodeInstance(item, hasContent)
{
}
bool PositionerNodeInstance::isPositioner() const
{
return true;
}
bool PositionerNodeInstance::isResizable() const
{
return false;
}
void PositionerNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
{
if (name == "move" || name == "add")
return;
QmlGraphicsItemNodeInstance::setPropertyVariant(name, value);
}
void PositionerNodeInstance::setPropertyBinding(const QString &name, const QString &expression)
{