forked from qt-creator/qt-creator
Moved qmljsdebugger to share & debugger lib support for qml app wizard
Reviewed-by: Alessandro Portale
This commit is contained in:
124
share/qtcreator/qmljsdebugger/editor/selectionindicator.cpp
Normal file
124
share/qtcreator/qmljsdebugger/editor/selectionindicator.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "selectionindicator.h"
|
||||
#include "qdeclarativedesignview_p.h"
|
||||
#include "qmlviewerconstants.h"
|
||||
|
||||
#include <QPen>
|
||||
#include <cmath>
|
||||
#include <QGraphicsScene>
|
||||
#include <QDebug>
|
||||
|
||||
namespace QmlViewer {
|
||||
|
||||
SelectionIndicator::SelectionIndicator(QDeclarativeDesignView *editorView, QGraphicsObject *layerItem)
|
||||
: m_layerItem(layerItem), m_view(editorView)
|
||||
{
|
||||
}
|
||||
|
||||
SelectionIndicator::~SelectionIndicator()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void SelectionIndicator::show()
|
||||
{
|
||||
foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash.values())
|
||||
item->show();
|
||||
}
|
||||
|
||||
void SelectionIndicator::hide()
|
||||
{
|
||||
foreach (QGraphicsPolygonItem *item, m_indicatorShapeHash.values())
|
||||
item->hide();
|
||||
}
|
||||
|
||||
void SelectionIndicator::clear()
|
||||
{
|
||||
if (!m_layerItem.isNull()) {
|
||||
QHashIterator<QGraphicsItem*, QGraphicsPolygonItem *> iter(m_indicatorShapeHash);
|
||||
while(iter.hasNext()) {
|
||||
iter.next();
|
||||
m_layerItem->scene()->removeItem(iter.value());
|
||||
delete iter.value();
|
||||
}
|
||||
}
|
||||
|
||||
m_indicatorShapeHash.clear();
|
||||
|
||||
}
|
||||
|
||||
QPolygonF SelectionIndicator::addBoundingRectToPolygon(QGraphicsItem *item, QPolygonF &polygon)
|
||||
{
|
||||
// ### remove this if statement when QTBUG-12172 gets fixed
|
||||
if (item->boundingRect() != QRectF(0,0,0,0))
|
||||
polygon = polygon.united(item->mapToScene(item->boundingRect()));
|
||||
|
||||
foreach(QGraphicsItem *child, item->childItems()) {
|
||||
if (!QDeclarativeDesignViewPrivate::get(m_view)->isEditorItem(child))
|
||||
addBoundingRectToPolygon(child, polygon);
|
||||
}
|
||||
return polygon;
|
||||
}
|
||||
|
||||
void SelectionIndicator::setItems(const QList<QWeakPointer<QGraphicsObject> > &itemList)
|
||||
{
|
||||
clear();
|
||||
|
||||
// set selections to also all children if they are not editor items
|
||||
|
||||
foreach (QWeakPointer<QGraphicsObject> obj, itemList) {
|
||||
if (obj.isNull())
|
||||
continue;
|
||||
|
||||
QGraphicsItem *item = obj.data();
|
||||
|
||||
QGraphicsPolygonItem *newSelectionIndicatorGraphicsItem = new QGraphicsPolygonItem(m_layerItem.data());
|
||||
if (!m_indicatorShapeHash.contains(item)) {
|
||||
m_indicatorShapeHash.insert(item, newSelectionIndicatorGraphicsItem);
|
||||
|
||||
QPolygonF boundingShapeInSceneSpace;
|
||||
addBoundingRectToPolygon(item, boundingShapeInSceneSpace);
|
||||
|
||||
QRectF boundingRect = m_view->adjustToScreenBoundaries(boundingShapeInSceneSpace.boundingRect());
|
||||
QPolygonF boundingRectInLayerItemSpace = m_layerItem->mapFromScene(boundingRect);
|
||||
|
||||
QPen pen;
|
||||
pen.setColor(QColor(108, 141, 221));
|
||||
newSelectionIndicatorGraphicsItem->setData(Constants::EditorItemDataKey, QVariant(true));
|
||||
newSelectionIndicatorGraphicsItem->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
newSelectionIndicatorGraphicsItem->setPolygon(boundingRectInLayerItemSpace);
|
||||
newSelectionIndicatorGraphicsItem->setPen(pen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace QmlViewer
|
||||
|
||||
Reference in New Issue
Block a user