Qt 4.8
liveselectionindicator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** 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.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "liveselectionindicator.h"
43 
44 #include "../qdeclarativeviewinspector_p.h"
45 #include "../qmlinspectorconstants.h"
46 
47 #include <QtGui/QGraphicsRectItem>
48 #include <QtGui/QGraphicsObject>
49 #include <QtGui/QGraphicsScene>
50 #include <QtGui/QPen>
51 
52 namespace QmlJSDebugger {
53 
55  QGraphicsObject *layerItem)
56  : m_layerItem(layerItem)
57  , m_view(viewInspector)
58 {
59 }
60 
62 {
63  clear();
64 }
65 
67 {
69  item->show();
70 }
71 
73 {
75  item->hide();
76 }
77 
79 {
80  if (!m_layerItem.isNull()) {
81  QGraphicsScene *scene = m_layerItem.data()->scene();
82  foreach (QGraphicsRectItem *item, m_indicatorShapeHash) {
83  scene->removeItem(item);
84  delete item;
85  }
86  }
87 
89 
90 }
91 
93 {
94  clear();
95 
96  foreach (const QWeakPointer<QGraphicsObject> &object, itemList) {
97  if (object.isNull())
98  continue;
99 
100  QGraphicsItem *item = object.data();
101 
102  if (!m_indicatorShapeHash.contains(item)) {
103  QGraphicsRectItem *selectionIndicator = new QGraphicsRectItem(m_layerItem.data());
104  m_indicatorShapeHash.insert(item, selectionIndicator);
105 
107  const QRectF boundingRectInLayerItemSpace = m_layerItem.data()->mapRectFromScene(boundingRect);
108 
109  selectionIndicator->setData(Constants::EditorItemDataKey, true);
110  selectionIndicator->setFlag(QGraphicsItem::ItemIsSelectable, false);
111  selectionIndicator->setRect(boundingRectInLayerItemSpace);
112  selectionIndicator->setPen(QColor(108, 141, 221));
113  }
114  }
115 }
116 
117 } //namespace QmlJSDebugger
118 
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
QHash< QGraphicsItem *, QGraphicsRectItem * > m_indicatorShapeHash
void clear()
Removes all items from the hash.
Definition: qhash.h:574
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
void setItems(const QList< QWeakPointer< QGraphicsObject > > &itemList)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QWeakPointer< QGraphicsObject > m_layerItem
QRectF mapRectToScene(const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s coordinate system, to the scene coordinate system...
bool isNull() const
Returns true if this object is holding a reference to a null pointer.
T * data() const
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static const QRectF boundingRect(const QPointF *points, int pointCount)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QRectF mapRectFromScene(const QRectF &rect) const
Maps the rectangle rect, which is in scene coordinates, to this item&#39;s coordinate system...
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
QVariant data(int key) const
Returns this item&#39;s custom data for the key key as a QVariant.
void setData(int key, const QVariant &value)
Sets this item&#39;s custom data for the key key to value.
void setPen(const QPen &pen)
Sets the pen for this item to pen.
QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace)
void hide()
Hides the item.
void setRect(const QRectF &rect)
Sets the item&#39;s rectangle to be the given rectangle.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
static const int EditorItemDataKey
The QGraphicsObject class provides a base class for all graphics items that require signals...
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
LiveSelectionIndicator(QDeclarativeViewInspector *viewInspector, QGraphicsObject *layerItem)
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void show()
Shows the item.