]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewImage.cpp
Remove obsolete (and false) comment.
[lyx.git] / src / graphics / PreviewImage.cpp
index 07d04d7b4d6f8659f0686b8dd8d2f0ffcf25bb1f..b80bf9415b5175bdabf77d1e50b2af144e733137 100644 (file)
 #include <config.h>
 
 #include "PreviewImage.h"
+
+#include "Buffer.h"
+#include "Dimension.h"
 #include "GraphicsImage.h"
 #include "GraphicsLoader.h"
 #include "PreviewLoader.h"
 
 #include "support/FileName.h"
-#include "support/lyxlib.h"
 
-#include <boost/bind.hpp>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
-
-using support::FileName;
-
 namespace graphics {
 
-class PreviewImage::Impl : public boost::signals::trackable {
+class PreviewImage::Impl {
 public:
        ///
        Impl(PreviewImage & p, PreviewLoader & l,
@@ -73,6 +72,12 @@ string const & PreviewImage::snippet() const
 }
 
 
+support::FileName const & PreviewImage::filename() const
+{
+       return pimpl_->iloader_.filename();
+}
+
+
 Dimension PreviewImage::dim() const
 {
        Dimension dim;
@@ -80,7 +85,7 @@ Dimension PreviewImage::dim() const
        if (!image)
                return dim;
 
-       dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
+       dim.asc = int(pimpl_->ascent_frac_ * double(image->height()) + 0.5);
        dim.des = image->height() - dim.asc;
        dim.wid = image->width();
        return dim;
@@ -93,20 +98,30 @@ Image const * PreviewImage::image() const
 }
 
 
-PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
-                        string const & s,
-                        FileName const & bf,
-                        double af)
-       : parent_(p), ploader_(l), iloader_(bf),
+PreviewLoader & PreviewImage::previewLoader() const
+{
+       return pimpl_->ploader_;
+}
+
+
+PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l, string const & s,
+                         FileName const & bf, double af)
+       : parent_(p), ploader_(l), iloader_(l.buffer().fileName(), bf),
          snippet_(s), ascent_frac_(af)
 {
-       iloader_.connect(boost::bind(&Impl::statusChanged, this));
+       iloader_.setDisplayPixelRatio(l.displayPixelRatio());
+       // This connection is destroyed at the same time as this.
+       iloader_.connect([this](){ statusChanged(); });
 }
 
 
 PreviewImage::Impl::~Impl()
 {
-       iloader_.filename().removeFile();
+       // If these images are generated for a clone, then that may be
+       // because we are previewing. We therefore do not want to delete
+       // them when this Buffer is destroyed.
+       if (!ploader_.buffer().isClone())
+               iloader_.filename().removeFile();
 }
 
 
@@ -136,7 +151,10 @@ void PreviewImage::Impl::statusChanged()
        case ErrorUnknown:
                //iloader_.filename().removeFile();
                ploader_.remove(snippet_);
-               break;
+               // FIXME: We need to return here, because PreviewLoader::remove
+               // removes the preview image from the cache, which deletes this
+               // object, so we should not try to do anything here.
+               return;
 
        case Ready:
                iloader_.filename().removeFile();