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"
|
2020-02-11 11:33:25 +02:00
|
|
|
#include "edit3dview.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
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager_p.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <qmldesigner/qmldesignerconstants.h>
|
|
|
|
|
|
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>
|
2020-01-24 17:14:05 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
|
|
#include <advanceddockingsystem/dockareawidget.h>
|
|
|
|
|
#include <advanceddockingsystem/docksplitter.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
using Core::MiniSplitter;
|
|
|
|
|
using Core::IEditor;
|
|
|
|
|
using Core::EditorManager;
|
|
|
|
|
|
|
|
|
|
using namespace QmlDesigner;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
debug = false
|
|
|
|
|
};
|
|
|
|
|
|
2018-02-01 10:25:07 +01:00
|
|
|
static void hideToolButtons(QList<QToolButton*> &buttons)
|
|
|
|
|
{
|
2020-01-24 17:14:05 +01:00
|
|
|
for (QToolButton *button : buttons)
|
2018-02-01 10:25:07 +01:00
|
|
|
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()
|
|
|
|
|
{
|
2020-01-24 17:14:05 +01:00
|
|
|
for (QPointer<QWidget> widget : m_viewWidgets) {
|
2015-07-17 19:09:28 +02:00
|
|
|
if (widget)
|
|
|
|
|
widget.clear();
|
|
|
|
|
}
|
2013-02-06 17:12:04 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
delete m_dockManager;
|
2010-04-26 13:53:26 +02:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
for (Core::INavigationWidgetFactory *factory : factories) {
|
2018-02-01 10:25:07 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
void DesignModeWidget::readSettings() // readPerspectives
|
2010-03-23 14:01:25 +01:00
|
|
|
{
|
2020-01-24 17:14:05 +01:00
|
|
|
return;
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
void DesignModeWidget::saveSettings() // savePerspectives
|
2010-03-23 14:01:25 +01:00
|
|
|
{
|
2020-01-24 17:14:05 +01:00
|
|
|
return;
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
bool DesignModeWidget::eventFilter(QObject *obj, QEvent *event) // TODO
|
2016-12-22 11:07:09 +01:00
|
|
|
{
|
2020-01-24 17:14:05 +01:00
|
|
|
if (event->type() == QEvent::Hide) {
|
|
|
|
|
qDebug() << ">>> HIDE";
|
|
|
|
|
m_outputPaneDockWidget->toggleView(false);
|
|
|
|
|
return true;
|
|
|
|
|
} else if (event->type() == QEvent::Show) {
|
|
|
|
|
qDebug() << ">>> SHOW";
|
|
|
|
|
m_outputPaneDockWidget->toggleView(true);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
// standard event processing
|
|
|
|
|
return QObject::eventFilter(obj, event);
|
|
|
|
|
}
|
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
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
m_dockManager = new ADS::DockManager(this);
|
|
|
|
|
m_dockManager->setConfigFlags(ADS::DockManager::DefaultNonOpaqueConfig);
|
|
|
|
|
m_dockManager->setSettings(Core::ICore::settings(QSettings::UserScope));
|
|
|
|
|
|
|
|
|
|
QString sheet = QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/dockwidgets.css"));
|
|
|
|
|
m_dockManager->setStyleSheet(Theme::replaceCssColors(sheet));
|
|
|
|
|
|
|
|
|
|
// Setup Actions and Menus
|
|
|
|
|
Core::ActionContainer *mwindow = Core::ActionManager::actionContainer(Core::Constants::M_WINDOW);
|
|
|
|
|
// Window > Views
|
|
|
|
|
Core::ActionContainer *mviews = Core::ActionManager::createMenu(Core::Constants::M_WINDOW_VIEWS);
|
|
|
|
|
mviews->menu()->addSeparator();
|
|
|
|
|
// Window > Workspaces
|
|
|
|
|
Core::ActionContainer *mworkspaces = Core::ActionManager::createMenu(QmlDesigner::Constants::M_WINDOW_WORKSPACES);
|
|
|
|
|
mwindow->addMenu(mworkspaces, Core::Constants::G_WINDOW_VIEWS);
|
|
|
|
|
mworkspaces->menu()->setTitle(tr("&Workspaces"));
|
|
|
|
|
mworkspaces->setOnAllDisabledBehavior(Core::ActionContainer::Show); // TODO what does it exactly do?!
|
|
|
|
|
|
|
|
|
|
// Connect opening of the 'window' menu with creation of the workspaces menu
|
|
|
|
|
connect(mwindow->menu(), &QMenu::aboutToShow, this, &DesignModeWidget::aboutToShowWorkspaces);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Create a DockWidget for each QWidget and add them to the DockManager
|
|
|
|
|
const Core::Context designContext(Core::Constants::C_DESIGN_MODE);
|
|
|
|
|
static const Core::Id actionToggle("QmlDesigner.Toggle");
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// First get all navigation views
|
|
|
|
|
QList<Core::INavigationWidgetFactory *> factories = Core::INavigationWidgetFactory::allNavigationFactories();
|
|
|
|
|
|
|
|
|
|
for (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;
|
2020-01-24 17:14:05 +01:00
|
|
|
QString uniqueId;
|
|
|
|
|
QString title;
|
|
|
|
|
|
2012-08-03 15:24:33 +02:00
|
|
|
if (factory->id() == "Projects") {
|
2010-03-23 14:01:25 +01:00
|
|
|
navigationView = factory->createWidget();
|
2014-03-31 16:15:14 +02:00
|
|
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
2020-01-24 17:14:05 +01:00
|
|
|
navigationView.widget->setWindowTitle(tr(factory->id().name()));
|
|
|
|
|
uniqueId = "Projects";
|
|
|
|
|
title = "Projects";
|
|
|
|
|
}
|
|
|
|
|
if (factory->id() == "File System") {
|
2010-03-23 14:01:25 +01:00
|
|
|
navigationView = factory->createWidget();
|
2014-03-31 16:15:14 +02:00
|
|
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
2020-01-24 17:14:05 +01:00
|
|
|
navigationView.widget->setWindowTitle(tr(factory->id().name()));
|
|
|
|
|
uniqueId = "FileSystem";
|
|
|
|
|
title = "File System";
|
|
|
|
|
}
|
|
|
|
|
if (factory->id() == "Open Documents") {
|
2010-03-23 14:01:25 +01:00
|
|
|
navigationView = factory->createWidget();
|
2014-03-31 16:15:14 +02:00
|
|
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
2020-01-24 17:14:05 +01:00
|
|
|
navigationView.widget->setWindowTitle(tr(factory->id().name()));
|
|
|
|
|
uniqueId = "OpenDocuments";
|
|
|
|
|
title = "Open Documents";
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-20 13:49:26 +02:00
|
|
|
if (navigationView.widget) {
|
2020-01-24 17:14:05 +01:00
|
|
|
// Apply stylesheet to QWidget
|
2011-04-20 13:49:26 +02:00
|
|
|
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)));
|
2020-01-24 17:14:05 +01:00
|
|
|
|
|
|
|
|
// Create DockWidget
|
|
|
|
|
ADS::DockWidget *dockWidget = new ADS::DockWidget(uniqueId);
|
|
|
|
|
dockWidget->setWidget(navigationView.widget);
|
|
|
|
|
dockWidget->setWindowTitle(title);
|
|
|
|
|
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, dockWidget);
|
|
|
|
|
|
|
|
|
|
// Create menu action
|
|
|
|
|
auto command = Core::ActionManager::registerAction(dockWidget->toggleViewAction(),
|
|
|
|
|
actionToggle.withSuffix(uniqueId + "Widget"),
|
|
|
|
|
designContext);
|
|
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
|
mviews->addAction(command);
|
2011-04-20 13:49:26 +02:00
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Afterwards get all the other widgets
|
|
|
|
|
for (const WidgetInfo &widgetInfo : viewManager().widgetInfos()) {
|
|
|
|
|
// Create DockWidget
|
|
|
|
|
ADS::DockWidget *dockWidget = new ADS::DockWidget(widgetInfo.uniqueId);
|
|
|
|
|
dockWidget->setWidget(widgetInfo.widget);
|
|
|
|
|
dockWidget->setWindowTitle(widgetInfo.tabName);
|
|
|
|
|
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, dockWidget);
|
|
|
|
|
|
|
|
|
|
// Add to view widgets
|
|
|
|
|
m_viewWidgets.append(widgetInfo.widget);
|
|
|
|
|
|
|
|
|
|
// Create menu action
|
|
|
|
|
auto command = Core::ActionManager::registerAction(dockWidget->toggleViewAction(),
|
|
|
|
|
actionToggle.withSuffix(widgetInfo.uniqueId + "Widget"),
|
|
|
|
|
designContext);
|
|
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
|
mviews->addAction(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally the output pane
|
|
|
|
|
{
|
|
|
|
|
auto outputPanePlaceholder = new Core::OutputPanePlaceHolder(Core::Constants::MODE_DESIGN);
|
|
|
|
|
m_outputPaneDockWidget = new ADS::DockWidget("OutputPane");
|
|
|
|
|
m_outputPaneDockWidget->setWidget(outputPanePlaceholder);
|
|
|
|
|
m_outputPaneDockWidget->setWindowTitle("Output Pane");
|
|
|
|
|
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, m_outputPaneDockWidget);
|
|
|
|
|
// Create menu action
|
|
|
|
|
auto command = Core::ActionManager::registerAction(m_outputPaneDockWidget->toggleViewAction(),
|
|
|
|
|
actionToggle.withSuffix("OutputPaneWidget"),
|
|
|
|
|
designContext);
|
|
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
|
mviews->addAction(command);
|
|
|
|
|
|
|
|
|
|
//outputPanePlaceholder->installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create toolbars
|
|
|
|
|
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);
|
2020-01-24 17:14:05 +01:00
|
|
|
m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
|
|
|
|
m_toolBar->setNavigationVisible(true);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
connect(m_toolBar, &Core::EditorToolBar::goForwardClicked, this, &DesignModeWidget::toolBarOnGoForwardClicked);
|
|
|
|
|
connect(m_toolBar, &Core::EditorToolBar::goBackClicked, this, &DesignModeWidget::toolBarOnGoBackClicked);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
QToolBar* toolBarWrapper = new QToolBar();
|
|
|
|
|
toolBarWrapper->addWidget(m_toolBar);
|
|
|
|
|
toolBarWrapper->addWidget(createCrumbleBarFrame());
|
|
|
|
|
toolBarWrapper->setMovable(false);
|
|
|
|
|
addToolBar(Qt::TopToolBarArea, toolBarWrapper);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
if (currentDesignDocument())
|
|
|
|
|
setupNavigatorHistory(currentDesignDocument()->textEditor());
|
2013-03-07 17:04:11 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Get a list of all available workspaces
|
|
|
|
|
QStringList workspaces = m_dockManager->workspaces();
|
|
|
|
|
QString workspace = ADS::Constants::FACTORY_DEFAULT_NAME;
|
2015-07-17 19:09:28 +02:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// If there is no factory default workspace create one and write the xml file
|
|
|
|
|
if (!workspaces.contains(ADS::Constants::FACTORY_DEFAULT_NAME)) {
|
|
|
|
|
createFactoryDefaultWorkspace();
|
|
|
|
|
// List of workspaces needs to be updated
|
|
|
|
|
workspaces = m_dockManager->workspaces();
|
2013-03-07 17:04:11 +01:00
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Determine workspace to restore at startup
|
|
|
|
|
if (m_dockManager->autoRestorLastWorkspace()) {
|
|
|
|
|
QString lastWorkspace = m_dockManager->lastWorkspace();
|
|
|
|
|
if (!lastWorkspace.isEmpty() && workspaces.contains(lastWorkspace))
|
|
|
|
|
workspace = lastWorkspace;
|
|
|
|
|
else
|
|
|
|
|
qDebug() << "Couldn't restore last workspace!";
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
if (workspace.isNull() && workspaces.contains(ADS::Constants::DEFAULT_NAME)) {
|
|
|
|
|
workspace = ADS::Constants::DEFAULT_NAME;
|
2010-03-23 14:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
m_dockManager->openWorkspace(workspace);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
viewManager().enableWidgets();
|
|
|
|
|
readSettings();
|
|
|
|
|
show();
|
|
|
|
|
}
|
2010-04-26 08:42:41 +02:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
void DesignModeWidget::aboutToShowWorkspaces()
|
|
|
|
|
{
|
|
|
|
|
Core::ActionContainer *aci = Core::ActionManager::actionContainer(QmlDesigner::Constants::M_WINDOW_WORKSPACES);
|
|
|
|
|
QMenu *menu = aci->menu();
|
|
|
|
|
menu->clear();
|
2016-04-26 16:00:08 +02:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
auto *ag = new QActionGroup(menu);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
connect(ag, &QActionGroup::triggered, this, [this](QAction *action) {
|
|
|
|
|
QString workspace = action->data().toString();
|
|
|
|
|
m_dockManager->openWorkspace(workspace);
|
2016-04-26 16:00:08 +02:00
|
|
|
});
|
2010-12-03 13:51:54 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
QAction *action = menu->addAction("Manage...");
|
|
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
m_dockManager, &ADS::DockManager::showWorkspaceMananger);
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
menu->addSeparator();
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
for (const auto &workspace : m_dockManager->workspaces())
|
|
|
|
|
{
|
|
|
|
|
QAction *action = ag->addAction(workspace);
|
|
|
|
|
action->setData(workspace);
|
|
|
|
|
action->setCheckable(true);
|
|
|
|
|
if (workspace == m_dockManager->activeWorkspace())
|
|
|
|
|
action->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
menu->addActions(ag->actions());
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
void DesignModeWidget::createFactoryDefaultWorkspace()
|
|
|
|
|
{
|
|
|
|
|
ADS::DockAreaWidget* centerArea = nullptr;
|
|
|
|
|
ADS::DockAreaWidget* leftArea = nullptr;
|
|
|
|
|
ADS::DockAreaWidget* rightArea = nullptr;
|
|
|
|
|
ADS::DockAreaWidget* bottomArea = nullptr;
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Iterate over all widgets and only get the central once to start with creating the factory
|
|
|
|
|
// default workspace layout.
|
|
|
|
|
for (const WidgetInfo &widgetInfo : viewManager().widgetInfos()) {
|
|
|
|
|
if (widgetInfo.placementHint == widgetInfo.CentralPane) {
|
|
|
|
|
ADS::DockWidget *dockWidget = m_dockManager->findDockWidget(widgetInfo.uniqueId);
|
|
|
|
|
if (centerArea)
|
|
|
|
|
m_dockManager->addDockWidget(ADS::CenterDockWidgetArea, dockWidget, centerArea);
|
|
|
|
|
else
|
|
|
|
|
centerArea = m_dockManager->addDockWidget(ADS::CenterDockWidgetArea, dockWidget);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Iterate over all widgets and get the remaining left, right and bottom widgets
|
|
|
|
|
for (const WidgetInfo &widgetInfo : viewManager().widgetInfos()) {
|
|
|
|
|
if (widgetInfo.placementHint == widgetInfo.LeftPane) {
|
|
|
|
|
ADS::DockWidget *dockWidget = m_dockManager->findDockWidget(widgetInfo.uniqueId);
|
|
|
|
|
if (leftArea)
|
|
|
|
|
m_dockManager->addDockWidget(ADS::CenterDockWidgetArea, dockWidget, leftArea);
|
|
|
|
|
else
|
|
|
|
|
leftArea = m_dockManager->addDockWidget(ADS::LeftDockWidgetArea, dockWidget, centerArea);
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
if (widgetInfo.placementHint == widgetInfo.RightPane) {
|
|
|
|
|
ADS::DockWidget *dockWidget = m_dockManager->findDockWidget(widgetInfo.uniqueId);
|
|
|
|
|
if (rightArea)
|
|
|
|
|
m_dockManager->addDockWidget(ADS::CenterDockWidgetArea, dockWidget, rightArea);
|
|
|
|
|
else
|
|
|
|
|
rightArea = m_dockManager->addDockWidget(ADS::RightDockWidgetArea, dockWidget, centerArea);
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
if (widgetInfo.placementHint == widgetInfo.BottomPane) {
|
|
|
|
|
ADS::DockWidget *dockWidget = m_dockManager->findDockWidget(widgetInfo.uniqueId);
|
|
|
|
|
if (bottomArea)
|
|
|
|
|
m_dockManager->addDockWidget(ADS::CenterDockWidgetArea, dockWidget, bottomArea);
|
|
|
|
|
else
|
|
|
|
|
bottomArea = m_dockManager->addDockWidget(ADS::BottomDockWidgetArea, dockWidget, centerArea);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Iterate over all 'special' widgets
|
|
|
|
|
QStringList specialWidgets = {"Projects", "FileSystem", "OpenDocuments"};
|
|
|
|
|
ADS::DockAreaWidget* leftBottomArea = nullptr;
|
|
|
|
|
for (const QString &uniqueId : specialWidgets) {
|
|
|
|
|
ADS::DockWidget *dockWidget = m_dockManager->findDockWidget(uniqueId);
|
|
|
|
|
if (leftBottomArea)
|
|
|
|
|
m_dockManager->addDockWidget(ADS::CenterDockWidgetArea, dockWidget, leftBottomArea);
|
|
|
|
|
else
|
|
|
|
|
leftBottomArea = m_dockManager->addDockWidget(ADS::BottomDockWidgetArea, dockWidget, leftArea);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the last widget 'OutputPane' as the bottom bottom area
|
|
|
|
|
ADS::DockWidget *dockWidget = m_dockManager->findDockWidget("OutputPane");
|
|
|
|
|
m_dockManager->addDockWidget(ADS::BottomDockWidgetArea, dockWidget, bottomArea);
|
|
|
|
|
|
|
|
|
|
// TODO This is just a test
|
|
|
|
|
auto splitter = centerArea->dockContainer()->rootSplitter();
|
|
|
|
|
splitter->setSizes({100, 800, 100});
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
m_dockManager->createWorkspace(ADS::Constants::FACTORY_DEFAULT_NAME);
|
|
|
|
|
|
|
|
|
|
// Write the xml file
|
|
|
|
|
Utils::FilePath fileName = m_dockManager->workspaceNameToFileName(ADS::Constants::FACTORY_DEFAULT_NAME);
|
|
|
|
|
QString errorString;
|
|
|
|
|
Utils::FileSaver fileSaver(fileName.toString(), QIODevice::Text);
|
|
|
|
|
QByteArray data = m_dockManager->saveState();
|
|
|
|
|
if (!fileSaver.hasError()) {
|
|
|
|
|
fileSaver.write(data);
|
|
|
|
|
}
|
|
|
|
|
if (!fileSaver.finalize()) {
|
|
|
|
|
errorString = fileSaver.errorString();
|
|
|
|
|
}
|
2010-03-23 14:01:25 +01: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;
|
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
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
void DesignModeWidget::addNavigatorHistoryEntry(const Utils::FilePath &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;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2019-08-29 10:36:01 +02:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2013-08-05 12:39:26 +02:00
|
|
|
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
|
|
|
{
|
2020-01-24 17:14:05 +01:00
|
|
|
auto dockWidget = m_dockManager->findDockWidget("TextEditor");
|
|
|
|
|
if (dockWidget)
|
|
|
|
|
dockWidget->toggleView(true);
|
2016-11-18 16:06:09 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-28 11:58:53 +01:00
|
|
|
void DesignModeWidget::contextHelp(const Core::IContext::HelpCallback &callback) const
|
2010-03-08 09:47:45 +01:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
if (currentDesignDocument())
|
2019-01-28 11:58:53 +01:00
|
|
|
currentDesignDocument()->contextHelp(callback);
|
2018-01-17 16:06:13 +01:00
|
|
|
else
|
2019-01-28 13:00:03 +01:00
|
|
|
callback({});
|
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
|