OSDN Git Service

8ad0a89d3751eb26e16b7ab2e9065ffce86fb473
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / formeditor / dragtool.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 DRAGTOOL_H
35 #define DRAGTOOL_H
36
37 #include "abstractformeditortool.h"
38 #include "movemanipulator.h"
39 #include "selectionindicator.h"
40 #include "resizeindicator.h"
41
42 #include <QHash>
43 #include <QObject>
44 #include <QScopedPointer>
45
46
47 namespace QmlDesigner {
48
49 class DragTool;
50
51 namespace Internal {
52
53 class TimerHandler : public QObject
54 {
55     Q_OBJECT
56
57 public:
58     TimerHandler(DragTool *tool) : QObject(), m_dragTool(tool) {}
59 public slots:
60     void clearMoveDelay();
61
62 private:
63     DragTool *m_dragTool;
64 };
65 }
66
67 class DragTool : public AbstractFormEditorTool
68 {
69 public:
70     DragTool(FormEditorView* editorView);
71     virtual ~DragTool();
72
73     void mousePressEvent(const QList<QGraphicsItem*> &itemList,
74                          QGraphicsSceneMouseEvent *event);
75     void mouseMoveEvent(const QList<QGraphicsItem*> &itemList,
76                         QGraphicsSceneMouseEvent *event);
77     void mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
78                            QGraphicsSceneMouseEvent *event);
79     void mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList,
80                                QGraphicsSceneMouseEvent *event);
81     void hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
82                         QGraphicsSceneMouseEvent *event);
83
84     void keyPressEvent(QKeyEvent *event);
85     void keyReleaseEvent(QKeyEvent *keyEvent);
86
87     void itemsAboutToRemoved(const QList<FormEditorItem*> &itemList);
88
89     void selectedItemsChanged(const QList<FormEditorItem*> &itemList);
90
91     void updateMoveManipulator();
92
93     void beginWithPoint(const QPointF &beginPoint);
94
95
96     virtual void dropEvent(QGraphicsSceneDragDropEvent * event);
97     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent * event);
98     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent * event);
99     virtual void dragMoveEvent(QGraphicsSceneDragDropEvent * event);
100
101     //void beginWithPoint(const QPointF &beginPoint);
102
103     void clear();
104
105     void formEditorItemsChanged(const QList<FormEditorItem*> &itemList);
106
107     void instancesCompleted(const QList<FormEditorItem*> &itemList);
108
109     void clearMoveDelay();
110
111 protected:
112
113
114 private:
115
116     void createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, QmlItemNode parentNode, QPointF scenePos);
117     void createQmlItemNodeFromImage(const QString &imageName, QmlItemNode parentNode, QPointF scenePos);
118     FormEditorItem* calculateContainer(const QPointF &point, FormEditorItem * currentItem = 0);
119
120     void begin(QPointF scenePos);
121     void end(QPointF scenePos);
122     void move(QPointF scenePos);
123
124     MoveManipulator m_moveManipulator;
125     SelectionIndicator m_selectionIndicator;
126     QWeakPointer<FormEditorItem> m_movingItem;
127     RewriterTransaction m_rewriterTransaction;
128     QmlItemNode m_dragNode;
129     QScopedPointer<Internal::TimerHandler> m_timerHandler;
130     bool m_blockMove;
131     QPointF m_startPoint;
132 };
133
134
135 }
136 #endif // DRAGTOOL_H