diff --git a/lib/crop/cropwidget.cpp b/lib/crop/cropwidget.cpp --- a/lib/crop/cropwidget.cpp +++ b/lib/crop/cropwidget.cpp @@ -72,6 +72,14 @@ return cropRatio() > 0; } + QSize imageRatio() + { + const int width = mDocument->width(); + const int height = mDocument->height(); + const int divisor = gcd(width, height); + return QSize(width / divisor, height / divisor); + } + double cropRatio() const { int index = ratioComboBox->currentIndex(); @@ -137,6 +145,10 @@ << QSizeF(4, 3) << QSizeF(5, 4); + // First item added is index 0 therefore is default + addRatioToComboBox(imageRatio(), i18n("Current Image")); + // Size of 0 means ratioIsConstrained returns false + addRatioToComboBox(QSize(0, 0), i18n("Freeform")); addRatioToComboBox(QSizeF(1, 1), i18n("Square")); addRatioToComboBox(screenRatio(), i18n("This Screen")); addSectionHeaderToComboBox(i18n("Landscape")); @@ -162,6 +174,8 @@ // Do not use i18n("%1:%2") because ':' should not be translated, it is // used to parse the ratio string. edit->setPlaceholderText(QString("%1:%2").arg(i18n("Width")).arg(i18n("Height"))); + + ratioComboBox->setCurrentIndex(0); } QRect cropRect() const @@ -225,6 +239,8 @@ d->initDialogButtonBox(); connect(d->ratioComboBox, &QComboBox::editTextChanged, this, &CropWidget::slotRatioComboBoxEditTextChanged); + // Call this once manually so default ratio is applied + applyRatioConstraint(); // Don't do this before signals are connected, otherwise the tool won't get // initialized