OSDN Git Service

refactored faketoolbar into core -> designmodetoolbar
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designmodewidget.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
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 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef DESIGNMODEWIDGET_H
31 #define DESIGNMODEWIDGET_H
32
33 #include <coreplugin/minisplitter.h>
34 #include <coreplugin/editormanager/ieditor.h>
35 #include <texteditor/itexteditor.h>
36
37 #include <integrationcore.h>
38
39 #include <allpropertiesbox.h>
40 #include <designdocumentcontroller.h>
41 #include <itemlibrary.h>
42 #include <navigatorwidget.h>
43 #include <stateseditorwidget.h>
44 #include <modelnode.h>
45
46
47 #include <QWeakPointer>
48 #include <QDeclarativeError>
49 #include <QtCore/QHash>
50 #include <QtGui/QWidget>
51 #include <QtGui/QToolBar>
52 #include <QtGui/QComboBox>
53 #include <QtGui/QLabel>
54
55 QT_BEGIN_NAMESPACE
56 class QStackedWidget;
57 class QTabWidget;
58 class QVBoxLayout;
59 class QToolButton;
60 QT_END_NAMESPACE
61
62 namespace Core {
63     class SideBar;
64     class OpenEditorsModel;
65     class DesignModeToolBar;
66 }
67
68 namespace QmlDesigner {
69
70 namespace Internal {
71
72 class DesignMode;
73 class DocumentWidget;
74 class DesignModeWidget;
75
76 class DocumentWarningWidget : public QFrame
77 {
78     Q_OBJECT
79     Q_DISABLE_COPY(DocumentWarningWidget)
80 public:
81     explicit DocumentWarningWidget(DocumentWidget *documentWidget, QWidget *parent = 0);
82
83     void setError(const RewriterView::Error &error);
84
85 private slots:
86     void goToError();
87
88 private:
89     QLabel *m_errorMessage;
90     QLabel *m_goToError;
91     DocumentWidget *m_documentWidget;
92     RewriterView::Error m_error;
93 };
94
95 class DocumentWidget : public QWidget
96 {
97     Q_OBJECT
98     Q_DISABLE_COPY(DocumentWidget)
99 public:
100     explicit DocumentWidget(TextEditor::ITextEditor *textEditor, QPlainTextEdit *textEdit, QmlDesigner::DesignDocumentController *document, DesignModeWidget *mainWidget);
101     ~DocumentWidget();
102
103     QmlDesigner::DesignDocumentController *document() const;
104     TextEditor::ITextEditor *textEditor() const;
105
106     void setAutoSynchronization(bool sync);
107
108     void readSettings();
109     void saveSettings();
110
111 protected:
112     void resizeEvent(QResizeEvent *event);
113
114 private slots:
115     void enable();
116     void disable(const QList<RewriterView::Error> &errors);
117     void updateErrorStatus(const QList<RewriterView::Error> &errors);
118     void closeEditor();
119
120 private:
121     void setup();
122     bool isInNodeDefinition(int nodeOffset, int nodeLength, int cursorPos) const;
123     QmlDesigner::ModelNode nodeForPosition(int cursorPos) const;
124
125     TextEditor::ITextEditor *m_textEditor;
126     QWeakPointer<QPlainTextEdit> m_textBuffer;
127     QmlDesigner::DesignDocumentController *m_document;
128     DesignModeWidget *m_mainWidget;
129     QSplitter *m_mainSplitter;
130     Core::SideBar *m_leftSideBar;
131     Core::SideBar *m_rightSideBar;
132
133     QToolBar *m_designToolBar;
134     Core::DesignModeToolBar *m_fakeToolBar;
135
136     bool m_isDisabled;
137     DocumentWarningWidget *m_warningWidget;
138 };
139
140 class DesignModeWidget : public QWidget
141 {
142     Q_OBJECT
143     Q_DISABLE_COPY(DesignModeWidget)
144 public:
145     explicit DesignModeWidget(QWidget *parent = 0);
146     ~DesignModeWidget();
147
148 //    void syncWithTextEdit(bool sync);
149
150     void showEditor(Core::IEditor *editor);
151     void closeEditors(const QList<Core::IEditor*> editors);
152     QString contextHelpId() const;
153
154     QAction *undoAction() const;
155     QAction *redoAction() const;
156     QAction *deleteAction() const;
157     QAction *cutAction() const;
158     QAction *copyAction() const;
159     QAction *pasteAction() const;
160     QAction *selectAllAction() const;
161
162 private slots:
163     void undo();
164     void redo();
165     void deleteSelected();
166     void cutSelected();
167     void copySelected();
168     void paste();
169     void selectAll();
170
171     void undoAvailable(bool isAvailable);
172     void redoAvailable(bool isAvailable);
173
174 private:
175     void setCurrentDocumentWidget(DocumentWidget *newDocumentWidget);
176
177     QStackedWidget *m_documentWidgetStack;
178     QHash<QPlainTextEdit*,DocumentWidget*> m_documentHash;
179     DocumentWidget *m_currentDocumentWidget;
180     QPlainTextEdit *m_currentTextEdit;
181
182     QAction *m_undoAction;
183     QAction *m_redoAction;
184     QAction *m_deleteAction;
185     QAction *m_cutAction;
186     QAction *m_copyAction;
187     QAction *m_pasteAction;
188     QAction *m_selectAllAction;
189
190     bool m_syncWithTextEdit;
191 };
192
193 } // namespace Internal
194 } // namespace Designer
195
196 #endif // DESIGNMODEWIDGET_H