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 "subcomponentmasklayeritem.h"
35 #include "qmlobserverconstants.h"
36 #include "qdeclarativeviewobserver.h"
39 namespace QmlJSDebugger {
41 SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeViewObserver *observer,
42 QGraphicsItem *parentItem) :
43 QGraphicsPolygonItem(parentItem),
46 m_borderRect(new QGraphicsRectItem(this))
48 m_borderRect->setRect(0,0,0,0);
49 m_borderRect->setPen(QPen(QColor(60, 60, 60), 1));
50 m_borderRect->setData(Constants::EditorItemDataKey, QVariant(true));
52 setBrush(QBrush(QColor(160,160,160)));
56 int SubcomponentMaskLayerItem::type() const
58 return Constants::EditorItemType;
61 static QRectF resizeRect(const QRectF &newRect, const QRectF &oldRect)
63 QRectF result = newRect;
64 if (oldRect.left() < newRect.left())
65 result.setLeft(oldRect.left());
67 if (oldRect.top() < newRect.top())
68 result.setTop(oldRect.top());
70 if (oldRect.right() > newRect.right())
71 result.setRight(oldRect.right());
73 if (oldRect.bottom() > newRect.bottom())
74 result.setBottom(oldRect.bottom());
80 void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item)
82 QGraphicsItem *prevItem = m_currentItem;
88 QPolygonF viewPoly(QRectF(m_observer->declarativeView()->rect()));
89 viewPoly = m_observer->declarativeView()->mapToScene(viewPoly.toPolygon());
91 QRectF itemRect = item->boundingRect() | item->childrenBoundingRect();
92 QPolygonF itemPoly(itemRect);
93 itemPoly = item->mapToScene(itemPoly);
95 // if updating the same item as before, resize the rectangle only bigger, not smaller.
96 if (prevItem == item && prevItem != 0) {
97 m_itemPolyRect = resizeRect(itemPoly.boundingRect(), m_itemPolyRect);
99 m_itemPolyRect = itemPoly.boundingRect();
101 QRectF borderRect = m_itemPolyRect;
102 borderRect.adjust(-1, -1, 1, 1);
103 m_borderRect->setRect(borderRect);
105 itemPoly = viewPoly.subtracted(QPolygonF(m_itemPolyRect));
106 setPolygon(itemPoly);
109 QGraphicsItem *SubcomponentMaskLayerItem::currentItem() const
111 return m_currentItem;
114 } // namespace QmlJSDebugger