2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:57:40 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include "designmodewidget.h"
|
2017-02-06 10:46:52 +01:00
|
|
|
#include "switchsplittabwidget.h"
|
2016-04-29 11:24:28 +02:00
|
|
|
|
2017-01-05 17:44:10 +01:00
|
|
|
#include <designeractionmanager.h>
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
#include "qmldesignerplugin.h"
|
2013-08-05 12:39:26 +02:00
|
|
|
#include "crumblebar.h"
|
2016-04-28 14:21:33 +02:00
|
|
|
#include "documentwarningwidget.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2016-04-29 22:15:30 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
2014-03-24 12:47:16 +01:00
|
|
|
#include <nodeinstanceview.h>
|
2013-01-23 12:31:22 +01:00
|
|
|
#include <itemlibrarywidget.h>
|
2017-03-07 16:06:02 +01:00
|
|
|
#include <theme.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2017-02-06 10:46:52 +01:00
|
|
|
#include <coreplugin/outputpane.h>
|
2016-04-29 22:15:30 +02:00
|
|
|
#include <coreplugin/modemanager.h>
|
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-01-07 12:14:35 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/minisplitter.h>
|
|
|
|
|
#include <coreplugin/sidebar.h>
|
2010-03-10 12:48:17 +01:00
|
|
|
#include <coreplugin/editortoolbar.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2010-03-23 14:01:25 +01:00
|
|
|
#include <coreplugin/inavigationwidgetfactory.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2016-07-18 14:51:13 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
2013-08-05 12:39:26 +02:00
|
|
|
#include <QToolBar>
|
2016-04-29 12:05:33 +02:00
|
|
|
#include <QLayout>
|
|
|
|
|
#include <QBoxLayout>
|
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_PROJECTS[] = "Projects";
|
|
|
|
|
const char SB_FILESYSTEM[] = "FileSystem";
|
|
|
|
|
const char SB_OPENDOCUMENTS[] = "OpenDocuments";
|
2010-04-29 11:59:42 +02:00
|
|
|
|
2018-02-01 10:25:07 +01:00
|
|
|
static void hideToolButtons(QList<QToolButton*> &buttons)
|
|
|
|
|
{
|
|
|
|
|
foreach (QToolButton *button, buttons)
|
|
|
|
|
button->hide();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
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);
|
2018-07-11 07:31:38 +02:00
|
|
|
~ItemLibrarySideBarItem() override;
|
2010-12-14 16:52:29 +01:00
|
|
|
|
2018-07-11 07:31:38 +02:00
|
|
|
QList<QToolButton *> createToolBarWidgets() override;
|
2010-12-14 16:52:29 +01:00
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
2018-07-24 23:56:45 +02:00
|
|
|
ItemLibrarySideBarItem::~ItemLibrarySideBarItem() = default;
|
2010-12-14 16:52:29 +01:00
|
|
|
|
|
|
|
|
QList<QToolButton *> ItemLibrarySideBarItem::createToolBarWidgets()
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<ItemLibraryWidget*>(widget())->createToolBarWidgets();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-21 12:51:39 +01:00
|
|
|
class DesignerSideBarItem : public Core::SideBarItem
|
2011-04-28 17:12:45 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2013-03-21 12:51:39 +01:00
|
|
|
explicit DesignerSideBarItem(QWidget *widget, WidgetInfo::ToolBarWidgetFactoryInterface *createToolBarWidgets, const QString &id);
|
2018-07-11 07:31:38 +02:00
|
|
|
~DesignerSideBarItem() override;
|
2011-04-28 17:12:45 +02:00
|
|
|
|
2018-07-11 07:31:38 +02:00
|
|
|
QList<QToolButton *> createToolBarWidgets() override;
|
2011-04-28 17:12:45 +02:00
|
|
|
|
2013-03-21 12:51:39 +01:00
|
|
|
private:
|
|
|
|
|
WidgetInfo::ToolBarWidgetFactoryInterface *m_toolBarWidgetFactory;
|
|
|
|
|
|
|
|
|
|
};
|
2011-04-28 17:12:45 +02:00
|
|
|
|
2013-03-21 12:51:39 +01:00
|
|
|
DesignerSideBarItem::DesignerSideBarItem(QWidget *widget, WidgetInfo::ToolBarWidgetFactoryInterface *toolBarWidgetFactory, const QString &id)
|
|
|
|
|
: Core::SideBarItem(widget, id) , m_toolBarWidgetFactory(toolBarWidgetFactory)
|
2011-04-28 17:12:45 +02:00
|
|
|
{
|
2013-03-21 12:51:39 +01:00
|
|
|
}
|
2011-04-28 17:12:45 +02:00
|
|
|
|
2013-03-21 12:51:39 +01:00
|
|
|
DesignerSideBarItem::~DesignerSideBarItem()
|
|
|
|
|
{
|
|
|
|
|
delete m_toolBarWidgetFactory;
|
2011-04-28 17:12:45 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-21 12:51:39 +01:00
|
|
|
QList<QToolButton *> DesignerSideBarItem::createToolBarWidgets()
|
2011-04-28 17:12:45 +02:00
|
|
|
{
|
2013-03-21 12:51:39 +01:00
|
|
|
if (m_toolBarWidgetFactory)
|
|
|
|
|
return m_toolBarWidgetFactory->createToolBarWidgets();
|
|
|
|
|
|
|
|
|
|
return QList<QToolButton *>();
|
2011-04-28 17:12:45 +02:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
// ---------- DesignModeWidget
|
2018-02-06 16:51:28 +01:00
|
|
|
DesignModeWidget::DesignModeWidget()
|
|
|
|
|
: m_toolBar(new Core::EditorToolBar(this))
|
2016-05-10 11:45:26 +02:00
|
|
|
, m_crumbleBar(new CrumbleBar(this))
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-06 17:12:04 +01:00
|
|
|
DesignModeWidget::~DesignModeWidget()
|
|
|
|
|
{
|
2015-07-17 19:09:28 +02:00
|
|
|
m_leftSideBar.reset();
|
|
|
|
|
m_rightSideBar.reset();
|
|
|
|
|
|
|
|
|
|
foreach (QPointer<QWidget> widget, m_viewWidgets) {
|
|
|
|
|
if (widget)
|
|
|
|
|
widget.clear();
|
|
|
|
|
}
|
2013-02-06 17:12:04 +01:00
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 10:25:07 +01:00
|
|
|
QWidget *DesignModeWidget::createProjectExplorerWidget(QWidget *parent)
|
|
|
|
|
{
|
2018-02-22 09:23:06 +01:00
|
|
|
const QList<Core::INavigationWidgetFactory *> factories =
|
|
|
|
|
Core::INavigationWidgetFactory::allNavigationFactories();
|
2018-02-01 10:25:07 +01:00
|
|
|
|
|
|
|
|
Core::NavigationView navigationView;
|
|
|
|
|
navigationView.widget = nullptr;
|
|
|
|
|
|
|
|
|
|
foreach (Core::INavigationWidgetFactory *factory, factories) {
|
|
|
|
|
if (factory->id() == "Projects") {
|
|
|
|
|
navigationView = factory->createWidget();
|
|
|
|
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
|
|
|
|
navigationView.widget->setParent(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return navigationView.widget;
|
|
|
|
|
}
|
|
|
|
|
|
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");
|
2014-05-12 14:09:02 +02:00
|
|
|
m_leftSideBar->readSettings(settings, QStringLiteral("LeftSideBar"));
|
|
|
|
|
m_rightSideBar->readSettings(settings, QStringLiteral("RightSideBar"));
|
2010-03-23 14:01:25 +01:00
|
|
|
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");
|
2014-05-12 14:09:02 +02:00
|
|
|
m_leftSideBar->saveSettings(settings, QStringLiteral("LeftSideBar"));
|
|
|
|
|
m_rightSideBar->saveSettings(settings, QStringLiteral("RightSideBar"));
|
2010-03-23 14:01:25 +01:00
|
|
|
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;
|
2017-03-24 12:27:19 +01:00
|
|
|
|
2013-03-07 17:04:11 +01:00
|
|
|
viewManager().enableWidgets();
|
2010-03-23 14:01:25 +01:00
|
|
|
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
|
|
|
|
2013-03-07 17:04:11 +01:00
|
|
|
viewManager().disableWidgets();
|
2010-03-23 14:01:25 +01:00
|
|
|
m_isDisabled = true;
|
|
|
|
|
}
|
2010-01-13 11:44:13 +01:00
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
void DesignModeWidget::switchTextOrForm()
|
2016-12-22 11:07:09 +01:00
|
|
|
{
|
2017-02-06 10:46:52 +01:00
|
|
|
if (m_centralTabWidget->currentWidget() == viewManager().widget("TextEditor"))
|
|
|
|
|
m_centralTabWidget->switchTo(viewManager().widget("FormEditor"));
|
|
|
|
|
else
|
|
|
|
|
m_centralTabWidget->switchTo(viewManager().widget("TextEditor"));
|
2016-12-22 11:07:09 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
void DesignModeWidget::setup()
|
|
|
|
|
{
|
2018-01-25 16:41:24 +01:00
|
|
|
auto &actionManager = viewManager().designerActionManager();
|
|
|
|
|
actionManager.createDefaultDesignerActions();
|
|
|
|
|
actionManager.createDefaultAddResourceHandler();
|
|
|
|
|
actionManager.polishActions();
|
2017-07-26 17:17:45 +02:00
|
|
|
|
2012-06-18 11:34:15 +02:00
|
|
|
QList<Core::INavigationWidgetFactory *> factories =
|
2018-01-18 12:18:01 +01:00
|
|
|
Core::INavigationWidgetFactory::allNavigationFactories();
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2016-05-10 11:45:26 +02:00
|
|
|
QWidget *openDocumentsWidget = nullptr;
|
|
|
|
|
QWidget *projectsExplorer = nullptr;
|
|
|
|
|
QWidget *fileSystemExplorer = nullptr;
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2011-11-09 12:07:41 +01:00
|
|
|
foreach (Core::INavigationWidgetFactory *factory, factories) {
|
2010-03-23 14:01:25 +01:00
|
|
|
Core::NavigationView navigationView;
|
2018-07-24 23:56:45 +02:00
|
|
|
navigationView.widget = nullptr;
|
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;
|
2014-03-31 16:15:14 +02:00
|
|
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
2010-03-23 14:01:25 +01:00
|
|
|
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;
|
2014-03-31 16:15:14 +02:00
|
|
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
2010-03-23 14:01:25 +01:00
|
|
|
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;
|
2014-03-31 16:15:14 +02:00
|
|
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
2010-03-23 14:01:25 +01:00
|
|
|
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; }";
|
2017-03-07 16:06:02 +01:00
|
|
|
navigationView.widget->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
2011-04-20 13:49:26 +02:00
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-24 23:56:45 +02:00
|
|
|
auto toolBar = new QToolBar;
|
2013-08-05 12:39:26 +02:00
|
|
|
toolBar->addAction(viewManager().componentViewAction());
|
2015-07-09 13:45:38 +02:00
|
|
|
toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
2017-01-05 17:44:10 +01:00
|
|
|
DesignerActionToolBar *designerToolBar = QmlDesignerPlugin::instance()->viewManager().designerActionManager().createToolBar(m_toolBar);
|
|
|
|
|
|
|
|
|
|
designerToolBar->layout()->addWidget(toolBar);
|
|
|
|
|
|
|
|
|
|
m_toolBar->addCenterToolBar(designerToolBar);
|
|
|
|
|
|
|
|
|
|
m_toolBar->setMinimumWidth(320);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
m_mainSplitter = new MiniSplitter(this);
|
|
|
|
|
m_mainSplitter->setObjectName("mainSplitter");
|
|
|
|
|
|
2013-03-07 17:04:11 +01:00
|
|
|
QList<Core::SideBarItem*> sideBarItems;
|
|
|
|
|
QList<Core::SideBarItem*> leftSideBarItems;
|
|
|
|
|
QList<Core::SideBarItem*> rightSideBarItems;
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2013-03-07 17:04:11 +01:00
|
|
|
foreach (const WidgetInfo &widgetInfo, viewManager().widgetInfos()) {
|
|
|
|
|
if (widgetInfo.placementHint == widgetInfo.LeftPane) {
|
2013-03-21 12:51:39 +01:00
|
|
|
Core::SideBarItem *sideBarItem = new DesignerSideBarItem(widgetInfo.widget, widgetInfo.toolBarWidgetFactory, widgetInfo.uniqueId);
|
2013-03-07 17:04:11 +01:00
|
|
|
sideBarItems.append(sideBarItem);
|
|
|
|
|
leftSideBarItems.append(sideBarItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (widgetInfo.placementHint == widgetInfo.RightPane) {
|
2013-03-21 12:51:39 +01:00
|
|
|
Core::SideBarItem *sideBarItem = new DesignerSideBarItem(widgetInfo.widget, widgetInfo.toolBarWidgetFactory, widgetInfo.uniqueId);
|
2013-03-07 17:04:11 +01:00
|
|
|
sideBarItems.append(sideBarItem);
|
|
|
|
|
rightSideBarItems.append(sideBarItem);
|
2015-07-17 19:09:28 +02:00
|
|
|
|
2013-03-07 17:04:11 +01:00
|
|
|
}
|
2015-07-17 19:09:28 +02:00
|
|
|
m_viewWidgets.append(widgetInfo.widget);
|
2013-03-07 17:04:11 +01:00
|
|
|
}
|
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));
|
2013-03-07 17:04:11 +01:00
|
|
|
sideBarItems.append(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));
|
2013-03-07 17:04:11 +01:00
|
|
|
sideBarItems.append(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));
|
2013-03-07 17:04:11 +01:00
|
|
|
sideBarItems.append(openDocumentsItem);
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-07 17:04:11 +01:00
|
|
|
m_leftSideBar.reset(new Core::SideBar(sideBarItems, leftSideBarItems));
|
|
|
|
|
m_rightSideBar.reset(new Core::SideBar(sideBarItems, rightSideBarItems));
|
2010-04-26 08:42:41 +02:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
connect(m_leftSideBar.data(), &Core::SideBar::availableItemsChanged, [=](){
|
|
|
|
|
// event comes from m_leftSidebar, so update right side.
|
|
|
|
|
m_rightSideBar->setUnavailableItemIds(m_leftSideBar->unavailableItemIds());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_rightSideBar.data(), &Core::SideBar::availableItemsChanged, [=](){
|
|
|
|
|
// event comes from m_rightSidebar, so update left side.
|
|
|
|
|
m_leftSideBar->setUnavailableItemIds(m_rightSideBar->unavailableItemIds());
|
|
|
|
|
});
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose, [=](){
|
|
|
|
|
m_leftSideBar.reset();
|
|
|
|
|
m_rightSideBar.reset();
|
|
|
|
|
});
|
2010-12-03 13:51:54 +01:00
|
|
|
|
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
|
|
|
|
2015-01-30 10:19:13 +01:00
|
|
|
connect(m_toolBar, &Core::EditorToolBar::goForwardClicked, this, &DesignModeWidget::toolBarOnGoForwardClicked);
|
|
|
|
|
connect(m_toolBar, &Core::EditorToolBar::goBackClicked, this, &DesignModeWidget::toolBarOnGoBackClicked);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
if (currentDesignDocument())
|
|
|
|
|
setupNavigatorHistory(currentDesignDocument()->textEditor());
|
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());
|
2013-03-07 17:04:11 +01:00
|
|
|
m_mainSplitter->addWidget(createCenterWidget());
|
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);
|
2017-04-26 14:32:02 +02:00
|
|
|
m_mainSplitter->setSizes({150, 300, 150});
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
QLayout *mainLayout = new QBoxLayout(QBoxLayout::RightToLeft, this);
|
|
|
|
|
mainLayout->setMargin(0);
|
|
|
|
|
mainLayout->setSpacing(0);
|
|
|
|
|
mainLayout->addWidget(m_mainSplitter);
|
|
|
|
|
|
2013-03-07 17:04:11 +01:00
|
|
|
viewManager().enableWidgets();
|
2010-03-23 14:01:25 +01:00
|
|
|
m_leftSideBar->setEnabled(true);
|
|
|
|
|
m_rightSideBar->setEnabled(true);
|
2014-07-01 20:11:59 +02:00
|
|
|
m_leftSideBar->setCloseWhenEmpty(false);
|
|
|
|
|
m_rightSideBar->setCloseWhenEmpty(false);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
|
|
|
|
readSettings();
|
|
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2013-05-31 12:52:53 +02:00
|
|
|
Core::EditorManager::openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter),
|
|
|
|
|
Core::Id(), Core::EditorManager::DoNotMakeVisible);
|
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;
|
2013-05-31 12:52:53 +02:00
|
|
|
Core::EditorManager::openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter),
|
|
|
|
|
Core::Id(), Core::EditorManager::DoNotMakeVisible);
|
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
|
|
|
}
|
|
|
|
|
|
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)
|
2016-10-07 14:16:49 +02:00
|
|
|
addNavigatorHistoryEntry(editor->document()->filePath());
|
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
|
|
|
}
|
|
|
|
|
|
2016-10-07 14:16:49 +02:00
|
|
|
void DesignModeWidget::addNavigatorHistoryEntry(const Utils::FileName &fileName)
|
2011-06-20 16:33:10 +02:00
|
|
|
{
|
|
|
|
|
if (m_navigatorHistoryCounter > 0)
|
2016-10-07 14:16:49 +02:00
|
|
|
m_navigatorHistory.insert(m_navigatorHistoryCounter + 1, fileName.toString());
|
2011-06-20 16:33:10 +02:00
|
|
|
else
|
2016-10-07 14:16:49 +02:00
|
|
|
m_navigatorHistory.append(fileName.toString());
|
2011-06-20 16:33:10 +02:00
|
|
|
|
|
|
|
|
++m_navigatorHistoryCounter;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 11:12:03 +02:00
|
|
|
static QTabWidget *createWidgetsInTabWidget(const QList<WidgetInfo> &widgetInfos)
|
2013-03-07 17:04:11 +01:00
|
|
|
{
|
2018-07-24 23:56:45 +02:00
|
|
|
auto tabWidget = new QTabWidget;
|
2013-03-07 17:04:11 +01:00
|
|
|
|
|
|
|
|
foreach (const WidgetInfo &widgetInfo, widgetInfos)
|
|
|
|
|
tabWidget->addTab(widgetInfo.widget, widgetInfo.tabName);
|
|
|
|
|
|
|
|
|
|
return tabWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 17:49:40 +01:00
|
|
|
static QWidget *createbottomSideBarWidget(const QList<WidgetInfo> &widgetInfos)
|
2013-02-04 18:49:03 +01:00
|
|
|
{
|
|
|
|
|
//### we now own these here
|
2013-03-07 17:04:11 +01:00
|
|
|
QList<WidgetInfo> topWidgetInfos;
|
2014-03-19 17:18:30 +01:00
|
|
|
foreach (const WidgetInfo &widgetInfo, widgetInfos) {
|
2017-01-12 17:49:40 +01:00
|
|
|
if (widgetInfo.placementHint == widgetInfo.BottomPane)
|
2013-03-07 17:04:11 +01:00
|
|
|
topWidgetInfos.append(widgetInfo);
|
|
|
|
|
}
|
2013-02-04 18:49:03 +01:00
|
|
|
|
2018-01-13 18:49:39 +01:00
|
|
|
QWidget *widget = topWidgetInfos.constFirst().widget;
|
2017-11-07 14:34:08 +01:00
|
|
|
if (topWidgetInfos.count() > 1) {
|
|
|
|
|
QWidget *background = new QWidget();
|
|
|
|
|
background->setProperty("designerBackgroundColor", true);
|
|
|
|
|
|
|
|
|
|
QString sheet = QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"));
|
2018-04-10 10:42:43 +02:00
|
|
|
sheet.prepend("QWidget[designerBackgroundColor=\"true\"] {background-color: creatorTheme.QmlDesigner_BackgroundColorDarkAlternate;}");
|
2017-11-07 14:34:08 +01:00
|
|
|
|
|
|
|
|
background->setStyleSheet(Theme::replaceCssColors(sheet));
|
|
|
|
|
background->setLayout(new QVBoxLayout);
|
|
|
|
|
background->layout()->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
background->layout()->addWidget(createWidgetsInTabWidget(topWidgetInfos));
|
|
|
|
|
widget = background;
|
|
|
|
|
}
|
|
|
|
|
return widget;
|
2014-03-14 17:33:58 +01:00
|
|
|
}
|
2013-02-04 18:49:03 +01:00
|
|
|
|
2014-03-19 17:18:30 +01:00
|
|
|
static Core::MiniSplitter *createCentralSplitter(const QList<WidgetInfo> &widgetInfos)
|
2014-03-14 17:33:58 +01:00
|
|
|
{
|
2013-02-04 18:49:03 +01:00
|
|
|
// editor and output panes
|
2018-07-24 23:56:45 +02:00
|
|
|
auto outputPlaceholderSplitter = new Core::MiniSplitter;
|
2014-03-14 17:33:58 +01:00
|
|
|
outputPlaceholderSplitter->setOrientation(Qt::Vertical);
|
|
|
|
|
|
2018-07-24 23:56:45 +02:00
|
|
|
auto switchSplitTabWidget = new SwitchSplitTabWidget();
|
2017-02-06 10:46:52 +01:00
|
|
|
|
|
|
|
|
foreach (const WidgetInfo &widgetInfo, widgetInfos) {
|
|
|
|
|
if (widgetInfo.placementHint == widgetInfo.CentralPane)
|
|
|
|
|
switchSplitTabWidget->addTab(widgetInfo.widget, widgetInfo.tabName);
|
|
|
|
|
}
|
2016-10-26 15:33:06 +02:00
|
|
|
|
2017-02-06 10:46:52 +01:00
|
|
|
outputPlaceholderSplitter->addWidget(switchSplitTabWidget);
|
2017-01-23 17:36:58 +01:00
|
|
|
|
|
|
|
|
QWidget *bottomSideBar = createbottomSideBarWidget(widgetInfos);
|
|
|
|
|
bottomSideBar->setObjectName("bottomSideBar");
|
|
|
|
|
outputPlaceholderSplitter->addWidget(bottomSideBar);
|
|
|
|
|
|
|
|
|
|
auto outputPanePlaceholder = new Core::OutputPanePlaceHolder(Core::Constants::MODE_DESIGN, outputPlaceholderSplitter);
|
2014-03-14 17:33:58 +01:00
|
|
|
outputPlaceholderSplitter->addWidget(outputPanePlaceholder);
|
|
|
|
|
|
2018-04-11 10:41:06 +02:00
|
|
|
outputPlaceholderSplitter->setStretchFactor(0, 10);
|
|
|
|
|
outputPlaceholderSplitter->setStretchFactor(1, 1);
|
2014-03-14 17:33:58 +01:00
|
|
|
return outputPlaceholderSplitter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *DesignModeWidget::createCenterWidget()
|
|
|
|
|
{
|
|
|
|
|
QWidget *centerWidget = new QWidget;
|
|
|
|
|
|
2018-07-24 23:56:45 +02:00
|
|
|
auto horizontalLayout = new QVBoxLayout(centerWidget);
|
2014-03-14 17:33:58 +01:00
|
|
|
horizontalLayout->setMargin(0);
|
|
|
|
|
horizontalLayout->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
horizontalLayout->addWidget(m_toolBar);
|
|
|
|
|
horizontalLayout->addWidget(createCrumbleBarFrame());
|
2013-03-07 17:04:11 +01:00
|
|
|
|
2016-11-18 16:06:09 +01:00
|
|
|
Core::MiniSplitter *centralSplitter = createCentralSplitter(viewManager().widgetInfos());
|
2017-02-06 10:46:52 +01:00
|
|
|
m_centralTabWidget = centralSplitter->findChild<SwitchSplitTabWidget*>();
|
2016-11-18 16:06:09 +01:00
|
|
|
Q_ASSERT(m_centralTabWidget);
|
2017-02-06 10:46:52 +01:00
|
|
|
m_centralTabWidget->switchTo(viewManager().widget("FormEditor"));
|
|
|
|
|
|
2017-01-23 17:36:58 +01:00
|
|
|
m_bottomSideBar = centralSplitter->findChild<QWidget*>("bottomSideBar");
|
|
|
|
|
Q_ASSERT(m_bottomSideBar);
|
2016-11-18 16:06:09 +01:00
|
|
|
horizontalLayout->addWidget(centralSplitter);
|
2013-02-04 18:49:03 +01:00
|
|
|
|
|
|
|
|
return centerWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 12:39:26 +02:00
|
|
|
QWidget *DesignModeWidget::createCrumbleBarFrame()
|
|
|
|
|
{
|
2018-07-24 23:56:45 +02:00
|
|
|
auto frame = new Utils::StyledBar(this);
|
2017-11-10 23:46:07 +01:00
|
|
|
frame->setSingleRow(false);
|
2018-07-24 23:56:45 +02:00
|
|
|
auto layout = new QHBoxLayout(frame);
|
2013-08-05 12:39:26 +02:00
|
|
|
layout->setMargin(0);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
layout->addWidget(m_crumbleBar->crumblePath());
|
|
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CrumbleBar *DesignModeWidget::crumbleBar() const
|
|
|
|
|
{
|
|
|
|
|
return m_crumbleBar;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 10:46:52 +01:00
|
|
|
void DesignModeWidget::showInternalTextEditor()
|
2016-11-18 16:06:09 +01:00
|
|
|
{
|
2017-02-06 10:46:52 +01:00
|
|
|
m_centralTabWidget->switchTo(viewManager().widget("TextEditor"));
|
2016-11-18 16:06:09 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-17 16:06:13 +01:00
|
|
|
void DesignModeWidget::contextHelpId(const Core::IContext::HelpIdCallback &callback) const
|
2010-03-08 09:47:45 +01:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
if (currentDesignDocument())
|
2018-01-17 16:06:13 +01:00
|
|
|
currentDesignDocument()->contextHelpId(callback);
|
|
|
|
|
else
|
|
|
|
|
callback(QString());
|
2010-03-08 09:47:45 +01:00
|
|
|
}
|
|
|
|
|
|
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
|