forked from qt-creator/qt-creator
QmlDesigner: Add GraphicalNodeInstance as abstraction for item and window
Change-Id: Icaba711464f672a3bfbb9d83a449d47e72ba11ff Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
@@ -0,0 +1,558 @@
|
||||
#include "graphicalnodeinstance.h"
|
||||
|
||||
#include "qt5nodeinstanceserver.h"
|
||||
|
||||
#include <QQmlExpression>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QQuickView>
|
||||
|
||||
#include <private/qquickitem_p.h>
|
||||
#include <private/qquicktextinput_p.h>
|
||||
#include <private/qquicktextedit_p.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
bool GraphicalNodeInstance::s_createEffectItem = false;
|
||||
|
||||
GraphicalNodeInstance::GraphicalNodeInstance(QObject *object)
|
||||
: ObjectNodeInstance(object),
|
||||
m_hasHeight(false),
|
||||
m_hasWidth(false),
|
||||
m_hasContent(true),
|
||||
m_x(0.0),
|
||||
m_y(0.0),
|
||||
m_width(0.0),
|
||||
m_height(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::setHasContent(bool hasContent)
|
||||
{
|
||||
m_hasContent = hasContent;
|
||||
}
|
||||
|
||||
DesignerSupport *GraphicalNodeInstance::designerSupport() const
|
||||
{
|
||||
return qt5NodeInstanceServer()->designerSupport();
|
||||
}
|
||||
|
||||
Qt5NodeInstanceServer *GraphicalNodeInstance::qt5NodeInstanceServer() const
|
||||
{
|
||||
return qobject_cast<Qt5NodeInstanceServer*>(nodeInstanceServer());
|
||||
}
|
||||
|
||||
|
||||
bool GraphicalNodeInstance::isGraphical() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GraphicalNodeInstance::anyItemHasContent(QQuickItem *quickItem)
|
||||
{
|
||||
if (quickItem->flags().testFlag(QQuickItem::ItemHasContents))
|
||||
return true;
|
||||
|
||||
foreach (QQuickItem *childItem, quickItem->childItems()) {
|
||||
if (anyItemHasContent(childItem))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
double GraphicalNodeInstance::x() const
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
|
||||
double GraphicalNodeInstance::y() const
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
|
||||
QQuickItem *GraphicalNodeInstance::quickItem() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GraphicalNodeInstance::childItemsHaveContent(QQuickItem *quickItem)
|
||||
{
|
||||
foreach (QQuickItem *childItem, quickItem->childItems()) {
|
||||
if (anyItemHasContent(childItem))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GraphicalNodeInstance::hasContent() const
|
||||
{
|
||||
if (m_hasContent)
|
||||
return true;
|
||||
|
||||
return childItemsHaveContent(quickItem());
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::createEffectItem(bool createEffectItem)
|
||||
{
|
||||
s_createEffectItem = createEffectItem;
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::updateDirtyNodeRecursive()
|
||||
{
|
||||
foreach (QQuickItem *childItem, quickItem()->childItems())
|
||||
updateDirtyNodeRecursive(childItem);
|
||||
|
||||
DesignerSupport::updateDirtyNode(quickItem());
|
||||
}
|
||||
|
||||
GraphicalNodeInstance::~GraphicalNodeInstance()
|
||||
{
|
||||
if (quickItem())
|
||||
designerSupport()->derefFromEffectItem(quickItem());
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::updateDirtyNodeRecursive(QQuickItem *parentItem) const
|
||||
{
|
||||
foreach (QQuickItem *childItem, parentItem->childItems()) {
|
||||
if (!nodeInstanceServer()->hasInstanceForObject(childItem))
|
||||
updateDirtyNodeRecursive(childItem);
|
||||
}
|
||||
|
||||
DesignerSupport::updateDirtyNode(parentItem);
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::updateAllDirtyNodeRecursive(QQuickItem *parentItem) const
|
||||
{
|
||||
foreach (QQuickItem *childItem, parentItem->childItems())
|
||||
updateDirtyNodeRecursive(childItem);
|
||||
|
||||
DesignerSupport::updateDirtyNode(parentItem);
|
||||
}
|
||||
|
||||
QImage GraphicalNodeInstance::renderImage() const
|
||||
{
|
||||
updateDirtyNodeRecursive(quickItem());
|
||||
|
||||
QRectF boundingRect = boundingRectWithStepChilds(quickItem());
|
||||
|
||||
QImage renderImage = designerSupport()->renderImageForItem(quickItem(), boundingRect, boundingRect.size().toSize());
|
||||
|
||||
renderImage = renderImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
|
||||
return renderImage;
|
||||
}
|
||||
|
||||
QImage GraphicalNodeInstance::renderPreviewImage(const QSize &previewImageSize) const
|
||||
{
|
||||
QRectF previewItemBoundingRect = boundingRect();
|
||||
|
||||
if (previewItemBoundingRect.isValid() && quickItem())
|
||||
return designerSupport()->renderImageForItem(quickItem(), previewItemBoundingRect, previewImageSize);
|
||||
|
||||
return QImage();
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance)
|
||||
{
|
||||
if (instanceId() == 0) {
|
||||
DesignerSupport::setRootItem(nodeInstanceServer()->quickView(), quickItem());
|
||||
} else {
|
||||
quickItem()->setParentItem(qobject_cast<QQuickItem*>(nodeInstanceServer()->quickView()->rootObject()));
|
||||
}
|
||||
|
||||
if (s_createEffectItem || instanceId() == 0)
|
||||
designerSupport()->refFromEffectItem(quickItem());
|
||||
|
||||
ObjectNodeInstance::initialize(objectNodeInstance);
|
||||
quickItem()->update();
|
||||
}
|
||||
|
||||
QPointF GraphicalNodeInstance::position() const
|
||||
{
|
||||
return quickItem()->position();
|
||||
}
|
||||
|
||||
QTransform GraphicalNodeInstance::customTransform() const
|
||||
{
|
||||
return QTransform();
|
||||
}
|
||||
|
||||
QTransform GraphicalNodeInstance::sceneTransform() const
|
||||
{
|
||||
return DesignerSupport::windowTransform(quickItem());
|
||||
}
|
||||
|
||||
double GraphicalNodeInstance::rotation() const
|
||||
{
|
||||
return quickItem()->rotation();
|
||||
}
|
||||
|
||||
double GraphicalNodeInstance::scale() const
|
||||
{
|
||||
return quickItem()->scale();
|
||||
}
|
||||
|
||||
QPointF GraphicalNodeInstance::transformOriginPoint() const
|
||||
{
|
||||
return quickItem()->transformOriginPoint();
|
||||
}
|
||||
|
||||
double GraphicalNodeInstance::zValue() const
|
||||
{
|
||||
return quickItem()->z();
|
||||
}
|
||||
|
||||
double GraphicalNodeInstance::opacity() const
|
||||
{
|
||||
return quickItem()->opacity();
|
||||
}
|
||||
|
||||
QSizeF GraphicalNodeInstance::size() const
|
||||
{
|
||||
double width;
|
||||
|
||||
if (DesignerSupport::isValidWidth(quickItem())) {
|
||||
width = quickItem()->width();
|
||||
} else {
|
||||
width = quickItem()->implicitWidth();
|
||||
}
|
||||
|
||||
double height;
|
||||
|
||||
if (DesignerSupport::isValidHeight(quickItem())) {
|
||||
height = quickItem()->height();
|
||||
} else {
|
||||
height = quickItem()->implicitHeight();
|
||||
}
|
||||
|
||||
|
||||
return QSizeF(width, height);
|
||||
}
|
||||
|
||||
static inline bool isRectangleSane(const QRectF &rect)
|
||||
{
|
||||
return rect.isValid() && (rect.width() < 10000) && (rect.height() < 10000);
|
||||
}
|
||||
|
||||
QRectF GraphicalNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem) const
|
||||
{
|
||||
QRectF boundingRect = parentItem->boundingRect();
|
||||
|
||||
foreach (QQuickItem *childItem, parentItem->childItems()) {
|
||||
if (!nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
QRectF transformedRect = childItem->mapRectToItem(parentItem, boundingRectWithStepChilds(childItem));
|
||||
if (isRectangleSane(transformedRect))
|
||||
boundingRect = boundingRect.united(transformedRect);
|
||||
}
|
||||
}
|
||||
|
||||
return boundingRect;
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::resetHorizontal()
|
||||
{
|
||||
setPropertyVariant("x", m_x);
|
||||
if (m_width > 0.0) {
|
||||
setPropertyVariant("width", m_width);
|
||||
} else {
|
||||
setPropertyVariant("width", quickItem()->implicitWidth());
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::resetVertical()
|
||||
{
|
||||
setPropertyVariant("y", m_y);
|
||||
if (m_height > 0.0) {
|
||||
setPropertyVariant("height", m_height);
|
||||
} else {
|
||||
setPropertyVariant("height", quickItem()->implicitWidth());
|
||||
}
|
||||
}
|
||||
|
||||
int GraphicalNodeInstance::penWidth() const
|
||||
{
|
||||
return DesignerSupport::borderWidth(quickItem());
|
||||
}
|
||||
|
||||
|
||||
QList<ServerNodeInstance> GraphicalNodeInstance::childItemsForChild(QQuickItem *childItem) const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
|
||||
if (childItem) {
|
||||
foreach (QQuickItem *childItem, childItem->childItems())
|
||||
{
|
||||
if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(childItem));
|
||||
} else {
|
||||
instanceList.append(childItemsForChild(childItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
QList<ServerNodeInstance> GraphicalNodeInstance::childItems() const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
|
||||
foreach (QQuickItem *childItem, quickItem()->childItems())
|
||||
{
|
||||
if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(childItem));
|
||||
} else { //there might be an item in between the parent instance
|
||||
//and the child instance.
|
||||
//Popular example is flickable which has a viewport item between
|
||||
//the flickable item and the flickable children
|
||||
instanceList.append(childItemsForChild(childItem)); //In such a case we go deeper inside the item and
|
||||
//search for child items with instances.
|
||||
}
|
||||
}
|
||||
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalNodeInstance::setPropertyVariant(const PropertyName &name, const QVariant &value)
|
||||
{
|
||||
if (name == "state")
|
||||
return; // states are only set by us
|
||||
|
||||
if (name == "height") {
|
||||
m_height = value.toDouble();
|
||||
if (value.isValid())
|
||||
m_hasHeight = true;
|
||||
else
|
||||
m_hasHeight = false;
|
||||
}
|
||||
|
||||
if (name == "width") {
|
||||
m_width = value.toDouble();
|
||||
if (value.isValid())
|
||||
m_hasWidth = true;
|
||||
else
|
||||
m_hasWidth = false;
|
||||
}
|
||||
|
||||
if (name == "x")
|
||||
m_x = value.toDouble();
|
||||
|
||||
if (name == "y")
|
||||
m_y = value.toDouble();
|
||||
|
||||
ObjectNodeInstance::setPropertyVariant(name, value);
|
||||
|
||||
quickItem()->update();
|
||||
|
||||
refresh();
|
||||
|
||||
if (isInPositioner())
|
||||
parentInstance()->refreshPositioner();
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::setPropertyBinding(const PropertyName &name, const QString &expression)
|
||||
{
|
||||
if (name == "state")
|
||||
return; // states are only set by us
|
||||
|
||||
ObjectNodeInstance::setPropertyBinding(name, expression);
|
||||
|
||||
quickItem()->update();
|
||||
|
||||
refresh();
|
||||
|
||||
if (isInPositioner())
|
||||
parentInstance()->refreshPositioner();
|
||||
}
|
||||
|
||||
QVariant GraphicalNodeInstance::property(const PropertyName &name) const
|
||||
{
|
||||
if (name == "visible")
|
||||
return quickItem()->isVisible();
|
||||
|
||||
return ObjectNodeInstance::property(name);
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::resetProperty(const PropertyName &name)
|
||||
{
|
||||
if (name == "height") {
|
||||
m_hasHeight = false;
|
||||
m_height = 0.0;
|
||||
}
|
||||
|
||||
if (name == "width") {
|
||||
m_hasWidth = false;
|
||||
m_width = 0.0;
|
||||
}
|
||||
|
||||
if (name == "x")
|
||||
m_x = 0.0;
|
||||
|
||||
if (name == "y")
|
||||
m_y = 0.0;
|
||||
|
||||
DesignerSupport::resetAnchor(quickItem(), name);
|
||||
|
||||
if (name == "anchors.fill") {
|
||||
resetHorizontal();
|
||||
resetVertical();
|
||||
} else if (name == "anchors.centerIn") {
|
||||
resetHorizontal();
|
||||
resetVertical();
|
||||
} else if (name == "anchors.top") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.left") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.right") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.bottom") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.horizontalCenter") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.verticalCenter") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.baseline") {
|
||||
resetVertical();
|
||||
}
|
||||
|
||||
ObjectNodeInstance::resetProperty(name);
|
||||
|
||||
quickItem()->update();
|
||||
|
||||
if (isInPositioner())
|
||||
parentInstance()->refreshPositioner();
|
||||
}
|
||||
|
||||
|
||||
static bool isValidAnchorName(const PropertyName &name)
|
||||
{
|
||||
static PropertyNameList anchorNameList(PropertyNameList() << "anchors.top"
|
||||
<< "anchors.left"
|
||||
<< "anchors.right"
|
||||
<< "anchors.bottom"
|
||||
<< "anchors.verticalCenter"
|
||||
<< "anchors.horizontalCenter"
|
||||
<< "anchors.fill"
|
||||
<< "anchors.centerIn"
|
||||
<< "anchors.baseline");
|
||||
|
||||
return anchorNameList.contains(name);
|
||||
}
|
||||
|
||||
bool GraphicalNodeInstance::hasAnchor(const PropertyName &name) const
|
||||
{
|
||||
return DesignerSupport::hasAnchor(quickItem(), name);
|
||||
}
|
||||
|
||||
QPair<PropertyName, ServerNodeInstance> GraphicalNodeInstance::anchor(const PropertyName &name) const
|
||||
{
|
||||
if (!isValidAnchorName(name) || !DesignerSupport::hasAnchor(quickItem(), name))
|
||||
return ObjectNodeInstance::anchor(name);
|
||||
|
||||
QPair<QString, QObject*> nameObjectPair = DesignerSupport::anchorLineTarget(quickItem(), name, context());
|
||||
|
||||
QObject *targetObject = nameObjectPair.second;
|
||||
PropertyName targetName = nameObjectPair.first.toUtf8();
|
||||
|
||||
if (targetObject && nodeInstanceServer()->hasInstanceForObject(targetObject)) {
|
||||
return qMakePair(targetName, nodeInstanceServer()->instanceForObject(targetObject));
|
||||
} else {
|
||||
return ObjectNodeInstance::anchor(name);
|
||||
}
|
||||
}
|
||||
|
||||
static void doComponentCompleteRecursive(QQuickItem *item)
|
||||
{
|
||||
if (item) {
|
||||
if (DesignerSupport::isComponentComplete(item))
|
||||
return;
|
||||
|
||||
foreach (QQuickItem *childItem, item->childItems())
|
||||
doComponentCompleteRecursive(childItem);
|
||||
|
||||
static_cast<QQmlParserStatus*>(item)->componentComplete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void disableTextCursor(QQuickItem *item)
|
||||
{
|
||||
foreach (QQuickItem *childItem, item->childItems())
|
||||
disableTextCursor(childItem);
|
||||
|
||||
QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(item);
|
||||
if (textInput)
|
||||
textInput->setCursorVisible(false);
|
||||
|
||||
QQuickTextEdit *textEdit = qobject_cast<QQuickTextEdit*>(item);
|
||||
if (textEdit)
|
||||
textEdit->setCursorVisible(false);
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::doComponentComplete()
|
||||
{
|
||||
doComponentCompleteRecursive(quickItem());
|
||||
|
||||
disableTextCursor(quickItem());
|
||||
|
||||
quickItem()->update();
|
||||
}
|
||||
|
||||
bool GraphicalNodeInstance::isAnchoredByChildren() const
|
||||
{
|
||||
if (DesignerSupport::areChildrenAnchoredTo(quickItem(), quickItem())) // search in children for a anchor to this item
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QRectF GraphicalNodeInstance::boundingRect() const
|
||||
{
|
||||
if (quickItem()) {
|
||||
if (quickItem()->clip()) {
|
||||
return quickItem()->boundingRect();
|
||||
} else {
|
||||
return boundingRectWithStepChilds(quickItem());
|
||||
}
|
||||
}
|
||||
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
static void repositioning(QQuickItem *item)
|
||||
{
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
// QQmlBasePositioner *positioner = qobject_cast<QQmlBasePositioner*>(item);
|
||||
// if (positioner)
|
||||
// positioner->rePositioning();
|
||||
|
||||
if (item->parentItem())
|
||||
repositioning(item->parentItem());
|
||||
}
|
||||
|
||||
void GraphicalNodeInstance::refresh()
|
||||
{
|
||||
repositioning(quickItem());
|
||||
}
|
||||
|
||||
QList<ServerNodeInstance> GraphicalNodeInstance::stateInstances() const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
QList<QObject*> stateList = DesignerSupport::statesForItem(quickItem());
|
||||
foreach (QObject *state, stateList)
|
||||
{
|
||||
if (state && nodeInstanceServer()->hasInstanceForObject(state))
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(state));
|
||||
}
|
||||
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace QmlDesigner
|
@@ -0,0 +1,95 @@
|
||||
#ifndef QMLDESIGNER_GRAPHICALNODEINSTANCE_H
|
||||
#define QMLDESIGNER_GRAPHICALNODEINSTANCE_H
|
||||
|
||||
#include "objectnodeinstance.h"
|
||||
|
||||
#include <designersupport.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
class GraphicalNodeInstance : public ObjectNodeInstance
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<QuickItemNodeInstance> Pointer;
|
||||
typedef QWeakPointer<QuickItemNodeInstance> WeakPointer;
|
||||
|
||||
~GraphicalNodeInstance();
|
||||
|
||||
void initialize(const ObjectNodeInstance::Pointer &objectNodeInstance);
|
||||
|
||||
bool isGraphical() const;
|
||||
bool hasContent() const;
|
||||
|
||||
QRectF boundingRect() const;
|
||||
QTransform customTransform() const;
|
||||
QTransform sceneTransform() const;
|
||||
double opacity() const;
|
||||
double rotation() const;
|
||||
double scale() const;
|
||||
QPointF transformOriginPoint() const;
|
||||
double zValue() const;
|
||||
QPointF position() const;
|
||||
QSizeF size() const;
|
||||
|
||||
QImage renderImage() const;
|
||||
QImage renderPreviewImage(const QSize &previewImageSize) const;
|
||||
|
||||
QList<ServerNodeInstance> childItems() const;
|
||||
|
||||
void updateDirtyNodeRecursive();
|
||||
static void createEffectItem(bool createEffectItem);
|
||||
|
||||
int penWidth() const;
|
||||
|
||||
void setPropertyVariant(const PropertyName &name, const QVariant &value);
|
||||
void setPropertyBinding(const PropertyName &name, const QString &expression);
|
||||
|
||||
QVariant property(const PropertyName &name) const;
|
||||
void resetProperty(const PropertyName &name) ;
|
||||
|
||||
QList<ServerNodeInstance> stateInstances() const;
|
||||
|
||||
bool isAnchoredByChildren() const;
|
||||
bool hasAnchor(const PropertyName &name) const;
|
||||
QPair<PropertyName, ServerNodeInstance> anchor(const PropertyName &name) const;
|
||||
|
||||
void doComponentComplete();
|
||||
|
||||
protected:
|
||||
explicit GraphicalNodeInstance(QObject *object);
|
||||
void setHasContent(bool hasContent);
|
||||
DesignerSupport *designerSupport() const;
|
||||
Qt5NodeInstanceServer *qt5NodeInstanceServer() const;
|
||||
void updateDirtyNodeRecursive(QQuickItem *parentItem) const;
|
||||
void updateAllDirtyNodeRecursive(QQuickItem *parentItem) const;
|
||||
QRectF boundingRectWithStepChilds(QQuickItem *parentItem) const;
|
||||
void resetHorizontal();
|
||||
void resetVertical();
|
||||
QList<ServerNodeInstance> childItemsForChild(QQuickItem *childItem) const;
|
||||
void refresh();
|
||||
static bool anyItemHasContent(QQuickItem *quickItem);
|
||||
static bool childItemsHaveContent(QQuickItem *quickItem);
|
||||
|
||||
double x() const;
|
||||
double y() const;
|
||||
|
||||
virtual QQuickItem *quickItem() const;
|
||||
|
||||
private: // functions
|
||||
|
||||
private: // variables
|
||||
bool m_hasHeight;
|
||||
bool m_hasWidth;
|
||||
bool m_hasContent;
|
||||
double m_x;
|
||||
double m_y;
|
||||
double m_width;
|
||||
double m_height;
|
||||
static bool s_createEffectItem;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlDesigner
|
||||
|
||||
#endif // QMLDESIGNER_GRAPHICALNODEINSTANCE_H
|
@@ -1,6 +1,7 @@
|
||||
INCLUDEPATH += $$PWD/
|
||||
|
||||
HEADERS += $$PWD/qt5nodeinstanceserver.h
|
||||
HEADERS += $$PWD//graphicalnodeinstance.h
|
||||
HEADERS += $$PWD/qt5informationnodeinstanceserver.h
|
||||
HEADERS += $$PWD/qt5rendernodeinstanceserver.h
|
||||
HEADERS += $$PWD/qt5previewnodeinstanceserver.h
|
||||
@@ -24,6 +25,7 @@ HEADERS += $$PWD/positionernodeinstance.h
|
||||
HEADERS += $$PWD/quickwindownodeinstance.h
|
||||
|
||||
SOURCES += $$PWD/qt5nodeinstanceserver.cpp
|
||||
SOURCES += $$PWD/graphicalnodeinstance.cpp
|
||||
SOURCES += $$PWD/qt5informationnodeinstanceserver.cpp
|
||||
SOURCES += $$PWD/qt5rendernodeinstanceserver.cpp
|
||||
SOURCES += $$PWD/qt5previewnodeinstanceserver.cpp
|
||||
|
@@ -194,6 +194,16 @@ bool ObjectNodeInstance::isQuickItem() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ObjectNodeInstance::isQuickWindow() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ObjectNodeInstance::isGraphical() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ObjectNodeInstance::equalGraphicsItem(QGraphicsItem * /*item*/) const
|
||||
{
|
||||
return false;
|
||||
|
@@ -64,7 +64,6 @@ class ObjectNodeInstance
|
||||
public:
|
||||
typedef QSharedPointer<ObjectNodeInstance> Pointer;
|
||||
typedef QWeakPointer<ObjectNodeInstance> WeakPointer;
|
||||
explicit ObjectNodeInstance(QObject *object);
|
||||
|
||||
virtual ~ObjectNodeInstance();
|
||||
void destroy();
|
||||
@@ -98,6 +97,8 @@ public:
|
||||
virtual bool isTransition() const;
|
||||
virtual bool isPositioner() const;
|
||||
virtual bool isQuickItem() const;
|
||||
virtual bool isQuickWindow() const;
|
||||
virtual bool isGraphical() const;
|
||||
|
||||
virtual bool equalGraphicsItem(QGraphicsItem *item) const;
|
||||
|
||||
@@ -182,6 +183,7 @@ public:
|
||||
virtual void updateDirtyNodeRecursive();
|
||||
|
||||
protected:
|
||||
explicit ObjectNodeInstance(QObject *object);
|
||||
void doResetProperty(const PropertyName &propertyName);
|
||||
void removeFromOldProperty(QObject *object, QObject *oldParent, const PropertyName &oldParentProperty);
|
||||
void addToNewProperty(QObject *object, QObject *newParent, const PropertyName &newParentProperty);
|
||||
|
@@ -65,7 +65,7 @@ void Qt5PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands()
|
||||
{
|
||||
static bool inFunction = false;
|
||||
|
||||
if (!rootNodeInstance().holdsQuickItem())
|
||||
if (!rootNodeInstance().holdsGraphical())
|
||||
return;
|
||||
|
||||
if (!inFunction && nodeInstanceClient()->bytesToWrite() < 10000) {
|
||||
|
@@ -45,105 +45,15 @@
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
bool QuickItemNodeInstance::s_createEffectItem = false;
|
||||
|
||||
QuickItemNodeInstance::QuickItemNodeInstance(QQuickItem *item)
|
||||
: ObjectNodeInstance(item),
|
||||
m_hasHeight(false),
|
||||
m_hasWidth(false),
|
||||
: GraphicalNodeInstance(item),
|
||||
m_isResizable(true),
|
||||
m_hasContent(true),
|
||||
m_isMovable(true),
|
||||
m_x(0.0),
|
||||
m_y(0.0),
|
||||
m_width(0.0),
|
||||
m_height(0.0)
|
||||
m_isMovable(true)
|
||||
{
|
||||
}
|
||||
|
||||
QuickItemNodeInstance::~QuickItemNodeInstance()
|
||||
{
|
||||
if (quickItem())
|
||||
designerSupport()->derefFromEffectItem(quickItem());
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::hasContent() const
|
||||
{
|
||||
if (m_hasContent)
|
||||
return true;
|
||||
|
||||
return childItemsHaveContent(quickItem());
|
||||
}
|
||||
|
||||
QList<ServerNodeInstance> QuickItemNodeInstance::childItems() const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
|
||||
foreach (QQuickItem *childItem, quickItem()->childItems())
|
||||
{
|
||||
if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(childItem));
|
||||
} else { //there might be an item in between the parent instance
|
||||
//and the child instance.
|
||||
//Popular example is flickable which has a viewport item between
|
||||
//the flickable item and the flickable children
|
||||
instanceList.append(childItemsForChild(childItem)); //In such a case we go deeper inside the item and
|
||||
//search for child items with instances.
|
||||
}
|
||||
}
|
||||
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
QList<ServerNodeInstance> QuickItemNodeInstance::childItemsForChild(QQuickItem *childItem) const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
|
||||
if (childItem) {
|
||||
foreach (QQuickItem *childItem, childItem->childItems())
|
||||
{
|
||||
if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(childItem));
|
||||
} else {
|
||||
instanceList.append(childItemsForChild(childItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::setHasContent(bool hasContent)
|
||||
{
|
||||
m_hasContent = hasContent;
|
||||
}
|
||||
|
||||
|
||||
bool QuickItemNodeInstance::anyItemHasContent(QQuickItem *quickItem)
|
||||
{
|
||||
if (quickItem->flags().testFlag(QQuickItem::ItemHasContents))
|
||||
return true;
|
||||
|
||||
foreach (QQuickItem *childItem, quickItem->childItems()) {
|
||||
if (anyItemHasContent(childItem))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::childItemsHaveContent(QQuickItem *quickItem)
|
||||
{
|
||||
foreach (QQuickItem *childItem, quickItem->childItems()) {
|
||||
if (anyItemHasContent(childItem))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QPointF QuickItemNodeInstance::position() const
|
||||
{
|
||||
return quickItem()->position();
|
||||
}
|
||||
|
||||
static QTransform transformForItem(QQuickItem *item, NodeInstanceServer *nodeInstanceServer)
|
||||
@@ -160,40 +70,6 @@ QTransform QuickItemNodeInstance::transform() const
|
||||
return transformForItem(quickItem(), nodeInstanceServer());
|
||||
}
|
||||
|
||||
QTransform QuickItemNodeInstance::customTransform() const
|
||||
{
|
||||
return QTransform();
|
||||
}
|
||||
|
||||
QTransform QuickItemNodeInstance::sceneTransform() const
|
||||
{
|
||||
return DesignerSupport::windowTransform(quickItem());
|
||||
}
|
||||
|
||||
double QuickItemNodeInstance::rotation() const
|
||||
{
|
||||
return quickItem()->rotation();
|
||||
}
|
||||
|
||||
double QuickItemNodeInstance::scale() const
|
||||
{
|
||||
return quickItem()->scale();
|
||||
}
|
||||
|
||||
QPointF QuickItemNodeInstance::transformOriginPoint() const
|
||||
{
|
||||
return quickItem()->transformOriginPoint();
|
||||
}
|
||||
|
||||
double QuickItemNodeInstance::zValue() const
|
||||
{
|
||||
return quickItem()->z();
|
||||
}
|
||||
|
||||
double QuickItemNodeInstance::opacity() const
|
||||
{
|
||||
return quickItem()->opacity();
|
||||
}
|
||||
|
||||
QObject *QuickItemNodeInstance::parent() const
|
||||
{
|
||||
@@ -202,53 +78,6 @@ QObject *QuickItemNodeInstance::parent() const
|
||||
|
||||
return quickItem()->parentItem();
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::equalQuickItem(QQuickItem *item) const
|
||||
{
|
||||
return item == quickItem();
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::updateDirtyNodeRecursive(QQuickItem *parentItem) const
|
||||
{
|
||||
foreach (QQuickItem *childItem, parentItem->childItems()) {
|
||||
if (!nodeInstanceServer()->hasInstanceForObject(childItem))
|
||||
updateDirtyNodeRecursive(childItem);
|
||||
}
|
||||
|
||||
DesignerSupport::updateDirtyNode(parentItem);
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::updateAllDirtyNodeRecursive(QQuickItem *parentItem) const
|
||||
{
|
||||
foreach (QQuickItem *childItem, parentItem->childItems())
|
||||
updateDirtyNodeRecursive(childItem);
|
||||
|
||||
DesignerSupport::updateDirtyNode(parentItem);
|
||||
}
|
||||
|
||||
QImage QuickItemNodeInstance::renderImage() const
|
||||
{
|
||||
updateDirtyNodeRecursive(quickItem());
|
||||
|
||||
QRectF boundingRect = boundingRectWithStepChilds(quickItem());
|
||||
|
||||
QImage renderImage = designerSupport()->renderImageForItem(quickItem(), boundingRect, boundingRect.size().toSize());
|
||||
|
||||
renderImage = renderImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
|
||||
return renderImage;
|
||||
}
|
||||
|
||||
QImage QuickItemNodeInstance::renderPreviewImage(const QSize &previewImageSize) const
|
||||
{
|
||||
QRectF previewItemBoundingRect = boundingRect();
|
||||
|
||||
if (previewItemBoundingRect.isValid() && quickItem())
|
||||
return designerSupport()->renderImageForItem(quickItem(), previewItemBoundingRect, previewImageSize);
|
||||
|
||||
return QImage();
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::isMovable() const
|
||||
{
|
||||
if (isRootNodeInstance())
|
||||
@@ -280,212 +109,12 @@ QuickItemNodeInstance::Pointer QuickItemNodeInstance::create(QObject *object)
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void disableTextCursor(QQuickItem *item)
|
||||
{
|
||||
foreach (QQuickItem *childItem, item->childItems())
|
||||
disableTextCursor(childItem);
|
||||
|
||||
QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(item);
|
||||
if (textInput)
|
||||
textInput->setCursorVisible(false);
|
||||
|
||||
QQuickTextEdit *textEdit = qobject_cast<QQuickTextEdit*>(item);
|
||||
if (textEdit)
|
||||
textEdit->setCursorVisible(false);
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance)
|
||||
{
|
||||
if (instanceId() == 0) {
|
||||
DesignerSupport::setRootItem(nodeInstanceServer()->quickView(), quickItem());
|
||||
} else {
|
||||
quickItem()->setParentItem(qobject_cast<QQuickItem*>(nodeInstanceServer()->quickView()->rootObject()));
|
||||
}
|
||||
|
||||
if (s_createEffectItem || instanceId() == 0)
|
||||
designerSupport()->refFromEffectItem(quickItem());
|
||||
|
||||
ObjectNodeInstance::initialize(objectNodeInstance);
|
||||
quickItem()->update();
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::isQuickItem() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QSizeF QuickItemNodeInstance::size() const
|
||||
{
|
||||
double width;
|
||||
|
||||
if (DesignerSupport::isValidWidth(quickItem())) {
|
||||
width = quickItem()->width();
|
||||
} else {
|
||||
width = quickItem()->implicitWidth();
|
||||
}
|
||||
|
||||
double height;
|
||||
|
||||
if (DesignerSupport::isValidHeight(quickItem())) {
|
||||
height = quickItem()->height();
|
||||
} else {
|
||||
height = quickItem()->implicitHeight();
|
||||
}
|
||||
|
||||
|
||||
return QSizeF(width, height);
|
||||
}
|
||||
|
||||
static inline bool isRectangleSane(const QRectF &rect)
|
||||
{
|
||||
return rect.isValid() && (rect.width() < 10000) && (rect.height() < 10000);
|
||||
}
|
||||
|
||||
QRectF QuickItemNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem) const
|
||||
{
|
||||
QRectF boundingRect = parentItem->boundingRect();
|
||||
|
||||
foreach (QQuickItem *childItem, parentItem->childItems()) {
|
||||
if (!nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
QRectF transformedRect = childItem->mapRectToItem(parentItem, boundingRectWithStepChilds(childItem));
|
||||
if (isRectangleSane(transformedRect))
|
||||
boundingRect = boundingRect.united(transformedRect);
|
||||
}
|
||||
}
|
||||
|
||||
return boundingRect;
|
||||
}
|
||||
|
||||
QRectF QuickItemNodeInstance::boundingRect() const
|
||||
{
|
||||
if (quickItem()) {
|
||||
if (quickItem()->clip()) {
|
||||
return quickItem()->boundingRect();
|
||||
} else {
|
||||
return boundingRectWithStepChilds(quickItem());
|
||||
}
|
||||
}
|
||||
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::setPropertyVariant(const PropertyName &name, const QVariant &value)
|
||||
{
|
||||
if (name == "state")
|
||||
return; // states are only set by us
|
||||
|
||||
if (name == "height") {
|
||||
m_height = value.toDouble();
|
||||
if (value.isValid())
|
||||
m_hasHeight = true;
|
||||
else
|
||||
m_hasHeight = false;
|
||||
}
|
||||
|
||||
if (name == "width") {
|
||||
m_width = value.toDouble();
|
||||
if (value.isValid())
|
||||
m_hasWidth = true;
|
||||
else
|
||||
m_hasWidth = false;
|
||||
}
|
||||
|
||||
if (name == "x")
|
||||
m_x = value.toDouble();
|
||||
|
||||
if (name == "y")
|
||||
m_y = value.toDouble();
|
||||
|
||||
ObjectNodeInstance::setPropertyVariant(name, value);
|
||||
|
||||
quickItem()->update();
|
||||
|
||||
refresh();
|
||||
|
||||
if (isInPositioner())
|
||||
parentInstance()->refreshPositioner();
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::setPropertyBinding(const PropertyName &name, const QString &expression)
|
||||
{
|
||||
if (name == "state")
|
||||
return; // states are only set by us
|
||||
|
||||
ObjectNodeInstance::setPropertyBinding(name, expression);
|
||||
|
||||
quickItem()->update();
|
||||
|
||||
refresh();
|
||||
|
||||
if (isInPositioner())
|
||||
parentInstance()->refreshPositioner();
|
||||
}
|
||||
|
||||
QVariant QuickItemNodeInstance::property(const PropertyName &name) const
|
||||
{
|
||||
return ObjectNodeInstance::property(name);
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::resetHorizontal()
|
||||
{
|
||||
setPropertyVariant("x", m_x);
|
||||
if (m_width > 0.0) {
|
||||
setPropertyVariant("width", m_width);
|
||||
} else {
|
||||
setPropertyVariant("width", quickItem()->implicitWidth());
|
||||
}
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::resetVertical()
|
||||
{
|
||||
setPropertyVariant("y", m_y);
|
||||
if (m_height > 0.0) {
|
||||
setPropertyVariant("height", m_height);
|
||||
} else {
|
||||
setPropertyVariant("height", quickItem()->implicitWidth());
|
||||
}
|
||||
}
|
||||
|
||||
static void repositioning(QQuickItem *item)
|
||||
{
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
// QQmlBasePositioner *positioner = qobject_cast<QQmlBasePositioner*>(item);
|
||||
// if (positioner)
|
||||
// positioner->rePositioning();
|
||||
|
||||
if (item->parentItem())
|
||||
repositioning(item->parentItem());
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::refresh()
|
||||
{
|
||||
repositioning(quickItem());
|
||||
}
|
||||
|
||||
static void doComponentCompleteRecursive(QQuickItem *item)
|
||||
{
|
||||
if (item) {
|
||||
if (DesignerSupport::isComponentComplete(item))
|
||||
return;
|
||||
|
||||
foreach (QQuickItem *childItem, item->childItems())
|
||||
doComponentCompleteRecursive(childItem);
|
||||
|
||||
static_cast<QQmlParserStatus*>(item)->componentComplete();
|
||||
}
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::doComponentComplete()
|
||||
{
|
||||
doComponentCompleteRecursive(quickItem());
|
||||
|
||||
disableTextCursor(quickItem());
|
||||
|
||||
quickItem()->update();
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::isResizable() const
|
||||
{
|
||||
if (isRootNodeInstance())
|
||||
@@ -494,64 +123,9 @@ bool QuickItemNodeInstance::isResizable() const
|
||||
return m_isResizable && quickItem() && quickItem()->parentItem();
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::setResizable(bool resizeable)
|
||||
void QuickItemNodeInstance::setResizable(bool resizable)
|
||||
{
|
||||
m_isResizable = resizeable;
|
||||
}
|
||||
|
||||
int QuickItemNodeInstance::penWidth() const
|
||||
{
|
||||
return DesignerSupport::borderWidth(quickItem());
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::resetProperty(const PropertyName &name)
|
||||
{
|
||||
if (name == "height") {
|
||||
m_hasHeight = false;
|
||||
m_height = 0.0;
|
||||
}
|
||||
|
||||
if (name == "width") {
|
||||
m_hasWidth = false;
|
||||
m_width = 0.0;
|
||||
}
|
||||
|
||||
if (name == "x")
|
||||
m_x = 0.0;
|
||||
|
||||
if (name == "y")
|
||||
m_y = 0.0;
|
||||
|
||||
DesignerSupport::resetAnchor(quickItem(), name);
|
||||
|
||||
if (name == "anchors.fill") {
|
||||
resetHorizontal();
|
||||
resetVertical();
|
||||
} else if (name == "anchors.centerIn") {
|
||||
resetHorizontal();
|
||||
resetVertical();
|
||||
} else if (name == "anchors.top") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.left") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.right") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.bottom") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.horizontalCenter") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.verticalCenter") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.baseline") {
|
||||
resetVertical();
|
||||
}
|
||||
|
||||
ObjectNodeInstance::resetProperty(name);
|
||||
|
||||
quickItem()->update();
|
||||
|
||||
if (isInPositioner())
|
||||
parentInstance()->refreshPositioner();
|
||||
m_isResizable = resizable;
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const PropertyName &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const PropertyName &newParentProperty)
|
||||
@@ -570,10 +144,10 @@ void QuickItemNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParen
|
||||
|
||||
if (oldParentInstance && oldParentInstance->isPositioner() && !(newParentInstance && newParentInstance->isPositioner())) {
|
||||
if (!hasBindingForProperty("x"))
|
||||
setPropertyVariant("x", m_x);
|
||||
setPropertyVariant("x", x());
|
||||
|
||||
if (!hasBindingForProperty("y"))
|
||||
setPropertyVariant("y", m_y);
|
||||
setPropertyVariant("y", y());
|
||||
}
|
||||
|
||||
refresh();
|
||||
@@ -583,56 +157,6 @@ void QuickItemNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParen
|
||||
parentInstance()->refreshPositioner();
|
||||
}
|
||||
|
||||
static bool isValidAnchorName(const PropertyName &name)
|
||||
{
|
||||
static PropertyNameList anchorNameList(PropertyNameList() << "anchors.top"
|
||||
<< "anchors.left"
|
||||
<< "anchors.right"
|
||||
<< "anchors.bottom"
|
||||
<< "anchors.verticalCenter"
|
||||
<< "anchors.horizontalCenter"
|
||||
<< "anchors.fill"
|
||||
<< "anchors.centerIn"
|
||||
<< "anchors.baseline");
|
||||
|
||||
return anchorNameList.contains(name);
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::hasAnchor(const PropertyName &name) const
|
||||
{
|
||||
return DesignerSupport::hasAnchor(quickItem(), name);
|
||||
}
|
||||
|
||||
QPair<PropertyName, ServerNodeInstance> QuickItemNodeInstance::anchor(const PropertyName &name) const
|
||||
{
|
||||
if (!isValidAnchorName(name) || !DesignerSupport::hasAnchor(quickItem(), name))
|
||||
return ObjectNodeInstance::anchor(name);
|
||||
|
||||
QPair<QString, QObject*> nameObjectPair = DesignerSupport::anchorLineTarget(quickItem(), name, context());
|
||||
|
||||
QObject *targetObject = nameObjectPair.second;
|
||||
PropertyName targetName = nameObjectPair.first.toUtf8();
|
||||
|
||||
if (targetObject && nodeInstanceServer()->hasInstanceForObject(targetObject)) {
|
||||
return qMakePair(targetName, nodeInstanceServer()->instanceForObject(targetObject));
|
||||
} else {
|
||||
return ObjectNodeInstance::anchor(name);
|
||||
}
|
||||
}
|
||||
|
||||
QList<ServerNodeInstance> QuickItemNodeInstance::stateInstances() const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
QList<QObject*> stateList = DesignerSupport::statesForItem(quickItem());
|
||||
foreach (QObject *state, stateList)
|
||||
{
|
||||
if (state && nodeInstanceServer()->hasInstanceForObject(state))
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(state));
|
||||
}
|
||||
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::isAnchoredBySibling() const
|
||||
{
|
||||
if (quickItem()->parentItem()) {
|
||||
@@ -647,43 +171,16 @@ bool QuickItemNodeInstance::isAnchoredBySibling() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuickItemNodeInstance::isAnchoredByChildren() const
|
||||
{
|
||||
if (DesignerSupport::areChildrenAnchoredTo(quickItem(), quickItem())) // search in children for a anchor to this item
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QQuickItem *QuickItemNodeInstance::quickItem() const
|
||||
{
|
||||
if (object() == 0)
|
||||
return 0;
|
||||
|
||||
Q_ASSERT(qobject_cast<QQuickItem*>(object()));
|
||||
return static_cast<QQuickItem*>(object());
|
||||
}
|
||||
|
||||
DesignerSupport *QuickItemNodeInstance::designerSupport() const
|
||||
{
|
||||
return qt5NodeInstanceServer()->designerSupport();
|
||||
}
|
||||
|
||||
Qt5NodeInstanceServer *QuickItemNodeInstance::qt5NodeInstanceServer() const
|
||||
{
|
||||
return qobject_cast<Qt5NodeInstanceServer*>(nodeInstanceServer());
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::createEffectItem(bool createEffectItem)
|
||||
{
|
||||
s_createEffectItem = createEffectItem;
|
||||
}
|
||||
|
||||
void QuickItemNodeInstance::updateDirtyNodeRecursive()
|
||||
{
|
||||
updateAllDirtyNodeRecursive(quickItem());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlDesigner
|
||||
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "objectnodeinstance.h"
|
||||
#include "graphicalnodeinstance.h"
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <designersupport.h>
|
||||
@@ -40,7 +40,7 @@
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
class QuickItemNodeInstance : public ObjectNodeInstance
|
||||
class QuickItemNodeInstance : public GraphicalNodeInstance
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<QuickItemNodeInstance> Pointer;
|
||||
@@ -49,91 +49,27 @@ public:
|
||||
~QuickItemNodeInstance();
|
||||
|
||||
static Pointer create(QObject *objectToBeWrapped);
|
||||
void initialize(const ObjectNodeInstance::Pointer &objectNodeInstance) Q_DECL_OVERRIDE;
|
||||
|
||||
bool isQuickItem() const Q_DECL_OVERRIDE;
|
||||
|
||||
QRectF boundingRect() const Q_DECL_OVERRIDE;
|
||||
QPointF position() const Q_DECL_OVERRIDE;
|
||||
QSizeF size() const Q_DECL_OVERRIDE;
|
||||
QTransform transform() const Q_DECL_OVERRIDE;
|
||||
QTransform customTransform() const Q_DECL_OVERRIDE;
|
||||
QTransform sceneTransform() const Q_DECL_OVERRIDE;
|
||||
double opacity() const Q_DECL_OVERRIDE;
|
||||
|
||||
QObject *parent() const Q_DECL_OVERRIDE;
|
||||
|
||||
double rotation() const Q_DECL_OVERRIDE;
|
||||
double scale() const Q_DECL_OVERRIDE;
|
||||
QPointF transformOriginPoint() const Q_DECL_OVERRIDE;
|
||||
double zValue() const Q_DECL_OVERRIDE;
|
||||
|
||||
bool equalQuickItem(QQuickItem *item) const;
|
||||
|
||||
bool hasContent() const Q_DECL_OVERRIDE;
|
||||
|
||||
QList<ServerNodeInstance> childItems() const Q_DECL_OVERRIDE;
|
||||
QList<ServerNodeInstance> childItemsForChild(QQuickItem *childItem) const;
|
||||
|
||||
bool isMovable() const Q_DECL_OVERRIDE;
|
||||
void setMovable(bool movable);
|
||||
|
||||
void setPropertyVariant(const PropertyName &name, const QVariant &value) Q_DECL_OVERRIDE;
|
||||
void setPropertyBinding(const PropertyName &name, const QString &expression) Q_DECL_OVERRIDE;
|
||||
|
||||
QVariant property(const PropertyName &name) const Q_DECL_OVERRIDE;
|
||||
void resetProperty(const PropertyName &name) Q_DECL_OVERRIDE;
|
||||
|
||||
void reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const PropertyName &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const PropertyName &newParentProperty) Q_DECL_OVERRIDE;
|
||||
|
||||
int penWidth() const Q_DECL_OVERRIDE;
|
||||
|
||||
bool hasAnchor(const PropertyName &name) const Q_DECL_OVERRIDE;
|
||||
QPair<PropertyName, ServerNodeInstance> anchor(const PropertyName &name) const Q_DECL_OVERRIDE;
|
||||
bool isAnchoredBySibling() const Q_DECL_OVERRIDE;
|
||||
bool isAnchoredByChildren() const Q_DECL_OVERRIDE;
|
||||
void doComponentComplete() Q_DECL_OVERRIDE;
|
||||
|
||||
bool isResizable() const Q_DECL_OVERRIDE;
|
||||
void setResizable(bool resizeable);
|
||||
|
||||
void setHasContent(bool hasContent);
|
||||
|
||||
QList<ServerNodeInstance> stateInstances() const Q_DECL_OVERRIDE;
|
||||
|
||||
QImage renderImage() const Q_DECL_OVERRIDE;
|
||||
QImage renderPreviewImage(const QSize &previewImageSize) const Q_DECL_OVERRIDE;
|
||||
|
||||
DesignerSupport *designerSupport() const;
|
||||
Qt5NodeInstanceServer *qt5NodeInstanceServer() const;
|
||||
|
||||
static void createEffectItem(bool createEffectItem);
|
||||
|
||||
void updateDirtyNodeRecursive() Q_DECL_OVERRIDE;
|
||||
bool isMovable() const Q_DECL_OVERRIDE;
|
||||
bool isQuickItem() const Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
QuickItemNodeInstance(QQuickItem*);
|
||||
QQuickItem *quickItem() const;
|
||||
void resetHorizontal();
|
||||
void resetVertical();
|
||||
void refresh();
|
||||
QRectF boundingRectWithStepChilds(QQuickItem *parentItem) const;
|
||||
void updateDirtyNodeRecursive(QQuickItem *parentItem) const;
|
||||
void updateAllDirtyNodeRecursive(QQuickItem *parentItem) const;
|
||||
static bool anyItemHasContent(QQuickItem *graphicsItem);
|
||||
static bool childItemsHaveContent(QQuickItem *graphicsItem);
|
||||
void setMovable(bool movable);
|
||||
void setResizable(bool resizable);
|
||||
|
||||
private: //variables
|
||||
bool m_hasHeight;
|
||||
bool m_hasWidth;
|
||||
bool m_isResizable;
|
||||
bool m_hasContent;
|
||||
bool m_isMovable;
|
||||
double m_x;
|
||||
double m_y;
|
||||
double m_width;
|
||||
double m_height;
|
||||
static bool s_createEffectItem;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -29,160 +29,22 @@
|
||||
|
||||
#include "quickwindownodeinstance.h"
|
||||
|
||||
#include "qt5nodeinstanceserver.h"
|
||||
|
||||
#include <QQmlExpression>
|
||||
#include <QQuickView>
|
||||
#include <QQuickItem>
|
||||
|
||||
#include <private/qquickitem_p.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QHash>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
bool QuickWindowNodeInstance::s_createEffectItem = false;
|
||||
|
||||
QuickWindowNodeInstance::QuickWindowNodeInstance(QQuickWindow *item)
|
||||
: ObjectNodeInstance(item),
|
||||
m_hasHeight(false),
|
||||
m_hasWidth(false),
|
||||
m_hasContent(true),
|
||||
m_x(0.0),
|
||||
m_y(0.0),
|
||||
m_width(0.0),
|
||||
m_height(0.0)
|
||||
: GraphicalNodeInstance(item)
|
||||
{
|
||||
}
|
||||
|
||||
QuickWindowNodeInstance::~QuickWindowNodeInstance()
|
||||
{
|
||||
if (quickItem())
|
||||
designerSupport()->derefFromEffectItem(quickItem());
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::hasContent() const
|
||||
{
|
||||
if (m_hasContent)
|
||||
return true;
|
||||
|
||||
return childItemsHaveContent(quickItem());
|
||||
}
|
||||
|
||||
QList<ServerNodeInstance> QuickWindowNodeInstance::childItems() const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
|
||||
foreach (QQuickItem *childItem, quickItem()->childItems())
|
||||
{
|
||||
if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(childItem));
|
||||
} else { //there might be an item in between the parent instance
|
||||
//and the child instance.
|
||||
//Popular example is flickable which has a viewport item between
|
||||
//the flickable item and the flickable children
|
||||
instanceList.append(childItemsForChild(childItem)); //In such a case we go deeper inside the item and
|
||||
//search for child items with instances.
|
||||
}
|
||||
}
|
||||
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
QList<ServerNodeInstance> QuickWindowNodeInstance::childItemsForChild(QQuickItem *childItem) const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
|
||||
if (childItem) {
|
||||
foreach (QQuickItem *childItem, childItem->childItems())
|
||||
{
|
||||
if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(childItem));
|
||||
} else {
|
||||
instanceList.append(childItemsForChild(childItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::setHasContent(bool hasContent)
|
||||
{
|
||||
m_hasContent = hasContent;
|
||||
}
|
||||
|
||||
|
||||
bool QuickWindowNodeInstance::anyItemHasContent(QQuickItem *quickItem)
|
||||
{
|
||||
if (quickItem->flags().testFlag(QQuickItem::ItemHasContents))
|
||||
return true;
|
||||
|
||||
foreach (QQuickItem *childItem, quickItem->childItems()) {
|
||||
if (anyItemHasContent(childItem))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::childItemsHaveContent(QQuickItem *quickItem)
|
||||
{
|
||||
foreach (QQuickItem *childItem, quickItem->childItems()) {
|
||||
if (anyItemHasContent(childItem))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QPointF QuickWindowNodeInstance::position() const
|
||||
{
|
||||
return quickItem()->position();
|
||||
}
|
||||
|
||||
QTransform QuickWindowNodeInstance::transform() const
|
||||
{
|
||||
return DesignerSupport::parentTransform(quickItem());
|
||||
}
|
||||
|
||||
QTransform QuickWindowNodeInstance::customTransform() const
|
||||
{
|
||||
return QTransform();
|
||||
}
|
||||
|
||||
QTransform QuickWindowNodeInstance::sceneTransform() const
|
||||
{
|
||||
return DesignerSupport::windowTransform(quickItem());
|
||||
}
|
||||
|
||||
double QuickWindowNodeInstance::rotation() const
|
||||
{
|
||||
return quickItem()->rotation();
|
||||
}
|
||||
|
||||
double QuickWindowNodeInstance::scale() const
|
||||
{
|
||||
return quickItem()->scale();
|
||||
}
|
||||
|
||||
QPointF QuickWindowNodeInstance::transformOriginPoint() const
|
||||
{
|
||||
return quickItem()->transformOriginPoint();
|
||||
}
|
||||
|
||||
double QuickWindowNodeInstance::zValue() const
|
||||
{
|
||||
return quickItem()->z();
|
||||
}
|
||||
|
||||
double QuickWindowNodeInstance::opacity() const
|
||||
{
|
||||
return quickItem()->opacity();
|
||||
}
|
||||
|
||||
QObject *QuickWindowNodeInstance::parent() const
|
||||
@@ -190,49 +52,6 @@ QObject *QuickWindowNodeInstance::parent() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::equalQuickItem(QQuickItem *item) const
|
||||
{
|
||||
return item == quickItem();
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::updateDirtyNodeRecursive(QQuickItem *parentItem) const
|
||||
{
|
||||
foreach (QQuickItem *childItem, parentItem->childItems()) {
|
||||
if (!nodeInstanceServer()->hasInstanceForObject(childItem))
|
||||
updateDirtyNodeRecursive(childItem);
|
||||
}
|
||||
|
||||
DesignerSupport::updateDirtyNode(parentItem);
|
||||
}
|
||||
|
||||
QImage QuickWindowNodeInstance::renderImage() const
|
||||
{
|
||||
updateDirtyNodeRecursive(quickItem());
|
||||
|
||||
QRectF boundingRect = boundingRectWithStepChilds(quickItem());
|
||||
|
||||
QImage renderImage = designerSupport()->renderImageForItem(quickItem(), boundingRect, boundingRect.size().toSize());
|
||||
|
||||
renderImage = renderImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
|
||||
return renderImage;
|
||||
}
|
||||
|
||||
QImage QuickWindowNodeInstance::renderPreviewImage(const QSize &previewImageSize) const
|
||||
{
|
||||
QRectF previewItemBoundingRect = boundingRect();
|
||||
|
||||
if (previewItemBoundingRect.isValid() && quickItem())
|
||||
return designerSupport()->renderImageForItem(quickItem(), previewItemBoundingRect, previewImageSize);
|
||||
|
||||
return QImage();
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::isMovable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QuickWindowNodeInstance::Pointer QuickWindowNodeInstance::create(QObject *object)
|
||||
{
|
||||
QQuickWindow *quickWindow = qobject_cast<QQuickWindow*>(object);
|
||||
@@ -261,229 +80,13 @@ QuickWindowNodeInstance::Pointer QuickWindowNodeInstance::create(QObject *object
|
||||
return instance;
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance)
|
||||
{
|
||||
if (instanceId() == 0) {
|
||||
DesignerSupport::setRootItem(nodeInstanceServer()->quickView(), quickItem());
|
||||
} else {
|
||||
quickItem()->setParentItem(qobject_cast<QQuickItem*>(nodeInstanceServer()->quickView()->rootObject()));
|
||||
}
|
||||
|
||||
if (s_createEffectItem || instanceId() == 0)
|
||||
designerSupport()->refFromEffectItem(quickItem());
|
||||
|
||||
ObjectNodeInstance::initialize(objectNodeInstance);
|
||||
quickItem()->update();
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::isQuickItem() const
|
||||
bool QuickWindowNodeInstance::isQuickWindow() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QSizeF QuickWindowNodeInstance::size() const
|
||||
{
|
||||
double width;
|
||||
|
||||
if (DesignerSupport::isValidWidth(quickItem())) {
|
||||
width = quickItem()->width();
|
||||
} else {
|
||||
width = quickItem()->implicitWidth();
|
||||
}
|
||||
|
||||
double height;
|
||||
|
||||
if (DesignerSupport::isValidHeight(quickItem())) {
|
||||
height = quickItem()->height();
|
||||
} else {
|
||||
height = quickItem()->implicitHeight();
|
||||
}
|
||||
|
||||
|
||||
return QSizeF(width, height);
|
||||
}
|
||||
|
||||
static inline bool isRectangleSane(const QRectF &rect)
|
||||
{
|
||||
return rect.isValid() && (rect.width() < 10000) && (rect.height() < 10000);
|
||||
}
|
||||
|
||||
QRectF QuickWindowNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem) const
|
||||
{
|
||||
QRectF boundingRect = parentItem->boundingRect();
|
||||
|
||||
foreach (QQuickItem *childItem, parentItem->childItems()) {
|
||||
if (!nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
QRectF transformedRect = childItem->mapRectToItem(parentItem, boundingRectWithStepChilds(childItem));
|
||||
if (isRectangleSane(transformedRect))
|
||||
boundingRect = boundingRect.united(transformedRect);
|
||||
}
|
||||
}
|
||||
|
||||
return boundingRect;
|
||||
}
|
||||
|
||||
QRectF QuickWindowNodeInstance::boundingRect() const
|
||||
{
|
||||
if (quickItem()) {
|
||||
if (quickItem()->clip()) {
|
||||
return quickItem()->boundingRect();
|
||||
} else {
|
||||
return boundingRectWithStepChilds(quickItem());
|
||||
}
|
||||
}
|
||||
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::setPropertyVariant(const PropertyName &name, const QVariant &value)
|
||||
{
|
||||
if (name == "state")
|
||||
return; // states are only set by us
|
||||
|
||||
if (name == "height") {
|
||||
m_height = value.toDouble();
|
||||
if (value.isValid())
|
||||
m_hasHeight = true;
|
||||
else
|
||||
m_hasHeight = false;
|
||||
}
|
||||
|
||||
if (name == "width") {
|
||||
m_width = value.toDouble();
|
||||
if (value.isValid())
|
||||
m_hasWidth = true;
|
||||
else
|
||||
m_hasWidth = false;
|
||||
}
|
||||
|
||||
if (name == "x")
|
||||
m_x = value.toDouble();
|
||||
|
||||
if (name == "y")
|
||||
m_y = value.toDouble();
|
||||
|
||||
ObjectNodeInstance::setPropertyVariant(name, value);
|
||||
|
||||
quickItem()->update();
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::setPropertyBinding(const PropertyName &name, const QString &expression)
|
||||
{
|
||||
if (name == "state")
|
||||
return; // states are only set by us
|
||||
|
||||
ObjectNodeInstance::setPropertyBinding(name, expression);
|
||||
|
||||
quickItem()->update();
|
||||
}
|
||||
|
||||
QVariant QuickWindowNodeInstance::property(const PropertyName &name) const
|
||||
{
|
||||
if (name == "visible")
|
||||
return quickItem()->isVisible();
|
||||
return ObjectNodeInstance::property(name);
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::resetHorizontal()
|
||||
{
|
||||
setPropertyVariant("x", m_x);
|
||||
if (m_width > 0.0) {
|
||||
setPropertyVariant("width", m_width);
|
||||
} else {
|
||||
setPropertyVariant("width", quickItem()->implicitWidth());
|
||||
}
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::resetVertical()
|
||||
{
|
||||
setPropertyVariant("y", m_y);
|
||||
if (m_height > 0.0) {
|
||||
setPropertyVariant("height", m_height);
|
||||
} else {
|
||||
setPropertyVariant("height", quickItem()->implicitWidth());
|
||||
}
|
||||
}
|
||||
|
||||
static void doComponentCompleteRecursive(QQuickItem *item)
|
||||
{
|
||||
if (item) {
|
||||
if (DesignerSupport::isComponentComplete(item))
|
||||
return;
|
||||
|
||||
foreach (QQuickItem *childItem, item->childItems())
|
||||
doComponentCompleteRecursive(childItem);
|
||||
|
||||
static_cast<QQmlParserStatus*>(item)->componentComplete();
|
||||
}
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::doComponentComplete()
|
||||
{
|
||||
doComponentCompleteRecursive(quickItem());
|
||||
|
||||
quickItem()->update();
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::isResizable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int QuickWindowNodeInstance::penWidth() const
|
||||
{
|
||||
return DesignerSupport::borderWidth(quickItem());
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::resetProperty(const PropertyName &name)
|
||||
{
|
||||
if (name == "height") {
|
||||
m_hasHeight = false;
|
||||
m_height = 0.0;
|
||||
}
|
||||
|
||||
if (name == "width") {
|
||||
m_hasWidth = false;
|
||||
m_width = 0.0;
|
||||
}
|
||||
|
||||
if (name == "x")
|
||||
m_x = 0.0;
|
||||
|
||||
if (name == "y")
|
||||
m_y = 0.0;
|
||||
|
||||
DesignerSupport::resetAnchor(quickItem(), name);
|
||||
|
||||
if (name == "anchors.fill") {
|
||||
resetHorizontal();
|
||||
resetVertical();
|
||||
} else if (name == "anchors.centerIn") {
|
||||
resetHorizontal();
|
||||
resetVertical();
|
||||
} else if (name == "anchors.top") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.left") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.right") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.bottom") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.horizontalCenter") {
|
||||
resetHorizontal();
|
||||
} else if (name == "anchors.verticalCenter") {
|
||||
resetVertical();
|
||||
} else if (name == "anchors.baseline") {
|
||||
resetVertical();
|
||||
}
|
||||
|
||||
ObjectNodeInstance::resetProperty(name);
|
||||
|
||||
quickItem()->update();
|
||||
|
||||
if (isInPositioner())
|
||||
parentInstance()->refreshPositioner();
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const PropertyName &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const PropertyName &newParentProperty)
|
||||
{
|
||||
@@ -492,101 +95,20 @@ void QuickWindowNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldPar
|
||||
DesignerSupport::updateDirtyNode(quickItem());
|
||||
}
|
||||
|
||||
static bool isValidAnchorName(const PropertyName &name)
|
||||
{
|
||||
static PropertyNameList anchorNameList(PropertyNameList() << "anchors.top"
|
||||
<< "anchors.left"
|
||||
<< "anchors.right"
|
||||
<< "anchors.bottom"
|
||||
<< "anchors.verticalCenter"
|
||||
<< "anchors.horizontalCenter"
|
||||
<< "anchors.fill"
|
||||
<< "anchors.centerIn"
|
||||
<< "anchors.baseline");
|
||||
|
||||
return anchorNameList.contains(name);
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::hasAnchor(const PropertyName &name) const
|
||||
{
|
||||
return DesignerSupport::hasAnchor(quickItem(), name);
|
||||
}
|
||||
|
||||
QPair<PropertyName, ServerNodeInstance> QuickWindowNodeInstance::anchor(const PropertyName &name) const
|
||||
{
|
||||
if (!isValidAnchorName(name) || !DesignerSupport::hasAnchor(quickItem(), name))
|
||||
return ObjectNodeInstance::anchor(name);
|
||||
|
||||
QPair<QString, QObject*> nameObjectPair = DesignerSupport::anchorLineTarget(quickItem(), name, context());
|
||||
|
||||
QObject *targetObject = nameObjectPair.second;
|
||||
PropertyName targetName = nameObjectPair.first.toUtf8();
|
||||
|
||||
if (targetObject && nodeInstanceServer()->hasInstanceForObject(targetObject)) {
|
||||
return qMakePair(targetName, nodeInstanceServer()->instanceForObject(targetObject));
|
||||
} else {
|
||||
return ObjectNodeInstance::anchor(name);
|
||||
}
|
||||
}
|
||||
|
||||
QList<ServerNodeInstance> QuickWindowNodeInstance::stateInstances() const
|
||||
{
|
||||
QList<ServerNodeInstance> instanceList;
|
||||
QList<QObject*> stateList = DesignerSupport::statesForItem(quickItem());
|
||||
foreach (QObject *state, stateList)
|
||||
{
|
||||
if (state && nodeInstanceServer()->hasInstanceForObject(state))
|
||||
instanceList.append(nodeInstanceServer()->instanceForObject(state));
|
||||
}
|
||||
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::isAnchoredBySibling() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuickWindowNodeInstance::isAnchoredByChildren() const
|
||||
{
|
||||
if (DesignerSupport::areChildrenAnchoredTo(quickItem(), quickItem())) // search in children for a anchor to this item
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QQuickItem *QuickWindowNodeInstance::quickItem() const
|
||||
{
|
||||
if (object() == 0)
|
||||
return 0;
|
||||
|
||||
Q_ASSERT(qobject_cast<QQuickWindow*>(object()));
|
||||
return static_cast<QQuickWindow*>(object())->contentItem();
|
||||
}
|
||||
|
||||
DesignerSupport *QuickWindowNodeInstance::designerSupport() const
|
||||
{
|
||||
return qt5NodeInstanceServer()->designerSupport();
|
||||
}
|
||||
|
||||
Qt5NodeInstanceServer *QuickWindowNodeInstance::qt5NodeInstanceServer() const
|
||||
{
|
||||
return qobject_cast<Qt5NodeInstanceServer*>(nodeInstanceServer());
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::createEffectItem(bool createEffectItem)
|
||||
{
|
||||
s_createEffectItem = createEffectItem;
|
||||
}
|
||||
|
||||
void QuickWindowNodeInstance::updateDirtyNodeRecursive()
|
||||
{
|
||||
foreach (QQuickItem *childItem, quickItem()->childItems())
|
||||
updateDirtyNodeRecursive(childItem);
|
||||
|
||||
DesignerSupport::updateDirtyNode(quickItem());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlDesigner
|
||||
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "objectnodeinstance.h"
|
||||
#include "graphicalnodeinstance.h"
|
||||
|
||||
#include <QQuickWindow>
|
||||
#include <designersupport.h>
|
||||
@@ -40,7 +40,7 @@
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
class QuickWindowNodeInstance : public ObjectNodeInstance
|
||||
class QuickWindowNodeInstance : public GraphicalNodeInstance
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<QuickWindowNodeInstance> Pointer;
|
||||
@@ -49,88 +49,27 @@ public:
|
||||
~QuickWindowNodeInstance();
|
||||
|
||||
static Pointer create(QObject *objectToBeWrapped);
|
||||
void initialize(const ObjectNodeInstance::Pointer &objectNodeInstance);
|
||||
|
||||
bool isQuickItem() const Q_DECL_OVERRIDE;
|
||||
|
||||
QRectF boundingRect() const Q_DECL_OVERRIDE;
|
||||
QPointF position() const Q_DECL_OVERRIDE;
|
||||
QSizeF size() const Q_DECL_OVERRIDE;
|
||||
QTransform transform() const Q_DECL_OVERRIDE;
|
||||
QTransform customTransform() const Q_DECL_OVERRIDE;
|
||||
QTransform sceneTransform() const Q_DECL_OVERRIDE;
|
||||
double opacity() const Q_DECL_OVERRIDE;
|
||||
bool isQuickWindow() const Q_DECL_OVERRIDE;
|
||||
|
||||
QObject *parent() const Q_DECL_OVERRIDE;
|
||||
|
||||
double rotation() const Q_DECL_OVERRIDE;
|
||||
double scale() const Q_DECL_OVERRIDE;
|
||||
QPointF transformOriginPoint() const Q_DECL_OVERRIDE;
|
||||
double zValue() const Q_DECL_OVERRIDE;
|
||||
|
||||
bool equalQuickItem(QQuickItem *item) const;
|
||||
|
||||
bool hasContent() const Q_DECL_OVERRIDE;
|
||||
|
||||
QList<ServerNodeInstance> childItems() const Q_DECL_OVERRIDE;
|
||||
QList<ServerNodeInstance> childItemsForChild(QQuickItem *childItem) const;
|
||||
|
||||
bool isMovable() const Q_DECL_OVERRIDE;
|
||||
|
||||
void setPropertyVariant(const PropertyName &name, const QVariant &value) Q_DECL_OVERRIDE;
|
||||
void setPropertyBinding(const PropertyName &name, const QString &expression) Q_DECL_OVERRIDE;
|
||||
|
||||
QVariant property(const PropertyName &name) const Q_DECL_OVERRIDE;
|
||||
void resetProperty(const PropertyName &name) Q_DECL_OVERRIDE;
|
||||
|
||||
void reparent(const ObjectNodeInstance::Pointer &oldParentInstance,
|
||||
const PropertyName &oldParentProperty,
|
||||
const ObjectNodeInstance::Pointer &newParentInstance,
|
||||
const PropertyName &newParentProperty) Q_DECL_OVERRIDE;
|
||||
const PropertyName &newParentProperty);
|
||||
|
||||
int penWidth() const Q_DECL_OVERRIDE;
|
||||
|
||||
bool hasAnchor(const PropertyName &name) const Q_DECL_OVERRIDE;
|
||||
QPair<PropertyName, ServerNodeInstance> anchor(const PropertyName &name) const Q_DECL_OVERRIDE;
|
||||
bool isAnchoredBySibling() const Q_DECL_OVERRIDE;
|
||||
bool isAnchoredByChildren() const Q_DECL_OVERRIDE;
|
||||
void doComponentComplete() Q_DECL_OVERRIDE;
|
||||
|
||||
bool isResizable() const Q_DECL_OVERRIDE;
|
||||
|
||||
void setHasContent(bool hasContent);
|
||||
|
||||
QList<ServerNodeInstance> stateInstances() const Q_DECL_OVERRIDE;
|
||||
|
||||
QImage renderImage() const Q_DECL_OVERRIDE;
|
||||
QImage renderPreviewImage(const QSize &previewImageSize) const Q_DECL_OVERRIDE;
|
||||
|
||||
DesignerSupport *designerSupport() const;
|
||||
Qt5NodeInstanceServer *qt5NodeInstanceServer() const;
|
||||
|
||||
static void createEffectItem(bool createEffectItem);
|
||||
|
||||
void updateDirtyNodeRecursive() Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
QuickWindowNodeInstance(QQuickWindow*);
|
||||
QQuickItem *quickItem() const;
|
||||
void resetHorizontal();
|
||||
void resetVertical();
|
||||
QRectF boundingRectWithStepChilds(QQuickItem *parentItem) const;
|
||||
void updateDirtyNodeRecursive(QQuickItem *parentItem) const;
|
||||
static bool anyItemHasContent(QQuickItem *graphicsItem);
|
||||
static bool childItemsHaveContent(QQuickItem *graphicsItem);
|
||||
|
||||
private: //variables
|
||||
bool m_hasHeight;
|
||||
bool m_hasWidth;
|
||||
bool m_hasContent;
|
||||
double m_x;
|
||||
double m_y;
|
||||
double m_width;
|
||||
double m_height;
|
||||
static bool s_createEffectItem;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -150,9 +150,9 @@ void ServerNodeInstance::setNodeSource(const QString &source)
|
||||
m_nodeInstance->setNodeSource(source);
|
||||
}
|
||||
|
||||
bool ServerNodeInstance::holdsQuickItem() const
|
||||
bool ServerNodeInstance::holdsGraphical() const
|
||||
{
|
||||
return m_nodeInstance->isQuickItem();
|
||||
return m_nodeInstance->isGraphical();
|
||||
}
|
||||
|
||||
void ServerNodeInstance::updateDirtyNodeRecursive()
|
||||
|
@@ -196,7 +196,7 @@ private: // functions
|
||||
|
||||
void setNodeSource(const QString &source);
|
||||
|
||||
bool holdsQuickItem() const;
|
||||
bool holdsGraphical() const;
|
||||
|
||||
void updateDirtyNodeRecursive();
|
||||
|
||||
|
Reference in New Issue
Block a user