OSDN Git Service

a5ccfa56f75a8551bdab2f226d71c35cfd9083d3
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / formeditor / anchorlinehandleitem.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 "anchorlinehandleitem.h"
35
36 #include <formeditoritem.h>
37 #include <QPen>
38 #include <cmath>
39
40 namespace QmlDesigner {
41
42 AnchorLineHandleItem::AnchorLineHandleItem(QGraphicsItem *parent, const AnchorLineController &anchorLineController)
43     : QGraphicsPathItem(parent),
44     m_anchorLineControllerData(anchorLineController.weakPointer())
45 {
46     setFlag(QGraphicsItem::ItemIsMovable, true);
47     setHiglighted(false);
48 }
49
50 void AnchorLineHandleItem::setHandlePath(const QPainterPath & path)
51 {
52     setPath(path);
53     update();
54 }
55
56 QRectF AnchorLineHandleItem::boundingRect() const
57 {
58     return QGraphicsPathItem::boundingRect();
59 }
60
61 QPainterPath AnchorLineHandleItem::shape() const
62 {
63     return QGraphicsPathItem::shape();
64 }
65
66 AnchorLineController AnchorLineHandleItem::anchorLineController() const
67 {
68     Q_ASSERT(!m_anchorLineControllerData.isNull());
69     return AnchorLineController(m_anchorLineControllerData.toStrongRef());
70 }
71
72 AnchorLine::Type AnchorLineHandleItem::anchorLine() const
73 {
74     if (isTopHandle())
75         return AnchorLine::Top;
76
77     if (isLeftHandle())
78         return AnchorLine::Left;
79
80     if (isRightHandle())
81         return AnchorLine::Right;
82
83      if (isBottomHandle())
84         return AnchorLine::Bottom;
85
86     return AnchorLine::Invalid;
87 }
88
89 AnchorLineHandleItem* AnchorLineHandleItem::fromGraphicsItem(QGraphicsItem *item)
90 {
91     return qgraphicsitem_cast<AnchorLineHandleItem*>(item);
92 }
93
94 bool AnchorLineHandleItem::isTopHandle() const
95 {
96     return anchorLineController().isTopHandle(this);
97 }
98
99 bool AnchorLineHandleItem::isLeftHandle() const
100 {
101     return anchorLineController().isLeftHandle(this);
102 }
103
104 bool AnchorLineHandleItem::isRightHandle() const
105 {
106     return anchorLineController().isRightHandle(this);
107 }
108
109 bool AnchorLineHandleItem::isBottomHandle() const
110 {
111     return anchorLineController().isBottomHandle(this);
112 }
113
114 AnchorLine::Type AnchorLineHandleItem::anchorLineType() const
115 {
116     if (isTopHandle())
117         return AnchorLine::Top;
118
119     if (isBottomHandle())
120         return AnchorLine::Bottom;
121
122     if (isLeftHandle())
123         return AnchorLine::Left;
124
125     if (isRightHandle())
126         return AnchorLine::Right;
127
128
129     return AnchorLine::Invalid;
130 }
131
132 QPointF AnchorLineHandleItem::itemSpacePosition() const
133 {
134     return parentItem()->mapToItem(anchorLineController().formEditorItem(), pos());
135 }
136
137 void AnchorLineHandleItem::setHiglighted(bool highlight)
138 {
139     if (highlight) {
140         QPen pen;
141         pen.setColor(QColor(108, 141, 221));
142         setPen(pen);
143         setBrush(QColor(108, 141, 221, 140));
144     } else {
145         QPen pen;
146         pen.setColor(QColor(108, 141, 221));
147         setPen(pen);
148         setBrush(QColor(108, 141, 221, 60));
149     }
150 }
151
152 } // namespace QmlDesigner