Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percussion panel - notation preview now reflects number of staff lines at input position (#26347) [4.5.0 port] #26838

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -210,6 +211,7 @@ DropArea {
padModel: root.padModel
panelMode: root.panelMode
useNotationPreview: root.useNotationPreview
notationPreviewNumStaffLines: root.notationPreviewNumStaffLines

footerHeight: prv.footerHeight

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Column {

property int panelMode: -1
property bool useNotationPreview: false
property alias notationPreviewNumStaffLines: notationPreview.numStaffLines

property alias footerHeight: footerArea.height

Expand Down
11 changes: 5 additions & 6 deletions src/notation/utilities/engravingitempreviewpainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utilities/engravingitempreviewpainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 21 additions & 1 deletion src/notation/view/paintedengravingitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,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;
Expand All @@ -57,6 +75,8 @@ void PaintedEngravingItem::setSpatium(double spatium)
return;
}
m_spatium = spatium;

update();
emit spatiumChanged();
}

Expand Down Expand Up @@ -86,7 +106,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());

Expand Down
8 changes: 8 additions & 0 deletions src/notation/view/paintedengravingitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -47,19 +49,25 @@ 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);

void paint(QPainter* painter) override;

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;
};
}
14 changes: 14 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ 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();

return staff ? staff->lines(inputState.tick()) : 0;
}

PercussionPanelPadListModel* PercussionPanelModel::padListModel() const
{
return m_padListModel;
Expand Down Expand Up @@ -245,6 +257,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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/notation/view/percussionpanel/percussionpanelmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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();
Expand All @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion src/palette/internal/palettecelliconengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading