void ImageTransformation::setPostRotation(double const degrees) { m_postRotateXform = calcPostRotateXform(degrees); m_postRotation = degrees; update(); }
void ImageTransformation::preScaleToDpi(Dpi const& dpi) { if (m_origDpi.isNull() || dpi.isNull()) { return; } m_preScaledDpi = dpi; double const xscale = (double)dpi.horizontal() / m_origDpi.horizontal(); double const yscale = (double)dpi.vertical() / m_origDpi.vertical(); QSizeF const new_pre_scaled_image_size( m_origRect.width() * xscale, m_origRect.height() * yscale ); // Undo's for the specified steps. QTransform const undo21(m_preRotateXform.inverted() * m_preScaleXform.inverted()); QTransform const undo4321(m_postRotateXform.inverted() * m_preCropXform.inverted() * undo21); // Update transform #1: pre-scale. m_preScaleXform.reset(); m_preScaleXform.scale(xscale, yscale); // Update transform #2: pre-rotate. m_preRotateXform = m_preRotation.transform(new_pre_scaled_image_size); // Update transform #3: pre-crop. QTransform const redo12(m_preScaleXform * m_preRotateXform); m_preCropArea = (undo21 * redo12).map(m_preCropArea); m_preCropXform = calcCropXform(m_preCropArea); // Update transform #4: post-rotate. m_postRotateXform = calcPostRotateXform(m_postRotation); // Update transform #5: post-crop. QTransform const redo1234(redo12 * m_preCropXform * m_postRotateXform); m_postCropArea = (undo4321 * redo1234).map(m_postCropArea); m_postCropXform = calcCropXform(m_postCropArea); // Update transform #6: post-scale. m_postScaleXform = calcPostScaleXform(m_postScaledDpi); update(); }
void ImageTransformation::preScaleToDpi(Dpi const& dpi) { if (m_origDpi.isNull() || dpi.isNull()) { return; } m_preScaledDpi = dpi; double const xscale = (double)dpi.horizontal() / m_origDpi.horizontal(); double const yscale = (double)dpi.vertical() / m_origDpi.vertical(); QSizeF const new_pre_scaled_image_size( m_origRect.width() * xscale, m_origRect.height() * yscale ); // Reverse pre-rotation. QPolygonF tmp_crop_area(m_preRotateXform.inverted().map(m_cropArea)); // Reverse pre-scaling. tmp_crop_area = m_preScaleXform.inverted().map(tmp_crop_area); // Update m_preScaleXform and m_preRotateXform. m_preScaleXform.reset(); m_preScaleXform.scale(xscale, yscale); m_preRotateXform = m_preRotation.transform(new_pre_scaled_image_size); // Apply new pre-scaling. tmp_crop_area = m_preScaleXform.map(tmp_crop_area); // Re-apply pre-rotation. m_cropArea = m_preRotateXform.map(tmp_crop_area); m_cropXform = calcCropXform(m_cropArea); m_postRotateXform = calcPostRotateXform(m_postRotation); update(); }