Skip to content

Commit

Permalink
Add the possibility to show toolbar items for dock panels
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup committed Mar 24, 2024
1 parent d27f51d commit a80b234
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/appshell/qml/NotationPage/NotationPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ DockPage {

Component.onCompleted: {
mixerPanel.contextMenuModel = contextMenuModel
mixerPanel.toolbarComponent = toolbarComponent
}

onResizeRequested: function(newWidth, newHeight) {
Expand Down
2 changes: 2 additions & 0 deletions src/appshell/qml/dockwindow/DockFrame.qml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Rectangle {
tabsModel: frameModel.tabs
currentIndex: Boolean(root.frameCpp) && root.frameCpp.currentIndex >= 0 ? root.frameCpp.currentIndex : 0

currentToolbarComponent: frameModel.currentDockToolbarComponent

navigationPanel: navPanel

function setCurrentDockWidget(index: int) {
Expand Down
13 changes: 13 additions & 0 deletions src/appshell/qml/dockwindow/DockTabBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Rectangle {
property NavigationPanel navigationPanel: null
readonly property string currentItemNavigationName: tabs.currentItem && tabs.currentItem.navigation ? tabs.currentItem.navigation.name : ""

property alias currentToolbarComponent: toolbarLoader.sourceComponent

signal tabClicked(int index)
signal handleContextMenuItemRequested(string itemId)

Expand Down Expand Up @@ -130,7 +132,18 @@ Rectangle {
cursorShape: Qt.SizeAllCursor
}

Loader {
id: toolbarLoader

anchors.top: parent.top
anchors.left: tabs.right
anchors.right: parent.right
anchors.bottom: bottomSeparatorContainer.top
}

Item {
id: bottomSeparatorContainer

anchors.left: tabs.right
anchors.right: parent.right
anchors.bottom: parent.bottom
Expand Down
23 changes: 23 additions & 0 deletions src/appshell/view/dockwindow/dockpanelview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ DockPanelView::~DockPanelView()

dockWidget->setProperty(DOCK_PANEL_PROPERTY, QVariant::fromValue(nullptr));
dockWidget->setProperty(CONTEXT_MENU_MODEL_PROPERTY, QVariant::fromValue(nullptr));
dockWidget->setProperty(TOOLBAR_COMPONENT_PROPERTY, QVariant::fromValue(nullptr));
}

QString DockPanelView::groupName() const
Expand Down Expand Up @@ -193,12 +194,19 @@ void DockPanelView::componentComplete()

dockWidget->setProperty(DOCK_PANEL_PROPERTY, QVariant::fromValue(this));
dockWidget->setProperty(CONTEXT_MENU_MODEL_PROPERTY, QVariant::fromValue(m_menuModel));
dockWidget->setProperty(TOOLBAR_COMPONENT_PROPERTY, QVariant::fromValue(m_toolbarComponent));

connect(m_menuModel, &AbstractMenuModel::itemsChanged, [dockWidget, this]() {
if (dockWidget) {
dockWidget->setProperty(CONTEXT_MENU_MODEL_PROPERTY, QVariant::fromValue(m_menuModel));
}
});

connect(this, &DockPanelView::toolbarComponentChanged, this, [this, dockWidget]() {
if (dockWidget) {
dockWidget->setProperty(TOOLBAR_COMPONENT_PROPERTY, QVariant::fromValue(m_toolbarComponent));
}
});
}

QObject* DockPanelView::navigationSection() const
Expand All @@ -221,6 +229,11 @@ AbstractMenuModel* DockPanelView::contextMenuModel() const
return m_menuModel->customMenuModel();
}

QQmlComponent* DockPanelView::toolbarComponent() const
{
return m_toolbarComponent;
}

void DockPanelView::setContextMenuModel(AbstractMenuModel* model)
{
if (m_menuModel->customMenuModel() == model) {
Expand All @@ -232,6 +245,16 @@ void DockPanelView::setContextMenuModel(AbstractMenuModel* model)
emit contextMenuModelChanged();
}

void DockPanelView::setToolbarComponent(QQmlComponent* component)
{
if (m_toolbarComponent == component) {
return;
}

m_toolbarComponent = component;
emit toolbarComponentChanged();
}

bool DockPanelView::isTabAllowed(const DockPanelView* tab) const
{
IF_ASSERT_FAILED(tab) {
Expand Down
10 changes: 8 additions & 2 deletions src/appshell/view/dockwindow/dockpanelview.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

#include "internal/dockbase.h"

#include "framework/uicomponents/view/qmllistproperty.h"

#include "uicomponents/view/abstractmenumodel.h"

class QQmlComponent;

namespace mu::uicomponents {
class AbstractMenuModel;
}
Expand All @@ -43,6 +43,7 @@ class DockPanelView : public DockBase
Q_PROPERTY(
mu::uicomponents::AbstractMenuModel
* contextMenuModel READ contextMenuModel WRITE setContextMenuModel NOTIFY contextMenuModelChanged)
Q_PROPERTY(QQmlComponent * toolbarComponent READ toolbarComponent WRITE setToolbarComponent NOTIFY toolbarComponentChanged)

public:
explicit DockPanelView(QQuickItem* parent = nullptr);
Expand All @@ -51,6 +52,7 @@ class DockPanelView : public DockBase
QString groupName() const;
QObject* navigationSection() const;
uicomponents::AbstractMenuModel* contextMenuModel() const;
QQmlComponent* toolbarComponent() const;

bool isTabAllowed(const DockPanelView* tab) const;
void addPanelAsTab(DockPanelView* tab);
Expand All @@ -60,11 +62,13 @@ public slots:
void setGroupName(const QString& name);
void setNavigationSection(QObject* newNavigation);
void setContextMenuModel(uicomponents::AbstractMenuModel* model);
void setToolbarComponent(QQmlComponent* component);

signals:
void groupNameChanged();
void navigationSectionChanged();
void contextMenuModelChanged();
void toolbarComponentChanged();

private:
void componentComplete() override;
Expand All @@ -74,6 +78,8 @@ public slots:

class DockPanelMenuModel;
DockPanelMenuModel* m_menuModel = nullptr;

QQmlComponent* m_toolbarComponent = nullptr;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/appshell/view/dockwindow/docktypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace mu::dock {
inline const char* CONTEXT_MENU_MODEL_PROPERTY("contextMenuModel");
inline const char* DOCK_PANEL_PROPERTY("dockPanel");
inline const char* TOOLBAR_COMPONENT_PROPERTY("toolbarComponent");

//! NOTE: need to be synchronized with Window shadow(see DockFloatingWindow margins)
inline constexpr int DOCK_WINDOW_SHADOW(8);
Expand Down
9 changes: 8 additions & 1 deletion src/appshell/view/dockwindow/internal/dockframemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ bool DockFrameModel::eventFilter(QObject* watched, QEvent* event)
return QObject::eventFilter(watched, event);
}

if (propertyChangeEvent->propertyName() == CONTEXT_MENU_MODEL_PROPERTY) {
if (propertyChangeEvent->propertyName() == CONTEXT_MENU_MODEL_PROPERTY
|| propertyChangeEvent->propertyName() == TOOLBAR_COMPONENT_PROPERTY) {
emit tabsChanged();

if (watched == currentDockWidget()) {
Expand Down Expand Up @@ -87,6 +88,7 @@ QVariantList DockFrameModel::tabs() const
QVariantMap tab;
tab["title"] = dock->title();
tab[CONTEXT_MENU_MODEL_PROPERTY] = dock->property(CONTEXT_MENU_MODEL_PROPERTY);
tab[TOOLBAR_COMPONENT_PROPERTY] = dock->property(TOOLBAR_COMPONENT_PROPERTY);

result << tab;
}
Expand Down Expand Up @@ -204,6 +206,11 @@ QVariant DockFrameModel::currentDockContextMenuModel() const
return currentDockProperty(CONTEXT_MENU_MODEL_PROPERTY);
}

QVariant DockFrameModel::currentDockToolbarComponent() const
{
return currentDockProperty(TOOLBAR_COMPONENT_PROPERTY);
}

bool DockFrameModel::highlightingVisible() const
{
return highlightingRect().isValid();
Expand Down
2 changes: 2 additions & 0 deletions src/appshell/view/dockwindow/internal/dockframemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DockFrameModel : public QObject
Q_PROPERTY(QObject * navigationSection READ navigationSection NOTIFY navigationSectionChanged)
Q_PROPERTY(QString currentDockUniqueName READ currentDockUniqueName NOTIFY currentDockChanged)
Q_PROPERTY(QVariant currentDockContextMenuModel READ currentDockContextMenuModel NOTIFY currentDockChanged)
Q_PROPERTY(QVariant currentDockToolbarComponent READ currentDockToolbarComponent NOTIFY currentDockChanged)

Q_PROPERTY(bool highlightingVisible READ highlightingVisible NOTIFY highlightingVisibleChanged)
Q_PROPERTY(QRect highlightingRect READ highlightingRect NOTIFY highlightingVisibleChanged)
Expand All @@ -63,6 +64,7 @@ class DockFrameModel : public QObject
QObject* navigationSection() const;
QString currentDockUniqueName() const;
QVariant currentDockContextMenuModel() const;
QVariant currentDockToolbarComponent() const;

bool highlightingVisible() const;
QRect highlightingRect() const;
Expand Down
1 change: 1 addition & 0 deletions src/playback/playback.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<file>qml/MuseScore/Playback/internal/MeasureAndBeatFields.qml</file>
<file>qml/MuseScore/Playback/internal/TempoSlider.qml</file>
<file>qml/MuseScore/Playback/MixerPanel.qml</file>
<file>qml/MuseScore/Playback/internal/MixerPanelToolbar.qml</file>
<file>qml/MuseScore/Playback/internal/MixerPanelSection.qml</file>
<file>qml/MuseScore/Playback/internal/MixerBalanceSection.qml</file>
<file>qml/MuseScore/Playback/internal/MixerVolumeSection.qml</file>
Expand Down
4 changes: 4 additions & 0 deletions src/playback/qml/MuseScore/Playback/MixerPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ ColumnLayout {
id: root

property alias contextMenuModel: contextMenuModel
property Component toolbarComponent: MixerPanelToolbar {
navigation.section: root.navigationSection
navigation.order: 1
}

property NavigationSection navigationSection: null
property NavigationPanel navigationPanel: mixerPanelModel.count > 0 ? mixerPanelModel.get(0).channelItem.panel : null // first panel
Expand Down
52 changes: 52 additions & 0 deletions src/playback/qml/MuseScore/Playback/internal/MixerPanelToolbar.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2023 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.15

import MuseScore.Ui 1.0
import MuseScore.UiComponents 1.0

Item {
id: root

property alias navigation: navPanel

anchors.fill: parent

NavigationPanel {
id: navPanel
name: "MixerPanelToolbarPanel"
enabled: root.enabled && root.visible
}

FlatButton {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 2

icon: IconCode.SETTINGS_COG
text: qsTrc("playback", "Customize mixer")
orientation: Qt.Horizontal

navigation.panel: navPanel
navigation.row: 0
}
}

0 comments on commit a80b234

Please sign in to comment.