dragtool.h 4.68 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30 31 32 33 34 35 36

#ifndef DRAGTOOL_H
#define DRAGTOOL_H

#include "abstractformeditortool.h"
#include "movemanipulator.h"
#include "selectionindicator.h"

Thomas Hartmann's avatar
Thomas Hartmann committed
37 38
#include <QObject>
#include <QScopedPointer>
39
#include <QPointer>
40 41 42

namespace QmlDesigner {

Thomas Hartmann's avatar
Thomas Hartmann committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
class DragTool;

namespace Internal {

class TimerHandler : public QObject
{
    Q_OBJECT

public:
    TimerHandler(DragTool *tool) : QObject(), m_dragTool(tool) {}
public slots:
    void clearMoveDelay();

private:
    DragTool *m_dragTool;
};
59
}
60 61 62 63 64

class DragTool : public AbstractFormEditorTool
{
public:
    DragTool(FormEditorView* editorView);
65
    virtual ~DragTool();
66 67

    void mousePressEvent(const QList<QGraphicsItem*> &itemList,
68
                         QGraphicsSceneMouseEvent *event) QTC_OVERRIDE;
69
    void mouseMoveEvent(const QList<QGraphicsItem*> &itemList,
70
                        QGraphicsSceneMouseEvent *event) QTC_OVERRIDE;
71
    void mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
72
                           QGraphicsSceneMouseEvent *event) QTC_OVERRIDE;
73
    void mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList,
74
                               QGraphicsSceneMouseEvent *event) QTC_OVERRIDE;
75
    void hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
76
                        QGraphicsSceneMouseEvent *event) QTC_OVERRIDE;
77

78 79
    void keyPressEvent(QKeyEvent *event) QTC_OVERRIDE;
    void keyReleaseEvent(QKeyEvent *keyEvent) QTC_OVERRIDE;
80

81
    void itemsAboutToRemoved(const QList<FormEditorItem*> &itemList) QTC_OVERRIDE;
82

83 84
    void selectedItemsChanged(const QList<FormEditorItem*> &itemList) QTC_OVERRIDE;
    void instancesParentChanged(const QList<FormEditorItem *> &itemList) QTC_OVERRIDE;
85
    void instancePropertyChange(const QList<QPair<ModelNode, PropertyName> > &propertyList) QTC_OVERRIDE;
86 87 88 89 90 91

    void updateMoveManipulator();

    void beginWithPoint(const QPointF &beginPoint);


92 93 94 95
    virtual void dropEvent(QGraphicsSceneDragDropEvent * event) QTC_OVERRIDE;
    virtual void dragEnterEvent(QGraphicsSceneDragDropEvent * event) QTC_OVERRIDE;
    virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent * event) QTC_OVERRIDE;
    virtual void dragMoveEvent(QGraphicsSceneDragDropEvent * event) QTC_OVERRIDE;
96 97 98

    //void beginWithPoint(const QPointF &beginPoint);

99
    void clear() QTC_OVERRIDE;
100

101
    void formEditorItemsChanged(const QList<FormEditorItem*> &itemList) QTC_OVERRIDE;
102

103
    void instancesCompleted(const QList<FormEditorItem*> &itemList) QTC_OVERRIDE;
104

Thomas Hartmann's avatar
Thomas Hartmann committed
105 106
    void clearMoveDelay();

107
protected:
108
    void abort();
109 110 111


private:
112
    void commitTransaction();
113
    void createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, QmlItemNode parentNode, QPointF scenePos);
114 115 116 117
    void createQmlItemNodeFromImage(const QString &imageName, QmlItemNode parentNode, QPointF scenePos);
    FormEditorItem* calculateContainer(const QPointF &point, FormEditorItem * currentItem = 0);

    void begin(QPointF scenePos);
118 119
    void end();
    void end(Snapper::Snapping useSnapping);
120 121 122 123
    void move(QPointF scenePos);

    MoveManipulator m_moveManipulator;
    SelectionIndicator m_selectionIndicator;
124
    QPointer<FormEditorItem> m_movingItem;
125 126
    RewriterTransaction m_rewriterTransaction;
    QmlItemNode m_dragNode;
Thomas Hartmann's avatar
Thomas Hartmann committed
127 128
    QScopedPointer<Internal::TimerHandler> m_timerHandler;
    bool m_blockMove;
129
    QPointF m_startPoint;
130
    bool m_Aborted;
131 132
};

Thomas Hartmann's avatar
Thomas Hartmann committed
133

134 135
}
#endif // DRAGTOOL_H