propertyeditor.h 6.06 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef QmlPropertyView_h
#define QmlPropertyView_h

#include <qmlmodelview.h>
34
#include <QDeclarativeView>
35
#include <QHash>
36
#include <QDeclarativePropertyMap>
37
#include <QStackedWidget>
38
39
40

#include "qmlanchorbindingproxy.h"

41
QT_BEGIN_NAMESPACE
42
43
class QShortcut;
class QStackedWidget;
44
QT_END_NAMESPACE
45

46
47
class PropertyEditorValue;

48
49
namespace QmlDesigner {

50
class PropertyEditorTransaction;
51
52
class CollapseButton;
class StackedWidget;
53

54
55
56
57
58
59
class PropertyEditor: public QmlModelView
{
    Q_OBJECT

    class NodeType {
    public:
60
        NodeType(PropertyEditor *propertyEditor);
61
62
        ~NodeType();

63
        void setup(const QmlObjectNode &fxObjectNode, const QString &stateName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor);
64
        void initialSetup(const QString &typeName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor);
65
66
        void setValue(const QmlObjectNode &fxObjectNode, const QString &name, const QVariant &value);

67
        QDeclarativeView *m_view;
68
        Internal::QmlAnchorBindingProxy m_backendAnchorBinding;
69
        QDeclarativePropertyMap m_backendValuesPropertyMap;
70
        QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction;
71
        QScopedPointer<PropertyEditorValue> m_dummyPropertyEditorValue;
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    };

public:
    PropertyEditor(QWidget *parent = 0);
    ~PropertyEditor();

    void setQmlDir(const QString &qmlDirPath);

    QWidget* createPropertiesPage();

    void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
                              const QList<ModelNode> &lastSelectedNodeList);
    void nodeAboutToBeRemoved(const ModelNode &removedNode);

    void propertiesAdded(const NodeState &state, const QList<NodeProperty>& propertyList);
87
    void propertiesRemoved(const QList<AbstractProperty>& propertyList);
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    void propertyValuesChanged(const NodeState &state, const QList<NodeProperty>& propertyList);

    void modelAttached(Model *model);

    void modelAboutToBeDetached(Model *model);

    ModelState modelState() const;

    void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange);
    void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);

    void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);

protected:
    void timerEvent(QTimerEvent *event);
103
104
    void otherPropertyChanged(const QmlObjectNode &, const QString &propertyName);
    void transformChanged(const QmlObjectNode &qmlObjectNode, const QString &propertyName);
105
    void stateChanged(const QmlModelState &newQmlModelState, const QmlModelState &oldQmlModelState);
Kai Koehne's avatar
Kai Koehne committed
106
107

    void setupPane(const QString &typeName);
108
    void setValue(const QmlObjectNode &fxObjectNode, const QString &name, const QVariant &value);
109
110
111
112
113

private slots:
    void reloadQml();
    void changeValue(const QString &name);
    void changeExpression(const QString &name);
114
115
116
    void expand();
    void collapse();
    void updateCollapseButton();
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

private: //functions
    QString qmlFileName(const NodeMetaInfo &nodeInfo) const;
    QUrl fileToUrl(const QString &filePath) const;
    QUrl qmlForNode(const ModelNode &modelNode) const;
    QString locateQmlFile(const QString &relativePath) const;
    void select(const ModelNode& node);

    void resetView();
    void delayedResetView();


private: //variables
    ModelNode m_selectedNode;
    QWidget *m_parent;
    QShortcut *m_updateShortcut;
    int m_timerId;
134
135
    StackedWidget* m_stackedWidget;
    CollapseButton *m_collapseButton;
136
137
138
    QString m_qmlDir;
    QHash<QString, NodeType *> m_typeHash;
    NodeType *m_currentType;
139
    bool m_locked;
140
141
};

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

class StackedWidget : public QStackedWidget
{
Q_OBJECT

public:
    StackedWidget(QWidget *parent = 0) : QStackedWidget(parent) {}

signals:
    void resized();
protected:
    void resizeEvent(QResizeEvent * event)
    {
        QStackedWidget::resizeEvent(event);
        emit resized();
    }
};

class CollapseButton : public QWidget
{
Q_OBJECT

public:

    CollapseButton(QWidget *parent = 0);
    bool isCollapsed() const
    { return m_collapsed; }

signals:
    void expand();
    void collapse();

protected:
    void paintEvent(QPaintEvent *event);

177
    void mouseReleaseEvent(QMouseEvent *)
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
    {
        if (m_collapsed) {
            m_collapsed = false;
            emit expand();
        } else {
            m_collapsed = true;
            emit collapse();
        }
        update();
    }

    void enterEvent ( QEvent *)
    {
         m_hovered = true;
         setOpacity(0.9);
         update();
    }

    void leaveEvent ( QEvent *)
    {
        m_hovered = false;
        setOpacity(0.4);
        update();
    }

    void setOpacity(qreal opacity);

private:
    bool m_collapsed;
    bool m_hovered;
    QPixmap m_pixmap_normal;
    QPixmap m_pixmap_hover;
    QPixmap m_pixmap_normal_mirrored;
    QPixmap m_pixmap_hover_mirrored;
};

214
215
216
}

#endif // QmlPropertyView_h