2010-01-07 12:14:35 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "designmodewidget.h"
|
|
|
|
|
#include "qmldesignerconstants.h"
|
2010-04-23 09:32:45 +02:00
|
|
|
#include "styledoutputpaneplaceholder.h"
|
2010-11-17 12:59:08 +01:00
|
|
|
#include "designmodecontext.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include <model.h>
|
|
|
|
|
#include <rewriterview.h>
|
2010-03-23 14:01:25 +01:00
|
|
|
#include <formeditorwidget.h>
|
2010-12-08 16:46:25 +01:00
|
|
|
#include <stateseditorwidget.h>
|
2010-12-10 17:57:42 +01:00
|
|
|
#include <itemlibrarywidget.h>
|
2011-05-24 18:47:33 +02:00
|
|
|
#include <componentaction.h>
|
|
|
|
|
#include <toolbox.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-04-23 09:32:45 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
#include <coreplugin/outputpane.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/minisplitter.h>
|
|
|
|
|
#include <coreplugin/sidebar.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/openeditorsmodel.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2010-03-10 12:48:17 +01:00
|
|
|
#include <coreplugin/editortoolbar.h>
|
2010-03-23 14:01:25 +01:00
|
|
|
#include <coreplugin/inavigationwidgetfactory.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include <utils/parameteraction.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
#include <QtCore/QEvent>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
|
#include <QtGui/QPlainTextEdit>
|
|
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
#include <QtGui/QScrollArea>
|
|
|
|
|
#include <QtGui/QTabWidget>
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
#include <QtGui/QLabel>
|
2010-03-23 14:01:25 +01:00
|
|
|
#include <QtGui/QProgressDialog>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
using Core::MiniSplitter;
|
|
|
|
|
using Core::IEditor;
|
|
|
|
|
using Core::EditorManager;
|
|
|
|
|
|
|
|
|
|
using namespace QmlDesigner;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
debug = false
|
|
|
|
|
};
|
|
|
|
|
|
2010-04-29 11:59:42 +02:00
|
|
|
const char * const SB_NAVIGATOR = "Navigator";
|
|
|
|
|
const char * const SB_LIBRARY = "Library";
|
|
|
|
|
const char * const SB_PROPERTIES = "Properties";
|
|
|
|
|
const char * const SB_PROJECTS = "Projects";
|
|
|
|
|
const char * const SB_FILESYSTEM = "FileSystem";
|
|
|
|
|
const char * const SB_OPENDOCUMENTS = "OpenDocuments";
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
DocumentWarningWidget::DocumentWarningWidget(DesignModeWidget *parent) :
|
2010-12-16 12:59:05 +01:00
|
|
|
Utils::FakeToolTip(parent),
|
2010-01-07 12:14:35 +01:00
|
|
|
m_errorMessage(new QLabel("Placeholder", this)),
|
|
|
|
|
m_goToError(new QLabel(this)),
|
2010-03-23 14:01:25 +01:00
|
|
|
m_designModeWidget(parent)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-12-16 12:59:05 +01:00
|
|
|
setWindowFlags(Qt::Widget); //We only want the visual style from a ToolTip
|
2010-01-07 12:14:35 +01:00
|
|
|
setForegroundRole(QPalette::ToolTipText);
|
|
|
|
|
setBackgroundRole(QPalette::ToolTipBase);
|
|
|
|
|
setAutoFillBackground(true);
|
|
|
|
|
|
|
|
|
|
m_errorMessage->setForegroundRole(QPalette::ToolTipText);
|
|
|
|
|
m_goToError->setText(tr("<a href=\"goToError\">Go to error</a>"));
|
|
|
|
|
m_goToError->setForegroundRole(QPalette::Link);
|
|
|
|
|
connect(m_goToError, SIGNAL(linkActivated(QString)), this, SLOT(goToError()));
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
|
layout->setMargin(20);
|
|
|
|
|
layout->setSpacing(5);
|
|
|
|
|
layout->addWidget(m_errorMessage);
|
|
|
|
|
layout->addWidget(m_goToError, 1, Qt::AlignRight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocumentWarningWidget::setError(const RewriterView::Error &error)
|
|
|
|
|
{
|
|
|
|
|
m_error = error;
|
2010-04-12 11:37:03 +02:00
|
|
|
QString str;
|
|
|
|
|
if (error.type() == RewriterView::Error::ParseError) {
|
|
|
|
|
str = tr("%3 (%1:%2)").arg(QString::number(error.line()), QString::number(error.column()), error.description());
|
2010-04-12 12:29:13 +02:00
|
|
|
m_goToError->show();
|
2010-04-12 11:37:03 +02:00
|
|
|
} else if (error.type() == RewriterView::Error::InternalError) {
|
2010-04-12 12:29:13 +02:00
|
|
|
str = tr("Internal error (%1)").arg(error.description());
|
|
|
|
|
m_goToError->hide();
|
2010-04-12 11:37:03 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
m_errorMessage->setText(str);
|
|
|
|
|
resize(layout()->totalSizeHint());
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:52:29 +01:00
|
|
|
class ItemLibrarySideBarItem : public Core::SideBarItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit ItemLibrarySideBarItem(ItemLibraryWidget *widget, const QString &id);
|
|
|
|
|
virtual ~ItemLibrarySideBarItem();
|
|
|
|
|
|
|
|
|
|
virtual QList<QToolButton *> createToolBarWidgets();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ItemLibrarySideBarItem::ItemLibrarySideBarItem(ItemLibraryWidget *widget, const QString &id) : Core::SideBarItem(widget, id) {}
|
|
|
|
|
|
|
|
|
|
ItemLibrarySideBarItem::~ItemLibrarySideBarItem()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QToolButton *> ItemLibrarySideBarItem::createToolBarWidgets()
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<ItemLibraryWidget*>(widget())->createToolBarWidgets();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-28 17:12:45 +02:00
|
|
|
class NavigatorSideBarItem : public Core::SideBarItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit NavigatorSideBarItem(NavigatorWidget *widget, const QString &id);
|
|
|
|
|
virtual ~NavigatorSideBarItem();
|
|
|
|
|
|
|
|
|
|
virtual QList<QToolButton *> createToolBarWidgets();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NavigatorSideBarItem::NavigatorSideBarItem(NavigatorWidget *widget, const QString &id) : Core::SideBarItem(widget, id) {}
|
|
|
|
|
|
|
|
|
|
NavigatorSideBarItem::~NavigatorSideBarItem()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QToolButton *> NavigatorSideBarItem::createToolBarWidgets()
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<NavigatorWidget*>(widget())->createToolBarWidgets();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void DocumentWarningWidget::goToError()
|
|
|
|
|
{
|
2011-04-06 12:35:56 +02:00
|
|
|
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column() - 1);
|
2010-09-03 11:57:46 +02:00
|
|
|
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- DesignModeWidget
|
2010-02-26 11:08:17 +01:00
|
|
|
DesignModeWidget::DesignModeWidget(QWidget *parent) :
|
2010-01-07 12:14:35 +01:00
|
|
|
QWidget(parent),
|
2010-03-23 14:01:25 +01:00
|
|
|
m_syncWithTextEdit(false),
|
2011-06-20 16:33:10 +02:00
|
|
|
m_textEditor(0),
|
2010-03-23 14:01:25 +01:00
|
|
|
m_mainSplitter(0),
|
|
|
|
|
m_leftSideBar(0),
|
|
|
|
|
m_rightSideBar(0),
|
2010-04-23 15:40:34 +02:00
|
|
|
m_isDisabled(false),
|
|
|
|
|
m_showSidebars(true),
|
2010-04-06 10:49:16 +02:00
|
|
|
m_initStatus(NotInitialized),
|
2011-06-20 16:33:10 +02:00
|
|
|
m_warningWidget(0),
|
|
|
|
|
m_navigatorHistoryCounter(-1),
|
|
|
|
|
m_keepNavigatorHistory(false)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
m_undoAction = new QAction(tr("&Undo"), this);
|
|
|
|
|
connect(m_undoAction, SIGNAL(triggered()), this, SLOT(undo()));
|
|
|
|
|
m_redoAction = new QAction(tr("&Redo"), this);
|
|
|
|
|
connect(m_redoAction, SIGNAL(triggered()), this, SLOT(redo()));
|
|
|
|
|
m_deleteAction = new Utils::ParameterAction(tr("Delete"), tr("Delete \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
|
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
|
|
|
|
|
m_cutAction = new Utils::ParameterAction(tr("Cu&t"), tr("Cut \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
|
connect(m_cutAction, SIGNAL(triggered()), this, SLOT(cutSelected()));
|
|
|
|
|
m_copyAction = new Utils::ParameterAction(tr("&Copy"), tr("Copy \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
|
connect(m_copyAction, SIGNAL(triggered()), this, SLOT(copySelected()));
|
|
|
|
|
m_pasteAction = new Utils::ParameterAction(tr("&Paste"), tr("Paste \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
|
connect(m_pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
|
2010-01-25 15:22:08 +01:00
|
|
|
m_selectAllAction = new Utils::ParameterAction(tr("Select &All"), tr("Select All \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
|
|
|
|
|
connect(m_selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
|
2010-04-23 15:40:34 +02:00
|
|
|
m_hideSidebarsAction = new QAction(tr("Toggle Full Screen"), this);
|
|
|
|
|
connect(m_hideSidebarsAction, SIGNAL(triggered()), this, SLOT(toggleSidebars()));
|
2010-04-26 11:30:14 +02:00
|
|
|
m_restoreDefaultViewAction = new QAction(tr("&Restore Default View"), this);
|
|
|
|
|
connect(m_restoreDefaultViewAction, SIGNAL(triggered()), SLOT(restoreDefaultView()));
|
2010-04-26 13:53:26 +02:00
|
|
|
m_toggleLeftSidebarAction = new QAction(tr("Toggle &Left Sidebar"), this);
|
|
|
|
|
connect(m_toggleLeftSidebarAction, SIGNAL(triggered()), SLOT(toggleLeftSidebar()));
|
|
|
|
|
m_toggleRightSidebarAction = new QAction(tr("Toggle &Right Sidebar"), this);
|
|
|
|
|
connect(m_toggleRightSidebarAction, SIGNAL(triggered()), SLOT(toggleRightSidebar()));
|
2010-04-23 09:32:45 +02:00
|
|
|
|
|
|
|
|
Core::ModeManager *modeManager = Core::ModeManager::instance();
|
|
|
|
|
Core::IMode *designmode = modeManager->mode(Core::Constants::MODE_DESIGN);
|
|
|
|
|
m_outputPlaceholderSplitter = new Core::MiniSplitter;
|
|
|
|
|
m_outputPanePlaceholder = new StyledOutputpanePlaceHolder(designmode, m_outputPlaceholderSplitter);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DesignModeWidget::~DesignModeWidget()
|
|
|
|
|
{
|
2010-04-23 15:40:34 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-26 11:30:14 +02:00
|
|
|
void DesignModeWidget::restoreDefaultView()
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
m_leftSideBar->closeAllWidgets();
|
|
|
|
|
m_rightSideBar->closeAllWidgets();
|
|
|
|
|
m_leftSideBar->readSettings(settings, "none.LeftSideBar");
|
|
|
|
|
m_rightSideBar->readSettings(settings, "none.RightSideBar");
|
|
|
|
|
m_leftSideBar->show();
|
|
|
|
|
m_rightSideBar->show();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-26 13:53:26 +02:00
|
|
|
void DesignModeWidget::toggleLeftSidebar()
|
|
|
|
|
{
|
|
|
|
|
if (m_leftSideBar)
|
|
|
|
|
m_leftSideBar->setVisible(!m_leftSideBar->isVisible());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::toggleRightSidebar()
|
|
|
|
|
{
|
|
|
|
|
if (m_rightSideBar)
|
|
|
|
|
m_rightSideBar->setVisible(!m_rightSideBar->isVisible());
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 15:40:34 +02:00
|
|
|
void DesignModeWidget::toggleSidebars()
|
|
|
|
|
{
|
|
|
|
|
if (m_initStatus == Initializing)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_showSidebars = !m_showSidebars;
|
|
|
|
|
|
|
|
|
|
if (m_leftSideBar)
|
|
|
|
|
m_leftSideBar->setVisible(m_showSidebars);
|
|
|
|
|
if (m_rightSideBar)
|
|
|
|
|
m_rightSideBar->setVisible(m_showSidebars);
|
2010-12-08 16:46:25 +01:00
|
|
|
if (!m_statesEditorView.isNull())
|
|
|
|
|
m_statesEditorView->widget()->setVisible(m_showSidebars);
|
2010-04-23 15:40:34 +02:00
|
|
|
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
void DesignModeWidget::showEditor(Core::IEditor *editor)
|
|
|
|
|
{
|
2011-06-20 16:33:10 +02:00
|
|
|
if (m_textEditor && editor)
|
|
|
|
|
if (m_textEditor->file()->fileName() == editor->file()->fileName())
|
|
|
|
|
return;
|
2010-04-06 10:49:16 +02:00
|
|
|
//
|
|
|
|
|
// Prevent recursive calls to function by explicitly managing initialization status
|
|
|
|
|
// (QApplication::processEvents is called explicitly at a number of places)
|
|
|
|
|
//
|
|
|
|
|
if (m_initStatus == Initializing)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_initStatus == NotInitialized) {
|
|
|
|
|
m_initStatus = Initializing;
|
|
|
|
|
setup();
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
QString fileName;
|
|
|
|
|
QPlainTextEdit *textEdit = 0;
|
|
|
|
|
TextEditor::ITextEditor *textEditor = 0;
|
|
|
|
|
|
|
|
|
|
if (editor) {
|
|
|
|
|
fileName = editor->file()->fileName();
|
|
|
|
|
textEdit = qobject_cast<QPlainTextEdit*>(editor->widget());
|
|
|
|
|
textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);
|
2010-03-26 12:39:26 +01:00
|
|
|
if (textEditor)
|
|
|
|
|
m_fakeToolBar->addEditor(textEditor);
|
2011-06-20 16:33:10 +02:00
|
|
|
if (!m_keepNavigatorHistory)
|
|
|
|
|
addNavigatorHistoryEntry(fileName);
|
|
|
|
|
setupNavigatorHistory();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << fileName;
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
if (textEdit)
|
|
|
|
|
m_currentTextEdit = textEdit;
|
|
|
|
|
|
|
|
|
|
if (textEditor)
|
|
|
|
|
m_textEditor = textEditor;
|
|
|
|
|
DesignDocumentController *document = 0;
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-09 10:44:38 +01:00
|
|
|
if (textEdit && textEditor && fileName.endsWith(QLatin1String(".qml"))) {
|
2010-01-07 12:14:35 +01:00
|
|
|
if (m_documentHash.contains(textEdit)) {
|
2010-03-23 14:01:25 +01:00
|
|
|
document = m_documentHash.value(textEdit).data();
|
2010-01-07 12:14:35 +01:00
|
|
|
} else {
|
2010-03-23 14:01:25 +01:00
|
|
|
DesignDocumentController *newDocument = new DesignDocumentController(this);
|
|
|
|
|
|
2010-09-23 15:26:58 +02:00
|
|
|
newDocument->setNodeInstanceView(m_nodeInstanceView.data());
|
2011-05-20 14:32:43 +02:00
|
|
|
newDocument->setPropertyEditorView(m_propertyEditorView.data());
|
2011-04-28 17:15:27 +02:00
|
|
|
newDocument->setNavigator(m_navigatorView.data());
|
2010-12-08 16:46:25 +01:00
|
|
|
newDocument->setStatesEditorView(m_statesEditorView.data());
|
2010-12-10 17:57:42 +01:00
|
|
|
newDocument->setItemLibraryView(m_itemLibraryView.data());
|
2010-03-23 14:01:25 +01:00
|
|
|
newDocument->setFormEditorView(m_formEditorView.data());
|
2011-05-24 18:47:33 +02:00
|
|
|
newDocument->setComponentView(m_componentView.data());
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2010-09-23 15:26:58 +02:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
newDocument->setFileName(fileName);
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
document = newDocument;
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
m_documentHash.insert(textEdit, document);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
setCurrentDocument(document);
|
2010-04-06 10:49:16 +02:00
|
|
|
|
|
|
|
|
m_initStatus = Initialized;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::closeEditors(QList<Core::IEditor*> editors)
|
|
|
|
|
{
|
|
|
|
|
foreach (Core::IEditor* editor, editors) {
|
|
|
|
|
if (QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit*>(editor->widget())) {
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentTextEdit.data() == textEdit) {
|
|
|
|
|
setCurrentDocument(0);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
if (m_documentHash.contains(textEdit)) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << editor->file()->fileName();
|
2010-03-23 14:01:25 +01:00
|
|
|
DesignDocumentController *document = m_documentHash.take(textEdit).data();
|
2010-01-07 12:14:35 +01:00
|
|
|
delete document;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *DesignModeWidget::undoAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_undoAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *DesignModeWidget::redoAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_redoAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *DesignModeWidget::deleteAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_deleteAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *DesignModeWidget::cutAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_cutAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *DesignModeWidget::copyAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_copyAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *DesignModeWidget::pasteAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_pasteAction;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 15:22:08 +01:00
|
|
|
QAction *DesignModeWidget::selectAllAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_selectAllAction;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 15:40:34 +02:00
|
|
|
QAction *DesignModeWidget::hideSidebarsAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_hideSidebarsAction;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-26 13:53:26 +02:00
|
|
|
QAction *DesignModeWidget::toggleLeftSidebarAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_toggleLeftSidebarAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *DesignModeWidget::toggleRightSidebarAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_toggleRightSidebarAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-04-26 11:30:14 +02:00
|
|
|
QAction *DesignModeWidget::restoreDefaultViewAction() const
|
|
|
|
|
{
|
|
|
|
|
return m_restoreDefaultViewAction;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
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);
|
2010-06-25 14:39:05 +02:00
|
|
|
m_mainSplitter->setOpaqueResize(); // force opaque resize since it used to be off
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void DesignModeWidget::undo()
|
|
|
|
|
{
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController)
|
|
|
|
|
m_currentDesignDocumentController->undo();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::redo()
|
|
|
|
|
{
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController)
|
|
|
|
|
m_currentDesignDocumentController->redo();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::deleteSelected()
|
|
|
|
|
{
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController)
|
|
|
|
|
m_currentDesignDocumentController->deleteSelected();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::cutSelected()
|
|
|
|
|
{
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController)
|
|
|
|
|
m_currentDesignDocumentController->cutSelected();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::copySelected()
|
|
|
|
|
{
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController)
|
|
|
|
|
m_currentDesignDocumentController->copySelected();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::paste()
|
|
|
|
|
{
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController)
|
|
|
|
|
m_currentDesignDocumentController->paste();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-25 15:22:08 +01:00
|
|
|
void DesignModeWidget::selectAll()
|
|
|
|
|
{
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController)
|
|
|
|
|
m_currentDesignDocumentController->selectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::closeCurrentEditor()
|
|
|
|
|
{
|
2010-01-25 15:22:08 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
void DesignModeWidget::undoAvailable(bool isAvailable)
|
|
|
|
|
{
|
|
|
|
|
DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController &&
|
|
|
|
|
m_currentDesignDocumentController.data() == documentController) {
|
2010-01-07 12:14:35 +01:00
|
|
|
m_undoAction->setEnabled(isAvailable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::redoAvailable(bool isAvailable)
|
|
|
|
|
{
|
|
|
|
|
DesignDocumentController *documentController = qobject_cast<DesignDocumentController*>(sender());
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController &&
|
|
|
|
|
m_currentDesignDocumentController.data() == documentController) {
|
2010-01-07 12:14:35 +01:00
|
|
|
m_redoAction->setEnabled(isAvailable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
void DesignModeWidget::enable()
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
if (debug)
|
2010-03-23 14:01:25 +01:00
|
|
|
qDebug() << Q_FUNC_INFO;
|
|
|
|
|
m_warningWidget->setVisible(false);
|
|
|
|
|
m_formEditorView->widget()->setEnabled(true);
|
2010-12-08 16:46:25 +01:00
|
|
|
m_statesEditorView->widget()->setEnabled(true);
|
2010-03-23 14:01:25 +01:00
|
|
|
m_leftSideBar->setEnabled(true);
|
|
|
|
|
m_rightSideBar->setEnabled(true);
|
|
|
|
|
m_isDisabled = false;
|
|
|
|
|
}
|
2010-01-13 11:44:13 +01:00
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
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);
|
2010-12-08 16:46:25 +01:00
|
|
|
m_statesEditorView->widget()->setEnabled(false);
|
2010-03-23 14:01:25 +01:00
|
|
|
m_leftSideBar->setEnabled(false);
|
|
|
|
|
m_rightSideBar->setEnabled(false);
|
|
|
|
|
m_isDisabled = true;
|
|
|
|
|
}
|
2010-01-13 11:44:13 +01:00
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
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);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
void DesignModeWidget::setAutoSynchronization(bool sync)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << sync;
|
|
|
|
|
|
2011-06-08 17:25:28 +02:00
|
|
|
RewriterView *rewriter = m_currentDesignDocumentController->rewriterView();
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
m_currentDesignDocumentController->blockModelSync(!sync);
|
|
|
|
|
|
|
|
|
|
if (sync) {
|
2011-06-08 17:25:28 +02:00
|
|
|
if (rewriter && m_currentDesignDocumentController->model())
|
|
|
|
|
rewriter->setSelectedModelNodes(QList<ModelNode>());
|
2010-03-23 14:01:25 +01:00
|
|
|
// 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
|
|
|
|
|
const int cursorPos = m_currentTextEdit->textCursor().position();
|
|
|
|
|
ModelNode node = nodeForPosition(cursorPos);
|
2011-06-08 17:25:28 +02:00
|
|
|
if (rewriter && node.isValid()) {
|
2010-03-23 14:01:25 +01:00
|
|
|
rewriter->setSelectedModelNodes(QList<ModelNode>() << node);
|
|
|
|
|
}
|
|
|
|
|
enable();
|
|
|
|
|
} else {
|
|
|
|
|
disable(errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(m_currentDesignDocumentController.data(), SIGNAL(qmlErrorsChanged(QList<RewriterView::Error>)),
|
|
|
|
|
this, SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
} else {
|
2010-03-23 14:01:25 +01:00
|
|
|
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_currentDesignDocumentController) {
|
|
|
|
|
setAutoSynchronization(false);
|
|
|
|
|
saveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-24 17:25:00 +01:00
|
|
|
if (currentDesignDocumentController()) {
|
|
|
|
|
disconnect(currentDesignDocumentController(), SIGNAL(undoAvailable(bool)),
|
|
|
|
|
this, SLOT(undoAvailable(bool)));
|
|
|
|
|
disconnect(currentDesignDocumentController(), SIGNAL(redoAvailable(bool)),
|
|
|
|
|
this, SLOT(redoAvailable(bool)));
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
m_currentDesignDocumentController = newDesignDocumentController;
|
|
|
|
|
|
2010-03-25 16:53:07 +01:00
|
|
|
if (currentDesignDocumentController()) {
|
|
|
|
|
connect(currentDesignDocumentController(), SIGNAL(undoAvailable(bool)),
|
2010-03-23 14:01:25 +01:00
|
|
|
this, SLOT(undoAvailable(bool)));
|
2010-03-25 16:53:07 +01:00
|
|
|
connect(currentDesignDocumentController(), SIGNAL(redoAvailable(bool)),
|
2010-03-23 14:01:25 +01:00
|
|
|
this, SLOT(redoAvailable(bool)));
|
2010-03-25 16:53:07 +01:00
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
if (m_currentDesignDocumentController) {
|
|
|
|
|
|
|
|
|
|
setAutoSynchronization(true);
|
|
|
|
|
m_undoAction->setEnabled(m_currentDesignDocumentController->isUndoAvailable());
|
|
|
|
|
m_redoAction->setEnabled(m_currentDesignDocumentController->isRedoAvailable());
|
|
|
|
|
} else {
|
|
|
|
|
//detach all views
|
2010-01-07 12:14:35 +01:00
|
|
|
m_undoAction->setEnabled(false);
|
|
|
|
|
m_redoAction->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
void DesignModeWidget::setup()
|
|
|
|
|
{
|
|
|
|
|
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;
|
2010-04-29 11:59:42 +02:00
|
|
|
if (factory->id() == QLatin1String("Projects")) {
|
2010-03-23 14:01:25 +01:00
|
|
|
navigationView = factory->createWidget();
|
|
|
|
|
projectsExplorer = navigationView.widget;
|
|
|
|
|
projectsExplorer->setWindowTitle(tr("Projects"));
|
2010-04-29 11:59:42 +02:00
|
|
|
} else if (factory->id() == QLatin1String("File System")) {
|
2010-03-23 14:01:25 +01:00
|
|
|
navigationView = factory->createWidget();
|
|
|
|
|
fileSystemExplorer = navigationView.widget;
|
|
|
|
|
fileSystemExplorer->setWindowTitle(tr("File System"));
|
2010-04-29 11:59:42 +02:00
|
|
|
} else if (factory->id() == QLatin1String("Open Documents")) {
|
2010-03-23 14:01:25 +01:00
|
|
|
navigationView = factory->createWidget();
|
|
|
|
|
openDocumentsWidget = navigationView.widget;
|
|
|
|
|
openDocumentsWidget->setWindowTitle(tr("Open Documents"));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-20 13:49:26 +02:00
|
|
|
if (navigationView.widget) {
|
|
|
|
|
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
|
|
|
|
sheet += Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css");
|
|
|
|
|
sheet += "QLabel { background-color: #4f4f4f; }";
|
|
|
|
|
navigationView.widget->setStyleSheet(QString::fromLatin1(sheet));
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-23 15:26:58 +02:00
|
|
|
m_nodeInstanceView = new NodeInstanceView(this);
|
2011-04-13 17:52:17 +02:00
|
|
|
connect(m_nodeInstanceView.data(), SIGNAL(qmlPuppetCrashed()), this, SLOT(qmlPuppetCrashed()));
|
2010-04-16 17:02:58 +02:00
|
|
|
// Sidebar takes ownership
|
2011-04-28 17:15:27 +02:00
|
|
|
m_navigatorView = new NavigatorView;
|
2011-05-20 14:32:43 +02:00
|
|
|
m_propertyEditorView = new PropertyEditor(this);
|
2010-12-10 17:57:42 +01:00
|
|
|
m_itemLibraryView = new ItemLibraryView(this);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2010-12-08 16:46:25 +01:00
|
|
|
m_statesEditorView = new StatesEditorView(this);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
m_formEditorView = new FormEditorView(this);
|
|
|
|
|
|
2011-05-24 18:47:33 +02:00
|
|
|
m_componentView = new ComponentView(this);
|
|
|
|
|
m_formEditorView->widget()->toolBox()->addLeftSideAction(m_componentView->action());
|
2010-03-23 14:01:25 +01:00
|
|
|
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);
|
|
|
|
|
|
2011-04-28 17:15:27 +02:00
|
|
|
Core::SideBarItem *navigatorItem = new NavigatorSideBarItem(m_navigatorView->widget(), QLatin1String(SB_NAVIGATOR));
|
2010-12-14 16:52:29 +01:00
|
|
|
Core::SideBarItem *libraryItem = new ItemLibrarySideBarItem(m_itemLibraryView->widget(), QLatin1String(SB_LIBRARY));
|
2011-05-20 14:32:43 +02:00
|
|
|
Core::SideBarItem *propertiesItem = new Core::SideBarItem(m_propertyEditorView->widget(), QLatin1String(SB_PROPERTIES));
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2010-04-26 08:42:41 +02:00
|
|
|
// default items
|
2010-04-26 11:30:14 +02:00
|
|
|
m_sideBarItems << navigatorItem << libraryItem << propertiesItem;
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
if (projectsExplorer) {
|
2010-04-29 11:59:42 +02:00
|
|
|
Core::SideBarItem *projectExplorerItem = new Core::SideBarItem(projectsExplorer, QLatin1String(SB_PROJECTS));
|
2010-04-26 11:30:14 +02:00
|
|
|
m_sideBarItems << projectExplorerItem;
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fileSystemExplorer) {
|
2010-04-29 11:59:42 +02:00
|
|
|
Core::SideBarItem *fileSystemExplorerItem = new Core::SideBarItem(fileSystemExplorer, QLatin1String(SB_FILESYSTEM));
|
2010-04-26 11:30:14 +02:00
|
|
|
m_sideBarItems << fileSystemExplorerItem;
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-26 08:42:41 +02:00
|
|
|
if (openDocumentsWidget) {
|
2010-04-29 11:59:42 +02:00
|
|
|
Core::SideBarItem *openDocumentsItem = new Core::SideBarItem(openDocumentsWidget, QLatin1String(SB_OPENDOCUMENTS));
|
2010-04-26 11:30:14 +02:00
|
|
|
m_sideBarItems << openDocumentsItem;
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-26 11:30:14 +02:00
|
|
|
m_leftSideBar = new Core::SideBar(m_sideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem);
|
|
|
|
|
m_rightSideBar = new Core::SideBar(m_sideBarItems, QList<Core::SideBarItem*>() << propertiesItem);
|
2010-04-26 08:42:41 +02:00
|
|
|
|
|
|
|
|
connect(m_leftSideBar, SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsRight()));
|
|
|
|
|
connect(m_rightSideBar, SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsLeft()));
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2010-12-03 13:51:54 +01:00
|
|
|
connect(Core::ICore::instance(), SIGNAL(coreAboutToClose()),
|
|
|
|
|
this, SLOT(deleteSidebarWidgets()));
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
|
|
|
|
//m_fakeToolBar->addEditor(textEditor()); ### what does this mean?
|
2011-06-20 16:33:10 +02:00
|
|
|
m_fakeToolBar->setNavigationVisible(true);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
connect(m_fakeToolBar, SIGNAL(closeClicked()), this, SLOT(closeCurrentEditor()));
|
2011-06-20 16:33:10 +02:00
|
|
|
connect(m_fakeToolBar, SIGNAL(goForwardClicked()), this, SLOT(onGoForwardClicked()));
|
|
|
|
|
connect(m_fakeToolBar, SIGNAL(goBackClicked()), this, SLOT(onGoBackClicked()));
|
|
|
|
|
setupNavigatorHistory();
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
// 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
|
2010-12-08 16:46:25 +01:00
|
|
|
rightLayout->addWidget(m_statesEditorView->widget());
|
2010-04-23 09:32:45 +02:00
|
|
|
|
2011-04-28 17:15:27 +02:00
|
|
|
FormEditorContext *formEditorContext = new FormEditorContext(m_formEditorView->widget());
|
|
|
|
|
Core::ICore::instance()->addContextObject(formEditorContext);
|
|
|
|
|
|
|
|
|
|
NavigatorContext *navigatorContext = new NavigatorContext(m_navigatorView->widget());
|
|
|
|
|
Core::ICore::instance()->addContextObject(navigatorContext);
|
2010-11-17 12:59:08 +01:00
|
|
|
|
2010-04-23 09:32:45 +02:00
|
|
|
// editor and output panes
|
|
|
|
|
m_outputPlaceholderSplitter->addWidget(m_formEditorView->widget());
|
|
|
|
|
m_outputPlaceholderSplitter->addWidget(m_outputPanePlaceholder);
|
|
|
|
|
m_outputPlaceholderSplitter->setStretchFactor(0, 10);
|
|
|
|
|
m_outputPlaceholderSplitter->setStretchFactor(1, 0);
|
|
|
|
|
m_outputPlaceholderSplitter->setOrientation(Qt::Vertical);
|
|
|
|
|
|
|
|
|
|
rightLayout->addWidget(m_outputPlaceholderSplitter);
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// m_mainSplitter area:
|
|
|
|
|
m_mainSplitter->addWidget(m_leftSideBar);
|
|
|
|
|
m_mainSplitter->addWidget(centerWidget);
|
|
|
|
|
m_mainSplitter->addWidget(m_rightSideBar);
|
|
|
|
|
|
|
|
|
|
// Finishing touches:
|
|
|
|
|
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);
|
2010-12-08 16:46:25 +01:00
|
|
|
m_statesEditorView->widget()->setEnabled(true);
|
2010-03-23 14:01:25 +01:00
|
|
|
m_leftSideBar->setEnabled(true);
|
|
|
|
|
m_rightSideBar->setEnabled(true);
|
2010-04-26 08:42:41 +02:00
|
|
|
m_leftSideBar->setCloseWhenEmpty(true);
|
|
|
|
|
m_rightSideBar->setCloseWhenEmpty(true);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
readSettings();
|
|
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-26 08:42:41 +02:00
|
|
|
void DesignModeWidget::updateAvailableSidebarItemsRight()
|
|
|
|
|
{
|
|
|
|
|
// event comes from m_leftSidebar, so update right side.
|
2010-04-29 11:59:42 +02:00
|
|
|
m_rightSideBar->setUnavailableItemIds(m_leftSideBar->unavailableItemIds());
|
2010-04-26 08:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::updateAvailableSidebarItemsLeft()
|
|
|
|
|
{
|
|
|
|
|
// event comes from m_rightSidebar, so update left side.
|
2010-04-29 11:59:42 +02:00
|
|
|
m_leftSideBar->setUnavailableItemIds(m_rightSideBar->unavailableItemIds());
|
2010-04-26 08:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
2010-12-03 13:51:54 +01:00
|
|
|
void DesignModeWidget::deleteSidebarWidgets()
|
|
|
|
|
{
|
|
|
|
|
delete m_leftSideBar;
|
|
|
|
|
delete m_rightSideBar;
|
|
|
|
|
m_leftSideBar = 0;
|
|
|
|
|
m_rightSideBar = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-13 17:52:17 +02:00
|
|
|
void DesignModeWidget::qmlPuppetCrashed()
|
|
|
|
|
{
|
|
|
|
|
QList<RewriterView::Error> errorList;
|
|
|
|
|
RewriterView::Error error(tr("Qt Quick emulation layer crashed"));
|
|
|
|
|
errorList << error;
|
|
|
|
|
disable(errorList);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 16:33:10 +02:00
|
|
|
void DesignModeWidget::onGoBackClicked()
|
|
|
|
|
{
|
|
|
|
|
if (m_navigatorHistoryCounter > 0) {
|
|
|
|
|
--m_navigatorHistoryCounter;
|
|
|
|
|
m_keepNavigatorHistory = true;
|
|
|
|
|
|
|
|
|
|
Core::EditorManager::instance()->openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter));
|
|
|
|
|
|
|
|
|
|
m_keepNavigatorHistory = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::onGoForwardClicked()
|
|
|
|
|
{
|
|
|
|
|
if (m_navigatorHistoryCounter < (m_navigatorHistory.size() - 1)) {
|
|
|
|
|
++m_navigatorHistoryCounter;
|
|
|
|
|
m_keepNavigatorHistory = true;
|
|
|
|
|
|
|
|
|
|
Core::EditorManager::instance()->openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter));
|
|
|
|
|
|
|
|
|
|
m_keepNavigatorHistory = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 16:33:10 +02:00
|
|
|
void DesignModeWidget::setupNavigatorHistory()
|
|
|
|
|
{
|
|
|
|
|
const bool canGoBack = m_navigatorHistoryCounter > 0;
|
|
|
|
|
const bool canGoForward = m_navigatorHistoryCounter < (m_navigatorHistory.size() - 1);
|
|
|
|
|
m_fakeToolBar->setCanGoBack(canGoBack);
|
|
|
|
|
m_fakeToolBar->setCanGoForward(canGoForward);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::addNavigatorHistoryEntry(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
if (m_navigatorHistoryCounter > 0)
|
|
|
|
|
m_navigatorHistory.insert(m_navigatorHistoryCounter + 1, fileName);
|
|
|
|
|
else
|
|
|
|
|
m_navigatorHistory.append(fileName);
|
|
|
|
|
|
|
|
|
|
++m_navigatorHistoryCounter;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2010-03-08 09:47:45 +01:00
|
|
|
QString DesignModeWidget::contextHelpId() const
|
|
|
|
|
{
|
2010-03-23 14:01:25 +01:00
|
|
|
if (m_currentDesignDocumentController)
|
|
|
|
|
return m_currentDesignDocumentController->contextHelpId();
|
2010-03-08 09:47:45 +01:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Designer
|