2023-01-23 11:59:10 +01:00
|
|
|
// 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>
|
2023-02-03 10:36:14 +01:00
|
|
|
#include <qmldesignerconstants.h>
|
2023-01-23 11:59:10 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <utils/filepath.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
|
|
|
|
#include <QQmlEngine>
|
2023-01-27 12:24:35 +01:00
|
|
|
#include <QStatusBar>
|
|
|
|
|
#include <QToolBar>
|
2023-01-23 11:59:10 +01:00
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2023-01-27 12:24:35 +01:00
|
|
|
QmlDesigner::ToolBar::ToolBar() {}
|
2023-01-23 11:59:10 +01:00
|
|
|
|
|
|
|
|
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;
|
2023-01-26 17:10:51 +01:00
|
|
|
toolBar->setObjectName("QDS-TOOLBAR");
|
2023-01-23 11:59:10 +01:00
|
|
|
|
2023-01-25 19:34:14 +01:00
|
|
|
toolBar->setContextMenuPolicy(Qt::PreventContextMenu);
|
|
|
|
|
|
2023-01-23 11:59:10 +01:00
|
|
|
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);
|
|
|
|
|
|
2023-02-03 10:36:14 +01:00
|
|
|
quickWidget->setObjectName(Constants::OBJECT_NAME_TOP_TOOLBAR);
|
|
|
|
|
|
2023-01-23 11:59:10 +01:00
|
|
|
quickWidget->engine()->addImportPath(propertyEditorResourcesPath().toString() + "/imports");
|
|
|
|
|
|
|
|
|
|
Utils::FilePath qmlFilePath = qmlSourcesPath() / "Main.qml";
|
2023-01-27 12:24:35 +01:00
|
|
|
QTC_ASSERT(qmlFilePath.exists(), return);
|
2023-01-23 11:59:10 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2023-01-31 15:07:06 +01:00
|
|
|
quickWidget->setFixedHeight(Theme::toolbarSize());
|
2023-01-23 11:59:10 +01:00
|
|
|
quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
quickWidget->setMinimumWidth(200);
|
|
|
|
|
quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
|
|
|
|
2023-02-03 10:36:14 +01:00
|
|
|
quickWidget->setObjectName(Constants::OBJECT_NAME_STATUSBAR);
|
|
|
|
|
|
2023-01-23 11:59:10 +01:00
|
|
|
quickWidget->engine()->addImportPath(propertyEditorResourcesPath().toString() + "/imports");
|
|
|
|
|
|
|
|
|
|
Utils::FilePath qmlFilePath = qmlSourcesStatusBarPath() + QStringLiteral("/Main.qml");
|
2023-01-27 12:24:35 +01:00
|
|
|
QTC_ASSERT(qmlFilePath.exists(), return);
|
2023-01-23 11:59:10 +01:00
|
|
|
|
|
|
|
|
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);
|
2023-01-31 15:07:06 +01:00
|
|
|
Core::ICore::statusBar()->setFixedHeight(Theme::toolbarSize());
|
2023-01-23 11:59:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ToolBar::isVisible()
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = Core::ICore::settings();
|
|
|
|
|
const QString qdsToolbarEntry = "QML/Designer/TopToolBar";
|
|
|
|
|
|
|
|
|
|
return settings->value(qdsToolbarEntry, false).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace QmlDesigner
|