1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** 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