X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fgraphics%2FPreviewImage.cpp;h=b31af6fbd946d109eb875bedb2a03b0b9d996219;hb=a900667ea1bb516ac562a6c45e4f3a1e4071b01b;hp=306c2bfb12c524822f8e27a8b33201eaca2ec675;hpb=e7bb71ff4ebf16351ab238b5cb7514173dd4f84d;p=lyx.git diff --git a/src/graphics/PreviewImage.cpp b/src/graphics/PreviewImage.cpp index 306c2bfb12..b31af6fbd9 100644 --- a/src/graphics/PreviewImage.cpp +++ b/src/graphics/PreviewImage.cpp @@ -11,13 +11,16 @@ #include #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 using namespace std; using namespace lyx::support; @@ -25,7 +28,7 @@ using namespace lyx::support; namespace lyx { namespace graphics { -class PreviewImage::Impl : public boost::signals::trackable { +class PreviewImage::Impl { public: /// Impl(PreviewImage & p, PreviewLoader & l, @@ -33,7 +36,7 @@ public: /// ~Impl(); /// - Image const * image(); + Image const * image() const; /// void statusChanged(); @@ -70,6 +73,12 @@ string const & PreviewImage::snippet() const } +support::FileName const & PreviewImage::filename() const +{ + return pimpl_->iloader_.filename(); +} + + Dimension PreviewImage::dim() const { Dimension dim; @@ -77,7 +86,7 @@ Dimension PreviewImage::dim() const if (!image) return dim; - dim.asc = int(pimpl_->ascent_frac_ * double(image->height())); + dim.asc = support::iround(pimpl_->ascent_frac_ * double(image->height())); dim.des = image->height() - dim.asc; dim.wid = image->width(); return dim; @@ -90,24 +99,34 @@ 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(); } -Image const * PreviewImage::Impl::image() +Image const * PreviewImage::Impl::image() const { if (iloader_.status() == WaitingToLoad) iloader_.startLoading(); @@ -133,7 +152,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();