1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "liverubberbandselectionmanipulator.h"
44 #include "qdeclarativeviewinspector_p.h"
46 #include <QtWidgets/QGraphicsItem>
48 #include <QtCore/QDebug>
50 namespace QmlJSDebugger {
53 LiveRubberBandSelectionManipulator::LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem,
54 QDeclarativeViewInspector *editorView)
55 : m_selectionRectangleElement(layerItem),
56 m_editorView(editorView),
57 m_beginFormEditorItem(0),
60 m_selectionRectangleElement.hide();
63 void LiveRubberBandSelectionManipulator::clear()
65 m_selectionRectangleElement.clear();
67 m_beginPoint = QPointF();
69 m_oldSelectionList.clear();
72 QGraphicsItem *LiveRubberBandSelectionManipulator::topFormEditorItem(const QList<QGraphicsItem*>
75 if (itemList.isEmpty())
78 return itemList.first();
81 void LiveRubberBandSelectionManipulator::begin(const QPointF &beginPoint)
83 m_beginPoint = beginPoint;
84 m_selectionRectangleElement.setRect(m_beginPoint, m_beginPoint);
85 m_selectionRectangleElement.show();
87 QDeclarativeViewInspectorPrivate *inspectorPrivate
88 = QDeclarativeViewInspectorPrivate::get(m_editorView);
89 m_beginFormEditorItem = topFormEditorItem(inspectorPrivate->selectableItems(beginPoint));
90 m_oldSelectionList = m_editorView->selectedItems();
93 void LiveRubberBandSelectionManipulator::update(const QPointF &updatePoint)
95 m_selectionRectangleElement.setRect(m_beginPoint, updatePoint);
98 void LiveRubberBandSelectionManipulator::end()
100 m_oldSelectionList.clear();
101 m_selectionRectangleElement.hide();
105 void LiveRubberBandSelectionManipulator::select(SelectionType selectionType)
107 QDeclarativeViewInspectorPrivate *inspectorPrivate
108 = QDeclarativeViewInspectorPrivate::get(m_editorView);
109 QList<QGraphicsItem*> itemList
110 = inspectorPrivate->selectableItems(m_selectionRectangleElement.rect(),
111 Qt::IntersectsItemShape);
112 QList<QGraphicsItem*> newSelectionList;
114 foreach (QGraphicsItem* item, itemList) {
116 && item->parentItem()
117 && !newSelectionList.contains(item)
118 //&& m_beginFormEditorItem->childItems().contains(item) // TODO activate this test
121 newSelectionList.append(item);
125 if (newSelectionList.isEmpty() && m_beginFormEditorItem)
126 newSelectionList.append(m_beginFormEditorItem);
128 QList<QGraphicsItem*> resultList;
130 switch (selectionType) {
131 case AddToSelection: {
132 resultList.append(m_oldSelectionList);
133 resultList.append(newSelectionList);
136 case ReplaceSelection: {
137 resultList.append(newSelectionList);
140 case RemoveFromSelection: {
141 QSet<QGraphicsItem*> oldSelectionSet(m_oldSelectionList.toSet());
142 QSet<QGraphicsItem*> newSelectionSet(newSelectionList.toSet());
143 resultList.append(oldSelectionSet.subtract(newSelectionSet).toList());
147 m_editorView->setSelectedItems(resultList);
151 void LiveRubberBandSelectionManipulator::setItems(const QList<QGraphicsItem*> &itemList)
153 m_itemList = itemList;
156 QPointF LiveRubberBandSelectionManipulator::beginPoint() const
161 bool LiveRubberBandSelectionManipulator::isActive() const
166 } // namespace QtQuick1
167 } // namespace QmlJSDebugger