]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiImage.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiImage.cpp
index cf580b12530150370c2bbdb3b121602c35dec3b4..e7defe7ec585933bd5d3cb5dcd6e5230c5ecb97d 100644 (file)
@@ -31,8 +31,8 @@ using namespace lyx::support;
 namespace lyx {
 namespace graphics {
 
-/// Access to this class is through this static method.
-Image * GuiImage::newImage()
+/// Implement factory method defined in GraphicsImage.h
+Image * newImage()
 {
        return new GuiImage;
 }
@@ -90,7 +90,6 @@ bool GuiImage::load()
                LYXERR(Debug::GRAPHICS, "Unable to open image");
                return false;
        }
-       original_.detach();
        return true;
 }
 
@@ -110,13 +109,10 @@ bool GuiImage::setPixmap(Params const & params)
        is_transformed_ |= scale(params);
 
        // Clear the pixmap to save some memory.
-       if (is_transformed_) {
-               original_.detach();
+       if (is_transformed_)
                original_ = QImage();
-       } else {
-               transformed_.detach();
+       else
                transformed_ = QImage();
-       }
 
        return true;
 }
@@ -169,24 +165,20 @@ bool GuiImage::scale(Params const & params)
 {
        QImage const & image = is_transformed_ ? transformed_ : original_;
 
-       unsigned int w = image.width();
-       unsigned int h = image.height();
+       if (params.scale == 100)
+               return false;
 
-       // scale only when value > 0
-       if (params.scale > 0) {
-               w = (w * params.scale) / 100;
-               h = (h * params.scale) / 100;
-       }
+       qreal scale = qreal(params.scale) / 100.0;
 
-       LYXERR(Debug::GRAPHICS, "\n\tparams.scale  : " << params.scale
-                                << "\n\twidth         : " << w
-                                << "\n\theight        : " << h);
+#if (QT_VERSION >= 0x040500) && (QT_VERSION <= 0x040502)
+       // Due to a bug in Qt, LyX will crash for certain
+       // scaling factors and sizes of the image.
+       // see bug #5957: http://www.lyx.org/trac/ticket/5957
+       scale += 0.0001;
+#endif
 
-       if (w == image.width() && h == image.height())
-               return false;
-       
        QMatrix m;
-       m.scale(double(w) / image.width(), double(h) / image.height());
+       m.scale(scale, scale);
        transformed_ = image.transformed(m);
        return true;
 }