OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / formeditor / formeditoritem.h
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 #ifndef FORMEDITORITEM_H
35 #define FORMEDITORITEM_H
36
37 #include <QWeakPointer>
38 #include <QGraphicsWidget>
39 #include <qmlitemnode.h>
40 #include "snappinglinecreator.h"
41
42 QT_BEGIN_NAMESPACE
43 class QTimeLine;
44 QT_END_NAMESPACE
45
46 namespace QmlDesigner {
47
48 class FormEditorScene;
49 class FormEditorView;
50 class AbstractFormEditorTool;
51
52 namespace Internal {
53     class GraphicItemResizer;
54     class MoveController;
55 }
56
57 class FormEditorItem : public QGraphicsObject
58 {
59     Q_OBJECT
60
61     friend class QmlDesigner::FormEditorScene;
62 public:
63     ~FormEditorItem();
64
65     void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
66
67     bool isContainer() const;
68     QmlItemNode qmlItemNode() const;
69
70
71     enum { Type = UserType + 0xfffa };
72
73     int type() const;
74
75     static FormEditorItem* fromQGraphicsItem(QGraphicsItem *graphicsItem);
76
77     void updateSnappingLines(const QList<FormEditorItem*> &exceptionList,
78                              FormEditorItem *transformationSpaceItem);
79
80     SnapLineMap topSnappingLines() const;
81     SnapLineMap bottomSnappingLines() const;
82     SnapLineMap leftSnappingLines() const;
83     SnapLineMap rightSnappingLines() const;
84     SnapLineMap horizontalCenterSnappingLines() const;
85     SnapLineMap verticalCenterSnappingLines() const;
86
87     SnapLineMap topSnappingOffsets() const;
88     SnapLineMap bottomSnappingOffsets() const;
89     SnapLineMap leftSnappingOffsets() const;
90     SnapLineMap rightSnappingOffsets() const;
91
92     QList<FormEditorItem*> childFormEditorItems() const;
93     FormEditorScene *scene() const;
94     FormEditorItem *parentItem() const;
95
96     QRectF boundingRect() const;
97
98     void updateGeometry();
99     void updateVisibilty();
100
101     void showAttention();
102
103     FormEditorView *formEditorView() const;
104
105     void setHighlightBoundingRect(bool highlight);
106
107     void setContentVisible(bool visible);
108     bool isContentVisible() const;
109
110 protected:
111     AbstractFormEditorTool* tool() const;
112     void paintBoundingRect(QPainter *painter) const;
113
114 private slots:
115     void changeAttention(qreal value);
116
117 private: // functions
118     FormEditorItem(const QmlItemNode &qmlItemNode, FormEditorScene* scene);
119     void setup();
120     void setAttentionScale(double scale);
121     void setAttentionHighlight(double value);
122
123 private: // variables
124     SnappingLineCreator m_snappingLineCreator;
125     QmlItemNode m_qmlItemNode;
126     QWeakPointer<QTimeLine> m_attentionTimeLine;
127     QTransform m_attentionTransform; // make item larger in anchor mode
128     QTransform m_inverseAttentionTransform;
129     QRectF m_boundingRect;
130     double m_borderWidth;
131     bool m_highlightBoundingRect;
132     bool m_isContentVisible;
133 };
134
135
136 inline int FormEditorItem::type() const
137 {
138     return UserType + 0xfffa;
139 }
140
141 }
142
143 #endif // FORMEDITORITEM_H