]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiImage.cpp
Correct early return position for if use_pixmap_cache_ check
[lyx.git] / src / frontends / qt4 / GuiImage.cpp
index 07c2c9854e30056ddd61a1827e33f048eacc44f1..eb5124fcadae65017e39fa3a51100bdc10b644fd 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <config.h>
+#include <math.h> /* ceil */
 
 #include "GuiImage.h"
 #include "qt_helpers.h"
@@ -63,13 +64,25 @@ QImage const & GuiImage::image() const
 
 unsigned int GuiImage::width() const
 {
+#if QT_VERSION >= 0x050000
+       return static_cast<unsigned int>(ceil(is_transformed_ ?
+               (transformed_.width() / transformed_.devicePixelRatio()) :
+               (original_.width() / original_.devicePixelRatio())));
+#else
        return is_transformed_ ? transformed_.width() : original_.width();
+#endif
 }
 
 
 unsigned int GuiImage::height() const
 {
+#if QT_VERSION >= 0x050000
+       return static_cast<unsigned int>(ceil(is_transformed_ ?
+               (transformed_.height() / transformed_.devicePixelRatio()) :
+               (original_.height() / original_.devicePixelRatio())));
+#else
        return is_transformed_ ? transformed_.height() : original_.height();
+#endif
 }
 
 
@@ -79,7 +92,7 @@ bool GuiImage::load(FileName const & filename)
                LYXERR(Debug::GRAPHICS, "Image is loaded already!");
                return false;
        }
-       fname_ = toqstr(filename.absFilename());
+       fname_ = toqstr(filename.absFileName());
        return load();
 }
 
@@ -103,7 +116,11 @@ bool GuiImage::setPixmap(Params const & params)
                if (!load())
                        return false;
        }
-               
+
+#if QT_VERSION >= 0x050000
+       original_.setDevicePixelRatio(params.pixel_ratio);
+#endif
+
        is_transformed_ = clip(params);
        is_transformed_ |= rotate(params);
        is_transformed_ |= scale(params);
@@ -124,8 +141,14 @@ bool GuiImage::clip(Params const & params)
                // No clipping is necessary.
                return false;
 
-       int const new_width  = params.bb.xr - params.bb.xl;
-       int const new_height = params.bb.yt - params.bb.yb;
+#if QT_VERSION >= 0x050000
+       double const pixelRatio = is_transformed_ ? transformed_.devicePixelRatio() : original_.devicePixelRatio();
+       int const new_width  = static_cast<int>((params.bb.xr.inBP() - params.bb.xl.inBP()) * pixelRatio);
+       int const new_height = static_cast<int>((params.bb.yt.inBP() - params.bb.yb.inBP()) * pixelRatio);
+#else
+       int const new_width  = static_cast<int>((params.bb.xr.inBP() - params.bb.xl.inBP()));
+       int const new_height = static_cast<int>((params.bb.yt.inBP() - params.bb.yb.inBP()));
+#endif
 
        QImage const & image = is_transformed_ ? transformed_ : original_;
 
@@ -139,9 +162,9 @@ bool GuiImage::clip(Params const & params)
        if (new_width == image.width() && new_height == image.height())
                return false;
 
-       int const xoffset_l = params.bb.xl;
-       int const yoffset_t = (image.height() > int(params.bb.yt))
-               ? image.height() - params.bb.yt : 0;
+       int const xoffset_l = params.bb.xl.inBP();
+       int const yoffset_t = (image.height() > params.bb.yt.inBP())
+               ? image.height() - params.bb.yt.inBP() : 0;
 
        transformed_ = image.copy(xoffset_l, yoffset_t, new_width, new_height);
        return true;
@@ -168,13 +191,17 @@ bool GuiImage::scale(Params const & params)
        if (params.scale == 100)
                return false;
 
+#if QT_VERSION >= 0x050000
+       double const pixelRatio = is_transformed_ ? transformed_.devicePixelRatio() : original_.devicePixelRatio();
+       qreal scale = qreal(params.scale) / 100.0 * pixelRatio;
+#else
        qreal scale = qreal(params.scale) / 100.0;
+#endif
 
-#if QT_VERSION >= 0x040500
+#if (QT_VERSION >= 0x040500) && (QT_VERSION <= 0x040502)
        // Due to a bug in Qt, LyX will crash for certain
-       // (integer) scaling factors and sizes of the image.
+       // scaling factors and sizes of the image.
        // see bug #5957: http://www.lyx.org/trac/ticket/5957
-       // FIXME: Add an upper version limit as soon as the bug is fixed in Qt.
        scale += 0.0001;
 #endif