fixed some issues by review

This commit is contained in:
Igor Korsukov 2020-07-10 10:46:56 +02:00
parent e861f1ee5d
commit 8cf1dad8ce
18 changed files with 253 additions and 144 deletions

View file

@ -181,3 +181,13 @@ mu::async::Notification MU3PaletteAdapter::paletteSearchRequested() const
{
return m_paletteSearchRequested;
}
void MU3PaletteAdapter::notifyElementDraggedToScoreView()
{
m_elementDraggedToScoreView.notify();
}
mu::async::Notification MU3PaletteAdapter::elementDraggedToScoreView() const
{
return m_elementDraggedToScoreView;
}

View file

@ -54,11 +54,14 @@ public:
void setPaletteEnabled(bool arg) override;
void requestPaletteSearch() override;
mu::async::Notification paletteSearchRequested() const override;
void notifyElementDraggedToScoreView() override;
mu::async::Notification elementDraggedToScoreView() const override;
private:
mu::ValCh<bool> m_paletteEnabled;
mu::async::Notification m_paletteSearchRequested;
mu::async::Notification m_elementDraggedToScoreView;
};
}

View file

@ -166,6 +166,7 @@ void PaletteWidget::applyCurrentPaletteElement()
void PaletteWidget::notifyElementDraggedToScoreView()
{
qmlInterface->notifyElementDraggedToScoreView();
adapter()->notifyElementDraggedToScoreView();
}
//---------------------------------------------------------

View file

@ -70,7 +70,7 @@ public:
virtual bool isDropAccepted(const QPointF& pos, Qt::KeyboardModifiers modifiers) = 0; //! NOTE Also may set drop target
virtual bool drop(const QPointF& pos, Qt::KeyboardModifiers modifiers) = 0;
virtual void endDrop() = 0;
virtual async::Notification droped() const = 0;
virtual async::Notification dropChanged() const = 0;
// Move
//! NOTE Perform operations on selected elements

View file

@ -64,7 +64,7 @@ Notation::Notation()
notifyAboutNotationChanged();
});
m_interaction->droped().onNotify(this, [this]() {
m_interaction->dropChanged().onNotify(this, [this]() {
notifyAboutNotationChanged();
});
}

View file

@ -973,7 +973,7 @@ void NotationInteraction::endDrop()
setDropTarget(nullptr);
}
mu::async::Notification NotationInteraction::droped() const
mu::async::Notification NotationInteraction::dropChanged() const
{
return m_dropChanged;
}

View file

@ -87,7 +87,7 @@ public:
bool isDropAccepted(const QPointF& pos, Qt::KeyboardModifiers modifiers) override;
bool drop(const QPointF& pos, Qt::KeyboardModifiers modifiers) override;
void endDrop() override;
async::Notification droped() const override;
async::Notification dropChanged() const override;
// Move
//! NOTE Perform operations on selected elements

View file

@ -41,6 +41,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/internal/workspacepalettestream.h
${CMAKE_CURRENT_LIST_DIR}/internal/paletteconfiguration.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/paletteconfiguration.h
${CMAKE_CURRENT_LIST_DIR}/internal/paletteworkspacesetup.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/paletteworkspacesetup.h
${CMAKE_CURRENT_LIST_DIR}/view/paletterootmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/view/paletterootmodel.h
)

View file

@ -166,3 +166,13 @@ mu::async::Notification MU4PaletteAdapter::paletteSearchRequested() const
{
return m_paletteSearchRequested;
}
void MU4PaletteAdapter::notifyElementDraggedToScoreView()
{
m_elementDraggedToScoreView.notify();
}
mu::async::Notification MU4PaletteAdapter::elementDraggedToScoreView() const
{
return m_elementDraggedToScoreView;
}

View file

@ -57,6 +57,8 @@ public:
void setPaletteEnabled(bool arg) override;
void requestPaletteSearch() override;
mu::async::Notification paletteSearchRequested() const override;
void notifyElementDraggedToScoreView() override;
mu::async::Notification elementDraggedToScoreView() const override;
private:
@ -64,6 +66,7 @@ private:
mutable Ms::PaletteWorkspace* m_paletteWorkspace = nullptr;
mutable QHash<QString, QAction*> m_actions;
mu::async::Notification m_paletteSearchRequested;
mu::async::Notification m_elementDraggedToScoreView;
};
}
}

View file

@ -0,0 +1,69 @@
//=============================================================================
// 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 "paletteworkspacesetup.h"
#include "log.h"
#include "workspacepalettestream.h"
#include "palette/paletteworkspace.h"
#include "palette/palettecreator.h"
using namespace mu::scene::palette;
void PaletteWorkspaceSetup::setup()
{
using namespace Ms;
if (!workspaceManager()) {
return;
}
Ms::PaletteWorkspace* paletteWorkspace = adapter()->paletteWorkspace();
auto applyWorkspaceData = [paletteWorkspace](std::shared_ptr<workspace::IWorkspace> w) {
std::shared_ptr<workspace::AbstractData> data = w->data("PaletteBox");
if (!data) {
LOGE() << "no palette data in workspace: " << w->name();
return false;
}
PaletteWorkspaceData* pdata = dynamic_cast<PaletteWorkspaceData*>(data.get());
IF_ASSERT_FAILED(pdata) {
return false;
}
paletteWorkspace->setDefaultPaletteTree(std::move(pdata->tree));
return true;
};
RetValCh<std::shared_ptr<workspace::IWorkspace> > workspace = workspaceManager()->currentWorkspace();
if (workspace.val) {
bool ok = applyWorkspaceData(workspace.val);
if (!ok) {
std::unique_ptr<PaletteTree> tree(PaletteCreator::newDefaultPaletteTree());
paletteWorkspace->setUserPaletteTree(std::move(tree));
}
}
workspace.ch.onReceive(nullptr, [paletteWorkspace, applyWorkspaceData](std::shared_ptr<workspace::IWorkspace> w) {
bool ok = applyWorkspaceData(w);
if (!ok) {
std::unique_ptr<PaletteTree> tree(PaletteCreator::newDefaultPaletteTree());
paletteWorkspace->setUserPaletteTree(std::move(tree));
}
});
}

View file

@ -0,0 +1,42 @@
//=============================================================================
// 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_PALETTE_PALETTEWORKSPACESETUP_H
#define MU_PALETTE_PALETTEWORKSPACESETUP_H
#include "modularity/ioc.h"
#include "workspace/iworkspacemanager.h"
#include "../ipaletteadapter.h"
namespace mu {
namespace scene {
namespace palette {
class PaletteWorkspaceSetup
{
INJECT(palette, workspace::IWorkspaceManager, workspaceManager)
INJECT(palette, IPaletteAdapter, adapter)
public:
void setup();
};
}
}
}
#endif // MU_PALETTE_PALETTEWORKSPACESETUP_H

View file

@ -80,6 +80,8 @@ public:
virtual void setPaletteEnabled(bool arg) = 0;
virtual void requestPaletteSearch() = 0;
virtual async::Notification paletteSearchRequested() const = 0;
virtual void notifyElementDraggedToScoreView() = 0;
virtual async::Notification elementDraggedToScoreView() const = 0;
};
}
}

View file

@ -29,13 +29,12 @@
#include "internal/paletteconfiguration.h"
#include "view/paletterootmodel.h"
#include "internal/palette/paletteworkspace.h"
#include "internal/palette/palettecreator.h"
#include "workspace/iworkspacedatastreamregister.h"
#include "workspace/iworkspacemanager.h"
#include "internal/workspacepalettestream.h"
#include "internal/paletteworkspacesetup.h"
#include "libmscore/score.h"
#include "libmscore/sym.h"
@ -109,43 +108,6 @@ void PaletteModule::onInit()
m_configuration->init();
// load workspace
auto workspaceManager = framework::ioc()->resolve<workspace::IWorkspaceManager>(moduleName());
if (!workspaceManager) {
return;
}
Ms::PaletteWorkspace* paletteWorkspace = m_adapter->paletteWorkspace();
auto applyWorkspaceData = [paletteWorkspace](std::shared_ptr<workspace::IWorkspace> w) {
std::shared_ptr<workspace::AbstractData> data = w->data("PaletteBox");
if (!data) {
LOGE() << "no palette data in workspace: " << w->name();
return false;
}
PaletteWorkspaceData* pdata = dynamic_cast<PaletteWorkspaceData*>(data.get());
IF_ASSERT_FAILED(pdata) {
return false;
}
paletteWorkspace->setDefaultPaletteTree(std::move(pdata->tree));
return true;
};
RetValCh<std::shared_ptr<workspace::IWorkspace> > workspace = workspaceManager->currentWorkspace();
if (workspace.val) {
bool ok = applyWorkspaceData(workspace.val);
if (!ok) {
std::unique_ptr<PaletteTree> tree(PaletteCreator::newDefaultPaletteTree());
paletteWorkspace->setUserPaletteTree(std::move(tree));
}
}
workspace.ch.onReceive(nullptr, [paletteWorkspace, applyWorkspaceData](std::shared_ptr<workspace::IWorkspace> w) {
bool ok = applyWorkspaceData(w);
if (!ok) {
std::unique_ptr<PaletteTree> tree(PaletteCreator::newDefaultPaletteTree());
paletteWorkspace->setUserPaletteTree(std::move(tree));
}
});
PaletteWorkspaceSetup w;
w.setup();
}

View file

@ -154,9 +154,9 @@ GridView {
// in case they are assigned as shortcuts in Preferences.
event.accepted = true; // intercept everything
switch (event.key) {
case Qt.Key_Up:
case Qt.Key_Down:
return;
case Qt.Key_Up:
case Qt.Key_Down:
return;
}
event.accepted = false; // allow key to function as shortcut (don't intercept)
}
@ -164,14 +164,14 @@ GridView {
Keys.onPressed: {
// NOTE: All keys must be intercepted with Keys.onShortcutOverride.
switch (event.key) {
case Qt.Key_Up:
focusPreviousItem();
break;
case Qt.Key_Down:
paletteTree.focusNextItem(false);
break;
default:
return; // don't accept event
case Qt.Key_Up:
focusPreviousItem();
break;
case Qt.Key_Down:
paletteTree.focusNextItem(false);
break;
default:
return; // don't accept event
}
event.accepted = true;
}
@ -209,7 +209,7 @@ GridView {
id: paletteDropArea
anchors { fill: parent/*; margins: 10*/ }
// keys: [ "application/musescore/symbol", "application/musescore/palette/cell" ]
// keys: [ "application/musescore/symbol", "application/musescore/palette/cell" ]
property var action
property var proposedAction: Qt.IgnoreAction
@ -281,7 +281,7 @@ GridView {
if (!action) {
onDragOverPaletteFinished();
return;
}
}
const destIndex = placeholder.active ? placeholder.index : paletteView.paletteModel.rowCount(paletteView.paletteRootIndex);
onDragOverPaletteFinished();
@ -317,8 +317,8 @@ GridView {
visible: parent.empty
font: ui.theme.font
text: paletteController && paletteController.canDropElements
? qsTr("Drag and drop any element here\n(Use %1+Shift to add custom element from the score)").arg(Qt.platform.os === "osx" ? "Cmd" : "Ctrl")
: qsTr("No elements")
? qsTr("Drag and drop any element here\n(Use %1+Shift to add custom element from the score)").arg(Qt.platform.os === "osx" ? "Cmd" : "Ctrl")
: qsTr("No elements")
verticalAlignment: Text.AlignVCenter
color: "grey"
wrapMode: Text.WordWrap
@ -358,9 +358,9 @@ GridView {
function moveCell(srcRow, destRow) {
return paletteController.move(
paletteRootIndex, srcRow,
paletteRootIndex, destRow
);
paletteRootIndex, srcRow,
paletteRootIndex, destRow
);
}
function insertCell(row, mimeData, action) {
@ -472,13 +472,13 @@ GridView {
// in case they are assigned as shortcuts in Preferences.
event.accepted = true; // intercept everything
switch (event.key) {
case Qt.Key_Up:
case Qt.Key_Down:
case Qt.Key_Left:
case Qt.Key_Right:
case Qt.Key_Backspace:
case Qt.Key_Delete:
return;
case Qt.Key_Up:
case Qt.Key_Down:
case Qt.Key_Left:
case Qt.Key_Right:
case Qt.Key_Backspace:
case Qt.Key_Delete:
return;
}
event.accepted = false; // allow key to function as shortcut (don't intercept)
}
@ -486,32 +486,32 @@ GridView {
Keys.onPressed: {
// NOTE: All keys must be intercepted with Keys.onShortcutOverride.
switch (event.key) {
case Qt.Key_Up:
focusPreviousItem();
break;
case Qt.Key_Down:
focusNextItem();
break;
case Qt.Key_Left:
paletteTree.currentItem.forceActiveFocus();
break;
case Qt.Key_Right:
if (moreButton.visible)
moreButton.forceActiveFocus();
break;
case Qt.Key_Backspace:
case Qt.Key_Delete:
removeSelectedCells();
break;
default:
return; // don't accept event
case Qt.Key_Up:
focusPreviousItem();
break;
case Qt.Key_Down:
focusNextItem();
break;
case Qt.Key_Left:
paletteTree.currentItem.forceActiveFocus();
break;
case Qt.Key_Right:
if (moreButton.visible)
moreButton.forceActiveFocus();
break;
case Qt.Key_Backspace:
case Qt.Key_Delete:
removeSelectedCells();
break;
default:
return; // don't accept event
}
event.accepted = true;
}
model: DelegateModel {
id: paletteCellDelegateModel
// model: paletteView.visible ? paletteView.paletteModel : null // TODO: use this optimization? TODO: apply it manually where appropriate (Custom palette breaks)
// model: paletteView.visible ? paletteView.paletteModel : null // TODO: use this optimization? TODO: apply it manually where appropriate (Custom palette breaks)
model: paletteView.paletteModel
rootIndex: paletteView.paletteRootIndex
@ -616,12 +616,12 @@ GridView {
// in case they are assigned as shortcuts in Preferences.
event.accepted = true; // intercept everything
switch (event.key) {
case Qt.Key_Space:
case Qt.Key_Enter:
case Qt.Key_Return:
case Qt.Key_Menu:
case Qt.Key_Asterisk:
return;
case Qt.Key_Space:
case Qt.Key_Enter:
case Qt.Key_Return:
case Qt.Key_Menu:
case Qt.Key_Asterisk:
return;
}
if (event.key === Qt.Key_F10 && event.modifiers & Qt.ShiftModifier)
return;
@ -635,39 +635,39 @@ GridView {
const shiftHeld = event.modifiers & Qt.ShiftModifier;
const ctrlHeld = event.modifiers & Qt.ControlModifier;
switch (event.key) {
case Qt.Key_Space:
if (paletteTree.typeAheadStr.length)
paletteView.typeAheadFind(' ');
else
paletteView.updateSelection(true);
break;
case Qt.Key_Enter:
case Qt.Key_Return:
paletteView.selectionModel.setCurrentIndex(modelIndex, ItemSelectionModel.ClearAndSelect);
paletteView.paletteController.applyPaletteElement(modelIndex, ui.keyboardModifiers());
break;
case Qt.Key_F10:
if (!shiftHeld)
return;
// fallthrough
case Qt.Key_Menu:
showCellMenu();
break;
case Qt.Key_Asterisk:
if (paletteTree.typeAheadStr.length)
paletteView.typeAheadFind('*');
else if (!paletteTree.expandCollapseAll(null))
paletteTree.currentItem.forceActiveFocus();
break;
default:
if (event.text.match(/[^\x00-\x20\x7F]+$/) !== null) {
// Pressed non-control character(s) (e.g. "D") so go
// to matching item (e.g. "D Major" in keysig palette)
paletteView.typeAheadFind(event.text);
}
else {
return; // don't accept event
}
case Qt.Key_Space:
if (paletteTree.typeAheadStr.length)
paletteView.typeAheadFind(' ');
else
paletteView.updateSelection(true);
break;
case Qt.Key_Enter:
case Qt.Key_Return:
paletteView.selectionModel.setCurrentIndex(modelIndex, ItemSelectionModel.ClearAndSelect);
paletteView.paletteController.applyPaletteElement(modelIndex, ui.keyboardModifiers());
break;
case Qt.Key_F10:
if (!shiftHeld)
return;
// fallthrough
case Qt.Key_Menu:
showCellMenu();
break;
case Qt.Key_Asterisk:
if (paletteTree.typeAheadStr.length)
paletteView.typeAheadFind('*');
else if (!paletteTree.expandCollapseAll(null))
paletteTree.currentItem.forceActiveFocus();
break;
default:
if (event.text.match(/[^\x00-\x20\x7F]+$/) !== null) {
// Pressed non-control character(s) (e.g. "D") so go
// to matching item (e.g. "D Major" in keysig palette)
paletteView.typeAheadFind(event.text);
}
else {
return; // don't accept event
}
}
event.accepted = true;
}
@ -739,13 +739,13 @@ GridView {
dropData = null;
}
}
// Drag.hotSpot: Qt.point(64, 0) // TODO
// Drag.hotSpot: Qt.point(64, 0) // TODO
function beginDrag() {
icon.grabToImage(function(result) {
Drag.imageSource = result.url
dragDropReorderTimer.restart();
})
Drag.imageSource = result.url
dragDropReorderTimer.restart();
})
}
function showCellMenu(useCursorPos) {
@ -762,12 +762,12 @@ GridView {
}
}
//-- Connections {
//-- // force not hiding palette cell if it is being dragged to a score
//-- enabled: paletteCell.paletteDrag
//-- target: mscore
//-- function onElementDraggedToScoreView() { paletteCell.paletteDrag = false; }
//-- }
Connections {
// force not hiding palette cell if it is being dragged to a score
enabled: paletteCell.paletteDrag
target: paletteRootModel
function onElementDraggedToScoreView() { paletteCell.paletteDrag = false; }
}
} // end ItemDelegate
} // end DelegateModel

View file

@ -29,14 +29,14 @@ import MuseScore.Palette 1.0
Item {
id: palettesWidget
readonly property PaletteWorkspace paletteWorkspace: rootModel.paletteWorkspace
readonly property PaletteWorkspace paletteWorkspace: paletteRootModel.paletteWorkspace
readonly property bool hasFocus: Window.activeFocusItem
implicitHeight: 4 * palettesWidgetHeader.implicitHeight
implicitWidth: paletteTree.implicitWidth
enabled: rootModel.paletteEnabled
enabled: paletteRootModel.paletteEnabled
function applyCurrentPaletteElement() {
paletteTree.applyCurrentElement();
@ -51,7 +51,7 @@ Item {
}
PaletteRootModel {
id: rootModel
id: paletteRootModel
onPaletteSearchRequested: {
palettesWidgetHeader.searchSelectAll()
@ -103,7 +103,7 @@ Item {
Rectangle {
// Shadow overlay for Tours. The usual overlay doesn't cover palettes
// as they reside in a window container above the main MuseScore window.
visible: rootModel.shadowOverlay
visible: paletteRootModel.shadowOverlay
anchors.fill: parent
z: 1000

View file

@ -31,6 +31,10 @@ PaletteRootModel::PaletteRootModel(QObject* parent)
adapter()->paletteSearchRequested().onNotify(this, [this]() {
emit paletteSearchRequested();
});
adapter()->elementDraggedToScoreView().onNotify(this, [this]() {
emit elementDraggedToScoreView();
});
}
bool PaletteRootModel::paletteEnabled() const

View file

@ -53,6 +53,7 @@ signals:
void paletteEnabledChanged(bool paletteEnabled);
void paletteSearchRequested();
void shadowOverlayChanged(bool shadowOverlay);
void elementDraggedToScoreView();
private: