Skip to content

Commit

Permalink
Merge pull request #24483 from mike-spa/canvasMargin
Browse files Browse the repository at this point in the history
Give the canvas some margin when first opening a score
  • Loading branch information
mike-spa authored Sep 17, 2024
2 parents d973725 + e8ad30b commit faa5a67
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/notation/view/abstractnotationpaintview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ void AbstractNotationPaintView::onLoadNotation(INotationPtr)
{
if (viewport().isValid() && !m_notation->viewState()->isMatrixInited()) {
m_inputController->initZoom();
m_inputController->initCanvasPos();
}

if (publishMode()) {
Expand Down Expand Up @@ -380,6 +381,7 @@ void AbstractNotationPaintView::onViewSizeChanged()
if (viewport().isValid()) {
if (!notation()->viewState()->isMatrixInited()) {
m_inputController->initZoom();
m_inputController->initCanvasPos();
} else {
m_inputController->updateZoomAfterSizeChange();
}
Expand Down
46 changes: 38 additions & 8 deletions src/notation/view/notationviewinputcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,27 @@ void NotationViewInputController::initZoom()
currentNotation()->viewState()->setMatrixInited(true);
}

void NotationViewInputController::initCanvasPos()
{
RectF notationContentRect = m_view->notationContentRect();
double totalScoreWidth = notationContentRect.width();
double totalScoreHeight = notationContentRect.height();

double curScaling = m_view->currentScaling();
double viewWidth = m_view->width() / curScaling;
double viewHeight = m_view->height() / curScaling;

const double canvasMargin = MScore::horizontalPageGapOdd;

bool centerHorizontally = totalScoreWidth < viewWidth - 2 * canvasMargin;
bool centerVertically = totalScoreHeight < viewHeight - 2 * canvasMargin;

double xMove = centerHorizontally ? 0.5 * (viewWidth - totalScoreWidth) : canvasMargin;
double yMove = centerVertically ? 0.5 * (viewHeight - totalScoreHeight) : canvasMargin;

m_view->moveCanvas(xMove, yMove);
}

void NotationViewInputController::updateZoomAfterSizeChange()
{
IF_ASSERT_FAILED(currentNotation()) {
Expand Down Expand Up @@ -279,9 +300,11 @@ void NotationViewInputController::doZoomToPageWidth()
return;
}

qreal pageWidth = notationStyle()->styleValue(mu::engraving::Sid::pageWidth).toDouble() * mu::engraving::DPI;
qreal pageWidth = notationStyle()->styleValue(mu::engraving::Sid::pageWidth).toDouble() * mu::engraving::DPI
+ 2 * MScore::horizontalPageGapOdd;
double viewWidth = m_view->width();

qreal scale = m_view->width() / pageWidth;
qreal scale = viewWidth / pageWidth;
setScaling(scale, PointF(), false);
}

Expand All @@ -301,11 +324,16 @@ void NotationViewInputController::doZoomToWholePage()
return;
}

qreal pageWidth = notationStyle()->styleValue(mu::engraving::Sid::pageWidth).toDouble() * mu::engraving::DPI;
qreal pageHeight = notationStyle()->styleValue(mu::engraving::Sid::pageHeight).toDouble() * mu::engraving::DPI;
qreal pageWidth = notationStyle()->styleValue(mu::engraving::Sid::pageWidth).toDouble() * mu::engraving::DPI
+ 2 * MScore::horizontalPageGapOdd;
qreal pageHeight = notationStyle()->styleValue(mu::engraving::Sid::pageHeight).toDouble() * mu::engraving::DPI
+ 2 * MScore::horizontalPageGapOdd;

double viewWidth = m_view->width();
double viewHeight = m_view->height();

qreal pageWidthScale = m_view->width() / pageWidth;
qreal pageHeightScale = m_view->height() / pageHeight;
qreal pageWidthScale = viewWidth / pageWidth;
qreal pageHeightScale = viewHeight / pageHeight;

qreal scale = std::min(pageWidthScale, pageHeightScale);
setScaling(scale, PointF(), false);
Expand All @@ -329,8 +357,10 @@ void NotationViewInputController::doZoomToTwoPages()

qreal viewWidth = m_view->width();
qreal viewHeight = m_view->height();
qreal pageWidth = notationStyle()->styleValue(mu::engraving::Sid::pageWidth).toDouble() * mu::engraving::DPI;
qreal pageHeight = notationStyle()->styleValue(mu::engraving::Sid::pageHeight).toDouble() * mu::engraving::DPI;
qreal pageWidth = notationStyle()->styleValue(mu::engraving::Sid::pageWidth).toDouble() * mu::engraving::DPI
+ 2 * MScore::horizontalPageGapOdd;
qreal pageHeight = notationStyle()->styleValue(mu::engraving::Sid::pageHeight).toDouble() * mu::engraving::DPI
+ 2 * MScore::horizontalPageGapOdd;

qreal pageHeightScale = 0.0;
qreal pageWidthScale = 0.0;
Expand Down
1 change: 1 addition & 0 deletions src/notation/view/notationviewinputcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class NotationViewInputController : public muse::actions::Actionable, public mus
void init();

void initZoom();
void initCanvasPos();
void updateZoomAfterSizeChange();
void zoomIn();
void zoomOut();
Expand Down

0 comments on commit faa5a67

Please sign in to comment.