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

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
// set selections to also all children if they are not editor items
foreach (QWeakPointer<QGraphicsObject> obj, itemList) {
if (obj.isNull())
foreach (QWeakPointer<QGraphicsObject> object, itemList) {
if (object.isNull())
continue;
QGraphicsItem *item = obj.data();
QGraphicsItem *item = object.data();
QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem = new QGraphicsPolygonItem(m_layerItem.data());
if (!m_indicatorShapeHash.contains(item)) {
......
......@@ -93,7 +93,8 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem
&& selectedNodes.contains(formEditorItem->qmlItemNode())
&& !formEditorItem->qmlItemNode().isRootNode()
&& formEditorItem->qmlItemNode().instanceIsMovable()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner()
&& (formEditorItem->qmlItemNode().hasShowContent()))
return true;
}
......@@ -101,7 +102,8 @@ bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*
foreach (QGraphicsItem *item, itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem
&& !formEditorItem->qmlItemNode().isRootNode()
&& formEditorItem->qmlItemNode().instanceIsMovable()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner()
&& selectedNodes.contains(formEditorItem->qmlItemNode()))
return true;
}
......
......@@ -200,8 +200,8 @@ FormEditorItem *FormEditorScene::addFormEditorItem(const QmlItemNode &qmlItemNod
QRectF sceneRect(qmlItemNode.instanceBoundingRect());
setSceneRect(sceneRect);
formLayerItem()->update();
manipulatorLayerItem()->update();
formLayerItem()->update();
manipulatorLayerItem()->update();
}
......
......@@ -322,10 +322,25 @@ FormEditorItem* MoveTool::containerFormEditorItem(const QList<QGraphicsItem*> &i
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)
{
FormEditorItem* ancestorItem = ancestorIfOtherItemsAreChild(selectedItemList);
QList<FormEditorItem*> filteredItemList = movalbeItems(selectedItemList);
FormEditorItem* ancestorItem = ancestorIfOtherItemsAreChild(filteredItemList);
if (ancestorItem != 0 && ancestorItem->qmlItemNode().isRootNode()) {
// view()->changeToSelectionTool();
......@@ -339,12 +354,12 @@ QList<FormEditorItem*> MoveTool::movingItems(const QList<FormEditorItem*> &selec
return ancestorItemList;
}
if (!haveSameParent(selectedItemList)) {
if (!haveSameParent(filteredItemList)) {
// view()->changeToSelectionTool();
return QList<FormEditorItem*>();
}
return selectedItemList;
return filteredItemList;
}
void MoveTool::formEditorItemsChanged(const QList<FormEditorItem*> &itemList)
......
......@@ -72,11 +72,12 @@ void ResizeIndicator::setItems(const QList<FormEditorItem*> &itemList)
foreach (FormEditorItem* item, itemList) {
if (item
&& item->qmlItemNode().isValid()
&& item->qmlItemNode().isRootNode())
continue;
ResizeController controller(m_layerItem, item);
m_itemControllerHash.insert(item, controller);
&& item->qmlItemNode().isValid()
&& item->qmlItemNode().instanceIsResizable()
&& !item->qmlItemNode().instanceIsInPositioner()) {
ResizeController controller(m_layerItem, item);
m_itemControllerHash.insert(item, controller);
}
}
}
......
......@@ -101,18 +101,20 @@ void RubberBandSelectionManipulator::select(SelectionType selectionType)
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem
&& formEditorItem->qmlItemNode().isValid()
&& m_beginFormEditorItem->childItems().contains(formEditorItem)
&& !formEditorItem->qmlItemNode().isRootNode())
&& formEditorItem->qmlItemNode().isValid()
&& m_beginFormEditorItem->childItems().contains(formEditorItem)
&& formEditorItem->qmlItemNode().instanceIsMovable()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner())
{
newNodeList.append(formEditorItem->qmlItemNode());
}
}
if (newNodeList.isEmpty()
&& m_beginFormEditorItem->qmlItemNode().isValid()
&& !m_beginFormEditorItem->qmlItemNode().isRootNode())
newNodeList.append(m_beginFormEditorItem->qmlItemNode());
&& m_beginFormEditorItem->qmlItemNode().isValid()
&& m_beginFormEditorItem->qmlItemNode().instanceIsMovable()
&& !m_beginFormEditorItem->qmlItemNode().instanceIsInPositioner())
newNodeList.append(m_beginFormEditorItem->qmlItemNode());
QList<QmlItemNode> nodeList;
......
......@@ -85,7 +85,7 @@ void SelectionIndicator::setItems(const QList<FormEditorItem*> &itemList)
clear();
foreach (FormEditorItem *item, itemList) {
if (item->qmlItemNode().isValid())
if (!item->qmlItemNode().isValid())
continue;
QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem = new QGraphicsPolygonItem(m_layerItem.data());
......
......@@ -145,7 +145,8 @@ void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
if (formEditorItem
&& formEditorItem->qmlItemNode().isValid()
&& !formEditorItem->qmlItemNode().isRootNode()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner()
&& formEditorItem->qmlItemNode().instanceIsMovable()
&& (formEditorItem->qmlItemNode().hasShowContent() || !m_selectOnlyContentItems))
{
topSelectableItem = formEditorItem;
......
......@@ -81,7 +81,8 @@ void SingleSelectionManipulator::select(SelectionType selectionType, bool select
if (formEditorItem
&& formEditorItem->qmlItemNode().isValid()
&& !formEditorItem->qmlItemNode().isRootNode()
&& formEditorItem->qmlItemNode().instanceIsMovable()
&& !formEditorItem->qmlItemNode().instanceIsInPositioner()
&& (formEditorItem->qmlItemNode().hasShowContent() || !selectOnlyContentItems))
{
selectedNode = formEditorItem->qmlItemNode();
......
......@@ -94,7 +94,8 @@ SOURCES += $$PWD/model/abstractview.cpp \
$$PWD/exceptions/rewritingexception.cpp \
$$PWD/instances/nodeinstancemetaobject.cpp \
$$PWD/instances/behaviornodeinstance.cpp \
$$PWD/instances/nodeinstancesignalspy.cpp
$$PWD/instances/nodeinstancesignalspy.cpp \
$$PWD/instances/positionernodeinstance.cpp
HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/abstractview.h \
......@@ -187,7 +188,8 @@ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/rewritingexception.h \
$$PWD/instances/nodeinstancemetaobject.h \
$$PWD/instances/behaviornodeinstance.h \
$$PWD/instances/nodeinstancesignalspy.h
$$PWD/instances/nodeinstancesignalspy.h \
$$PWD/instances/positionernodeinstance.h
contains(CONFIG, plugin) {
# If core.pri has been included in the qmldesigner plugin
......
......@@ -102,6 +102,7 @@ public:
bool isQDeclarativeView() const;
bool isGraphicsObject() const;
bool isTransition() const;
bool isPositioner() const;
bool equalGraphicsItem(QGraphicsItem *item) const;
......@@ -127,6 +128,9 @@ public:
bool isValid() const;
void makeInvalid();
bool hasContent() const;
bool isResizable() const;
bool isMovable() const;
bool isInPositioner() const;
bool isWrappingThisObject(QObject *object) const;
......
......@@ -68,6 +68,9 @@ public:
bool canReparent() const;
bool instanceIsAnchoredBySibling() const;
bool instanceIsAnchoredByChildren() const;
bool instanceIsMovable() const;
bool instanceIsResizable() const;
bool instanceIsInPositioner() const;
QRectF instanceBoundingRect() const;
QTransform instanceTransform() const;
......
......@@ -40,7 +40,8 @@ namespace Internal {
GraphicsObjectNodeInstance::GraphicsObjectNodeInstance(QGraphicsObject *graphicsObject, bool hasContent)
: ObjectNodeInstance(graphicsObject),
m_hasContent(hasContent)
m_hasContent(hasContent),
m_isMovable(true)
{
}
......@@ -232,5 +233,16 @@ void GraphicsObjectNodeInstance::paintUpdate()
{
graphicsObject()->update();
}
bool GraphicsObjectNodeInstance::isMovable() const
{
return m_isMovable && graphicsObject() && graphicsObject()->parentItem();
}
void GraphicsObjectNodeInstance::setMovable(bool movable)
{
m_isMovable = movable;
}
} // namespace Internal
} // namespace QmlDesigner
......@@ -74,12 +74,16 @@ public:
void paintUpdate();
bool isMovable() const;
void setMovable(bool movable);
protected:
QGraphicsObject *graphicsObject() const;
void paintRecursively(QGraphicsItem *graphicsItem, QPainter *painter) const;
static QPair<QGraphicsObject*, bool> createGraphicsObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context);
private: // variables
bool m_hasContent;
bool m_isMovable;
};
} // namespace Internal
......
......@@ -42,6 +42,7 @@
#include "componentnodeinstance.h"
#include "qmltransitionnodeinstance.h"
#include "qmlpropertychangesnodeinstance.h"
#include "positionernodeinstance.h"
#include "behaviornodeinstance.h"
#include "qmlstatenodeinstance.h"
#include "nodeabstractproperty.h"
......@@ -144,6 +145,8 @@ Internal::ObjectNodeInstance::Pointer NodeInstance::createInstance(const NodeMet
instance = Internal::QDeclarativeViewNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("Qt/QGraphicsWidget", 4, 7))
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))
instance = Internal::QmlGraphicsItemNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("Qt/QGraphicsScene", 4, 7))
......@@ -341,6 +344,11 @@ bool NodeInstance::isTransition() const
return m_nodeInstance->isTransition();
}
bool NodeInstance::isPositioner() const
{
return m_nodeInstance->isPositioner();
}
/*!
\brief Returns if the NodeInstance is a QGraphicsItem.
\returns true if this NodeInstance is a QGraphicsItem
......@@ -460,6 +468,21 @@ bool NodeInstance::hasContent() const
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
{
return m_nodeInstance->hasAnchor(name);
......
......@@ -98,7 +98,8 @@ bool ChildrenChangeEventFilter::eventFilter(QObject * /*object*/, QEvent *event)
ObjectNodeInstance::ObjectNodeInstance(QObject *object)
: m_deleteHeldInstance(true),
m_object(object),
m_metaObject(0)
m_metaObject(0),
m_isInPositioner(false)
{
}
......@@ -249,6 +250,11 @@ bool ObjectNodeInstance::isTransition() const
return false;
}
bool ObjectNodeInstance::isPositioner() const
{
return false;
}
bool ObjectNodeInstance::equalGraphicsItem(QGraphicsItem * /*item*/) const
{
return false;
......@@ -795,6 +801,26 @@ bool ObjectNodeInstance::hasContent() const
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()
{
}
......
......@@ -117,6 +117,8 @@ public:
virtual bool isQDeclarativeView() const;
virtual bool isGraphicsObject() const;
virtual bool isTransition() const;
virtual bool isPositioner() const;
virtual bool equalGraphicsItem(QGraphicsItem *item) const;
......@@ -165,6 +167,10 @@ public:
QObject *object() 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;
......@@ -207,6 +213,7 @@ private:
QWeakPointer<QObject> m_object;
NodeInstanceMetaObject *m_metaObject;
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)
{
if (name == "move" || name == "add")
return;
QmlGraphicsItemNodeInstance::setPropertyBinding(name, expression);
}
PositionerNodeInstance::Pointer PositionerNodeInstance::create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped)
{
QPair<QGraphicsObject*, bool> objectPair;
if (objectToBeWrapped)
objectPair = qMakePair(qobject_cast<QGraphicsObject*>(objectToBeWrapped), false);
else
objectPair = GraphicsObjectNodeInstance::createGraphicsObject(metaInfo, context);
QDeclarativeBasePositioner *positioner = dynamic_cast<QDeclarativeBasePositioner*>(objectPair.first);
if (positioner == 0)
throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__);
Pointer instance(new PositionerNodeInstance(positioner, objectPair.second));
static_cast<QDeclarativeParserStatus*>(positioner)->classBegin();
if (objectToBeWrapped)
instance->setDeleteHeldInstance(false); // the object isn't owned
instance->populateResetValueHash();
return instance;
}
}
} // namespace QmlDesigner
#ifndef POSITIONERNODEINSTANCE_H
#define POSITIONERNODEINSTANCE_H
#include "qmlgraphicsitemnodeinstance.h"
class QDeclarativeBasePositioner;
namespace QmlDesigner {
namespace Internal {
class PositionerNodeInstance : public QmlGraphicsItemNodeInstance
{
public:
typedef QSharedPointer<PositionerNodeInstance> Pointer;
typedef QWeakPointer<PositionerNodeInstance> WeakPointer;
static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped);
void setPropertyVariant(const QString &name, const QVariant &value);
void setPropertyBinding(const QString &name, const QString &expression);
bool isPositioner() const;
bool isResizable() const;
protected:
PositionerNodeInstance(QDeclarativeBasePositioner *item, bool hasContent);
};
} // namespace Internal
} // namespace QmlDesigner
#endif // POSITIONERNODEINSTANCE_H
......@@ -45,6 +45,8 @@
#include <private/qdeclarativeitem_p.h>
#include <private/qdeclarativeproperty_p.h>
#include <private/qdeclarativerectangle_p.h>
#include <private/qdeclarativepositioners_p.h>
#include <cmath>
......@@ -56,7 +58,8 @@ namespace Internal {
QmlGraphicsItemNodeInstance::QmlGraphicsItemNodeInstance(QDeclarativeItem *item, bool hasContent)
: GraphicsObjectNodeInstance(item, hasContent),
m_hasHeight(false),
m_hasWidth(false)
m_hasWidth(false),
m_isResizable(true)
{
}
......@@ -80,6 +83,9 @@ QmlGraphicsItemNodeInstance::Pointer QmlGraphicsItemNodeInstance::create(const N
Pointer instance(new QmlGraphicsItemNodeInstance(qmlGraphicsItem, objectPair.second));
if (qmlGraphicsItem->inherits("QDeclarativeText"))
instance->setResizable(false);
static_cast<QDeclarativeParserStatus*>(qmlGraphicsItem)->classBegin();
if (objectToBeWrapped)
......@@ -223,6 +229,8 @@ void QmlGraphicsItemNodeInstance::setPropertyVariant(const QString &name, const
}
GraphicsObjectNodeInstance::setPropertyVariant(name, value);
refresh();
}
void QmlGraphicsItemNodeInstance::setPropertyBinding(const QString &name, const QString &expression)
......@@ -288,6 +296,24 @@ void QmlGraphicsItemNodeInstance::resetVertical()
setPropertyVariant("height", qmlGraphicsItem()->implicitHeight());
}
static void repositioning(QDeclarativeItem *item)
{
if (!item)
return;
// QDeclarativeBasePositioner *positioner = qobject_cast<QDeclarativeBasePositioner*>(item);
// if (positioner)
// positioner->rePositioning();
if (item->parentObject())
repositioning(qobject_cast<QDeclarativeItem*>(item->parentObject()));
}
void QmlGraphicsItemNodeInstance::refresh()
{
repositioning(qmlGraphicsItem());
}
void QmlGraphicsItemNodeInstance::doComponentComplete()
{
if (qmlGraphicsItem()) {
......@@ -297,6 +323,16 @@ void QmlGraphicsItemNodeInstance::doComponentComplete()
}
}
bool QmlGraphicsItemNodeInstance::isResizable() const
{
return m_isResizable && qmlGraphicsItem() && qmlGraphicsItem()->parentItem();
}
void QmlGraphicsItemNodeInstance::setResizable(bool resizeable)
{
m_isResizable = resizeable;
}
int QmlGraphicsItemNodeInstance::penWidth() const
{
QDeclarativeRectangle *rectangle = qobject_cast<QDeclarativeRectangle*>(object());
......@@ -350,7 +386,19 @@ void QmlGraphicsItemNodeInstance::resetProperty(const QString &name)
void QmlGraphicsItemNodeInstance::reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty)
{
if (oldParentInstance.isValid() && oldParentInstance.isPositioner()) {
setInPositioner(false);
setMovable(true);
}
GraphicsObjectNodeInstance::reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty);
if (newParentInstance.isValid() && newParentInstance.isPositioner()) {
setInPositioner(true);
setMovable(false);
}
refresh();
}
//void QmlGraphicsItemNodeInstance::updateAnchors()
......
......@@ -70,16 +70,22 @@ public:
bool isAnchoredByChildren() const;
void doComponentComplete();
bool isResizable() const;
void setResizable(bool resizeable);
protected:
QmlGraphicsItemNodeInstance(QDeclarativeItem *item, bool hasContent);
QDeclarativeItem *qmlGraphicsItem() const;
QDeclarativeAnchors *anchors() const;
void resetHorizontal();
void resetVertical();
void refresh();
private: //variables
bool m_hasHeight;
bool m_hasWidth;
bool m_isResizable;
};
}
......