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"
|
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>
|
2020-03-09 08:30:17 +01:00
|
|
|
#include <coreplugin/modemanager.h>
|
2020-01-24 17:14:05 +01:00
|
|
|
#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
|
|
|
|
2020-03-02 15:13:20 +01:00
|
|
|
#include <utils/algorithm.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2016-07-18 14:51:13 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2020-04-20 09:34:38 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2020-09-18 10:54:22 +02:00
|
|
|
#include <QActionGroup>
|
2016-04-29 12:05:33 +02:00
|
|
|
#include <QBoxLayout>
|
2020-03-13 14:58:59 +01:00
|
|
|
#include <QComboBox>
|
2020-09-18 10:54:22 +02:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QLayout>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QToolBar>
|
2020-01-24 17:14:05 +01:00
|
|
|
|
|
|
|
|
#include <advanceddockingsystem/dockareawidget.h>
|
|
|
|
|
#include <advanceddockingsystem/docksplitter.h>
|
2020-04-20 09:34:38 +02:00
|
|
|
#include <advanceddockingsystem/iconprovider.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();
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2021-02-17 17:12:22 +01:00
|
|
|
for (QPointer<QWidget> widget : qAsConst(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-04-30 17:45:48 +02:00
|
|
|
static void addSpacerToToolBar(QToolBar *toolBar)
|
|
|
|
|
{
|
|
|
|
|
QWidget* empty = new QWidget();
|
2021-03-02 13:35:07 +01:00
|
|
|
empty->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2020-04-30 17:45:48 +02:00
|
|
|
toolBar->addWidget(empty);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 14:01:25 +01:00
|
|
|
void DesignModeWidget::setup()
|
|
|
|
|
{
|
2020-03-02 15:13:20 +01:00
|
|
|
auto settings = Core::ICore::settings(QSettings::UserScope);
|
|
|
|
|
|
2020-06-22 16:46:25 +02:00
|
|
|
ADS::DockManager::setConfigFlags(ADS::DockManager::DefaultNonOpaqueConfig);
|
|
|
|
|
ADS::DockManager::setConfigFlag(ADS::DockManager::FocusHighlighting, true);
|
2022-01-17 15:00:07 +02:00
|
|
|
ADS::DockManager::setConfigFlag(ADS::DockManager::DockAreaHasCloseButton, false);
|
|
|
|
|
ADS::DockManager::setConfigFlag(ADS::DockManager::DockAreaHasUndockButton, false);
|
|
|
|
|
ADS::DockManager::setConfigFlag(ADS::DockManager::DockAreaHasTabsMenuButton, false);
|
2021-12-08 13:44:02 +02:00
|
|
|
ADS::DockManager::setConfigFlag(ADS::DockManager::OpaqueSplitterResize, true);
|
2021-03-02 13:35:07 +01:00
|
|
|
ADS::DockManager::setConfigFlag(ADS::DockManager::AllTabsHaveCloseButton, true);
|
2020-01-24 17:14:05 +01:00
|
|
|
m_dockManager = new ADS::DockManager(this);
|
2020-03-02 15:13:20 +01:00
|
|
|
m_dockManager->setSettings(settings);
|
2021-04-22 16:15:26 +02:00
|
|
|
m_dockManager->setWorkspacePresetsPath(
|
2021-04-26 15:46:09 +02:00
|
|
|
Core::ICore::resourcePath("qmldesigner/workspacePresets/").toString());
|
2020-01-24 17:14:05 +01:00
|
|
|
|
|
|
|
|
QString sheet = QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/dockwidgets.css"));
|
|
|
|
|
m_dockManager->setStyleSheet(Theme::replaceCssColors(sheet));
|
|
|
|
|
|
2020-04-20 09:34:38 +02:00
|
|
|
// Setup icons
|
|
|
|
|
const QString closeUnicode = Theme::getIconUnicode(Theme::Icon::adsClose);
|
|
|
|
|
|
|
|
|
|
const QString fontName = "qtds_propertyIconFont.ttf";
|
2021-03-02 13:35:07 +01:00
|
|
|
const QSize size = QSize(28, 28);
|
2020-04-20 09:34:38 +02:00
|
|
|
|
2021-03-02 13:35:07 +01:00
|
|
|
auto tabCloseIconNormal = Utils::StyleHelper::IconFontHelper(
|
|
|
|
|
closeUnicode, Theme::getColor(Theme::DStabInactiveIcon), size, QIcon::Normal, QIcon::Off);
|
|
|
|
|
auto tabCloseIconActive = Utils::StyleHelper::IconFontHelper(
|
|
|
|
|
closeUnicode, Theme::getColor(Theme::DStabActiveIcon), size, QIcon::Active, QIcon::Off);
|
|
|
|
|
auto tabCloseIconFocus = Utils::StyleHelper::IconFontHelper(
|
|
|
|
|
closeUnicode, Theme::getColor(Theme::DStabFocusIcon), size, QIcon::Selected, QIcon::Off);
|
2020-07-13 17:24:49 +02:00
|
|
|
|
2021-03-02 13:35:07 +01:00
|
|
|
const QIcon tabsCloseIcon = Utils::StyleHelper::getIconFromIconFont(
|
|
|
|
|
fontName, {tabCloseIconNormal,
|
|
|
|
|
tabCloseIconActive,
|
|
|
|
|
tabCloseIconFocus});
|
2020-07-13 17:24:49 +02:00
|
|
|
|
2020-11-18 22:42:51 +01:00
|
|
|
ADS::DockManager::iconProvider().registerCustomIcon(ADS::TabCloseIcon, tabsCloseIcon);
|
2020-04-20 09:34:38 +02:00
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Setup Actions and Menus
|
2020-03-11 07:29:47 +01:00
|
|
|
Core::ActionContainer *mview = Core::ActionManager::actionContainer(Core::Constants::M_VIEW);
|
2020-10-28 09:27:26 +01:00
|
|
|
// View > Views
|
2020-03-04 10:44:07 +01:00
|
|
|
Core::ActionContainer *mviews = Core::ActionManager::createMenu(Core::Constants::M_VIEW_VIEWS);
|
2020-01-24 17:14:05 +01:00
|
|
|
mviews->menu()->addSeparator();
|
2020-10-28 09:27:26 +01:00
|
|
|
// View > Workspaces
|
|
|
|
|
Core::ActionContainer *mworkspaces = Core::ActionManager::createMenu(QmlDesigner::Constants::M_VIEW_WORKSPACES);
|
2020-03-11 07:29:47 +01:00
|
|
|
mview->addMenu(mworkspaces, Core::Constants::G_VIEW_VIEWS);
|
2020-01-24 17:14:05 +01:00
|
|
|
mworkspaces->menu()->setTitle(tr("&Workspaces"));
|
2020-03-06 10:57:43 +01:00
|
|
|
mworkspaces->setOnAllDisabledBehavior(Core::ActionContainer::Show);
|
|
|
|
|
// Connect opening of the 'workspaces' menu with creation of the workspaces menu
|
|
|
|
|
connect(mworkspaces->menu(), &QMenu::aboutToShow, this, &DesignModeWidget::aboutToShowWorkspaces);
|
|
|
|
|
// Disable workspace menu when context is different to C_DESIGN_MODE
|
|
|
|
|
connect(Core::ICore::instance(), &Core::ICore::contextChanged,
|
|
|
|
|
this, [mworkspaces](const Core::Context &context){
|
|
|
|
|
if (context.contains(Core::Constants::C_DESIGN_MODE))
|
|
|
|
|
mworkspaces->menu()->setEnabled(true);
|
|
|
|
|
else
|
|
|
|
|
mworkspaces->menu()->setEnabled(false);
|
|
|
|
|
});
|
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);
|
2020-09-21 13:30:57 +02:00
|
|
|
static const Utils::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");
|
2020-04-16 17:30:34 +02:00
|
|
|
sheet += "QLabel { background-color: creatorTheme.DSsectionHeadBackground; }";
|
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);
|
|
|
|
|
|
2020-07-01 10:51:26 +02:00
|
|
|
// Set unique id as object name
|
|
|
|
|
navigationView.widget->setObjectName(uniqueId);
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// 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);
|
|
|
|
|
|
2020-07-01 10:51:26 +02:00
|
|
|
// Set unique id as object name
|
|
|
|
|
widgetInfo.widget->setObjectName(widgetInfo.uniqueId);
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// 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
|
|
|
|
|
{
|
2020-07-01 10:51:26 +02:00
|
|
|
const QString uniqueId = "OutputPane";
|
2020-01-24 17:14:05 +01:00
|
|
|
auto outputPanePlaceholder = new Core::OutputPanePlaceHolder(Core::Constants::MODE_DESIGN);
|
2020-07-01 10:51:26 +02:00
|
|
|
m_outputPaneDockWidget = new ADS::DockWidget(uniqueId);
|
2020-01-24 17:14:05 +01:00
|
|
|
m_outputPaneDockWidget->setWidget(outputPanePlaceholder);
|
2022-02-25 13:59:49 +01:00
|
|
|
m_outputPaneDockWidget->setWindowTitle(tr("Output"));
|
2020-01-24 17:14:05 +01:00
|
|
|
m_dockManager->addDockWidget(ADS::NoDockWidgetArea, m_outputPaneDockWidget);
|
2020-07-01 10:51:26 +02:00
|
|
|
|
|
|
|
|
// Set unique id as object name
|
|
|
|
|
outputPanePlaceholder->setObjectName(uniqueId);
|
|
|
|
|
|
2020-01-24 17:14:05 +01:00
|
|
|
// Create menu action
|
|
|
|
|
auto command = Core::ActionManager::registerAction(m_outputPaneDockWidget->toggleViewAction(),
|
|
|
|
|
actionToggle.withSuffix("OutputPaneWidget"),
|
|
|
|
|
designContext);
|
|
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
|
mviews->addAction(command);
|
|
|
|
|
|
2020-04-09 17:11:54 +02:00
|
|
|
connect(outputPanePlaceholder, &Core::OutputPanePlaceHolder::visibilityChangeRequested,
|
2020-04-09 13:53:04 +02:00
|
|
|
m_outputPaneDockWidget, &ADS::DockWidget::toggleView);
|
2020-01-24 17:14:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create toolbars
|
|
|
|
|
auto toolBar = new QToolBar();
|
2020-04-30 17:45:48 +02:00
|
|
|
|
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-03-02 15:13:20 +01:00
|
|
|
m_dockManager->initialize();
|
2020-03-09 08:30:17 +01:00
|
|
|
|
2020-09-21 13:30:57 +02:00
|
|
|
connect(Core::ModeManager::instance(),
|
|
|
|
|
&Core::ModeManager::currentModeChanged,
|
|
|
|
|
this,
|
|
|
|
|
[this](Utils::Id mode, Utils::Id oldMode) {
|
|
|
|
|
if (mode == Core::Constants::MODE_DESIGN) {
|
|
|
|
|
m_dockManager->reloadActiveWorkspace();
|
|
|
|
|
m_dockManager->setModeChangeState(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (oldMode == Core::Constants::MODE_DESIGN && mode != Core::Constants::MODE_DESIGN) {
|
|
|
|
|
m_dockManager->save();
|
|
|
|
|
m_dockManager->setModeChangeState(true);
|
|
|
|
|
for (auto floatingWidget : m_dockManager->floatingWidgets())
|
|
|
|
|
floatingWidget->hide();
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-03-09 08:30:17 +01:00
|
|
|
|
2020-04-30 17:45:48 +02:00
|
|
|
addSpacerToToolBar(toolBar);
|
|
|
|
|
|
2020-03-13 14:58:59 +01:00
|
|
|
auto workspaceComboBox = new QComboBox();
|
|
|
|
|
workspaceComboBox->setMinimumWidth(120);
|
|
|
|
|
workspaceComboBox->setToolTip(tr("Switch the active workspace."));
|
|
|
|
|
auto sortedWorkspaces = m_dockManager->workspaces();
|
|
|
|
|
Utils::sort(sortedWorkspaces);
|
|
|
|
|
workspaceComboBox->addItems(sortedWorkspaces);
|
|
|
|
|
workspaceComboBox->setCurrentText(m_dockManager->activeWorkspace());
|
|
|
|
|
toolBar->addWidget(workspaceComboBox);
|
|
|
|
|
|
|
|
|
|
connect(m_dockManager, &ADS::DockManager::workspaceListChanged,
|
|
|
|
|
workspaceComboBox, [this, workspaceComboBox]() {
|
|
|
|
|
workspaceComboBox->clear();
|
|
|
|
|
auto sortedWorkspaces = m_dockManager->workspaces();
|
|
|
|
|
Utils::sort(sortedWorkspaces);
|
|
|
|
|
workspaceComboBox->addItems(sortedWorkspaces);
|
|
|
|
|
workspaceComboBox->setCurrentText(m_dockManager->activeWorkspace());
|
|
|
|
|
});
|
|
|
|
|
connect(m_dockManager, &ADS::DockManager::workspaceLoaded, workspaceComboBox, &QComboBox::setCurrentText);
|
|
|
|
|
connect(workspaceComboBox, QOverload<int>::of(&QComboBox::activated),
|
|
|
|
|
m_dockManager, [this, workspaceComboBox] (int index) {
|
|
|
|
|
Q_UNUSED(index)
|
|
|
|
|
m_dockManager->openWorkspace(workspaceComboBox->currentText());
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-02 16:21:38 +01:00
|
|
|
const QIcon gaIcon = Utils::StyleHelper::getIconFromIconFont(
|
2021-03-02 13:35:07 +01:00
|
|
|
fontName, Theme::getIconUnicode(Theme::Icon::annotationBubble),
|
|
|
|
|
36, 36, Theme::getColor(Theme::IconsBaseColor));
|
2020-04-16 18:00:48 +02:00
|
|
|
toolBar->addAction(gaIcon, tr("Edit global annotation for current file."), [&](){
|
|
|
|
|
ModelNode node = currentDesignDocument()->rewriterView()->rootModelNode();
|
|
|
|
|
|
|
|
|
|
if (node.isValid()) {
|
|
|
|
|
m_globalAnnotationEditor.setModelNode(node);
|
|
|
|
|
m_globalAnnotationEditor.showWidget();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2020-10-28 09:27:26 +01:00
|
|
|
Core::ActionContainer *aci = Core::ActionManager::actionContainer(QmlDesigner::Constants::M_VIEW_WORKSPACES);
|
2020-01-24 17:14:05 +01:00
|
|
|
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
|
|
|
|
2022-02-07 12:28:24 +01:00
|
|
|
QAction *action = menu->addAction(tr("Manage..."));
|
2020-01-24 17:14:05 +01:00
|
|
|
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-03-02 15:13:20 +01:00
|
|
|
// Sort the list of workspaces
|
|
|
|
|
auto sortedWorkspaces = m_dockManager->workspaces();
|
|
|
|
|
Utils::sort(sortedWorkspaces);
|
|
|
|
|
|
2021-02-17 17:12:22 +01:00
|
|
|
for (const auto &workspace : qAsConst(sortedWorkspaces))
|
2020-01-24 17:14:05 +01:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
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;
|
2021-11-01 17:02:02 +01:00
|
|
|
Core::EditorManager::openEditor(Utils::FilePath::fromString(
|
|
|
|
|
m_navigatorHistory.at(m_navigatorHistoryCounter)),
|
2020-09-21 13:30:57 +02:00
|
|
|
Utils::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;
|
2021-11-01 17:02:02 +01:00
|
|
|
Core::EditorManager::openEditor(Utils::FilePath::fromString(
|
|
|
|
|
m_navigatorHistory.at(m_navigatorHistoryCounter)),
|
2020-09-21 13:30:57 +02:00
|
|
|
Utils::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
|