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

fix #279967: image resize not correctly honoring aspect ratio #5731

Merged
merged 1 commit into from Nov 23, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 52 additions & 1 deletion mscore/inspector/inspectorImage.cpp
Expand Up @@ -47,6 +47,12 @@ InspectorImage::InspectorImage(QWidget* parent)
};
const std::vector<InspectorPanel> ppList = { { b.title, b.panel } };

updateAspectRatio(); // initiate aspectRatio
connect(b.lockAspectRatio, &QCheckBox::toggled, this, &InspectorImage::lockAspectRatioClicked);

connect(b.size->xVal, QOverload<qreal>::of(&QDoubleSpinBox::valueChanged), this, &InspectorImage::widthChanged);
connect(b.size->yVal, QOverload<qreal>::of(&QDoubleSpinBox::valueChanged), this, &InspectorImage::heightChanged);

mapSignals(iiList, ppList);
}

Expand All @@ -56,10 +62,55 @@ InspectorImage::InspectorImage(QWidget* parent)

void InspectorImage::valueChanged(int idx)
{
InspectorBase::valueChanged(idx);
InspectorElementBase::valueChanged(idx);
Harmoniker1 marked this conversation as resolved.
Show resolved Hide resolved
setElement(); // DEBUG
}

//---------------------------------------------------------
// updateAspectRatio
//---------------------------------------------------------

void InspectorImage::updateAspectRatio()
{
Image* image = toImage(inspector->element());
qreal widthVal = image->size().width();
qreal heightVal = image->size().height();

_aspectRatio = heightVal != 0.0 ? widthVal / heightVal : 1.0;
}

//---------------------------------------------------------
// lockAspectRatioClicked
//---------------------------------------------------------

void InspectorImage::lockAspectRatioClicked(bool checked)
{
if (checked)
updateAspectRatio();
}

//---------------------------------------------------------
// widthChanged
//---------------------------------------------------------

void InspectorImage::widthChanged(qreal val)
{
Image* image = toImage(inspector->element());
if (image->lockAspectRatio() && val != 0.0) // to avoid stack overflow
b.size->yVal->setValue(val / _aspectRatio);
}

//---------------------------------------------------------
// heightChanged
//---------------------------------------------------------

void InspectorImage::heightChanged(qreal val)
{
Image* image = toImage(inspector->element());
if (image->lockAspectRatio() && val != 0.0) // to avoid stack overflow
b.size->xVal->setValue(val * _aspectRatio);
}

//---------------------------------------------------------
// postInit
//---------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions mscore/inspector/inspectorImage.h
Expand Up @@ -27,14 +27,21 @@ class InspectorImage : public InspectorElementBase {
Q_OBJECT

Ui::InspectorImage b;
qreal _aspectRatio; // used for widthChanged/heightChanged

virtual void postInit();

protected slots:
virtual void valueChanged(int idx) override;
void lockAspectRatioClicked(bool checked);
void widthChanged(qreal val);
void heightChanged(qreal val);

public:
InspectorImage(QWidget* parent);

protected:
void updateAspectRatio();
};


Expand Down