movemanipulator.h 4.28 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

#ifndef MOVEMANIPULATOR_H
#define MOVEMANIPULATOR_H

#include <QWeakPointer>
#include <QGraphicsItem>
#include <QHash>
#include <QPointF>
#include <QRectF>

#include "formeditoritem.h"
#include "rewritertransaction.h"
#include "snapper.h"
#include "formeditorview.h"

namespace QmlDesigner {

class ModelNodeChangeSet;
class Model;

class MoveManipulator
{
public:
    enum Snapping {
        UseSnapping,
54
        UseSnappingAndAnchoring,
55 56 57
        NoSnapping
    };

58 59 60 61 62
    enum State {
        UseActualState,
        UseBaseState
    };

63 64 65 66
    MoveManipulator(LayerItem *layerItem, FormEditorView *view);
    ~MoveManipulator();
    void setItems(const QList<FormEditorItem*> &itemList);
    void setItem(FormEditorItem* item);
67
    void synchronizeInstanceParent(const QList<FormEditorItem*> &itemList);
68
    void synchronizeParent(const QList<FormEditorItem*> &itemList, const ModelNode &parentNode);
69

70
    void begin(const QPointF& beginPoint);
71
    void update(const QPointF& updatePoint, Snapping useSnapping, State stateToBeManipulated = UseActualState);
72 73 74 75 76
    void reparentTo(FormEditorItem *newParent);
    void end(const QPointF& endPoint);

    void moveBy(double deltaX, double deltaY);

77 78 79
    void beginRewriterTransaction();
    void endRewriterTransaction();

80 81 82 83 84 85 86 87 88
    QPointF beginPoint() const;

    void clear();

    bool isActive() const;

protected:
    void setOpacityForAllElements(qreal opacity);

Marco Bubke's avatar
Marco Bubke committed
89
    QPointF findSnappingOffset(const QHash<FormEditorItem*, QRectF> &boundingRectHash);
90 91 92

    void deleteSnapLines();

Marco Bubke's avatar
Marco Bubke committed
93
    QHash<FormEditorItem*, QRectF> tanslatedBoundingRects(const QHash<FormEditorItem*, QRectF> &boundingRectHash, const QPointF& offset);
94 95 96
    QPointF calculateBoundingRectMovementOffset(const QPointF& updatePoint);
    QRectF boundingRect(FormEditorItem* item, const QPointF& updatePoint);

Marco Bubke's avatar
Marco Bubke committed
97
    void generateSnappingLines(const QHash<FormEditorItem*, QRectF> &boundingRectHash);
98 99 100 101
    void updateHashes();

    bool itemsCanReparented() const;

Marco Bubke's avatar
Marco Bubke committed
102 103
    void setPosition(QmlItemNode itemNode, const QPointF &position);

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
private:
    Snapper m_snapper;
    QWeakPointer<LayerItem> m_layerItem;
    QWeakPointer<FormEditorView> m_view;
    QList<FormEditorItem*> m_itemList;
    QHash<FormEditorItem*, QRectF> m_beginItemRectHash;
    QHash<FormEditorItem*, QPointF> m_beginPositionHash;
    QHash<FormEditorItem*, QPointF> m_beginPositionInSceneSpaceHash;
    QPointF m_beginPoint;
    QHash<FormEditorItem*, double> m_beginTopMarginHash;
    QHash<FormEditorItem*, double> m_beginLeftMarginHash;
    QHash<FormEditorItem*, double> m_beginRightMarginHash;
    QHash<FormEditorItem*, double> m_beginBottomMarginHash;
    QHash<FormEditorItem*, double> m_beginHorizontalCenterHash;
    QHash<FormEditorItem*, double> m_beginVerticalCenterHash;
    QList<QGraphicsItem*> m_graphicsLineList;
    bool m_isActive;
    RewriterTransaction m_rewriterTransaction;
122
    QPointF m_lastPosition;
123 124 125 126
};

}
#endif // MOVEMANIPULATOR_H