OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / formeditor / resizehandleitem.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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, 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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "resizehandleitem.h"
35
36 #include <formeditoritem.h>
37 #include <QCursor>
38
39 namespace QmlDesigner {
40
41 ResizeHandleItem::ResizeHandleItem(QGraphicsItem *parent, const ResizeController &resizeController)
42     : QGraphicsPixmapItem(QPixmap(":/icon/handle/resize_handle.png"), parent),
43     m_resizeControllerData(resizeController.weakPointer())
44 {
45     setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
46     setOffset(-pixmap().rect().center());
47     setFlag(QGraphicsItem::ItemIsMovable, true);
48     setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
49 }
50
51 void ResizeHandleItem::setHandlePosition(const QPointF & globalPosition, const QPointF & itemSpacePosition)
52 {
53     m_itemSpacePosition = itemSpacePosition;
54     setPos(globalPosition);
55 }
56
57 QRectF ResizeHandleItem::boundingRect() const
58 {
59     return QGraphicsPixmapItem::boundingRect().adjusted(-1, -1, 1, 1);
60 }
61
62 QPainterPath ResizeHandleItem::shape() const
63 {
64     return QGraphicsItem::shape();
65 }
66
67 ResizeController ResizeHandleItem::resizeController() const
68 {
69     Q_ASSERT(!m_resizeControllerData.isNull());
70     return ResizeController(m_resizeControllerData.toStrongRef());
71 }
72
73 ResizeHandleItem* ResizeHandleItem::fromGraphicsItem(QGraphicsItem *item)
74 {
75     return qgraphicsitem_cast<ResizeHandleItem*>(item);
76 }
77
78 bool ResizeHandleItem::isTopLeftHandle() const
79 {
80     return resizeController().isTopLeftHandle(this);
81 }
82
83 bool ResizeHandleItem::isTopRightHandle() const
84 {
85     return resizeController().isTopRightHandle(this);
86 }
87
88 bool ResizeHandleItem::isBottomLeftHandle() const
89 {
90     return resizeController().isBottomLeftHandle(this);
91 }
92
93 bool ResizeHandleItem::isBottomRightHandle() const
94 {
95     return resizeController().isBottomRightHandle(this);
96 }
97
98 bool ResizeHandleItem::isTopHandle() const
99 {
100     return resizeController().isTopHandle(this);
101 }
102
103 bool ResizeHandleItem::isLeftHandle() const
104 {
105     return resizeController().isLeftHandle(this);
106 }
107
108 bool ResizeHandleItem::isRightHandle() const
109 {
110     return resizeController().isRightHandle(this);
111 }
112
113 bool ResizeHandleItem::isBottomHandle() const
114 {
115     return resizeController().isBottomHandle(this);
116 }
117
118 QPointF ResizeHandleItem::itemSpacePosition() const
119 {
120     return m_itemSpacePosition;
121 }
122 }