Skip to content

Commit

Permalink
Percussions - provide mechanism for adding actions to DockFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
mathesoncalum committed Sep 10, 2024
1 parent 2f5cf79 commit 0569fb2
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/appshell/qml/NotationPage/NotationPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ DockPage {
navigationSection: root.navigationPanelSec(drumsetPanel.location)

DrumsetPanel {
navigationSection: timelinePanel.navigationSection
navigationSection: drumsetPanel.navigationSection
}
},

Expand All @@ -437,6 +437,10 @@ DockPage {
dropDestinations: root.horizontalPanelDropDestinations

navigationSection: root.navigationPanelSec(percussionPanel.location)

PercussionPanel {
// navigationSection: percussionPanel.navigationSection
}
}
]

Expand Down
2 changes: 2 additions & 0 deletions src/framework/dockwindow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/internal/dockseparator.h
${CMAKE_CURRENT_LIST_DIR}/internal/dockframemodel.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/dockframemodel.h
${CMAKE_CURRENT_LIST_DIR}/internal/dockframetoolbarmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/dockframetoolbarmodel.h
${CMAKE_CURRENT_LIST_DIR}/internal/docktabbar.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/docktabbar.h
${CMAKE_CURRENT_LIST_DIR}/internal/dockwindowactionscontroller.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/framework/dockwindow/dockmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "internal/dropcontroller.h"
#include "internal/dockseparator.h"
#include "internal/dockframemodel.h"
#include "internal/dockframetoolbarmodel.h"
#include "internal/docktabbar.h"
#include "internal/dockwindowactionscontroller.h"
#include "internal/dockwindowprovider.h"
Expand Down Expand Up @@ -142,6 +143,7 @@ void DockModule::registerUiTypes()
qmlRegisterType<DockCentralView>("Muse.Dock", 1, 0, "DockCentralView");
qmlRegisterType<DockPageView>("Muse.Dock", 1, 0, "DockPageView");
qmlRegisterType<DockFrameModel>("Muse.Dock", 1, 0, "DockFrameModel");
qmlRegisterType<DockFrameToolBarModel>("Muse.Dock", 1, 0, "DockFrameToolBarModel");

qmlRegisterUncreatableType<DockToolBarAlignment>("Muse.Dock", 1, 0, "DockToolBarAlignment", "Not creatable from QML");
qmlRegisterUncreatableType<DockLocation>("Muse.Dock", 1, 0, "Location", "Not creatable from QML");
Expand Down
153 changes: 153 additions & 0 deletions src/framework/dockwindow/internal/dockframetoolbarmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-Studio-CLA-applies
*
* MuseScore Studio
* Music Composition & Notation
*
* Copyright (C) 2024 MuseScore Limited
*
* 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/>.
*/

#include "dockframetoolbarmodel.h"

#include "uicomponents/view/toolbaritem.h"
#include "context/shortcutcontext.h"
#include "context/iuicontextresolver.h"

using namespace muse;
using namespace actions;
using namespace dock;
using namespace ui;
using namespace uicomponents;

Location DockFrameToolBarModel::location() const
{
return m_location;
}

QString DockFrameToolBarModel::currentDockUniqueName() const
{
return m_currentDockUniqueName;
}

void DockFrameToolBarModel::setLocation(const Location& location)
{
m_location = location;
}

void DockFrameToolBarModel::setCurrentDock(const QString& currentDockUniqueName)
{
m_currentDockUniqueName = currentDockUniqueName;

UiActionList actions;

switch (m_location) {
case Location::Center:
actions = centralActionsForDockName(m_currentDockUniqueName);
break;
case Location::Right:
actions = rightSideActionsForDockName(m_currentDockUniqueName);
break;
default:
break;
}

setItems(toolBarItemsForActionList(actions));
}

// TODO: This shouldn't live here...
const UiActionList DockFrameToolBarModel::m_percussionCentralActions = {
UiAction("percussion-write",
mu::context::UiCtxNotationFocused,
mu::context::CTX_ANY,
TranslatableString("action", "Write"),
TranslatableString("action", "Write"),
IconCode::Code::EDIT
),
UiAction("percussion-preview",
mu::context::UiCtxNotationFocused,
mu::context::CTX_ANY,
TranslatableString("action", "Preview"),
TranslatableString("action", "Preview"),
IconCode::Code::PLAY
),
};

// TODO: This shouldn't live here...
const UiActionList DockFrameToolBarModel::m_percussionRightSideActions = {
UiAction("percussion-layout",
mu::context::UiCtxNotationFocused,
mu::context::CTX_ANY,
TranslatableString("action", "Layout"),
TranslatableString("action", "Layout"),
IconCode::Code::SPLIT_VIEW_HORIZONTAL,
Checkable::No,
m_percussionLayoutSubActions
),
UiAction("percussion-customize-kit",
mu::context::UiCtxNotationFocused,
mu::context::CTX_ANY,
TranslatableString("action", "Customize kit"),
TranslatableString("action", "Customize kit")
),
};

// TODO: This shouldn't live here...
const std::vector<UiAction> DockFrameToolBarModel::m_percussionLayoutSubActions = {
UiAction("percussion-instrument-names",
mu::context::UiCtxNotationFocused,
mu::context::CTX_ANY,
TranslatableString("action", "Instrument names"),
TranslatableString("action", "Instrument names")
),
UiAction("percussion-notation-preview",
mu::context::UiCtxNotationFocused,
mu::context::CTX_ANY,
TranslatableString("action", "Notation preview"),
TranslatableString("action", "Notation preview")
),
UiAction("percussion-edit-layout",
mu::context::UiCtxNotationFocused,
mu::context::CTX_ANY,
TranslatableString("action", "Edit layout"),
TranslatableString("action", "Edit layout"),
IconCode::Code::CONFIGURE
),
UiAction("percussion-reset-layout",
mu::context::UiCtxNotationFocused,
mu::context::CTX_ANY,
TranslatableString("action", "Reset layout"),
TranslatableString("action", "Reset layout"),
IconCode::Code::UNDO
),
};

// TODO: Placeholder method - info will be pulled from elsewhere...
UiActionList DockFrameToolBarModel::centralActionsForDockName(const QString& dockUniqueName) const
{
if (dockUniqueName == "percussionPanel") {
return m_percussionCentralActions;
}
return {};
}

// TODO: Placeholder method - info will be pulled from elsewhere...
UiActionList DockFrameToolBarModel::rightSideActionsForDockName(const QString& dockUniqueName) const
{
if (dockUniqueName == "percussionPanel") {
return m_percussionRightSideActions;
}
return {};
}
66 changes: 66 additions & 0 deletions src/framework/dockwindow/internal/dockframetoolbarmodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2024 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/>.
*/

#ifndef MUSE_DOCK_DOCKFRAMETOOLBARMODEL_H
#define MUSE_DOCK_DOCKFRAMETOOLBARMODEL_H

#include "docktypes.h"
#include "uicomponents/view/abstracttoolbarmodel.h"

namespace muse::dock {
class DockFrameToolBarModel : public muse::uicomponents::AbstractToolBarModel
{
Q_OBJECT

Q_PROPERTY(QString currentDockUniqueName READ currentDockUniqueName
WRITE setCurrentDock NOTIFY currentDockUniqueNameChanged REQUIRED)
Q_PROPERTY(Location location READ location
WRITE setLocation NOTIFY locationChanged REQUIRED)

public:
Location location() const;
QString currentDockUniqueName() const;

public slots:
void setLocation(const Location& location);
void setCurrentDock(const QString& currentDockUniqueName);

signals:
void locationChanged(Location location);
void currentDockUniqueNameChanged(QString currentDockUniqueName);

private:
// TODO: Placeholder methods - info will be pulled from elsewhere...
muse::ui::UiActionList centralActionsForDockName(const QString& dockUniqueName) const;
muse::ui::UiActionList rightSideActionsForDockName(const QString& dockUniqueName) const;

// TODO: These shouldn't live here...
static const muse::ui::UiActionList m_percussionCentralActions;
static const muse::ui::UiActionList m_percussionRightSideActions;
static const std::vector<ui::UiAction> m_percussionLayoutSubActions;

Location m_location = Location::Undefined;
QString m_currentDockUniqueName;
};
}

#endif // MUSE_DOCK_DOCKFRAMETOOLBARMODEL_H
38 changes: 38 additions & 0 deletions src/framework/dockwindow/qml/Muse/Dock/DockFrame.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ Rectangle {
id: frameModel

frame: root.frameCpp

onCurrentDockChanged: {
centralToolBarModel.setCurrentDock(frameModel.currentDockUniqueName)
rightSideToolBarModel.setCurrentDock(frameModel.currentDockUniqueName)
}
}

NavigationPanel {
Expand Down Expand Up @@ -234,6 +239,39 @@ Rectangle {
}
}

StyledToolBarView {
id: centralToolBar

// TODO: Visuals haven't been refined yet (alignment, button accents, etc.) not a priority at the moment
anchors.centerIn: titleBar.visible ? titleBar : tabsPanel

visible: centralToolBarModel.length > 0

model: DockFrameToolBarModel {
id: centralToolBarModel

location: Location.Center
currentDockUniqueName: frameModel.currentDockUniqueName
}
}

StyledToolBarView {
id: rightSideToolBar

// TODO: Visuals haven't been refined yet (alignment, button accents, etc.) not a priority at the moment
anchors.verticalCenter: titleBar.visible ? titleBar.verticalCenter : tabsPanel.verticalCenter
anchors.right: titleBar.visible ? titleBar.right : tabsPanel.right

visible: rightSideToolBarModel.length > 0

model: DockFrameToolBarModel {
id: rightSideToolBarModel

location: Location.Right
currentDockUniqueName: frameModel.currentDockUniqueName
}
}

Rectangle {
visible: frameModel.highlightingVisible

Expand Down
25 changes: 14 additions & 11 deletions src/framework/ui/uiaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,28 @@ struct UiAction
IconCode::Code iconCode = IconCode::Code::NONE;
Checkable checkable = Checkable::No;
std::vector<std::string> shortcuts;
std::vector<UiAction> subActions;

UiAction() = default;
UiAction(const actions::ActionCode& code, UiContext ctx, std::string scCtx, Checkable ch = Checkable::No)
: code(code), uiCtx(ctx), scCtx(scCtx), checkable(ch) {}
UiAction(const actions::ActionCode& code, UiContext ctx, std::string scCtx, Checkable ch = Checkable::No,
std::vector<UiAction> subs = {})
: code(code), uiCtx(ctx), scCtx(scCtx), checkable(ch), subActions(subs) {}

UiAction(const actions::ActionCode& code, UiContext ctx, std::string scCtx, const MnemonicString& title,
Checkable ch = Checkable::No)
: code(code), uiCtx(ctx), scCtx(scCtx), title(title), checkable(ch) {}
Checkable ch = Checkable::No, std::vector<UiAction> subs = {})
: code(code), uiCtx(ctx), scCtx(scCtx), title(title), checkable(ch), subActions(subs) {}

UiAction(const actions::ActionCode& code, UiContext ctx, std::string scCtx, const MnemonicString& title,
const TranslatableString& desc, Checkable ch = Checkable::No)
: code(code), uiCtx(ctx), scCtx(scCtx), title(title), description(desc), checkable(ch) {}
const TranslatableString& desc, Checkable ch = Checkable::No, std::vector<UiAction> subs = {})
: code(code), uiCtx(ctx), scCtx(scCtx), title(title), description(desc), checkable(ch), subActions(subs) {}

UiAction(const actions::ActionCode& code, UiContext ctx, std::string scCtx, const MnemonicString& title,
const TranslatableString& desc, IconCode::Code icon, Checkable ch = Checkable::No)
: code(code), uiCtx(ctx), scCtx(scCtx), title(title), description(desc), iconCode(icon), checkable(ch) {}
const TranslatableString& desc, IconCode::Code icon, Checkable ch = Checkable::No, std::vector<UiAction> subs = {})
: code(code), uiCtx(ctx), scCtx(scCtx), title(title), description(desc), iconCode(icon), checkable(ch), subActions(subs) {}

UiAction(const actions::ActionCode& code, UiContext ctx, std::string scCtx, const MnemonicString& title, IconCode::Code icon,
Checkable ch = Checkable::No)
: code(code), uiCtx(ctx), scCtx(scCtx), title(title), iconCode(icon), checkable(ch) {}
Checkable ch = Checkable::No, std::vector<UiAction> subs = {})
: code(code), uiCtx(ctx), scCtx(scCtx), title(title), iconCode(icon), checkable(ch), subActions(subs) {}

bool isValid() const
{
Expand All @@ -91,7 +93,8 @@ struct UiAction
&& description == other.description
&& iconCode == other.iconCode
&& checkable == other.checkable
&& shortcuts == shortcuts;
&& shortcuts == other.shortcuts
&& subActions == other.subActions;
}
};

Expand Down
Loading

0 comments on commit 0569fb2

Please sign in to comment.