Remember best fit beween different image sizes

This commit is contained in:
2021-04-14 22:51:41 +02:00
parent 1a4b62f7cd
commit bbe8c0fe5c
2 changed files with 9 additions and 0 deletions
+8
View File
@@ -260,6 +260,7 @@ ImageScrollAreaGL::ImageScrollAreaGL(QWidget *parent) : QWidget(parent)
m_verticalScrollBar = new QScrollBar(Qt::Vertical, this);
m_horizontalScrollBar = new QScrollBar(Qt::Horizontal, this);
m_scale = 1.0f;
m_bestFit = false;
layout->setSpacing(0);
layout->addWidget(m_imageWidget, 0, 0);
@@ -280,6 +281,7 @@ void ImageScrollAreaGL::setImage(RawImage *image)
m_imageWidget->setImage(image);
m_imgWidth = image->width();
m_imgHeight = image->height();
if(m_bestFit)bestFit();
updateScrollbars();
}
@@ -288,6 +290,7 @@ void ImageScrollAreaGL::setImage(const QPixmap &pixmap)
m_imageWidget->setImage(pixmap);
m_imgWidth = pixmap.width();
m_imgHeight = pixmap.height();
if(m_bestFit)bestFit();
updateScrollbars();
}
@@ -333,6 +336,7 @@ void ImageScrollAreaGL::mousePressEvent(QMouseEvent *event)
void ImageScrollAreaGL::wheelEvent(QWheelEvent *event)
{
m_bestFit = false;
if(event->angleDelta().y() != 0)
zoom(event->angleDelta().y() / 1200.0f);
}
@@ -351,15 +355,18 @@ void ImageScrollAreaGL::zoom(float delta)
void ImageScrollAreaGL::zoomIn()
{
zoom(0.1f);
m_bestFit = false;
}
void ImageScrollAreaGL::zoomOut()
{
zoom(-0.1f);
m_bestFit = false;
}
void ImageScrollAreaGL::bestFit()
{
m_bestFit = true;
m_scale = std::min((float)m_imageWidget->width()/m_imgWidth, (float)m_imageWidget->height()/m_imgHeight);
zoom(0.0f);
}
@@ -368,6 +375,7 @@ void ImageScrollAreaGL::oneToOne()
{
m_scale = 1.0f;
zoom(0.0f);
m_bestFit = false;
}
void ImageScrollAreaGL::scrollEvent()