void DrawableButton::resized() { Button::resized(); if (currentImage != nullptr) { if (style == ImageRaw) currentImage->setOriginWithOriginalSize (Point<float>()); else currentImage->setTransformToFit (getImageBounds(), style == ImageStretched ? RectanglePlacement::stretchToFit : RectanglePlacement::centred); } }
//! Adapts image viewer's affine to display the passed viewer rect at maximized //! ratio void ImageViewer::adaptView(const QRect &geomRect) { if (!m_image) return; // Retrieve the rect in image reference and call the associated adaptView TRect imgBounds(getImageBounds(m_image)); TRectD imgBoundsD(imgBounds.x0, imgBounds.y0, imgBounds.x1 + 1, imgBounds.y1 + 1); TRectD geomRectD(geomRect.left(), geomRect.top(), geomRect.right() + 1, geomRect.bottom() + 1); TRectD viewRectD(getImgToWidgetAffine().inv() * geomRectD); TRect viewRect(tfloor(viewRectD.x0), tfloor(viewRectD.y0), tceil(viewRectD.x1) - 1, tceil(viewRectD.y1) - 1); adaptView(imgBounds, viewRect); }
void ImageViewer::fitView() { if (!m_image) return; TRect imgBounds(getImageBounds(m_image)); adaptView(imgBounds, imgBounds); }