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 "rubberbandselectionmanipulator.h"
35 #include "../qdeclarativeviewobserver_p.h"
39 namespace QmlJSDebugger {
41 RubberBandSelectionManipulator::RubberBandSelectionManipulator(QGraphicsObject *layerItem,
42 QDeclarativeViewObserver *editorView)
43 : m_selectionRectangleElement(layerItem),
44 m_editorView(editorView),
45 m_beginFormEditorItem(0),
48 m_selectionRectangleElement.hide();
51 void RubberBandSelectionManipulator::clear()
53 m_selectionRectangleElement.clear();
55 m_beginPoint = QPointF();
57 m_oldSelectionList.clear();
60 QGraphicsItem *RubberBandSelectionManipulator::topFormEditorItem(const QList<QGraphicsItem*>
63 if (itemList.isEmpty())
66 return itemList.first();
69 void RubberBandSelectionManipulator::begin(const QPointF& beginPoint)
71 m_beginPoint = beginPoint;
72 m_selectionRectangleElement.setRect(m_beginPoint, m_beginPoint);
73 m_selectionRectangleElement.show();
75 QDeclarativeViewObserverPrivate *observerPrivate
76 = QDeclarativeViewObserverPrivate::get(m_editorView);
77 m_beginFormEditorItem = topFormEditorItem(observerPrivate->selectableItems(beginPoint));
78 m_oldSelectionList = m_editorView->selectedItems();
81 void RubberBandSelectionManipulator::update(const QPointF& updatePoint)
83 m_selectionRectangleElement.setRect(m_beginPoint, updatePoint);
86 void RubberBandSelectionManipulator::end()
88 m_oldSelectionList.clear();
89 m_selectionRectangleElement.hide();
93 void RubberBandSelectionManipulator::select(SelectionType selectionType)
95 QDeclarativeViewObserverPrivate *observerPrivate
96 = QDeclarativeViewObserverPrivate::get(m_editorView);
97 QList<QGraphicsItem*> itemList
98 = observerPrivate->selectableItems(m_selectionRectangleElement.rect(),
99 Qt::IntersectsItemShape);
100 QList<QGraphicsItem*> newSelectionList;
102 foreach (QGraphicsItem* item, itemList) {
104 && item->parentItem()
105 && !newSelectionList.contains(item)
106 //&& m_beginFormEditorItem->childItems().contains(item) // TODO activate this test
109 newSelectionList.append(item);
113 if (newSelectionList.isEmpty() && m_beginFormEditorItem)
114 newSelectionList.append(m_beginFormEditorItem);
116 QList<QGraphicsItem*> resultList;
118 switch(selectionType) {
119 case AddToSelection: {
120 resultList.append(m_oldSelectionList);
121 resultList.append(newSelectionList);
124 case ReplaceSelection: {
125 resultList.append(newSelectionList);
128 case RemoveFromSelection: {
129 QSet<QGraphicsItem*> oldSelectionSet(m_oldSelectionList.toSet());
130 QSet<QGraphicsItem*> newSelectionSet(newSelectionList.toSet());
131 resultList.append(oldSelectionSet.subtract(newSelectionSet).toList());
135 m_editorView->setSelectedItems(resultList);
139 void RubberBandSelectionManipulator::setItems(const QList<QGraphicsItem*> &itemList)
141 m_itemList = itemList;
144 QPointF RubberBandSelectionManipulator::beginPoint() const
149 bool RubberBandSelectionManipulator::isActive() const
154 } // namespace QmlJSDebugger