forked from qt-creator/qt-creator
QmlDesigner: all views instanciated once and shared now
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <model.h>
|
||||
#include <rewriterview.h>
|
||||
#include <formeditorwidget.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/minisplitter.h>
|
||||
@@ -41,6 +42,8 @@
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/editortoolbar.h>
|
||||
#include <coreplugin/inavigationwidgetfactory.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/parameteraction.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -57,6 +60,7 @@
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QClipboard>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QProgressDialog>
|
||||
|
||||
using Core::MiniSplitter;
|
||||
using Core::IEditor;
|
||||
@@ -73,11 +77,11 @@ enum {
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
DocumentWarningWidget::DocumentWarningWidget(DocumentWidget *documentWidget, QWidget *parent) :
|
||||
DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) :
|
||||
QFrame(parent),
|
||||
m_errorMessage(new QLabel("Placeholder", this)),
|
||||
m_goToError(new QLabel(this)),
|
||||
m_documentWidget(documentWidget)
|
||||
m_designModeWidget(parent)
|
||||
{
|
||||
setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||
setLineWidth(1);
|
||||
@@ -108,264 +112,20 @@ void DocumentWarningWidget::setError(const RewriterView::Error &error)
|
||||
|
||||
void DocumentWarningWidget::goToError()
|
||||
{
|
||||
m_documentWidget->textEditor()->gotoLine(m_error.line(), m_error.column());
|
||||
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column());
|
||||
Core::EditorManager::instance()->ensureEditorManagerVisible();
|
||||
}
|
||||
|
||||
DocumentWidget::DocumentWidget(TextEditor::ITextEditor *textEditor, QPlainTextEdit *textEdit, QmlDesigner::DesignDocumentController *document, DesignModeWidget *mainWidget) :
|
||||
QWidget(),
|
||||
m_textEditor(textEditor),
|
||||
m_textBuffer(textEdit),
|
||||
m_document(document),
|
||||
m_mainWidget(mainWidget),
|
||||
m_mainSplitter(0),
|
||||
m_leftSideBar(0),
|
||||
m_rightSideBar(0),
|
||||
m_designToolBar(new QToolBar),
|
||||
m_fakeToolBar(Core::EditorManager::createToolBar(this)),
|
||||
m_isDisabled(false),
|
||||
m_warningWidget(0)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
|
||||
DocumentWidget::~DocumentWidget()
|
||||
{
|
||||
// Make sure component widgets are deleted first in SideBarItem::~SideBarItem
|
||||
// before the DesignDocumentController runs (and deletes them again).
|
||||
m_document->deleteLater();
|
||||
}
|
||||
|
||||
QmlDesigner::DesignDocumentController *DocumentWidget::document() const
|
||||
{
|
||||
return m_document;
|
||||
}
|
||||
|
||||
TextEditor::ITextEditor *DocumentWidget::textEditor() const
|
||||
{
|
||||
return m_textEditor;
|
||||
}
|
||||
|
||||
void DocumentWidget::setAutoSynchronization(bool sync)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << sync;
|
||||
|
||||
document()->blockModelSync(!sync);
|
||||
|
||||
if (sync) {
|
||||
// text editor -> visual editor
|
||||
if (!document()->model()) {
|
||||
document()->loadMaster(m_textBuffer.data());
|
||||
}
|
||||
|
||||
QList<RewriterView::Error> errors = document()->qmlErrors();
|
||||
if (errors.isEmpty()) {
|
||||
// set selection to text cursor
|
||||
RewriterView *rewriter = document()->rewriterView();
|
||||
const int cursorPos = m_textBuffer->textCursor().position();
|
||||
ModelNode node = nodeForPosition(cursorPos);
|
||||
if (node.isValid()) {
|
||||
rewriter->setSelectedModelNodes(QList<ModelNode>() << node);
|
||||
}
|
||||
enable();
|
||||
} else {
|
||||
disable(errors);
|
||||
}
|
||||
|
||||
connect(document(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
|
||||
this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
||||
|
||||
} else {
|
||||
if (document()->model() && document()->qmlErrors().isEmpty()) {
|
||||
RewriterView *rewriter = document()->rewriterView();
|
||||
// visual editor -> text editor
|
||||
ModelNode selectedNode;
|
||||
if (!rewriter->selectedModelNodes().isEmpty())
|
||||
selectedNode = rewriter->selectedModelNodes().first();
|
||||
|
||||
if (selectedNode.isValid()) {
|
||||
const int nodeOffset = rewriter->nodeOffset(selectedNode);
|
||||
if (nodeOffset > 0) {
|
||||
const ModelNode currentSelectedNode
|
||||
= nodeForPosition(m_textBuffer->textCursor().position());
|
||||
if (currentSelectedNode != selectedNode) {
|
||||
int line, column;
|
||||
textEditor()->convertPosition(nodeOffset, &line, &column);
|
||||
textEditor()->gotoLine(line, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
disconnect(document(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
|
||||
this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentWidget::enable()
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
m_warningWidget->setVisible(false);
|
||||
m_document->documentWidget()->setEnabled(true);
|
||||
m_document->statesEditorWidget()->setEnabled(true);
|
||||
m_leftSideBar->setEnabled(true);
|
||||
m_rightSideBar->setEnabled(true);
|
||||
m_isDisabled = false;
|
||||
}
|
||||
|
||||
void DocumentWidget::disable(const QList<RewriterView::Error> &errors)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT(!errors.isEmpty());
|
||||
m_warningWidget->setError(errors.first());
|
||||
m_warningWidget->setVisible(true);
|
||||
m_document->documentWidget()->setEnabled(false);
|
||||
m_document->statesEditorWidget()->setEnabled(false);
|
||||
m_leftSideBar->setEnabled(false);
|
||||
m_rightSideBar->setEnabled(false);
|
||||
m_isDisabled = true;
|
||||
}
|
||||
|
||||
void DocumentWidget::updateErrorStatus(const QList<RewriterView::Error> &errors)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << errors.count();
|
||||
|
||||
if (m_isDisabled && errors.isEmpty()) {
|
||||
enable();
|
||||
} else if (!errors.isEmpty()) {
|
||||
disable(errors);
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentWidget::readSettings()
|
||||
{
|
||||
QSettings *settings = Core::ICore::instance()->settings();
|
||||
|
||||
settings->beginGroup("Bauhaus");
|
||||
m_leftSideBar->readSettings(settings, QLatin1String("LeftSideBar"));
|
||||
m_rightSideBar->readSettings(settings, QLatin1String("RightSideBar"));
|
||||
if (settings->contains("MainSplitter")) {
|
||||
const QByteArray splitterState = settings->value("MainSplitter").toByteArray();
|
||||
m_mainSplitter->restoreState(splitterState);
|
||||
}
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void DocumentWidget::saveSettings()
|
||||
{
|
||||
QSettings *settings = Core::ICore::instance()->settings();
|
||||
|
||||
settings->beginGroup("Bauhaus");
|
||||
m_leftSideBar->saveSettings(settings, QLatin1String("LeftSideBar"));
|
||||
m_rightSideBar->saveSettings(settings, QLatin1String("RightSideBar"));
|
||||
settings->setValue("MainSplitter", m_mainSplitter->saveState());
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
|
||||
void DocumentWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
m_warningWidget->move(QPoint(event->size().width() / 2,
|
||||
event->size().height() / 2));
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
void DocumentWidget::setup()
|
||||
{
|
||||
m_mainSplitter = new MiniSplitter(this);
|
||||
m_mainSplitter->setObjectName("mainSplitter");
|
||||
|
||||
// warning frame should be not in layout, but still child of the widget
|
||||
m_warningWidget = new DocumentWarningWidget(this, this);
|
||||
m_warningWidget->setVisible(false);
|
||||
|
||||
// Left area:
|
||||
Core::SideBarItem *navigatorItem = new Core::SideBarItem(m_document->navigator());
|
||||
Core::SideBarItem *libraryItem = new Core::SideBarItem(m_document->itemLibrary());
|
||||
Core::SideBarItem *propertiesItem = new Core::SideBarItem(m_document->allPropertiesBox());
|
||||
|
||||
QList<Core::SideBarItem*> leftSideBarItems, rightSideBarItems;
|
||||
leftSideBarItems << navigatorItem << libraryItem;
|
||||
rightSideBarItems << propertiesItem;
|
||||
|
||||
m_leftSideBar = new Core::SideBar(leftSideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem);
|
||||
m_rightSideBar = new Core::SideBar(rightSideBarItems, QList<Core::SideBarItem*>() << propertiesItem);
|
||||
|
||||
m_designToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||
|
||||
m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
||||
m_fakeToolBar->addEditor(textEditor());
|
||||
m_fakeToolBar->addCenterToolBar(m_designToolBar);
|
||||
m_fakeToolBar->setNavigationVisible(false);
|
||||
|
||||
// right area:
|
||||
QWidget *centerWidget = new QWidget;
|
||||
{
|
||||
QVBoxLayout *rightLayout = new QVBoxLayout(centerWidget);
|
||||
rightLayout->setMargin(0);
|
||||
rightLayout->setSpacing(0);
|
||||
rightLayout->addWidget(m_fakeToolBar);
|
||||
rightLayout->addWidget(m_document->statesEditorWidget());
|
||||
rightLayout->addWidget(m_document->documentWidget());
|
||||
}
|
||||
|
||||
// m_mainSplitter area:
|
||||
m_mainSplitter->addWidget(m_leftSideBar);
|
||||
m_mainSplitter->addWidget(centerWidget);
|
||||
m_mainSplitter->addWidget(m_rightSideBar);
|
||||
|
||||
// Finishing touches:
|
||||
m_mainSplitter->setOpaqueResize(false);
|
||||
m_mainSplitter->setStretchFactor(1, 1);
|
||||
m_mainSplitter->setSizes(QList<int>() << 150 << 300 << 150);
|
||||
|
||||
QLayout *mainLayout = new QBoxLayout(QBoxLayout::RightToLeft, this);
|
||||
mainLayout->setMargin(0);
|
||||
mainLayout->setSpacing(0);
|
||||
mainLayout->addWidget(m_mainSplitter);
|
||||
}
|
||||
|
||||
bool DocumentWidget::isInNodeDefinition(int nodeOffset, int nodeLength, int cursorPos) const {
|
||||
return (nodeOffset <= cursorPos) && (nodeOffset + nodeLength > cursorPos);
|
||||
}
|
||||
|
||||
ModelNode DocumentWidget::nodeForPosition(int cursorPos) const
|
||||
{
|
||||
RewriterView *rewriter = m_document->rewriterView();
|
||||
QList<ModelNode> nodes = rewriter->allModelNodes();
|
||||
|
||||
ModelNode bestNode;
|
||||
int bestNodeOffset = -1;
|
||||
|
||||
foreach (const ModelNode &node, nodes) {
|
||||
const int nodeOffset = rewriter->nodeOffset(node);
|
||||
const int nodeLength = rewriter->nodeLength(node);
|
||||
if (isInNodeDefinition(nodeOffset, nodeLength, cursorPos)
|
||||
&& (nodeOffset > bestNodeOffset)) {
|
||||
bestNode = node;
|
||||
bestNodeOffset = nodeOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return bestNode;
|
||||
}
|
||||
|
||||
// ---------- DesignModeWidget
|
||||
DesignModeWidget::DesignModeWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_documentWidgetStack(new QStackedWidget),
|
||||
m_currentDocumentWidget(0),
|
||||
m_currentTextEdit(0),
|
||||
m_syncWithTextEdit(false)
|
||||
m_syncWithTextEdit(false),
|
||||
m_mainSplitter(0),
|
||||
m_leftSideBar(0),
|
||||
m_rightSideBar(0),
|
||||
m_setup(false),
|
||||
m_warningWidget(0)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
layout->addWidget(m_documentWidgetStack);
|
||||
|
||||
m_undoAction = new QAction(tr("&Undo"), this);
|
||||
connect(m_undoAction, SIGNAL(triggered()), this, SLOT(undo()));
|
||||
m_redoAction = new QAction(tr("&Redo"), this);
|
||||
@@ -380,11 +140,6 @@ DesignModeWidget::DesignModeWidget(QWidget *parent) :
|
||||
connect(m_pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
|
||||
m_selectAllAction = new Utils::ParameterAction(tr("Select &All"), tr("Select All \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
||||
connect(m_selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
|
||||
|
||||
QLabel *defaultBackground = new QLabel(tr("Loading ..."));
|
||||
defaultBackground->setAlignment(Qt::AlignCenter);
|
||||
|
||||
m_documentWidgetStack->addWidget(defaultBackground);
|
||||
}
|
||||
|
||||
DesignModeWidget::~DesignModeWidget()
|
||||
@@ -393,6 +148,9 @@ DesignModeWidget::~DesignModeWidget()
|
||||
|
||||
void DesignModeWidget::showEditor(Core::IEditor *editor)
|
||||
{
|
||||
show();
|
||||
setup();
|
||||
|
||||
QString fileName;
|
||||
QPlainTextEdit *textEdit = 0;
|
||||
TextEditor::ITextEditor *textEditor = 0;
|
||||
@@ -401,49 +159,52 @@ void DesignModeWidget::showEditor(Core::IEditor *editor)
|
||||
fileName = editor->file()->fileName();
|
||||
textEdit = qobject_cast<QPlainTextEdit*>(editor->widget());
|
||||
textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);
|
||||
m_fakeToolBar->addEditor(textEditor);
|
||||
}
|
||||
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << fileName;
|
||||
|
||||
m_currentTextEdit = textEdit;
|
||||
DocumentWidget *documentWidget = 0;
|
||||
if (textEdit)
|
||||
m_currentTextEdit = textEdit;
|
||||
|
||||
if (textEditor)
|
||||
m_textEditor = textEditor;
|
||||
DesignDocumentController *document = 0;
|
||||
|
||||
if (textEdit && textEditor && fileName.endsWith(QLatin1String(".qml"))) {
|
||||
if (m_documentHash.contains(textEdit)) {
|
||||
documentWidget = m_documentHash.value(textEdit);
|
||||
document = m_documentHash.value(textEdit).data();
|
||||
} else {
|
||||
DesignDocumentController *newDocument = new DesignDocumentController(0);
|
||||
DesignDocumentController *newDocument = new DesignDocumentController(this);
|
||||
|
||||
newDocument->setAllPropertiesBox(m_allPropertiesBox.data());
|
||||
newDocument->setNavigator(m_navigator.data());
|
||||
newDocument->setStatesEditorWidget(m_statesEditorWidget.data());
|
||||
newDocument->setItemLibrary(m_itemLibrary.data());
|
||||
newDocument->setFormEditorView(m_formEditorView.data());
|
||||
|
||||
newDocument->setFileName(fileName);
|
||||
|
||||
documentWidget = new DocumentWidget(textEditor, textEdit, newDocument, this);
|
||||
connect(documentWidget->document(), SIGNAL(undoAvailable(bool)),
|
||||
this, SLOT(undoAvailable(bool)));
|
||||
connect(documentWidget->document(), SIGNAL(redoAvailable(bool)),
|
||||
this, SLOT(redoAvailable(bool)));
|
||||
// connect(documentWidget->document(), SIGNAL(deleteAvailable(bool)),
|
||||
// this, SLOT(deleteAvailable(bool)));
|
||||
document = newDocument;
|
||||
|
||||
m_documentHash.insert(textEdit, documentWidget);
|
||||
m_documentWidgetStack->addWidget(documentWidget);
|
||||
m_documentHash.insert(textEdit, document);
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentDocumentWidget(documentWidget);
|
||||
setCurrentDocument(document);
|
||||
}
|
||||
|
||||
void DesignModeWidget::closeEditors(QList<Core::IEditor*> editors)
|
||||
{
|
||||
foreach (Core::IEditor* editor, editors) {
|
||||
if (QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit*>(editor->widget())) {
|
||||
if (m_currentTextEdit == textEdit) {
|
||||
setCurrentDocumentWidget(0);
|
||||
if (m_currentTextEdit.data() == textEdit) {
|
||||
setCurrentDocument(0);
|
||||
}
|
||||
if (m_documentHash.contains(textEdit)) {
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << editor->file()->fileName();
|
||||
DocumentWidget *document = m_documentHash.take(textEdit);
|
||||
m_documentWidgetStack->removeWidget(document);
|
||||
DesignDocumentController *document = m_documentHash.take(textEdit).data();
|
||||
delete document;
|
||||
}
|
||||
}
|
||||
@@ -485,53 +246,82 @@ QAction *DesignModeWidget::selectAllAction() const
|
||||
return m_selectAllAction;
|
||||
}
|
||||
|
||||
void DesignModeWidget::readSettings()
|
||||
{
|
||||
QSettings *settings = Core::ICore::instance()->settings();
|
||||
|
||||
settings->beginGroup("Bauhaus");
|
||||
m_leftSideBar->readSettings(settings, QLatin1String("LeftSideBar"));
|
||||
m_rightSideBar->readSettings(settings, QLatin1String("RightSideBar"));
|
||||
if (settings->contains("MainSplitter")) {
|
||||
const QByteArray splitterState = settings->value("MainSplitter").toByteArray();
|
||||
m_mainSplitter->restoreState(splitterState);
|
||||
}
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void DesignModeWidget::saveSettings()
|
||||
{
|
||||
QSettings *settings = Core::ICore::instance()->settings();
|
||||
|
||||
settings->beginGroup("Bauhaus");
|
||||
m_leftSideBar->saveSettings(settings, QLatin1String("LeftSideBar"));
|
||||
m_rightSideBar->saveSettings(settings, QLatin1String("RightSideBar"));
|
||||
settings->setValue("MainSplitter", m_mainSplitter->saveState());
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void DesignModeWidget::undo()
|
||||
{
|
||||
if (m_currentDocumentWidget)
|
||||
m_currentDocumentWidget->document()->undo();
|
||||
if (m_currentDesignDocumentController)
|
||||
m_currentDesignDocumentController->undo();
|
||||
}
|
||||
|
||||
void DesignModeWidget::redo()
|
||||
{
|
||||
if (m_currentDocumentWidget)
|
||||
m_currentDocumentWidget->document()->redo();
|
||||
if (m_currentDesignDocumentController)
|
||||
m_currentDesignDocumentController->redo();
|
||||
}
|
||||
|
||||
void DesignModeWidget::deleteSelected()
|
||||
{
|
||||
if (m_currentDocumentWidget)
|
||||
m_currentDocumentWidget->document()->deleteSelected();
|
||||
if (m_currentDesignDocumentController)
|
||||
m_currentDesignDocumentController->deleteSelected();
|
||||
}
|
||||
|
||||
void DesignModeWidget::cutSelected()
|
||||
{
|
||||
if (m_currentDocumentWidget)
|
||||
m_currentDocumentWidget->document()->cutSelected();
|
||||
if (m_currentDesignDocumentController)
|
||||
m_currentDesignDocumentController->cutSelected();
|
||||
}
|
||||
|
||||
void DesignModeWidget::copySelected()
|
||||
{
|
||||
if (m_currentDocumentWidget)
|
||||
m_currentDocumentWidget->document()->copySelected();
|
||||
if (m_currentDesignDocumentController)
|
||||
m_currentDesignDocumentController->copySelected();
|
||||
}
|
||||
|
||||
void DesignModeWidget::paste()
|
||||
{
|
||||
if (m_currentDocumentWidget)
|
||||
m_currentDocumentWidget->document()->paste();
|
||||
if (m_currentDesignDocumentController)
|
||||
m_currentDesignDocumentController->paste();
|
||||
}
|
||||
|
||||
void DesignModeWidget::selectAll()
|
||||
{
|
||||
if (m_currentDocumentWidget)
|
||||
m_currentDocumentWidget->document()->selectAll();
|
||||
if (m_currentDesignDocumentController)
|
||||
m_currentDesignDocumentController->selectAll();
|
||||
}
|
||||
|
||||
void DesignModeWidget::closeCurrentEditor()
|
||||
{
|
||||
}
|
||||
|
||||
void DesignModeWidget::undoAvailable(bool isAvailable)
|
||||
{
|
||||
DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
|
||||
if (m_currentDocumentWidget &&
|
||||
m_currentDocumentWidget->document() == documentController) {
|
||||
if (m_currentDesignDocumentController &&
|
||||
m_currentDesignDocumentController.data() == documentController) {
|
||||
m_undoAction->setEnabled(isAvailable);
|
||||
}
|
||||
}
|
||||
@@ -539,44 +329,333 @@ void DesignModeWidget::undoAvailable(bool isAvailable)
|
||||
void DesignModeWidget::redoAvailable(bool isAvailable)
|
||||
{
|
||||
DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
|
||||
if (m_currentDocumentWidget &&
|
||||
m_currentDocumentWidget->document() == documentController) {
|
||||
if (m_currentDesignDocumentController &&
|
||||
m_currentDesignDocumentController.data() == documentController) {
|
||||
m_redoAction->setEnabled(isAvailable);
|
||||
}
|
||||
}
|
||||
|
||||
void DesignModeWidget::setCurrentDocumentWidget(DocumentWidget *newDocumentWidget)
|
||||
|
||||
void DesignModeWidget::enable()
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << newDocumentWidget;
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
m_warningWidget->setVisible(false);
|
||||
m_formEditorView->widget()->setEnabled(true);
|
||||
m_statesEditorWidget->setEnabled(true);
|
||||
m_leftSideBar->setEnabled(true);
|
||||
m_rightSideBar->setEnabled(true);
|
||||
m_isDisabled = false;
|
||||
}
|
||||
|
||||
if (m_currentDocumentWidget == newDocumentWidget)
|
||||
void DesignModeWidget::disable(const QList<RewriterView::Error> &errors)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT(!errors.isEmpty());
|
||||
m_warningWidget->setError(errors.first());
|
||||
m_warningWidget->setVisible(true);
|
||||
m_warningWidget->move(width() / 2, height() / 2);
|
||||
m_formEditorView->widget()->setEnabled(false);
|
||||
m_statesEditorWidget->setEnabled(false);
|
||||
m_leftSideBar->setEnabled(false);
|
||||
m_rightSideBar->setEnabled(false);
|
||||
m_isDisabled = true;
|
||||
}
|
||||
|
||||
void DesignModeWidget::updateErrorStatus(const QList<RewriterView::Error> &errors)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << errors.count();
|
||||
|
||||
if (m_isDisabled && errors.isEmpty()) {
|
||||
enable();
|
||||
} else if (!errors.isEmpty()) {
|
||||
disable(errors);
|
||||
}
|
||||
}
|
||||
|
||||
void DesignModeWidget::setAutoSynchronization(bool sync)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << sync;
|
||||
|
||||
m_currentDesignDocumentController->blockModelSync(!sync);
|
||||
|
||||
if (sync) {
|
||||
// text editor -> visual editor
|
||||
if (!m_currentDesignDocumentController->model()) {
|
||||
m_currentDesignDocumentController->loadMaster(m_currentTextEdit.data());
|
||||
} else {
|
||||
m_currentDesignDocumentController->loadCurrentModel();
|
||||
}
|
||||
|
||||
QList<RewriterView::Error> errors = m_currentDesignDocumentController->qmlErrors();
|
||||
if (errors.isEmpty()) {
|
||||
// set selection to text cursor
|
||||
RewriterView *rewriter = m_currentDesignDocumentController->rewriterView();
|
||||
const int cursorPos = m_currentTextEdit->textCursor().position();
|
||||
ModelNode node = nodeForPosition(cursorPos);
|
||||
if (node.isValid()) {
|
||||
rewriter->setSelectedModelNodes(QList<ModelNode>() << node);
|
||||
}
|
||||
enable();
|
||||
} else {
|
||||
disable(errors);
|
||||
}
|
||||
|
||||
connect(m_currentDesignDocumentController.data(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
|
||||
this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
||||
|
||||
} else {
|
||||
if (m_currentDesignDocumentController->model() && m_currentDesignDocumentController->qmlErrors().isEmpty()) {
|
||||
RewriterView *rewriter = m_currentDesignDocumentController->rewriterView();
|
||||
// visual editor -> text editor
|
||||
ModelNode selectedNode;
|
||||
if (!rewriter->selectedModelNodes().isEmpty())
|
||||
selectedNode = rewriter->selectedModelNodes().first();
|
||||
|
||||
if (selectedNode.isValid()) {
|
||||
const int nodeOffset = rewriter->nodeOffset(selectedNode);
|
||||
if (nodeOffset > 0) {
|
||||
const ModelNode currentSelectedNode
|
||||
= nodeForPosition(m_currentTextEdit->textCursor().position());
|
||||
if (currentSelectedNode != selectedNode) {
|
||||
int line, column;
|
||||
m_textEditor->convertPosition(nodeOffset, &line, &column);
|
||||
m_textEditor->gotoLine(line, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
disconnect(m_currentDesignDocumentController.data(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
|
||||
this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
||||
}
|
||||
}
|
||||
|
||||
void DesignModeWidget::setCurrentDocument(DesignDocumentController *newDesignDocumentController)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << newDesignDocumentController;
|
||||
|
||||
if (m_currentDesignDocumentController.data() == newDesignDocumentController)
|
||||
return;
|
||||
|
||||
if (m_currentDocumentWidget) {
|
||||
m_currentDocumentWidget->setAutoSynchronization(false);
|
||||
m_currentDocumentWidget->saveSettings();
|
||||
if (m_currentDesignDocumentController) {
|
||||
setAutoSynchronization(false);
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
m_currentDocumentWidget = newDocumentWidget;
|
||||
disconnect(currentDesignDocumentController(), SIGNAL(undoAvailable(bool)),
|
||||
this, SLOT(undoAvailable(bool)));
|
||||
disconnect(currentDesignDocumentController(), SIGNAL(redoAvailable(bool)),
|
||||
this, SLOT(redoAvailable(bool)));
|
||||
disconnect(currentDesignDocumentController(), SIGNAL(deleteAvailable(bool)),
|
||||
this, SLOT(deleteAvailable(bool)));
|
||||
|
||||
if (m_currentDocumentWidget) {
|
||||
m_currentDocumentWidget->setAutoSynchronization(true);
|
||||
m_documentWidgetStack->setCurrentWidget(m_currentDocumentWidget);
|
||||
m_currentDocumentWidget->readSettings();
|
||||
m_undoAction->setEnabled(m_currentDocumentWidget->document()->isUndoAvailable());
|
||||
m_redoAction->setEnabled(m_currentDocumentWidget->document()->isRedoAvailable());
|
||||
m_currentDesignDocumentController = newDesignDocumentController;
|
||||
|
||||
connect(currentDesignDocumentController(), SIGNAL(undoAvailable(bool)),
|
||||
this, SLOT(undoAvailable(bool)));
|
||||
connect(currentDesignDocumentController(), SIGNAL(redoAvailable(bool)),
|
||||
this, SLOT(redoAvailable(bool)));
|
||||
connect(currentDesignDocumentController(), SIGNAL(deleteAvailable(bool)),
|
||||
this, SLOT(deleteAvailable(bool)));
|
||||
|
||||
if (m_currentDesignDocumentController) {
|
||||
|
||||
setAutoSynchronization(true);
|
||||
m_undoAction->setEnabled(m_currentDesignDocumentController->isUndoAvailable());
|
||||
m_redoAction->setEnabled(m_currentDesignDocumentController->isRedoAvailable());
|
||||
} else {
|
||||
m_documentWidgetStack->setCurrentIndex(0);
|
||||
//detach all views
|
||||
m_undoAction->setEnabled(false);
|
||||
m_redoAction->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void DesignModeWidget::setup()
|
||||
{
|
||||
if (m_setup)
|
||||
return;
|
||||
m_setup = true;
|
||||
|
||||
QList<Core::INavigationWidgetFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<Core::INavigationWidgetFactory>();
|
||||
|
||||
QWidget *openDocumentsWidget = 0;
|
||||
QWidget *projectsExplorer = 0;
|
||||
QWidget *fileSystemExplorer = 0;
|
||||
|
||||
|
||||
foreach(Core::INavigationWidgetFactory *factory, factories)
|
||||
{
|
||||
Core::NavigationView navigationView;
|
||||
navigationView.widget = 0;
|
||||
if (factory->displayName() == QLatin1String("Projects")) {
|
||||
navigationView = factory->createWidget();
|
||||
projectsExplorer = navigationView.widget;
|
||||
projectsExplorer->setWindowTitle(tr("Projects"));
|
||||
}
|
||||
if (factory->displayName() == QLatin1String("File System")) {
|
||||
navigationView = factory->createWidget();
|
||||
fileSystemExplorer = navigationView.widget;
|
||||
fileSystemExplorer->setWindowTitle(tr("File System"));
|
||||
}
|
||||
if (factory->displayName() == QLatin1String("Open Documents")) {
|
||||
navigationView = factory->createWidget();
|
||||
openDocumentsWidget = navigationView.widget;
|
||||
openDocumentsWidget->setWindowTitle(tr("Open Documents"));
|
||||
}
|
||||
|
||||
if (navigationView.widget)
|
||||
{
|
||||
QFile file(":/qmldesigner/stylesheet.css");
|
||||
file.open(QFile::ReadOnly);
|
||||
QFile file2(":/qmldesigner/scrollbar.css");
|
||||
file2.open(QFile::ReadOnly);
|
||||
|
||||
QString labelStyle = QLatin1String("QLabel { background-color: #707070; }");
|
||||
|
||||
QString styleSheet = file.readAll() + file2.readAll() + labelStyle;
|
||||
navigationView.widget->setStyleSheet(styleSheet);
|
||||
}
|
||||
}
|
||||
|
||||
m_navigator = new NavigatorView(this);
|
||||
|
||||
m_allPropertiesBox = new AllPropertiesBox(this);
|
||||
m_statesEditorWidget = new StatesEditorWidget(this);
|
||||
|
||||
m_formEditorView = new FormEditorView(this);
|
||||
|
||||
m_itemLibrary = new ItemLibrary(this);
|
||||
|
||||
m_designToolBar = new QToolBar;
|
||||
m_fakeToolBar = Core::EditorManager::createToolBar(this);
|
||||
|
||||
|
||||
m_mainSplitter = new MiniSplitter(this);
|
||||
m_mainSplitter->setObjectName("mainSplitter");
|
||||
|
||||
// warning frame should be not in layout, but still child of the widget
|
||||
m_warningWidget = new DocumentWarningWidget(this);
|
||||
m_warningWidget->setVisible(false);
|
||||
|
||||
// Left area:
|
||||
|
||||
Core::SideBarItem *navigatorItem = new Core::SideBarItem(m_navigator->widget());
|
||||
Core::SideBarItem *libraryItem = new Core::SideBarItem(m_itemLibrary.data());
|
||||
Core::SideBarItem *propertiesItem = new Core::SideBarItem(m_allPropertiesBox.data());
|
||||
|
||||
|
||||
QList<Core::SideBarItem*> leftSideBarItems, rightSideBarItems;
|
||||
leftSideBarItems << navigatorItem << libraryItem;
|
||||
rightSideBarItems << propertiesItem;
|
||||
|
||||
if (projectsExplorer) {
|
||||
Core::SideBarItem *projectExplorerItem = new Core::SideBarItem(projectsExplorer);
|
||||
rightSideBarItems << projectExplorerItem;
|
||||
}
|
||||
|
||||
if (fileSystemExplorer) {
|
||||
Core::SideBarItem *fileSystemExplorerItem = new Core::SideBarItem(fileSystemExplorer);
|
||||
rightSideBarItems << fileSystemExplorerItem;
|
||||
}
|
||||
|
||||
if (openDocumentsWidget) {
|
||||
Core::SideBarItem *openDocumentsItem = new Core::SideBarItem(openDocumentsWidget);
|
||||
rightSideBarItems << openDocumentsItem;
|
||||
}
|
||||
|
||||
m_leftSideBar = new Core::SideBar(leftSideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem);
|
||||
m_rightSideBar = new Core::SideBar(rightSideBarItems, QList<Core::SideBarItem*>() << propertiesItem);
|
||||
|
||||
m_designToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||
|
||||
m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
||||
//m_fakeToolBar->addEditor(textEditor()); ### what does this mean?
|
||||
m_fakeToolBar->addCenterToolBar(m_designToolBar);
|
||||
m_fakeToolBar->setNavigationVisible(false);
|
||||
|
||||
connect(m_fakeToolBar, SIGNAL(closeClicked()), this, SLOT(closeCurrentEditor()));
|
||||
|
||||
// right area:
|
||||
QWidget *centerWidget = new QWidget;
|
||||
{
|
||||
QVBoxLayout *rightLayout = new QVBoxLayout(centerWidget);
|
||||
rightLayout->setMargin(0);
|
||||
rightLayout->setSpacing(0);
|
||||
rightLayout->addWidget(m_fakeToolBar);
|
||||
//### we now own these here
|
||||
rightLayout->addWidget(m_statesEditorWidget.data());
|
||||
rightLayout->addWidget(m_formEditorView->widget());
|
||||
}
|
||||
|
||||
// m_mainSplitter area:
|
||||
m_mainSplitter->addWidget(m_leftSideBar);
|
||||
m_mainSplitter->addWidget(centerWidget);
|
||||
m_mainSplitter->addWidget(m_rightSideBar);
|
||||
|
||||
// Finishing touches:
|
||||
m_mainSplitter->setOpaqueResize(false);
|
||||
m_mainSplitter->setStretchFactor(1, 1);
|
||||
m_mainSplitter->setSizes(QList<int>() << 150 << 300 << 150);
|
||||
|
||||
QLayout *mainLayout = new QBoxLayout(QBoxLayout::RightToLeft, this);
|
||||
mainLayout->setMargin(0);
|
||||
mainLayout->setSpacing(0);
|
||||
mainLayout->addWidget(m_mainSplitter);
|
||||
|
||||
m_warningWidget->setVisible(false);
|
||||
m_statesEditorWidget->setEnabled(true);
|
||||
m_leftSideBar->setEnabled(true);
|
||||
m_rightSideBar->setEnabled(true);
|
||||
|
||||
readSettings();
|
||||
|
||||
show();
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void DesignModeWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (m_warningWidget)
|
||||
m_warningWidget->move(QPoint(event->size().width() / 2, event->size().height() / 2));
|
||||
QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
bool DesignModeWidget::isInNodeDefinition(int nodeOffset, int nodeLength, int cursorPos) const {
|
||||
return (nodeOffset <= cursorPos) && (nodeOffset + nodeLength > cursorPos);
|
||||
}
|
||||
|
||||
|
||||
ModelNode DesignModeWidget::nodeForPosition(int cursorPos) const
|
||||
{
|
||||
RewriterView *rewriter = m_currentDesignDocumentController->rewriterView();
|
||||
QList<ModelNode> nodes = rewriter->allModelNodes();
|
||||
|
||||
ModelNode bestNode;
|
||||
int bestNodeOffset = -1;
|
||||
|
||||
foreach (const ModelNode &node, nodes) {
|
||||
const int nodeOffset = rewriter->nodeOffset(node);
|
||||
const int nodeLength = rewriter->nodeLength(node);
|
||||
if (isInNodeDefinition(nodeOffset, nodeLength, cursorPos)
|
||||
&& (nodeOffset > bestNodeOffset)) {
|
||||
bestNode = node;
|
||||
bestNodeOffset = nodeOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return bestNode;
|
||||
}
|
||||
|
||||
|
||||
QString DesignModeWidget::contextHelpId() const
|
||||
{
|
||||
if (m_currentDocumentWidget)
|
||||
return m_currentDocumentWidget->document()->contextHelpId();
|
||||
if (m_currentDesignDocumentController)
|
||||
return m_currentDesignDocumentController->contextHelpId();
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user