1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "liverubberbandselectionmanipulator.h"
35 #include "../qdeclarativeviewobserver_p.h"
37 #include <QtGui/QGraphicsItem>
39 #include <QtCore/QDebug>
41 namespace QmlJSDebugger {
43 LiveRubberBandSelectionManipulator::LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem,
44 QDeclarativeViewObserver *editorView)
45 : m_selectionRectangleElement(layerItem),
46 m_editorView(editorView),
47 m_beginFormEditorItem(0),
50 m_selectionRectangleElement.hide();
53 void LiveRubberBandSelectionManipulator::clear()
55 m_selectionRectangleElement.clear();
57 m_beginPoint = QPointF();
59 m_oldSelectionList.clear();
62 QGraphicsItem *LiveRubberBandSelectionManipulator::topFormEditorItem(const QList<QGraphicsItem*>
65 if (itemList.isEmpty())
68 return itemList.first();
71 void LiveRubberBandSelectionManipulator::begin(const QPointF &beginPoint)
73 m_beginPoint = beginPoint;
74 m_selectionRectangleElement.setRect(m_beginPoint, m_beginPoint);
75 m_selectionRectangleElement.show();
77 QDeclarativeViewObserverPrivate *observerPrivate
78 = QDeclarativeViewObserverPrivate::get(m_editorView);
79 m_beginFormEditorItem = topFormEditorItem(observerPrivate->selectableItems(beginPoint));
80 m_oldSelectionList = m_editorView->selectedItems();
83 void LiveRubberBandSelectionManipulator::update(const QPointF &updatePoint)
85 m_selectionRectangleElement.setRect(m_beginPoint, updatePoint);
88 void LiveRubberBandSelectionManipulator::end()
90 m_oldSelectionList.clear();
91 m_selectionRectangleElement.hide();
95 void LiveRubberBandSelectionManipulator::select(SelectionType selectionType)
97 QDeclarativeViewObserverPrivate *observerPrivate
98 = QDeclarativeViewObserverPrivate::get(m_editorView);
99 QList<QGraphicsItem*> itemList
100 = observerPrivate->selectableItems(m_selectionRectangleElement.rect(),
101 Qt::IntersectsItemShape);
102 QList<QGraphicsItem*> newSelectionList;
104 foreach (QGraphicsItem* item, itemList) {
106 && item->parentItem()
107 && !newSelectionList.contains(item)
108 //&& m_beginFormEditorItem->childItems().contains(item) // TODO activate this test
111 newSelectionList.append(item);
115 if (newSelectionList.isEmpty() && m_beginFormEditorItem)
116 newSelectionList.append(m_beginFormEditorItem);
118 QList<QGraphicsItem*> resultList;
120 switch(selectionType) {
121 case AddToSelection: {
122 resultList.append(m_oldSelectionList);
123 resultList.append(newSelectionList);
126 case ReplaceSelection: {
127 resultList.append(newSelectionList);
130 case RemoveFromSelection: {
131 QSet<QGraphicsItem*> oldSelectionSet(m_oldSelectionList.toSet());
132 QSet<QGraphicsItem*> newSelectionSet(newSelectionList.toSet());
133 resultList.append(oldSelectionSet.subtract(newSelectionSet).toList());
137 m_editorView->setSelectedItems(resultList);
141 void LiveRubberBandSelectionManipulator::setItems(const QList<QGraphicsItem*> &itemList)
143 m_itemList = itemList;
146 QPointF LiveRubberBandSelectionManipulator::beginPoint() const
151 bool LiveRubberBandSelectionManipulator::isActive() const
156 } // namespace QmlJSDebugger