qdeclarativedesignview.h 3.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef QDECLARATIVEDESIGNVIEW_H
#define QDECLARATIVEDESIGNVIEW_H

#include "qmlviewerconstants.h"
#include <qdeclarativeview.h>

QT_FORWARD_DECLARE_CLASS(QDeclarativeItem);
QT_FORWARD_DECLARE_CLASS(QMouseEvent);
QT_FORWARD_DECLARE_CLASS(QToolBar);

namespace QmlViewer {

class AbstractFormEditorTool;
class SelectionTool;
class ZoomTool;
class ColorPickerTool;
class LayerItem;
class BoundingRectHighlighter;
class SubcomponentEditorTool;
class QmlToolbar;

class QDeclarativeDesignView : public QDeclarativeView
{
    Q_OBJECT
public:
26
27
28
29
    enum ContextFlags {
        IgnoreContext,
        ContextSensitive
    };
30
31
32
33
34
35
36
37
38
39
40
41

    explicit QDeclarativeDesignView(QWidget *parent = 0);
    ~QDeclarativeDesignView();

    void setSelectedItems(QList<QGraphicsItem *> items);
    QList<QGraphicsItem *> selectedItems() const;
    AbstractFormEditorTool *currentTool() const;

    LayerItem *manipulatorLayer() const;
    void changeTool(Constants::DesignTool tool,
                    Constants::ToolFlags flags = Constants::NoToolFlags);

42
    void clearHighlight();
43
44
    void highlight(QList<QGraphicsItem *> item, ContextFlags flags = ContextSensitive);
    void highlight(QGraphicsItem *item, ContextFlags flags = ContextSensitive);
45
46

    bool mouseInsideContextItem() const;
47
48
    bool isEditorItem(QGraphicsItem *item) const;

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    QList<QGraphicsItem*> selectableItems(const QPoint &pos) const;
    QList<QGraphicsItem*> selectableItems(const QPointF &scenePos) const;
    QList<QGraphicsItem*> selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const;
    QGraphicsItem *currentRootItem() const;

    QToolBar *toolbar() const;

public Q_SLOTS:
    void setDesignModeBehavior(bool value);
    bool designModeBehavior() const;
    void changeToSingleSelectTool();
    void changeToMarqueeSelectTool();
    void changeToZoomTool();
    void changeToColorPickerTool();

    void changeAnimationSpeed(qreal slowdownFactor);
    void continueExecution(qreal slowdownFactor = 1.0f);
    void pauseExecution();

Q_SIGNALS:
    void designModeBehaviorChanged(bool inDesignMode);
    void reloadRequested();
    void marqueeSelectToolActivated();
    void selectToolActivated();
    void zoomToolActivated();
    void colorPickerActivated();
    void selectedColorChanged(const QColor &color);

    void executionStarted(qreal slowdownFactor);
    void executionPaused();

protected:
81
    void leaveEvent(QEvent *);
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *keyEvent);
    void mouseDoubleClickEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);

private Q_SLOTS:
    void reloadView();
    void onStatusChanged(QDeclarativeView::Status status);
    void onCurrentObjectsChanged(QList<QObject*> objects);
    void applyChangesFromClient();

private:
    void createToolbar();
    void changeToSelectTool();
99
100
    QList<QGraphicsItem*> filterForCurrentContext(QList<QGraphicsItem*> &itemlist) const;
    QList<QGraphicsItem*> filterForSelection(QList<QGraphicsItem*> &itemlist) const;
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

private:
    QPointF m_cursorPos;
    QList<QGraphicsItem *> m_currentSelection;

    Constants::DesignTool m_currentToolMode;
    AbstractFormEditorTool *m_currentTool;

    SelectionTool *m_selectionTool;
    ZoomTool *m_zoomTool;
    ColorPickerTool *m_colorPickerTool;
    SubcomponentEditorTool *m_subcomponentEditorTool;
    LayerItem *m_manipulatorLayer;

    BoundingRectHighlighter *m_boundingRectHighlighter;

    bool m_designModeBehavior;

    bool m_executionPaused;
    qreal m_slowdownFactor;

    QmlToolbar *m_toolbar;
};

} //namespace QmlViewer

#endif // QDECLARATIVEDESIGNVIEW_H