Use new fitmode in viewer

This commit is contained in:
Felix Kauselmann 2015-09-14 10:05:48 +02:00
parent e55c431bde
commit 1fd8713121

View File

@ -328,35 +328,32 @@ void Viewer::updateContentSize()
//there is an image to resize //there is an image to resize
if(currentPage !=0 && !currentPage->isNull()) if(currentPage !=0 && !currentPage->isNull())
{ {
if(Configuration::getConfiguration().getAdjustToFullSize()) QSize pagefit;
YACReader::FitMode fitmode = Configuration::getConfiguration().getFitMode();
switch (fitmode)
{ {
content->resize(currentPage->width(),currentPage->height()); case YACReader::FitMode::FullRes:
} pagefit=currentPage->size();
else break;
{ case YACReader::FitMode::ToWidth:
float aspectRatio = (float)currentPage->width()/currentPage->height(); pagefit=currentPage->size();
//Fit to width pagefit.scale(width(), 0, Qt::KeepAspectRatioByExpanding);
if(Configuration::getConfiguration().getAdjustToWidth()) break;
{ case YACReader::FitMode::ToHeight:
adjustToWidthRatio = Configuration::getConfiguration().getFitToWidthRatio(); pagefit=currentPage->size();
if(static_cast<int>(width()*adjustToWidthRatio/aspectRatio)<height()) pagefit.scale(0, height(), Qt::KeepAspectRatioByExpanding);
if(static_cast<int>(height()*aspectRatio)>width()) break;
content->resize(width(),static_cast<int>(width()/aspectRatio)); //if everything fails showing the full page is a good idea
else case YACReader::FitMode::FullPage:
content->resize(static_cast<int>(height()*aspectRatio),height()); default:
else pagefit=currentPage->size();
content->resize(width()*adjustToWidthRatio,static_cast<int>(width()*adjustToWidthRatio/aspectRatio)); pagefit.scale(size(), Qt::KeepAspectRatio);
} break;
//Fit to height or fullsize/custom size
else
{
if(static_cast<int>(height()*aspectRatio)>width()) //page width exceeds window width
content->resize(width(),static_cast<int>(width()/aspectRatio));
else
content->resize(static_cast<int>(height()*aspectRatio),height());
}
} }
//apply scaling
content->resize(pagefit);
//TODO: updtateContentSize should only scale the pixmap once
if(devicePixelRatio()>1)//only in retina display if(devicePixelRatio()>1)//only in retina display
{ {
QPixmap page = currentPage->scaled(content->width()*devicePixelRatio(), content->height()*devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QPixmap page = currentPage->scaled(content->width()*devicePixelRatio(), content->height()*devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation);