Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

fit in

By: a guest on May 5th, 2012  |  syntax: C++  |  size: 0.54 KB  |  views: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void QSingleImageView::bestFit()
  2. {
  3.     Q_D(QSingleImageView);
  4.  
  5.     QSize imageSize = d->image.size();
  6.     QSize size = viewport()->size();
  7.  
  8.     int w = imageSize.width(), mw = size.width();
  9.     int h = imageSize.height(), mh = size.height();
  10.  
  11.     double rw = 1.0*mw/w, rh = 1.0*mh/h, factor = 1;
  12.  
  13.     if (rw < 1 && rh > 1)
  14.         factor = rw;
  15.     else if (rw > 1 && rh < 1)
  16.         factor = rh;
  17.     else if (rw < 1 && rh < 1)
  18.         factor = qMin(rw, rh);
  19.     else
  20.         factor = qMin(rw, rh);
  21.  
  22.     d->setZoomFactor(factor);
  23. }