2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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"
|
2013-01-23 12:31:22 +01:00
|
|
|
#include "qmldesignerplugin.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include <model.h>
|
|
|
|
|
#include <rewriterview.h>
|
2011-05-24 18:47:33 +02:00
|
|
|
#include <componentaction.h>
|
|
|
|
|
#include <toolbox.h>
|
2013-01-23 12:31:22 +01:00
|
|
|
#include <itemlibrarywidget.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-04-23 09:32:45 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2011-10-19 13:05:53 +02:00
|
|
|
#include <coreplugin/designmode.h>
|
2010-04-23 09:32:45 +02:00
|
|
|
#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>
|
2011-09-15 14:31:30 +02:00
|
|
|
#include <utils/crumblepath.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
|
#include <QTabWidget>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QClipboard>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QProgressDialog>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
using Core::MiniSplitter;
|
|
|
|
|
using Core::IEditor;
|
|
|
|
|
using Core::EditorManager;
|
|
|
|
|
|
|
|
|
|
using namespace QmlDesigner;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
debug = false
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-02 16:45:13 +01:00
|
|
|
const char SB_NAVIGATOR[] = "Navigator";
|
|
|
|
|
const char SB_LIBRARY[] = "Library";
|
|
|
|
|
const char SB_PROPERTIES[] = "Properties";
|
|
|
|
|
const char SB_PROJECTS[] = "Projects";
|
|
|
|
|
const char SB_FILESYSTEM[] = "FileSystem";
|
|
|
|
|
const char SB_OPENDOCUMENTS[] = "OpenDocuments";
|
2010-04-29 11:59:42 +02:00
|
|
|
|
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),
|
2012-12-05 22:57:32 +02:00
|
|
|
m_errorMessage(new QLabel(tr("Placeholder"), this)),
|
2010-01-07 12:14:35 +01:00
|
|
|
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:
|
2013-01-23 12:31:22 +01:00
|
|
|
explicit ItemLibrarySideBarItem(QWidget *widget, const QString &id);
|
2010-12-14 16:52:29 +01:00
|
|
|
virtual ~ItemLibrarySideBarItem();
|
|
|
|
|
|
|
|
|
|
virtual QList<QToolButton *> createToolBarWidgets();
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
ItemLibrarySideBarItem::ItemLibrarySideBarItem(QWidget *widget, const QString &id) : Core::SideBarItem(widget, id) {}
|
2010-12-14 16:52:29 +01:00
|
|
|
|
|
|
|
|
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:
|
2013-01-23 12:31:22 +01:00
|
|
|
explicit NavigatorSideBarItem(QWidget *widget, const QString &id);
|
2011-04-28 17:12:45 +02:00
|
|
|
virtual ~NavigatorSideBarItem();
|
|
|
|
|
|
|
|
|
|
virtual QList<QToolButton *> createToolBarWidgets();
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
NavigatorSideBarItem::NavigatorSideBarItem(QWidget *widget, const QString &id) : Core::SideBarItem(widget, id) {}
|
2011-04-28 17:12:45 +02:00
|
|
|
|
|
|
|
|
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);
|
2012-01-26 01:18:02 +01:00
|
|
|
Core::ModeManager::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_mainSplitter(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
|
|
|
{
|
2010-04-23 09:32:45 +02:00
|
|
|
m_outputPlaceholderSplitter = new Core::MiniSplitter;
|
2011-10-19 13:05:53 +02:00
|
|
|
m_outputPanePlaceholder = new StyledOutputpanePlaceHolder(Core::DesignMode::instance(), m_outputPlaceholderSplitter);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-06 17:12:04 +01:00
|
|
|
DesignModeWidget::~DesignModeWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-26 11:30:14 +02:00
|
|
|
void DesignModeWidget::restoreDefaultView()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2010-04-26 11:30:14 +02:00
|
|
|
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);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
viewManager().statesEditorWidget()->setVisible(m_showSidebars);
|
2010-04-23 15:40:34 +02:00
|
|
|
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
void DesignModeWidget::readSettings()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
settings->beginGroup("Bauhaus");
|
|
|
|
|
m_leftSideBar->saveSettings(settings, QLatin1String("LeftSideBar"));
|
|
|
|
|
m_rightSideBar->saveSettings(settings, QLatin1String("RightSideBar"));
|
|
|
|
|
settings->setValue("MainSplitter", m_mainSplitter->saveState());
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void DesignModeWidget::enableWidgets()
|
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);
|
2013-01-23 12:31:22 +01:00
|
|
|
viewManager().formEditorWidget()->setEnabled(true);
|
|
|
|
|
viewManager().statesEditorWidget()->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
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void DesignModeWidget::disableWidgets()
|
2010-03-23 14:01:25 +01:00
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO;
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
viewManager().formEditorWidget()->setEnabled(false);
|
|
|
|
|
viewManager().statesEditorWidget()->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();
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
if (m_isDisabled && errors.isEmpty()) {
|
|
|
|
|
enableWidgets();
|
|
|
|
|
} else if (!errors.isEmpty()) {
|
|
|
|
|
disableWidgets();
|
|
|
|
|
showErrorMessage(errors);
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
TextEditor::ITextEditor *DesignModeWidget::textEditor() const
|
2010-03-23 14:01:25 +01:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
return currentDesignDocument()->textEditor();
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void DesignModeWidget::setCurrentDesignDocument(DesignDocument *newDesignDocument)
|
2010-03-23 14:01:25 +01:00
|
|
|
{
|
|
|
|
|
if (debug)
|
2013-01-23 12:31:22 +01:00
|
|
|
qDebug() << Q_FUNC_INFO << newDesignDocument;
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
//viewManager().setDesignDocument(newDesignDocument);
|
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::setup()
|
|
|
|
|
{
|
2012-06-18 11:34:15 +02:00
|
|
|
QList<Core::INavigationWidgetFactory *> factories =
|
|
|
|
|
ExtensionSystem::PluginManager::getObjects<Core::INavigationWidgetFactory>();
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
QWidget *openDocumentsWidget = 0;
|
|
|
|
|
QWidget *projectsExplorer = 0;
|
|
|
|
|
QWidget *fileSystemExplorer = 0;
|
|
|
|
|
|
2011-11-09 12:07:41 +01:00
|
|
|
foreach (Core::INavigationWidgetFactory *factory, factories) {
|
2010-03-23 14:01:25 +01:00
|
|
|
Core::NavigationView navigationView;
|
|
|
|
|
navigationView.widget = 0;
|
2012-08-03 15:24:33 +02:00
|
|
|
if (factory->id() == "Projects") {
|
2010-03-23 14:01:25 +01:00
|
|
|
navigationView = factory->createWidget();
|
|
|
|
|
projectsExplorer = navigationView.widget;
|
|
|
|
|
projectsExplorer->setWindowTitle(tr("Projects"));
|
2012-08-03 15:24:33 +02:00
|
|
|
} else if (factory->id() == "File System") {
|
2010-03-23 14:01:25 +01:00
|
|
|
navigationView = factory->createWidget();
|
|
|
|
|
fileSystemExplorer = navigationView.widget;
|
|
|
|
|
fileSystemExplorer->setWindowTitle(tr("File System"));
|
2012-08-03 15:24:33 +02:00
|
|
|
} else if (factory->id() == "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; }";
|
2013-03-05 12:19:19 +01:00
|
|
|
navigationView.widget->setStyleSheet(QString::fromUtf8(sheet));
|
2011-04-20 13:49:26 +02:00
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-11 13:31:03 +01:00
|
|
|
m_toolBar = Core::EditorManager::createToolBar(this);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
Core::SideBarItem *navigatorItem = new NavigatorSideBarItem(viewManager().navigatorWidget(), QLatin1String(SB_NAVIGATOR));
|
|
|
|
|
Core::SideBarItem *libraryItem = new ItemLibrarySideBarItem(viewManager().itemLibraryWidget(), QLatin1String(SB_LIBRARY));
|
|
|
|
|
Core::SideBarItem *propertiesItem = new Core::SideBarItem(viewManager().propertyEditorWidget(), 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
|
|
|
}
|
|
|
|
|
|
2013-02-06 17:12:04 +01:00
|
|
|
m_leftSideBar.reset(new Core::SideBar(m_sideBarItems, QList<Core::SideBarItem*>() << navigatorItem << libraryItem));
|
|
|
|
|
m_rightSideBar.reset(new Core::SideBar(m_sideBarItems, QList<Core::SideBarItem*>() << propertiesItem));
|
2010-04-26 08:42:41 +02:00
|
|
|
|
2013-02-06 17:12:04 +01:00
|
|
|
connect(m_leftSideBar.data(), SIGNAL(availableItemsChanged()), SLOT(updateAvailableSidebarItemsRight()));
|
|
|
|
|
connect(m_rightSideBar.data(), 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()));
|
|
|
|
|
|
2013-02-11 13:31:03 +01:00
|
|
|
m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
|
|
|
|
m_toolBar->setNavigationVisible(true);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2013-02-11 13:31:03 +01:00
|
|
|
connect(m_toolBar, SIGNAL(goForwardClicked()), this, SLOT(toolBarOnGoForwardClicked()));
|
|
|
|
|
connect(m_toolBar, SIGNAL(goBackClicked()), this, SLOT(toolBarOnGoBackClicked()));
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
if (currentDesignDocument())
|
|
|
|
|
setupNavigatorHistory(currentDesignDocument()->textEditor());
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
// right area:
|
2013-02-04 18:49:03 +01:00
|
|
|
QWidget *centerWidget = createCenterWidget();
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
// m_mainSplitter area:
|
2013-02-06 17:12:04 +01:00
|
|
|
m_mainSplitter->addWidget(m_leftSideBar.data());
|
2010-03-23 14:01:25 +01:00
|
|
|
m_mainSplitter->addWidget(centerWidget);
|
2013-02-06 17:12:04 +01:00
|
|
|
m_mainSplitter->addWidget(m_rightSideBar.data());
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
// 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);
|
2013-01-23 12:31:22 +01:00
|
|
|
viewManager().statesEditorWidget()->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();
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2013-02-06 17:12:04 +01:00
|
|
|
m_leftSideBar.reset();
|
|
|
|
|
m_rightSideBar.reset();
|
2010-12-03 13:51:54 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-13 17:52:17 +02:00
|
|
|
void DesignModeWidget::qmlPuppetCrashed()
|
|
|
|
|
{
|
|
|
|
|
QList<RewriterView::Error> errorList;
|
|
|
|
|
RewriterView::Error error(tr("Qt Quick emulation layer crashed"));
|
2013-01-23 12:31:22 +01:00
|
|
|
errorList.append(error);
|
|
|
|
|
|
|
|
|
|
disableWidgets();
|
|
|
|
|
showErrorMessage(errorList);
|
2011-04-13 17:52:17 +02:00
|
|
|
}
|
|
|
|
|
|
2013-02-11 13:31:03 +01:00
|
|
|
void DesignModeWidget::toolBarOnGoBackClicked()
|
2011-06-20 16:33:10 +02:00
|
|
|
{
|
|
|
|
|
if (m_navigatorHistoryCounter > 0) {
|
|
|
|
|
--m_navigatorHistoryCounter;
|
|
|
|
|
m_keepNavigatorHistory = true;
|
2012-05-08 09:43:14 +02:00
|
|
|
Core::EditorManager::openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter));
|
2011-06-20 16:33:10 +02:00
|
|
|
m_keepNavigatorHistory = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-11 13:31:03 +01:00
|
|
|
void DesignModeWidget::toolBarOnGoForwardClicked()
|
2011-06-20 16:33:10 +02:00
|
|
|
{
|
|
|
|
|
if (m_navigatorHistoryCounter < (m_navigatorHistory.size() - 1)) {
|
|
|
|
|
++m_navigatorHistoryCounter;
|
|
|
|
|
m_keepNavigatorHistory = true;
|
2012-05-08 09:43:14 +02:00
|
|
|
Core::EditorManager::openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter));
|
2011-06-20 16:33:10 +02:00
|
|
|
m_keepNavigatorHistory = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
DesignDocument *DesignModeWidget::currentDesignDocument() const
|
2011-09-19 17:57:37 +02:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument();
|
2011-09-19 17:57:37 +02:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
ViewManager &DesignModeWidget::viewManager()
|
2011-09-19 17:57:37 +02:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
return QmlDesignerPlugin::instance()->viewManager();
|
2011-09-19 17:57:37 +02:00
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void DesignModeWidget::setupNavigatorHistory(Core::IEditor *editor)
|
2010-03-23 14:01:25 +01:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
if (!m_keepNavigatorHistory)
|
|
|
|
|
addNavigatorHistoryEntry(editor->document()->fileName());
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2011-06-20 16:33:10 +02:00
|
|
|
const bool canGoBack = m_navigatorHistoryCounter > 0;
|
|
|
|
|
const bool canGoForward = m_navigatorHistoryCounter < (m_navigatorHistory.size() - 1);
|
2013-02-11 13:31:03 +01:00
|
|
|
m_toolBar->setCanGoBack(canGoBack);
|
|
|
|
|
m_toolBar->setCanGoForward(canGoForward);
|
|
|
|
|
m_toolBar->setCurrentEditor(editor);
|
2011-06-20 16:33:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DesignModeWidget::addNavigatorHistoryEntry(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
if (m_navigatorHistoryCounter > 0)
|
|
|
|
|
m_navigatorHistory.insert(m_navigatorHistoryCounter + 1, fileName);
|
|
|
|
|
else
|
|
|
|
|
m_navigatorHistory.append(fileName);
|
|
|
|
|
|
|
|
|
|
++m_navigatorHistoryCounter;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 15:10:34 +01:00
|
|
|
QWidget *DesignModeWidget::createCenterWidget()
|
2013-02-04 18:49:03 +01:00
|
|
|
{
|
|
|
|
|
QWidget *centerWidget = new QWidget;
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *rightLayout = new QVBoxLayout(centerWidget);
|
|
|
|
|
rightLayout->setMargin(0);
|
|
|
|
|
rightLayout->setSpacing(0);
|
2013-02-11 13:31:03 +01:00
|
|
|
rightLayout->addWidget(m_toolBar);
|
2013-02-04 18:49:03 +01:00
|
|
|
//### we now own these here
|
|
|
|
|
rightLayout->addWidget(viewManager().statesEditorWidget());
|
|
|
|
|
|
|
|
|
|
FormEditorContext *formEditorContext = new FormEditorContext(viewManager().formEditorWidget());
|
|
|
|
|
Core::ICore::addContextObject(formEditorContext);
|
|
|
|
|
|
|
|
|
|
NavigatorContext *navigatorContext = new NavigatorContext(viewManager().navigatorWidget());
|
|
|
|
|
Core::ICore::addContextObject(navigatorContext);
|
|
|
|
|
|
|
|
|
|
// editor and output panes
|
|
|
|
|
m_outputPlaceholderSplitter->addWidget(viewManager().formEditorWidget());
|
|
|
|
|
m_outputPlaceholderSplitter->addWidget(m_outputPanePlaceholder);
|
|
|
|
|
m_outputPlaceholderSplitter->setStretchFactor(0, 10);
|
|
|
|
|
m_outputPlaceholderSplitter->setStretchFactor(1, 0);
|
|
|
|
|
m_outputPlaceholderSplitter->setOrientation(Qt::Vertical);
|
|
|
|
|
|
|
|
|
|
rightLayout->addWidget(m_outputPlaceholderSplitter);
|
|
|
|
|
|
|
|
|
|
return centerWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void DesignModeWidget::showErrorMessage(const QList<RewriterView::Error> &errors)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(!errors.isEmpty());
|
|
|
|
|
m_warningWidget->setError(errors.first());
|
|
|
|
|
m_warningWidget->setVisible(true);
|
|
|
|
|
m_warningWidget->move(width() / 2, height() / 2);
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2010-03-08 09:47:45 +01:00
|
|
|
QString DesignModeWidget::contextHelpId() const
|
|
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
if (currentDesignDocument())
|
|
|
|
|
return currentDesignDocument()->contextHelpId();
|
2010-03-08 09:47:45 +01:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void DesignModeWidget::initialize()
|
|
|
|
|
{
|
|
|
|
|
if (m_initStatus == NotInitialized) {
|
|
|
|
|
m_initStatus = Initializing;
|
|
|
|
|
setup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_initStatus = Initialized;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Designer
|