added fake play
This commit is contained in:
parent
2245bd16c6
commit
e74a742958
18 changed files with 519 additions and 104 deletions
|
@ -88,6 +88,7 @@ if (BUILD_UI_MU4)
|
|||
extensions
|
||||
notation
|
||||
notation_scene
|
||||
common_scene
|
||||
)
|
||||
endif(BUILD_UI_MU4)
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "mu4/extensions/extensionsmodule.h"
|
||||
#include "mu4/domain/notation/notationdomainmodule.h"
|
||||
#include "mu4/scenes/notation/notationscenemodule.h"
|
||||
#include "mu4/scenes/common/commonscenemodule.h"
|
||||
|
||||
#ifdef BUILD_TELEMETRY_MODULE
|
||||
#include "framework/telemetry/telemetrysetup.h"
|
||||
|
@ -55,6 +56,7 @@ ModulesSetup::ModulesSetup()
|
|||
<< new mu::extensions::ExtensionsModule()
|
||||
<< new mu::domain::notation::NotationDomainModule()
|
||||
<< new mu::scene::notation::NotationSceneModule()
|
||||
<< new mu::scene::common::CommonSceneModule()
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_TELEMETRY_MODULE
|
||||
|
|
|
@ -10,5 +10,9 @@ add_subdirectory(domain/notation)
|
|||
add_subdirectory(scores)
|
||||
add_subdirectory(extensions)
|
||||
|
||||
# Scenes common
|
||||
add_subdirectory(scenes/common)
|
||||
|
||||
# Notation
|
||||
add_subdirectory(scenes/notation)
|
||||
|
||||
|
|
|
@ -9,5 +9,6 @@
|
|||
<file>qml/NotationPage/NotationPage.qml</file>
|
||||
<file>qml/NotationPage/NotationToolBar.qml</file>
|
||||
<file>qml/Settings/SettingsPage.qml</file>
|
||||
<file>qml/PlayToolBar.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -39,31 +39,31 @@ static const QString windowQss = QString("QMainWindow { background: #808000; } "
|
|||
|
||||
static const QString statusQss = QString("QStatusBar { background: %1; } QStatusBar::item { border: 0 }");
|
||||
|
||||
DockWindow::DockWindow(QQuickItem* parent) :
|
||||
QQuickItem(parent), _pages(this)
|
||||
DockWindow::DockWindow(QQuickItem* parent)
|
||||
: QQuickItem(parent), m_toolbars(this), m_pages(this)
|
||||
{
|
||||
setFlag(QQuickItem::ItemHasContents, true);
|
||||
_window = new QMainWindow();
|
||||
_window->setMinimumSize(800, 600);
|
||||
m_window = new QMainWindow();
|
||||
m_window->setMinimumSize(800, 600);
|
||||
setWidth(1024);
|
||||
setHeight(800);
|
||||
|
||||
_eventsWatcher = new EventsWatcher(this);
|
||||
_window->installEventFilter(_eventsWatcher);
|
||||
connect(_eventsWatcher, &EventsWatcher::eventReceived, this, &DockWindow::onMainWindowEvent);
|
||||
m_eventsWatcher = new EventsWatcher(this);
|
||||
m_window->installEventFilter(m_eventsWatcher);
|
||||
connect(m_eventsWatcher, &EventsWatcher::eventReceived, this, &DockWindow::onMainWindowEvent);
|
||||
|
||||
_central = new QStackedWidget(_window);
|
||||
_window->setCentralWidget(_central);
|
||||
m_central = new QStackedWidget(m_window);
|
||||
m_window->setCentralWidget(m_central);
|
||||
|
||||
_window->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::West);
|
||||
_window->setTabPosition(Qt::RightDockWidgetArea, QTabWidget::East);
|
||||
_window->setAnimated(false);
|
||||
m_window->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::West);
|
||||
m_window->setTabPosition(Qt::RightDockWidgetArea, QTabWidget::East);
|
||||
m_window->setAnimated(false);
|
||||
|
||||
_statusbar = new QStatusBar(_window);
|
||||
_statusbar->setSizeGripEnabled(false);
|
||||
_window->setStatusBar(_statusbar);
|
||||
m_statusbar = new QStatusBar(m_window);
|
||||
m_statusbar->setSizeGripEnabled(false);
|
||||
m_window->setStatusBar(m_statusbar);
|
||||
|
||||
connect(_pages.notifier(), &QmlListPropertyNotifier::appended, this, &DockWindow::onPageAppended);
|
||||
connect(m_pages.notifier(), &QmlListPropertyNotifier::appended, this, &DockWindow::onPageAppended);
|
||||
connect(this, &DockWindow::colorChanged, this, &DockWindow::updateStyle);
|
||||
}
|
||||
|
||||
|
@ -73,17 +73,17 @@ void DockWindow::componentComplete()
|
|||
|
||||
updateStyle();
|
||||
|
||||
if (_toolbar) {
|
||||
DockToolBar::Widget t = _toolbar->widget();
|
||||
t.bar->setParent(_window);
|
||||
_window->addToolBar(t.bar);
|
||||
for (DockToolBar* t : m_toolbars.list()) {
|
||||
DockToolBar::Widget tw = t->widget();
|
||||
tw.bar->setParent(m_window);
|
||||
m_window->addToolBar(tw.bar);
|
||||
}
|
||||
|
||||
togglePage(nullptr, currentPage());
|
||||
|
||||
_window->show();
|
||||
m_window->show();
|
||||
|
||||
_isComponentComplete = true;
|
||||
m_isComponentComplete = true;
|
||||
}
|
||||
|
||||
void DockWindow::onMainWindowEvent(QEvent* e)
|
||||
|
@ -110,36 +110,36 @@ void DockWindow::togglePage(DockPage* old, DockPage* current)
|
|||
|
||||
void DockWindow::hidePage(DockPage* p)
|
||||
{
|
||||
p->setState(_window->saveState());
|
||||
p->setState(m_window->saveState());
|
||||
|
||||
QList<QWidget*> widgetsToHide;
|
||||
|
||||
DockCentral* central = p->central();
|
||||
if (central) {
|
||||
DockCentral::Widget cw = central->widget();
|
||||
_central->removeWidget(cw.widget);
|
||||
m_central->removeWidget(cw.widget);
|
||||
widgetsToHide << cw.widget;
|
||||
}
|
||||
|
||||
QList<DockPanel*> panels = p->panels();
|
||||
for (DockPanel* panel : panels) {
|
||||
DockPanel::Widget dw = panel->widget();
|
||||
_window->removeDockWidget(dw.panel);
|
||||
m_window->removeDockWidget(dw.panel);
|
||||
widgetsToHide << dw.panel;
|
||||
}
|
||||
|
||||
DockToolBar* tool = p->toolbar();
|
||||
if (tool) {
|
||||
DockToolBar::Widget tw = tool->widget();
|
||||
_window->removeToolBarBreak(tw.bar);
|
||||
_window->removeToolBar(tw.bar);
|
||||
m_window->removeToolBarBreak(tw.bar);
|
||||
m_window->removeToolBar(tw.bar);
|
||||
widgetsToHide << tw.bar;
|
||||
}
|
||||
|
||||
DockStatusBar* status = p->statusbar();
|
||||
if (status) {
|
||||
DockStatusBar::Widget sw = status->widget();
|
||||
_statusbar->removeWidget(sw.widget);
|
||||
m_statusbar->removeWidget(sw.widget);
|
||||
widgetsToHide << sw.widget;
|
||||
}
|
||||
|
||||
|
@ -149,8 +149,8 @@ void DockWindow::hidePage(DockPage* p)
|
|||
w->setParent(dummy);
|
||||
}
|
||||
|
||||
_window->update();
|
||||
_window->repaint();
|
||||
m_window->update();
|
||||
m_window->repaint();
|
||||
}
|
||||
|
||||
void DockWindow::showPage(DockPage* p)
|
||||
|
@ -163,9 +163,9 @@ void DockWindow::showPage(DockPage* p)
|
|||
if (tool) {
|
||||
DockToolBar::Widget tw = tool->widget();
|
||||
if (tw.breakArea != Qt::NoToolBarArea) {
|
||||
_window->addToolBarBreak(tw.breakArea);
|
||||
m_window->addToolBarBreak(tw.breakArea);
|
||||
}
|
||||
_window->addToolBar(tw.bar);
|
||||
m_window->addToolBar(tw.bar);
|
||||
widgetsToShow << tw.bar;
|
||||
}
|
||||
|
||||
|
@ -173,18 +173,18 @@ void DockWindow::showPage(DockPage* p)
|
|||
DockStatusBar* status = p->statusbar();
|
||||
if (status) {
|
||||
DockStatusBar::Widget sw = status->widget();
|
||||
_statusbar->setFixedHeight(sw.widget->height());
|
||||
_statusbar->addWidget(sw.widget, 1);
|
||||
widgetsToShow << sw.widget << _statusbar;
|
||||
m_statusbar->setFixedHeight(sw.widget->height());
|
||||
m_statusbar->addWidget(sw.widget, 1);
|
||||
widgetsToShow << sw.widget << m_statusbar;
|
||||
} else {
|
||||
widgetsToHide << _statusbar;
|
||||
widgetsToHide << m_statusbar;
|
||||
}
|
||||
|
||||
// Panels
|
||||
QList<DockPanel*> panels = p->panels();
|
||||
for (DockPanel* panel : panels) {
|
||||
DockPanel::Widget dw = panel->widget();
|
||||
_window->addDockWidget(dw.area, dw.panel);
|
||||
m_window->addDockWidget(dw.area, dw.panel);
|
||||
widgetsToShow << dw.panel;
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ void DockWindow::showPage(DockPage* p)
|
|||
LOGE() << "unable tabify, not found panel with name: " << dw.tabifyObjectName;
|
||||
continue;
|
||||
}
|
||||
_window->tabifyDockWidget(tp->widget().panel, dw.panel);
|
||||
m_window->tabifyDockWidget(tp->widget().panel, dw.panel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,13 +213,13 @@ void DockWindow::showPage(DockPage* p)
|
|||
DockCentral* central = p->central();
|
||||
if (central) {
|
||||
DockCentral::Widget cw = central->widget();
|
||||
_central->addWidget(cw.widget);
|
||||
m_central->addWidget(cw.widget);
|
||||
widgetsToShow << cw.widget;
|
||||
}
|
||||
|
||||
QByteArray state = p->state();
|
||||
if (!state.isEmpty()) {
|
||||
_window->restoreState(state);
|
||||
m_window->restoreState(state);
|
||||
}
|
||||
|
||||
for (QWidget* w : widgetsToShow) {
|
||||
|
@ -239,62 +239,51 @@ void DockWindow::updateStyle()
|
|||
|
||||
DockPage* DockWindow::currentPage() const
|
||||
{
|
||||
return page(_currentPageName);
|
||||
return page(m_currentPageName);
|
||||
}
|
||||
|
||||
QString DockWindow::title() const
|
||||
{
|
||||
return _title;
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void DockWindow::setTitle(QString title)
|
||||
{
|
||||
if (_title == title) {
|
||||
if (m_title == title) {
|
||||
return;
|
||||
}
|
||||
|
||||
_window->setWindowTitle(title);
|
||||
m_window->setWindowTitle(title);
|
||||
|
||||
_title = title;
|
||||
emit titleChanged(_title);
|
||||
m_title = title;
|
||||
emit titleChanged(m_title);
|
||||
}
|
||||
|
||||
QColor DockWindow::color() const
|
||||
{
|
||||
return _color;
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void DockWindow::setColor(QColor color)
|
||||
{
|
||||
if (_color == color) {
|
||||
if (m_color == color) {
|
||||
return;
|
||||
}
|
||||
|
||||
_color = color;
|
||||
emit colorChanged(_color);
|
||||
m_color = color;
|
||||
emit colorChanged(m_color);
|
||||
}
|
||||
|
||||
DockToolBar* DockWindow::toolbar() const
|
||||
QQmlListProperty<DockToolBar> DockWindow::toolbars()
|
||||
{
|
||||
return _toolbar;
|
||||
}
|
||||
|
||||
void DockWindow::setToolbar(DockToolBar* toolbar)
|
||||
{
|
||||
if (_toolbar == toolbar) {
|
||||
return;
|
||||
}
|
||||
|
||||
_toolbar = toolbar;
|
||||
_toolbar->setParentItem(this);
|
||||
emit toolbarChanged(_toolbar);
|
||||
return m_toolbars.property();
|
||||
}
|
||||
|
||||
DockPage* DockWindow::page(const QString& name) const
|
||||
{
|
||||
for (int i = 0; i < _pages.count(); ++i) {
|
||||
if (_pages.at(i)->objectName() == name) {
|
||||
return _pages.at(i);
|
||||
for (int i = 0; i < m_pages.count(); ++i) {
|
||||
if (m_pages.at(i)->objectName() == name) {
|
||||
return m_pages.at(i);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -302,12 +291,12 @@ DockPage* DockWindow::page(const QString& name) const
|
|||
|
||||
QQmlListProperty<DockPage> DockWindow::pages()
|
||||
{
|
||||
return _pages.property();
|
||||
return m_pages.property();
|
||||
}
|
||||
|
||||
void DockWindow::onPageAppended(int index)
|
||||
{
|
||||
DockPage* page = _pages.at(index);
|
||||
DockPage* page = m_pages.at(index);
|
||||
qInfo() << page->objectName();
|
||||
page->setParentItem(this);
|
||||
page->setWidth(this->width());
|
||||
|
@ -316,19 +305,19 @@ void DockWindow::onPageAppended(int index)
|
|||
|
||||
QString DockWindow::currentPageName() const
|
||||
{
|
||||
return _currentPageName;
|
||||
return m_currentPageName;
|
||||
}
|
||||
|
||||
void DockWindow::setCurrentPageName(QString currentPageName)
|
||||
{
|
||||
if (_currentPageName == currentPageName) {
|
||||
if (m_currentPageName == currentPageName) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isComponentComplete) {
|
||||
togglePage(page(_currentPageName), page(currentPageName));
|
||||
if (m_isComponentComplete) {
|
||||
togglePage(page(m_currentPageName), page(currentPageName));
|
||||
}
|
||||
|
||||
_currentPageName = currentPageName;
|
||||
emit currentPageNameChanged(_currentPageName);
|
||||
m_currentPageName = currentPageName;
|
||||
emit currentPageNameChanged(m_currentPageName);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class DockWindow : public QQuickItem
|
|||
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
|
||||
Q_PROPERTY(DockToolBar * toolbar READ toolbar WRITE setToolbar NOTIFY toolbarChanged)
|
||||
Q_PROPERTY(QQmlListProperty<mu::dock::DockToolBar> toolbars READ toolbars)
|
||||
|
||||
Q_PROPERTY(QQmlListProperty<mu::dock::DockPage> pages READ pages)
|
||||
Q_PROPERTY(QString currentPageName READ currentPageName WRITE setCurrentPageName NOTIFY currentPageNameChanged)
|
||||
|
@ -51,21 +51,20 @@ public:
|
|||
|
||||
QString title() const;
|
||||
QColor color() const;
|
||||
DockToolBar* toolbar() const;
|
||||
|
||||
QQmlListProperty<DockToolBar> toolbars();
|
||||
QQmlListProperty<DockPage> pages();
|
||||
|
||||
QString currentPageName() const;
|
||||
|
||||
public slots:
|
||||
void setTitle(QString title);
|
||||
void setColor(QColor color);
|
||||
void setToolbar(DockToolBar* toolbar);
|
||||
void setCurrentPageName(QString currentPageName);
|
||||
|
||||
signals:
|
||||
void titleChanged(QString title);
|
||||
void colorChanged(QColor color);
|
||||
void toolbarChanged(DockToolBar* toolbar);
|
||||
void currentPageNameChanged(QString currentPageName);
|
||||
|
||||
private slots:
|
||||
|
@ -84,16 +83,16 @@ private:
|
|||
void hidePage(DockPage* p);
|
||||
void showPage(DockPage* p);
|
||||
|
||||
QMainWindow* _window = nullptr;
|
||||
EventsWatcher* _eventsWatcher = nullptr;
|
||||
QString _title;
|
||||
DockToolBar* _toolbar = nullptr;
|
||||
QStackedWidget* _central = nullptr;
|
||||
QStatusBar* _statusbar = nullptr;
|
||||
QmlListProperty<DockPage> _pages;
|
||||
QString _currentPageName;
|
||||
bool _isComponentComplete = false;
|
||||
QColor _color;
|
||||
QMainWindow* m_window = nullptr;
|
||||
EventsWatcher* m_eventsWatcher = nullptr;
|
||||
QString m_title;
|
||||
QmlListProperty<DockToolBar> m_toolbars;
|
||||
QStackedWidget* m_central = nullptr;
|
||||
QStatusBar* m_statusbar = nullptr;
|
||||
QmlListProperty<DockPage> m_pages;
|
||||
QString m_currentPageName;
|
||||
bool m_isComponentComplete = false;
|
||||
QColor m_color;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,29 +9,43 @@ DockWindow {
|
|||
|
||||
id: dockWindow
|
||||
|
||||
title: "MuseScore Craft"
|
||||
title: "MuseScore 4"
|
||||
|
||||
color: ui.theme.window
|
||||
|
||||
currentPageName: "home"
|
||||
|
||||
toolbar: DockToolBar {
|
||||
toolbars: [
|
||||
DockToolBar {
|
||||
id: mainToolBar
|
||||
objectName: "mainToolBar"
|
||||
|
||||
id: windowToolBar
|
||||
objectName: "windowToolBar"
|
||||
width: 300
|
||||
height: 32
|
||||
color: dockWindow.color
|
||||
|
||||
width: 300
|
||||
height: 32
|
||||
color: dockWindow.color
|
||||
MainToolBar {
|
||||
color: dockWindow.color
|
||||
currentItem: dockWindow.currentPageName
|
||||
onSelected: {
|
||||
dockWindow.currentPageName = item;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
MainToolBar {
|
||||
color: windowToolBar.color
|
||||
currentItem: dockWindow.currentPageName
|
||||
onSelected: {
|
||||
dockWindow.currentPageName = item;
|
||||
DockToolBar {
|
||||
id: playToolBar
|
||||
objectName: "playToolBar"
|
||||
|
||||
width: 300
|
||||
height: 32
|
||||
color: dockWindow.color
|
||||
|
||||
PlayToolBar {
|
||||
color: dockWindow.color
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
HomePage {
|
||||
|
|
54
mu4/appshell/qml/PlayToolBar.qml
Normal file
54
mu4/appshell/qml/PlayToolBar.qml
Normal file
|
@ -0,0 +1,54 @@
|
|||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.2
|
||||
import MuseScore.CommonScene 1.0
|
||||
|
||||
Rectangle {
|
||||
|
||||
id: root
|
||||
|
||||
Row {
|
||||
anchors.fill: parent
|
||||
|
||||
Repeater {
|
||||
anchors.fill: parent
|
||||
model: toolModel
|
||||
Rectangle {
|
||||
id: item
|
||||
|
||||
property bool enabled: enabledRole
|
||||
|
||||
height: parent.height
|
||||
width: 60
|
||||
color: checkedRole ? "#34C1FF" : root.color
|
||||
opacity: item.enabled ? 1.0 : 0.5
|
||||
|
||||
Text {
|
||||
anchors.fill: parent
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font.family: "Roboto"
|
||||
font.capitalization: Font.Capitalize
|
||||
text: titleRole
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
if (item.enabled) {
|
||||
toolModel.click(nameRole)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlayToolBarModel {
|
||||
id: toolModel
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
toolModel.load()
|
||||
}
|
||||
|
||||
}
|
|
@ -35,6 +35,10 @@ public:
|
|||
virtual void setCurrentNotation(const std::shared_ptr<domain::notation::INotation>& notation) = 0;
|
||||
virtual std::shared_ptr<domain::notation::INotation> currentNotation() const = 0;
|
||||
virtual async::Notification currentNotationChanged() const = 0;
|
||||
|
||||
virtual bool isPlaying() const = 0;
|
||||
virtual void setIsPlaying(bool arg) = 0;
|
||||
virtual async::Notification isPlayingChanged() const = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,3 +36,19 @@ mu::async::Notification GlobalContext::currentNotationChanged() const
|
|||
{
|
||||
return m_notationChanged;
|
||||
}
|
||||
|
||||
bool GlobalContext::isPlaying() const
|
||||
{
|
||||
return m_isPlaying;
|
||||
}
|
||||
|
||||
void GlobalContext::setIsPlaying(bool arg)
|
||||
{
|
||||
m_isPlaying = arg;
|
||||
m_isPlayingChanged.notify();
|
||||
}
|
||||
|
||||
mu::async::Notification GlobalContext::isPlayingChanged() const
|
||||
{
|
||||
return m_isPlayingChanged;
|
||||
}
|
||||
|
|
|
@ -33,10 +33,17 @@ public:
|
|||
std::shared_ptr<domain::notation::INotation> currentNotation() const override;
|
||||
async::Notification currentNotationChanged() const override;
|
||||
|
||||
bool isPlaying() const override;
|
||||
void setIsPlaying(bool arg) override;
|
||||
async::Notification isPlayingChanged() const override;
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<domain::notation::INotation> m_notation;
|
||||
async::Notification m_notationChanged;
|
||||
|
||||
bool m_isPlaying = false;
|
||||
async::Notification m_isPlayingChanged;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
33
mu4/scenes/common/CMakeLists.txt
Normal file
33
mu4/scenes/common/CMakeLists.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
#=============================================================================
|
||||
# MuseScore
|
||||
# Music Composition & Notation
|
||||
#
|
||||
# Copyright (C) 2020 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 2.
|
||||
#
|
||||
# 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, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#=============================================================================
|
||||
|
||||
set(MODULE common_scene)
|
||||
|
||||
set(MODULE_SRC
|
||||
${CMAKE_CURRENT_LIST_DIR}/commonscenemodule.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/commonscenemodule.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/playtoolbarmodel.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/playtoolbarmodel.h
|
||||
)
|
||||
|
||||
include(${PROJECT_SOURCE_DIR}/build/module.cmake)
|
||||
|
||||
|
||||
|
||||
|
48
mu4/scenes/common/commonscenemodule.cpp
Normal file
48
mu4/scenes/common/commonscenemodule.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 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 2.
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#include "commonscenemodule.h"
|
||||
|
||||
#include <QtQml>
|
||||
#include "modularity/ioc.h"
|
||||
|
||||
#include "playtoolbarmodel.h"
|
||||
|
||||
using namespace mu::scene::common;
|
||||
|
||||
std::string CommonSceneModule::moduleName() const
|
||||
{
|
||||
return "common_scene";
|
||||
}
|
||||
|
||||
void CommonSceneModule::registerExports()
|
||||
{
|
||||
}
|
||||
|
||||
void CommonSceneModule::resolveImports()
|
||||
{
|
||||
}
|
||||
|
||||
void CommonSceneModule::registerResources()
|
||||
{
|
||||
}
|
||||
|
||||
void CommonSceneModule::registerUiTypes()
|
||||
{
|
||||
qmlRegisterType<PlayToolBarModel>("MuseScore.CommonScene", 1, 0, "PlayToolBarModel");
|
||||
}
|
43
mu4/scenes/common/commonscenemodule.h
Normal file
43
mu4/scenes/common/commonscenemodule.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 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 2.
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#ifndef MU_SCENECOMMON_COMMONSCENEMODULE_H
|
||||
#define MU_SCENECOMMON_COMMONSCENEMODULE_H
|
||||
|
||||
#include "modularity/imodulesetup.h"
|
||||
|
||||
namespace mu {
|
||||
namespace scene {
|
||||
namespace common {
|
||||
class CommonSceneModule : public framework::IModuleSetup
|
||||
{
|
||||
public:
|
||||
|
||||
std::string moduleName() const override;
|
||||
|
||||
void registerExports() override;
|
||||
void resolveImports() override;
|
||||
|
||||
void registerResources() override;
|
||||
void registerUiTypes() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MU_SCENECOMMON_COMMONSCENEMODULE_H
|
126
mu4/scenes/common/playtoolbarmodel.cpp
Normal file
126
mu4/scenes/common/playtoolbarmodel.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 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 2.
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#include "playtoolbarmodel.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::scene::common;
|
||||
using namespace mu::actions;
|
||||
using namespace mu::domain::notation;
|
||||
|
||||
PlayToolBarModel::PlayToolBarModel(QObject* parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QVariant PlayToolBarModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
const ActionItem& item = m_items.at(index.row());
|
||||
switch (role) {
|
||||
case TitleRole: return QString::fromStdString(item.action.title);
|
||||
case NameRole: return QString::fromStdString(item.action.name);
|
||||
case EnabledRole: return item.enabled;
|
||||
case CheckedRole: return item.checked;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int PlayToolBarModel::rowCount(const QModelIndex&) const
|
||||
{
|
||||
return m_items.count();
|
||||
}
|
||||
|
||||
QHash<int,QByteArray> PlayToolBarModel::roleNames() const
|
||||
{
|
||||
static const QHash<int, QByteArray> roles = {
|
||||
{ NameRole, "nameRole" },
|
||||
{ TitleRole, "titleRole" },
|
||||
{ EnabledRole, "enabledRole" },
|
||||
{ CheckedRole, "checkedRole" }
|
||||
};
|
||||
return roles;
|
||||
}
|
||||
|
||||
void PlayToolBarModel::load()
|
||||
{
|
||||
auto makeItem = [](const Action& action) {
|
||||
ActionItem item;
|
||||
item.action = action;
|
||||
return item;
|
||||
};
|
||||
|
||||
beginResetModel();
|
||||
|
||||
m_items << makeItem(Action { "domain/audio/play", "Play" });
|
||||
|
||||
endResetModel();
|
||||
|
||||
updateState();
|
||||
globalContext()->currentNotationChanged().onNotify(this, [this]() {
|
||||
updateState();
|
||||
});
|
||||
|
||||
globalContext()->isPlayingChanged().onNotify(this, [this]() {
|
||||
updateState();
|
||||
});
|
||||
}
|
||||
|
||||
void PlayToolBarModel::click(const QString& action)
|
||||
{
|
||||
LOGI() << action;
|
||||
|
||||
//! NOTE This is fake play, added for demonstration
|
||||
if (action == "domain/audio/play") {
|
||||
globalContext()->setIsPlaying(!globalContext()->isPlaying());
|
||||
}
|
||||
}
|
||||
|
||||
void PlayToolBarModel::updateState()
|
||||
{
|
||||
std::shared_ptr<INotation> notation = globalContext()->currentNotation();
|
||||
|
||||
if (!notation) {
|
||||
for (ActionItem& item : m_items) {
|
||||
item.enabled = false;
|
||||
item.checked = false;
|
||||
}
|
||||
} else {
|
||||
for (ActionItem& item : m_items) {
|
||||
item.enabled = true;
|
||||
item.checked = false;
|
||||
}
|
||||
|
||||
item("domain/audio/play").checked = globalContext()->isPlaying();
|
||||
}
|
||||
|
||||
emit dataChanged(index(0), index(rowCount() - 1));
|
||||
}
|
||||
|
||||
PlayToolBarModel::ActionItem& PlayToolBarModel::item(const actions::ActionName& name)
|
||||
{
|
||||
for (ActionItem& item : m_items) {
|
||||
if (item.action.name == name) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
LOGE() << "item not found with name: " << name;
|
||||
static ActionItem null;
|
||||
return null;
|
||||
}
|
70
mu4/scenes/common/playtoolbarmodel.h
Normal file
70
mu4/scenes/common/playtoolbarmodel.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 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 2.
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#ifndef MU_SCENECOMMON_PLAYTOOLBARMODEL_H
|
||||
#define MU_SCENECOMMON_PLAYTOOLBARMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
#include "modularity/ioc.h"
|
||||
#include "context/iglobalcontext.h"
|
||||
#include "async/asyncable.h"
|
||||
|
||||
namespace mu {
|
||||
namespace scene {
|
||||
namespace common {
|
||||
class PlayToolBarModel : public QAbstractListModel, public async::Asyncable
|
||||
{
|
||||
Q_OBJECT
|
||||
INJECT(notation_scene, context::IGlobalContext, globalContext)
|
||||
|
||||
public:
|
||||
explicit PlayToolBarModel(QObject* parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
QHash<int,QByteArray> roleNames() const override;
|
||||
|
||||
Q_INVOKABLE void load();
|
||||
Q_INVOKABLE void click(const QString& action);
|
||||
|
||||
private:
|
||||
|
||||
enum Roles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
TitleRole,
|
||||
EnabledRole,
|
||||
CheckedRole
|
||||
};
|
||||
|
||||
struct ActionItem {
|
||||
actions::Action action;
|
||||
bool enabled = false;
|
||||
bool checked = false;
|
||||
};
|
||||
|
||||
void updateState();
|
||||
|
||||
ActionItem& item(const actions::ActionName& name);
|
||||
QList<ActionItem> m_items;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MU_SCENECOMMON_PLAYTOOLBARMODEL_H
|
|
@ -81,6 +81,10 @@ void NotationToolBarModel::load()
|
|||
m_notationChanged.onNotify(this, [this]() {
|
||||
onNotationChanged();
|
||||
});
|
||||
|
||||
globalContext()->isPlayingChanged().onNotify(this, [this]() {
|
||||
updateState();
|
||||
});
|
||||
}
|
||||
|
||||
NotationToolBarModel::ActionItem& NotationToolBarModel::item(const actions::ActionName& name)
|
||||
|
@ -117,7 +121,8 @@ void NotationToolBarModel::onNotationChanged()
|
|||
void NotationToolBarModel::updateState()
|
||||
{
|
||||
std::shared_ptr<INotation> notation = globalContext()->currentNotation();
|
||||
if (!notation) {
|
||||
bool isPlaying = globalContext()->isPlaying();
|
||||
if (!notation || isPlaying) {
|
||||
for (ActionItem& item : m_items) {
|
||||
item.enabled = false;
|
||||
item.checked = false;
|
||||
|
@ -142,7 +147,7 @@ void NotationToolBarModel::updateState()
|
|||
}
|
||||
}
|
||||
|
||||
item("domain/notation/file-open").enabled = true;
|
||||
item("domain/notation/file-open").enabled = !isPlaying;
|
||||
|
||||
emit dataChanged(index(0), index(rowCount() - 1));
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ private:
|
|||
|
||||
void onNotationChanged();
|
||||
void updateState();
|
||||
void disabledAll();
|
||||
|
||||
struct ActionItem {
|
||||
actions::Action action;
|
||||
|
|
Loading…
Reference in a new issue