From e75d9001e5c16cb044ddb229bbb858e02d4028ef Mon Sep 17 00:00:00 2001 From: Ali Kianian Date: Sun, 17 Nov 2024 07:36:01 +0200 Subject: [PATCH] EffectComposer: Move live update button to Qml header Task-number: QDS-14123 Change-Id: I54d3bb7e916a5bf5f9b4e5b9db17692eed28aaaf Reviewed-by: Miikka Heikkinen --- .../CodeEditorHeader.qml | 16 ++++++- .../effectshaderscodeeditor.cpp | 47 +------------------ .../effectcomposer/effectshaderscodeeditor.h | 2 - 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/share/qtcreator/qmldesigner/effectComposerQmlSources/CodeEditorHeader.qml b/share/qtcreator/qmldesigner/effectComposerQmlSources/CodeEditorHeader.qml index 7a4b5a87b7c..065354bdc0e 100644 --- a/share/qtcreator/qmldesigner/effectComposerQmlSources/CodeEditorHeader.qml +++ b/share/qtcreator/qmldesigner/effectComposerQmlSources/CodeEditorHeader.qml @@ -3,9 +3,14 @@ import QtQuick import QtQuick.Layouts +import StudioControls as StudioControls import StudioTheme as StudioTheme Rectangle { + id: root + + property var rootView: shaderEditor + color: StudioTheme.Values.themeToolbarBackground ColumnLayout { @@ -19,10 +24,19 @@ Rectangle { ColumnChooser { table: uniformsView.tableView - text: "Columns" + text: qsTr("Columns") style: StudioTheme.Values.viewBarControlStyle Layout.topMargin: StudioTheme.Values.marginTopBottom } + + StudioControls.CheckBox { + text: qsTr("Live Update") + actionIndicatorVisible: false + style: StudioTheme.Values.viewBarControlStyle + Layout.topMargin: StudioTheme.Values.marginTopBottom + checked: root.rootView ? root.rootView.liveUpdate : false + onToggled: root.rootView.liveUpdate = checked + } } CodeEditorUniformsView { diff --git a/src/plugins/effectcomposer/effectshaderscodeeditor.cpp b/src/plugins/effectcomposer/effectshaderscodeeditor.cpp index fce41f27c4a..35f11879fcd 100644 --- a/src/plugins/effectcomposer/effectshaderscodeeditor.cpp +++ b/src/plugins/effectcomposer/effectshaderscodeeditor.cpp @@ -14,8 +14,6 @@ #include -#include -#include #include #include @@ -29,22 +27,14 @@ #include #include #include -#include #include namespace { -using IconId = QmlDesigner::DesignerIcons::IconId; - inline constexpr char EFFECTCOMPOSER_LIVE_UPDATE_KEY[] = "EffectComposer/CodeEditor/LiveUpdate"; inline constexpr char OBJECT_NAME_EFFECTCOMPOSER_SHADER_HEADER[] = "QQuickWidgetEffectComposerCodeEditorHeader"; -QIcon toolbarIcon(IconId iconId) -{ - return QmlDesigner::DesignerActionManager::instance().toolbarIcon(iconId); -}; - QString propertyEditorResourcesPath() { #ifdef SHARE_QML_PATH @@ -222,7 +212,6 @@ void EffectShadersCodeEditor::setupUIComponents() tabWidget->addTab(m_vertexEditor, tr("Vertex Shader")); verticalLayout->setContentsMargins(0, 0, 0, 0); - verticalLayout->addWidget(createToolbar()); verticalLayout->addWidget(splitter); splitter->addWidget(m_headerWidget.get()); splitter->addWidget(tabWidget); @@ -275,41 +264,6 @@ void EffectShadersCodeEditor::readAndApplyLiveUpdateSettings() setLiveUpdate(liveUpdateStatus); } -QToolBar *EffectShadersCodeEditor::createToolbar() -{ - using QmlDesigner::Theme; - - QToolBar *toolbar = new QToolBar(this); - - toolbar->setFixedHeight(Theme::toolbarSize()); - toolbar->setFloatable(false); - toolbar->setContentsMargins(0, 0, 0, 0); - - toolbar->setStyleSheet(Theme::replaceCssColors( - QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css")))); - - QAction *liveUpdateButton - = toolbar->addAction(toolbarIcon(IconId::LiveUpdateIcon), tr("Live Update")); - liveUpdateButton->setCheckable(true); - connect(liveUpdateButton, &QAction::toggled, this, &EffectShadersCodeEditor::setLiveUpdate); - - QAction *applyAction = toolbar->addAction(toolbarIcon(IconId::SyncIcon), tr("Apply")); - connect(applyAction, &QAction::triggered, this, &EffectShadersCodeEditor::rebakeRequested); - - auto syncLive = [liveUpdateButton, applyAction](bool liveState) { - liveUpdateButton->setChecked(liveState); - applyAction->setDisabled(liveState); - }; - - connect(this, &EffectShadersCodeEditor::liveUpdateChanged, this, syncLive); - syncLive(liveUpdate()); - - toolbar->addAction(liveUpdateButton); - toolbar->addAction(applyAction); - - return toolbar; -} - void EffectShadersCodeEditor::createHeader() { m_headerWidget = new StudioQuickWidget(this); @@ -320,6 +274,7 @@ void EffectShadersCodeEditor::createHeader() m_headerWidget->engine()->addImportPath(EffectUtils::nodesSourcesPath() + "/common"); m_headerWidget->setClearColor(QmlDesigner::Theme::getColor( QmlDesigner::Theme::Color::QmlDesigner_BackgroundColorDarkAlternate)); + m_headerWidget->rootContext()->setContextProperty("shaderEditor", QVariant::fromValue(this)); } void EffectShadersCodeEditor::reloadQml() diff --git a/src/plugins/effectcomposer/effectshaderscodeeditor.h b/src/plugins/effectcomposer/effectshaderscodeeditor.h index 2c2e136bd69..69ee9a19d38 100644 --- a/src/plugins/effectcomposer/effectshaderscodeeditor.h +++ b/src/plugins/effectcomposer/effectshaderscodeeditor.h @@ -8,7 +8,6 @@ #include QT_FORWARD_DECLARE_CLASS(QSettings) -QT_FORWARD_DECLARE_CLASS(QToolBar) class StudioQuickWidget; @@ -60,7 +59,6 @@ protected: private: void writeLiveUpdateSettings(); void readAndApplyLiveUpdateSettings(); - QToolBar *createToolbar(); void createHeader(); void reloadQml();