Scaling code refractoring, add fit to page mode and zoom levels

This commit is contained in:
Felix Kauselmann
2015-01-02 11:41:52 +01:00
parent 496a90daef
commit bf98cf3343
3 changed files with 53 additions and 3 deletions

View File

@ -326,9 +326,16 @@ void Viewer::updateContentSize()
}
else
{
float aspectRatio = (float)currentPage->width()/currentPage->height();
//float aspectRatio = (float)currentPage->width()/currentPage->height();
//Fit to width
if(Configuration::getConfiguration().getAdjustToWidth())
{
QSize pagefit=currentPage->size();
pagefit.scale(width(), 0, Qt::KeepAspectRatioByExpanding);
content->resize(pagefit);
}
/*
if(Configuration::getConfiguration().getAdjustToWidth())
{
adjustToWidthRatio = Configuration::getConfiguration().getFitToWidthRatio();
if(static_cast<int>(width()*adjustToWidthRatio/aspectRatio)<height())
@ -339,6 +346,7 @@ void Viewer::updateContentSize()
else
content->resize(width()*adjustToWidthRatio,static_cast<int>(width()*adjustToWidthRatio/aspectRatio));
}
//Fit to height or fullsize/custom size
else
{
@ -346,18 +354,26 @@ void Viewer::updateContentSize()
content->resize(width(),static_cast<int>(width()/aspectRatio));
else
content->resize(static_cast<int>(height()*aspectRatio),height());
}*/
else
{
QSize pagefit=currentPage->size();
pagefit.scale(0, height(), Qt::KeepAspectRatioByExpanding);
content->resize(pagefit);
}
}
if(Configuration::getConfiguration().getPageZoomLevel())
{
QSize pagesize=content->size();
pagesize.scale(content->width()*Configuration::getConfiguration().getPageZoomLevel(), content->height(), Qt::KeepAspectRatio);
pagesize.scale(content->width()*Configuration::getConfiguration().getPageZoomLevel(), 0, Qt::KeepAspectRatioByExpanding);
content->resize(pagesize);
}
if(devicePixelRatio()>1)//only in retina display
{
qDebug() << "Retina Display detected" << "devicePixelRatio:" << devicePixelRatio();
QPixmap page = currentPage->scaled(content->width()*devicePixelRatio(), content->height()*devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
page.setDevicePixelRatio(devicePixelRatio());
content->setPixmap(page);