From 4a1d29f7b5f066f745f3b873c38522cf90b9be12 Mon Sep 17 00:00:00 2001 From: Calum Matheson Date: Fri, 28 Feb 2025 15:06:46 +0000 Subject: [PATCH] Percussion panel - notation preview now reflects number of staff lines at input position --- .../NotationScene/PercussionPanel.qml | 1 + .../internal/PercussionPanelPad.qml | 2 ++ .../internal/PercussionPanelPadContent.qml | 1 + .../utilities/engravingitempreviewpainter.cpp | 11 +++++----- .../utilities/engravingitempreviewpainter.h | 2 +- src/notation/view/paintedengravingitem.cpp | 22 ++++++++++++++++++- src/notation/view/paintedengravingitem.h | 8 +++++++ .../percussionpanel/percussionpanelmodel.cpp | 18 +++++++++++++++ .../percussionpanel/percussionpanelmodel.h | 4 ++++ .../internal/palettecelliconengine.cpp | 3 ++- 10 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml b/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml index d322fd9025a9d..2fafdae1e40fb 100644 --- a/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml +++ b/src/notation/qml/MuseScore/NotationScene/PercussionPanel.qml @@ -285,6 +285,7 @@ Item { panelEnabled: percModel.enabled panelMode: percModel.currentPanelMode useNotationPreview: percModel.useNotationPreview + notationPreviewNumStaffLines: percModel.notationPreviewNumStaffLines // When swapping, only show the outline for the swap origin and the swap target... showEditOutline: percModel.currentPanelMode === PanelMode.EDIT_LAYOUT diff --git a/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPad.qml b/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPad.qml index 4ee59e504751c..695d40c7f16bc 100644 --- a/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPad.qml +++ b/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPad.qml @@ -35,6 +35,7 @@ DropArea { property int panelMode: -1 property bool useNotationPreview: false + property int notationPreviewNumStaffLines: 0 property bool showEditOutline: false property alias totalBorderWidth: padLoader.anchors.margins @@ -210,6 +211,7 @@ DropArea { padModel: root.padModel panelMode: root.panelMode useNotationPreview: root.useNotationPreview + notationPreviewNumStaffLines: root.notationPreviewNumStaffLines footerHeight: prv.footerHeight diff --git a/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml b/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml index f05d41a08b67f..5c16a075533c1 100644 --- a/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml +++ b/src/notation/qml/MuseScore/NotationScene/internal/PercussionPanelPadContent.qml @@ -32,6 +32,7 @@ Column { property int panelMode: -1 property bool useNotationPreview: false + property alias notationPreviewNumStaffLines: notationPreview.numStaffLines property alias footerHeight: footerArea.height diff --git a/src/notation/utilities/engravingitempreviewpainter.cpp b/src/notation/utilities/engravingitempreviewpainter.cpp index 001eac2da5afb..0d176e1b188c9 100644 --- a/src/notation/utilities/engravingitempreviewpainter.cpp +++ b/src/notation/utilities/engravingitempreviewpainter.cpp @@ -46,7 +46,7 @@ void EngravingItemPreviewPainter::paintPreview(mu::engraving::EngravingItem* ele } PointF origin = params.rect.center(); // draw element at center of cell by default - if (params.drawStaff) { + if (params.numStaffLines > 0) { const double topLinePos = paintStaff(params); // draw dummy staff lines onto rect. origin.setY(topLinePos); // vertical position relative to staff instead of cell center. } @@ -118,7 +118,7 @@ void EngravingItemPreviewPainter::paintPreviewForActionIcon(mu::engraving::Engra painter->restore(); } -/// Paint a 5 line staff centered within a QRect and return the distance from the +/// Paint a staff centered within a QRect and return the distance from the /// top of the QRect to the uppermost staff line. double EngravingItemPreviewPainter::paintStaff(PaintParams& params) { @@ -135,8 +135,7 @@ double EngravingItemPreviewPainter::paintStaff(PaintParams& params) pen.setWidthF(engraving::DefaultStyle::defaultStyle().styleS(Sid::staffLineWidth).val() * params.spatium); painter->setPen(pen); - constexpr int numStaffLines = 5; - const double staffHeight = params.spatium * (numStaffLines - 1); + const double staffHeight = params.spatium * (params.numStaffLines - 1); const double topLineDist = params.rect.center().y() - (staffHeight / 2.0); // lines bounded horizontally by edge of target (with small margin) @@ -146,7 +145,7 @@ double EngravingItemPreviewPainter::paintStaff(PaintParams& params) // draw staff lines with middle line centered vertically on target double y = topLineDist; - for (int i = 0; i < numStaffLines; ++i) { + for (int i = 0; i < params.numStaffLines; ++i) { painter->drawLine(LineF(x1, y, x2, y)); y += params.spatium; } @@ -178,7 +177,7 @@ void EngravingItemPreviewPainter::paintPreviewForItem(mu::engraving::EngravingIt PointF origin = element->ldata()->bbox().center(); - if (params.drawStaff) { + if (params.numStaffLines > 0) { // y = 0 is position of the element's parent. // If the parent is the staff (or a segment on the staff) then // y = 0 corresponds to the position of the top staff line. diff --git a/src/notation/utilities/engravingitempreviewpainter.h b/src/notation/utilities/engravingitempreviewpainter.h index 0d57faba52cd7..cb8da17148d47 100644 --- a/src/notation/utilities/engravingitempreviewpainter.h +++ b/src/notation/utilities/engravingitempreviewpainter.h @@ -48,7 +48,7 @@ class EngravingItemPreviewPainter bool useElementColors = false; bool colorsInversionEnabled = false; - bool drawStaff = false; + int numStaffLines = 0; }; static void paintPreview(mu::engraving::EngravingItem* element, PaintParams& params); diff --git a/src/notation/view/paintedengravingitem.cpp b/src/notation/view/paintedengravingitem.cpp index 9aaf23843fb7e..7b75a613db3c3 100644 --- a/src/notation/view/paintedengravingitem.cpp +++ b/src/notation/view/paintedengravingitem.cpp @@ -44,9 +44,27 @@ void PaintedEngravingItem::setEngravingItemVariant(QVariant engravingItemVariant return; } m_item = item; + + update(); emit engravingItemVariantChanged(); } +int PaintedEngravingItem::numStaffLines() const +{ + return m_numStaffLines; +} + +void PaintedEngravingItem::setNumStaffLines(int numStaffLines) +{ + if (m_numStaffLines == numStaffLines) { + return; + } + m_numStaffLines = numStaffLines; + + update(); + emit numStaffLinesChanged(); +} + double PaintedEngravingItem::spatium() const { return m_spatium; @@ -58,6 +76,8 @@ void PaintedEngravingItem::setSpatium(double spatium) return; } m_spatium = spatium; + + update(); emit spatiumChanged(); } @@ -87,7 +107,7 @@ void PaintedEngravingItem::paintNotationPreview(muse::draw::Painter& painter, qr params.spatium = m_spatium; - params.drawStaff = true; + params.numStaffLines = m_numStaffLines; painter.fillRect(params.rect, configuration()->noteBackgroundColor()); diff --git a/src/notation/view/paintedengravingitem.h b/src/notation/view/paintedengravingitem.h index bc33cb06aa343..3afb7f97ab9f7 100644 --- a/src/notation/view/paintedengravingitem.h +++ b/src/notation/view/paintedengravingitem.h @@ -39,6 +39,8 @@ class PaintedEngravingItem : public QQuickPaintedItem Q_OBJECT Q_PROPERTY(QVariant engravingItem READ engravingItemVariant WRITE setEngravingItemVariant NOTIFY engravingItemVariantChanged) + Q_PROPERTY(int numStaffLines READ numStaffLines WRITE setNumStaffLines NOTIFY numStaffLinesChanged) + Q_PROPERTY(double spatium READ spatium WRITE setSpatium NOTIFY spatiumChanged) public: @@ -47,6 +49,9 @@ class PaintedEngravingItem : public QQuickPaintedItem QVariant engravingItemVariant() const; void setEngravingItemVariant(QVariant engravingItemVariant); + int numStaffLines() const; + void setNumStaffLines(int numStaffLines); + double spatium() const; void setSpatium(double spatium); @@ -54,12 +59,15 @@ class PaintedEngravingItem : public QQuickPaintedItem signals: void engravingItemVariantChanged(); + void numStaffLinesChanged(); void spatiumChanged(); private: void paintNotationPreview(muse::draw::Painter& painter, qreal dpi) const; mu::engraving::ElementPtr m_item; + int m_numStaffLines = 0; + double m_spatium = 1.0; }; } diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.cpp b/src/notation/view/percussionpanel/percussionpanelmodel.cpp index b82882e27e807..61d958ded0776 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.cpp +++ b/src/notation/view/percussionpanel/percussionpanelmodel.cpp @@ -119,6 +119,22 @@ void PercussionPanelModel::setUseNotationPreview(bool useNotationPreview) emit useNotationPreviewChanged(m_useNotationPreview); } +int PercussionPanelModel::notationPreviewNumStaffLines() const +{ + if (!interaction()) { + return 0; + } + + const NoteInputState& inputState = interaction()->noteInput()->state(); + const Staff* staff = inputState.staff(); + + if (!staff) { + return 0; + } + + return staff->lines(inputState.tick()); +} + PercussionPanelPadListModel* PercussionPanelModel::padListModel() const { return m_padListModel; @@ -245,6 +261,8 @@ void PercussionPanelModel::customizeKit() void PercussionPanelModel::setUpConnections() { const auto updatePadModels = [this](Drumset* drumset) { + emit notationPreviewNumStaffLinesChanged(); + if (drumset && m_padListModel->drumset() && *drumset == *m_padListModel->drumset()) { return; } diff --git a/src/notation/view/percussionpanel/percussionpanelmodel.h b/src/notation/view/percussionpanel/percussionpanelmodel.h index 37096e64a305e..ad720130723e3 100644 --- a/src/notation/view/percussionpanel/percussionpanelmodel.h +++ b/src/notation/view/percussionpanel/percussionpanelmodel.h @@ -67,6 +67,7 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus Q_PROPERTY(PanelMode::Mode currentPanelMode READ currentPanelMode WRITE setCurrentPanelMode NOTIFY currentPanelModeChanged) Q_PROPERTY(bool useNotationPreview READ useNotationPreview WRITE setUseNotationPreview NOTIFY useNotationPreviewChanged) + Q_PROPERTY(int notationPreviewNumStaffLines READ notationPreviewNumStaffLines NOTIFY notationPreviewNumStaffLinesChanged) Q_PROPERTY(PercussionPanelPadListModel * padListModel READ padListModel NOTIFY padListModelChanged) @@ -87,6 +88,8 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus bool useNotationPreview() const; void setUseNotationPreview(bool useNotationPreview); + int notationPreviewNumStaffLines() const; + PercussionPanelPadListModel* padListModel() const; Q_INVOKABLE void init(); @@ -107,6 +110,7 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus void currentPanelModeChanged(const PanelMode::Mode& panelMode); void useNotationPreviewChanged(bool useNotationPreview); + void notationPreviewNumStaffLinesChanged(); void padListModelChanged(); diff --git a/src/palette/internal/palettecelliconengine.cpp b/src/palette/internal/palettecelliconengine.cpp index cc871c50e0596..03db1f7362126 100644 --- a/src/palette/internal/palettecelliconengine.cpp +++ b/src/palette/internal/palettecelliconengine.cpp @@ -85,7 +85,8 @@ void PaletteCellIconEngine::paintCell(Painter& painter, const RectF& rect, bool params.dpi = dpi; params.spatium = configuration()->paletteSpatium() * params.mag; - params.drawStaff = m_cell->drawStaff; + //! NOTE: Slight hack - we can now specify exactly now many staff lines we want... + params.numStaffLines = m_cell->drawStaff ? 5 : 0; notation::EngravingItemPreviewPainter::paintPreview(element, params); }