2010-07-08 14:00:33 +02:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-07-08 14:00:33 +02:00
|
|
|
**
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2010-07-08 14:00:33 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
** this package.
|
2010-07-08 14:00:33 +02:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-07-08 14:00:33 +02:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
#include "abstractliveedittool.h"
|
2010-09-14 13:39:32 +02:00
|
|
|
#include "qdeclarativeviewobserver.h"
|
2010-09-27 10:46:08 +02:00
|
|
|
#include "../qdeclarativeviewobserver_p.h"
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
#include <QDeclarativeEngine>
|
|
|
|
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include <QDeclarativeItem>
|
|
|
|
|
2010-09-22 09:59:18 +02:00
|
|
|
namespace QmlJSDebugger {
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewObserver *editorView)
|
2010-09-14 13:39:32 +02:00
|
|
|
: QObject(editorView), m_observer(editorView)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
AbstractLiveEditTool::~AbstractLiveEditTool()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QDeclarativeViewObserver *AbstractLiveEditTool::observer() const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
return m_observer;
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QDeclarativeView *AbstractLiveEditTool::view() const
|
2010-09-14 13:39:32 +02:00
|
|
|
{
|
|
|
|
return m_observer->declarativeView();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QGraphicsScene* AbstractLiveEditTool::scene() const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
return view()->scene();
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
void AbstractLiveEditTool::updateSelectedItems()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-15 13:38:10 +02:00
|
|
|
selectedItemsChanged(items());
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QList<QGraphicsItem*> AbstractLiveEditTool::items() const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
return observer()->selectedItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
void AbstractLiveEditTool::enterContext(QGraphicsItem *itemToEnter)
|
2010-08-26 17:11:17 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
observer()->data->enterContext(itemToEnter);
|
2010-08-26 17:11:17 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
bool AbstractLiveEditTool::topItemIsMovable(const QList<QGraphicsItem*> & itemList)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList);
|
|
|
|
if (firstSelectableItem == 0)
|
|
|
|
return false;
|
|
|
|
|
2010-12-01 11:46:49 +01:00
|
|
|
QDeclarativeItem *declarativeItem
|
|
|
|
= dynamic_cast<QDeclarativeItem*>(firstSelectableItem->toGraphicsObject());
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
if (declarativeItem != 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
bool AbstractLiveEditTool::topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> selectedItems = observer()->selectedItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
foreach (QGraphicsItem *item, itemList) {
|
|
|
|
QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
|
|
|
|
if (declarativeItem
|
2010-12-01 11:46:49 +01:00
|
|
|
&& selectedItems.contains(declarativeItem)
|
|
|
|
/*&& (declarativeItem->qmlItemNode().hasShowContent() || selectNonContentItems)*/)
|
2010-07-08 14:00:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
bool AbstractLiveEditTool::topItemIsResizeHandle(const QList<QGraphicsItem*> &/*itemList*/)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QDeclarativeItem *AbstractLiveEditTool::toQDeclarativeItem(QGraphicsItem *item)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
return dynamic_cast<QDeclarativeItem*>(item->toGraphicsObject());
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QGraphicsItem *AbstractLiveEditTool::topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
foreach (QGraphicsItem *item, itemList) {
|
|
|
|
if (item->flags().testFlag(QGraphicsItem::ItemIsMovable))
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QDeclarativeItem *AbstractLiveEditTool::topMovableDeclarativeItem(const QList<QGraphicsItem*>
|
|
|
|
&itemList)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
foreach (QGraphicsItem *item, itemList) {
|
|
|
|
QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
|
|
|
|
if (declarativeItem /*&& (declarativeItem->qmlItemNode().hasShowContent())*/)
|
|
|
|
return declarativeItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QList<QGraphicsObject*> AbstractLiveEditTool::toGraphicsObjectList(const QList<QGraphicsItem*>
|
|
|
|
&itemList)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
QList<QGraphicsObject*> gfxObjects;
|
|
|
|
foreach(QGraphicsItem *item, itemList) {
|
|
|
|
QGraphicsObject *obj = item->toGraphicsObject();
|
|
|
|
if (obj)
|
|
|
|
gfxObjects << obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gfxObjects;
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:59:43 +01:00
|
|
|
QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
QString className("QGraphicsItem");
|
|
|
|
QString objectStringId;
|
|
|
|
|
2010-07-28 11:20:49 +02:00
|
|
|
QString constructedName;
|
|
|
|
|
2010-07-26 15:31:59 +02:00
|
|
|
QGraphicsObject *gfxObject = item->toGraphicsObject();
|
2010-07-08 14:00:33 +02:00
|
|
|
if (gfxObject) {
|
|
|
|
className = gfxObject->metaObject()->className();
|
2010-07-28 11:20:49 +02:00
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
className.replace(QRegExp("_QMLTYPE_\\d+"), "");
|
2010-07-28 11:20:49 +02:00
|
|
|
className.replace(QRegExp("_QML_\\d+"), "");
|
|
|
|
if (className.startsWith(QLatin1String("QDeclarative")))
|
|
|
|
className = className.replace(QLatin1String("QDeclarative"), "");
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-26 15:31:59 +02:00
|
|
|
QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem*>(gfxObject);
|
2010-07-08 14:00:33 +02:00
|
|
|
if (declarativeItem) {
|
2010-09-14 13:39:32 +02:00
|
|
|
objectStringId = QDeclarativeViewObserver::idStringForObject(declarativeItem);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-07-28 11:20:49 +02:00
|
|
|
if (!objectStringId.isEmpty()) {
|
|
|
|
constructedName = objectStringId + " (" + className + ")";
|
|
|
|
} else {
|
2010-08-03 10:35:04 +02:00
|
|
|
if (!gfxObject->objectName().isEmpty()) {
|
2010-07-28 11:20:49 +02:00
|
|
|
constructedName = gfxObject->objectName() + " (" + className + ")";
|
2010-08-03 10:35:04 +02:00
|
|
|
} else {
|
|
|
|
constructedName = className;
|
|
|
|
}
|
2010-07-28 11:20:49 +02:00
|
|
|
}
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 10:35:04 +02:00
|
|
|
return constructedName;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|