Commit 01db2be3 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

- Moved computeZoomToFit to ImageViewPrivate

- Finished centering image in view

svn path=/trunk/playground/graphics/gwenview/; revision=655824
parent de1773e0
......@@ -48,6 +48,31 @@ struct ImageViewPrivate {
return QPoint(left, top);
}
qreal computeZoomToFit() const {
int width = mViewport->width();
int height = mViewport->height();
qreal zoom = qreal(width) / mImage.width();
if ( int(mImage.height() * zoom) > height) {
zoom = qreal(height) / mImage.height();
}
return zoom;
}
QImage createBuffer() const {
QSize visibleSize;
qreal zoom;
if (mZoomToFit) {
zoom = computeZoomToFit();
} else {
zoom = mZoom;
}
visibleSize = mImage.size() * zoom;
visibleSize = visibleSize.boundedTo(mViewport->size());
return QImage(visibleSize, QImage::Format_ARGB32);
}
};
......@@ -75,12 +100,15 @@ ImageView::~ImageView() {
void ImageView::setImage(const QImage& image) {
d->mImage = image;
d->mBuffer = d->createBuffer();
d->mBuffer.fill(qRgb(0, 0, 0));
if (d->mZoomToFit) {
setZoom(computeZoomToFit());
setZoom(d->computeZoomToFit());
} else {
updateScrollBars();
startScaler();
}
d->mViewport->update();
}
void ImageView::startScaler() {
......@@ -126,7 +154,7 @@ void ImageView::resizeEvent(QResizeEvent*) {
}
d->mBuffer = newBuffer;
if (d->mZoomToFit) {
setZoom(computeZoomToFit());
setZoom(d->computeZoomToFit());
} else {
updateScrollBars();
startScaler();
......@@ -150,7 +178,7 @@ bool ImageView::zoomToFit() const {
void ImageView::setZoomToFit(bool on) {
d->mZoomToFit = on;
if (d->mZoomToFit) {
setZoom(computeZoomToFit());
setZoom(d->computeZoomToFit());
} else {
setZoom(1.);
}
......@@ -178,16 +206,6 @@ void ImageView::updateScrollBars() {
verticalScrollBar()->setPageStep(height);
}
qreal ImageView::computeZoomToFit() const {
int width = d->mViewport->width();
int height = d->mViewport->height();
qreal zoom = qreal(width) / d->mImage.width();
if ( int(d->mImage.height() * zoom) > height) {
zoom = qreal(height) / d->mImage.height();
}
return zoom;
}
void ImageView::scrollContentsBy(int dx, int dy) {
// Scroll existing
......
......@@ -57,7 +57,6 @@ private Q_SLOTS:
private:
void updateScrollBars();
qreal computeZoomToFit() const;
void startScaler();
ImageViewPrivate* const d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment