OSDN Git Service

b39a73ba870e33399b2aa557786a4241c1ff8629
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / propertyeditor / propertyeditor.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 QmlPropertyView_h
35 #define QmlPropertyView_h
36
37 #include <qmlmodelview.h>
38 #include <declarativewidgetview.h>
39 #include <QHash>
40 #include <QDeclarativePropertyMap>
41 #include <QStackedWidget>
42 #include <QTimer>
43
44 #include "qmlanchorbindingproxy.h"
45 #include "designerpropertymap.h"
46 #include "propertyeditorvalue.h"
47 #include "propertyeditorcontextobject.h"
48
49 QT_BEGIN_NAMESPACE
50 class QShortcut;
51 class QStackedWidget;
52 class QTimer;
53 QT_END_NAMESPACE
54
55 class PropertyEditorValue;
56
57 namespace QmlDesigner {
58
59 class PropertyEditorTransaction;
60 class CollapseButton;
61 class StackedWidget;
62
63 class PropertyEditor: public QmlModelView
64 {
65     Q_OBJECT
66
67     class NodeType {
68     public:
69         NodeType(PropertyEditor *propertyEditor);
70         ~NodeType();
71
72         void setup(const QmlObjectNode &fxObjectNode, const QString &stateName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor);
73         void initialSetup(const QString &typeName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor);
74         void setValue(const QmlObjectNode &fxObjectNode, const QString &name, const QVariant &value);
75
76         DeclarativeWidgetView *m_view;
77         Internal::QmlAnchorBindingProxy m_backendAnchorBinding;
78         DesignerPropertyMap<PropertyEditorValue> m_backendValuesPropertyMap;
79         QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction;
80         QScopedPointer<PropertyEditorValue> m_dummyPropertyEditorValue;
81         QScopedPointer<PropertyEditorContextObject> m_contextObject;
82     };
83
84 public:
85     PropertyEditor(QWidget *parent = 0);
86     ~PropertyEditor();
87
88     void setQmlDir(const QString &qmlDirPath);
89
90     QWidget* createPropertiesPage();
91
92     void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
93                               const QList<ModelNode> &lastSelectedNodeList);
94     void nodeAboutToBeRemoved(const ModelNode &removedNode);
95
96     void propertiesAdded(const NodeState &state, const QList<NodeProperty>& propertyList);
97     void propertiesRemoved(const QList<AbstractProperty>& propertyList);
98     void propertyValuesChanged(const NodeState &state, const QList<NodeProperty>& propertyList);
99
100     void modelAttached(Model *model);
101
102     void modelAboutToBeDetached(Model *model);
103
104     ModelState modelState() const;
105
106     void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange);
107     void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
108
109     void instanceInformationsChange(const QVector<ModelNode> &nodeList);
110
111     void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
112     void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
113
114 protected:
115     void timerEvent(QTimerEvent *event);
116     void otherPropertyChanged(const QmlObjectNode &, const QString &propertyName);
117     void transformChanged(const QmlObjectNode &qmlObjectNode, const QString &propertyName);
118     void stateChanged(const QmlModelState &newQmlModelState, const QmlModelState &oldQmlModelState);
119
120     void setupPane(const QString &typeName);
121     void setValue(const QmlObjectNode &fxObjectNode, const QString &name, const QVariant &value);
122
123 private slots:
124     void reloadQml();
125     void changeValue(const QString &name);
126     void changeExpression(const QString &name);
127     void updateSize();
128     void setupPanes();
129
130 private: //functions
131     QString qmlFileName(const NodeMetaInfo &nodeInfo) const;
132     QUrl fileToUrl(const QString &filePath) const;
133     QUrl qmlForNode(const ModelNode &modelNode, QString &className) const;
134     QString locateQmlFile(const QString &relativePath) const;
135     void select(const ModelNode& node);
136
137     void resetView();
138     void delayedResetView();
139
140
141 private: //variables
142     ModelNode m_selectedNode;
143     QWidget *m_parent;
144     QShortcut *m_updateShortcut;
145     int m_timerId;
146     StackedWidget* m_stackedWidget;
147     QString m_qmlDir;
148     QHash<QString, NodeType *> m_typeHash;
149     NodeType *m_currentType;
150     bool m_locked;
151     bool m_setupCompleted;
152     QTimer *m_singleShotTimer;
153 };
154
155
156 class StackedWidget : public QStackedWidget
157 {
158 Q_OBJECT
159
160 public:
161     StackedWidget(QWidget *parent = 0) : QStackedWidget(parent) {}
162
163 signals:
164     void resized();
165 protected:
166     void resizeEvent(QResizeEvent * event)
167     {
168         QStackedWidget::resizeEvent(event);
169         emit resized();
170     }
171 };
172 }
173
174 #endif // QmlPropertyView_h