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 "resizehandleitem.h"
36 #include <formeditoritem.h>
39 namespace QmlDesigner {
41 ResizeHandleItem::ResizeHandleItem(QGraphicsItem *parent, const ResizeController &resizeController)
42 : QGraphicsPixmapItem(QPixmap(":/icon/handle/resize_handle.png"), parent),
43 m_resizeControllerData(resizeController.weakPointer())
45 setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
46 setOffset(-pixmap().rect().center());
47 setFlag(QGraphicsItem::ItemIsMovable, true);
48 setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
51 void ResizeHandleItem::setHandlePosition(const QPointF & globalPosition, const QPointF & itemSpacePosition)
53 m_itemSpacePosition = itemSpacePosition;
54 setPos(globalPosition);
57 QRectF ResizeHandleItem::boundingRect() const
59 return QGraphicsPixmapItem::boundingRect().adjusted(-1, -1, 1, 1);
62 QPainterPath ResizeHandleItem::shape() const
64 return QGraphicsItem::shape();
67 ResizeController ResizeHandleItem::resizeController() const
69 Q_ASSERT(!m_resizeControllerData.isNull());
70 return ResizeController(m_resizeControllerData.toStrongRef());
73 ResizeHandleItem* ResizeHandleItem::fromGraphicsItem(QGraphicsItem *item)
75 return qgraphicsitem_cast<ResizeHandleItem*>(item);
78 bool ResizeHandleItem::isTopLeftHandle() const
80 return resizeController().isTopLeftHandle(this);
83 bool ResizeHandleItem::isTopRightHandle() const
85 return resizeController().isTopRightHandle(this);
88 bool ResizeHandleItem::isBottomLeftHandle() const
90 return resizeController().isBottomLeftHandle(this);
93 bool ResizeHandleItem::isBottomRightHandle() const
95 return resizeController().isBottomRightHandle(this);
98 bool ResizeHandleItem::isTopHandle() const
100 return resizeController().isTopHandle(this);
103 bool ResizeHandleItem::isLeftHandle() const
105 return resizeController().isLeftHandle(this);
108 bool ResizeHandleItem::isRightHandle() const
110 return resizeController().isRightHandle(this);
113 bool ResizeHandleItem::isBottomHandle() const
115 return resizeController().isBottomHandle(this);
118 QPointF ResizeHandleItem::itemSpacePosition() const
120 return m_itemSpacePosition;