forked from qt-creator/qt-creator
QmlDesigner: Add top level toolbar
* Added Designer\TopToolBar=true to .ini to enable toolbar * Added backend to CrumbleBar * Added crumble bar * Added QML toolbar * Disabled original toolbar in DesignModeWidget * Added callback to DesignerActionManager * Added id to ZoomPreviewAction * Dock Manager is exposed in DesignModeWidget * Added new version of icon font Change-Id: I8c8ad16137c84229854a1d0fa6dfdf498edf4253 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
126
src/plugins/qmldesigner/components/toolbar/toolbar.cpp
Normal file
126
src/plugins/qmldesigner/components/toolbar/toolbar.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "toolbar.h"
|
||||
#include "toolbarbackend.h"
|
||||
|
||||
#include <theme.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QStatusBar>
|
||||
#include <QToolBar>
|
||||
#include <QMainWindow>
|
||||
#include <QQmlEngine>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
QmlDesigner::ToolBar::ToolBar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static Utils::FilePath propertyEditorResourcesPath()
|
||||
{
|
||||
#ifdef SHARE_QML_PATH
|
||||
if (qEnvironmentVariableIsSet("LOAD_QML_FROM_SOURCE"))
|
||||
return Utils::FilePath::fromString(QLatin1String(SHARE_QML_PATH) + "/propertyEditorQmlSources");
|
||||
#endif
|
||||
return Core::ICore::resourcePath("qmldesigner/propertyEditorQmlSources");
|
||||
}
|
||||
|
||||
Utils::FilePath qmlSourcesStatusBarPath()
|
||||
{
|
||||
#ifdef SHARE_QML_PATH
|
||||
if (qEnvironmentVariableIsSet("LOAD_QML_FROM_SOURCE"))
|
||||
return Utils::FilePath::fromString(QLatin1String(SHARE_QML_PATH) + "/statusbar");
|
||||
#endif
|
||||
return Core::ICore::resourcePath("qmldesigner/statusbar");
|
||||
}
|
||||
|
||||
Utils::FilePath qmlSourcesPath()
|
||||
{
|
||||
#ifdef SHARE_QML_PATH
|
||||
if (qEnvironmentVariableIsSet("LOAD_QML_FROM_SOURCE"))
|
||||
return Utils::FilePath::fromString(QLatin1String(SHARE_QML_PATH) + "/toolbar");
|
||||
#endif
|
||||
return Core::ICore::resourcePath("qmldesigner/toolbar");
|
||||
}
|
||||
|
||||
void ToolBar::create()
|
||||
{
|
||||
if (!isVisible())
|
||||
return;
|
||||
|
||||
ToolBarBackend::registerDeclarativeType();
|
||||
|
||||
auto window = Core::ICore::mainWindow();
|
||||
|
||||
//Core::ICore::statusBar()->hide();
|
||||
|
||||
auto toolBar = new QToolBar;
|
||||
|
||||
toolBar->setFloatable(false);
|
||||
toolBar->setMovable(false);
|
||||
|
||||
auto quickWidget = new QQuickWidget;
|
||||
|
||||
quickWidget->setFixedHeight(48);
|
||||
quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
quickWidget->setMinimumWidth(200);
|
||||
quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
|
||||
quickWidget->engine()->addImportPath(propertyEditorResourcesPath().toString() + "/imports");
|
||||
|
||||
Utils::FilePath qmlFilePath = qmlSourcesPath() / "Main.qml";
|
||||
QTC_ASSERT(qmlFilePath.exists(), return );
|
||||
|
||||
Theme::setupTheme(quickWidget->engine());
|
||||
|
||||
quickWidget->setSource(QUrl::fromLocalFile(qmlFilePath.toFSPathString()));
|
||||
|
||||
toolBar->addWidget(quickWidget);
|
||||
window->addToolBar(toolBar);
|
||||
}
|
||||
|
||||
void ToolBar::createStatusBar()
|
||||
{
|
||||
if (!isVisible())
|
||||
return;
|
||||
|
||||
ToolBarBackend::registerDeclarativeType();
|
||||
|
||||
auto quickWidget = new QQuickWidget;
|
||||
|
||||
quickWidget->setFixedHeight(24);
|
||||
quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
quickWidget->setMinimumWidth(200);
|
||||
quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
|
||||
quickWidget->engine()->addImportPath(propertyEditorResourcesPath().toString() + "/imports");
|
||||
|
||||
Utils::FilePath qmlFilePath = qmlSourcesStatusBarPath() + QStringLiteral("/Main.qml");
|
||||
QTC_ASSERT(qmlFilePath.exists(), return );
|
||||
|
||||
Theme::setupTheme(quickWidget->engine());
|
||||
|
||||
quickWidget->setSource(QUrl::fromLocalFile(qmlFilePath.toFSPathString()));
|
||||
|
||||
for (QWidget *w : Core::ICore::statusBar()->findChildren<QWidget *>(Qt::FindDirectChildrenOnly)) {
|
||||
w->hide();
|
||||
}
|
||||
|
||||
Core::ICore::statusBar()->addWidget(quickWidget);
|
||||
}
|
||||
|
||||
bool ToolBar::isVisible()
|
||||
{
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
const QString qdsToolbarEntry = "QML/Designer/TopToolBar";
|
||||
|
||||
return settings->value(qdsToolbarEntry, false).toBool();
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
Reference in New Issue
Block a user