]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewImage.cpp
Do not compute metrics at each preview when loading file
[lyx.git] / src / graphics / PreviewImage.cpp
index da0f1e21ceeb942207dd91152c937ef70a6d10a0..e94384c168a091935389b42fecaf1bfc52ad837d 100644 (file)
@@ -19,8 +19,8 @@
 #include "PreviewLoader.h"
 
 #include "support/FileName.h"
+#include "support/lyxlib.h"
 
-#include "support/bind.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -28,15 +28,15 @@ using namespace lyx::support;
 namespace lyx {
 namespace graphics {
 
-class PreviewImage::Impl : public boost::signals2::trackable {
+class PreviewImage::Impl {
 public:
        ///
        Impl(PreviewImage & p, PreviewLoader & l,
-            string const & s, FileName const & f, double af);
+            docstring const & s, FileName const & f, double af);
        ///
        ~Impl();
        ///
-       Image const * image();
+       Image const * image() const;
        ///
        void statusChanged();
 
@@ -47,14 +47,14 @@ public:
        ///
        Loader iloader_;
        ///
-       string const snippet_;
+       docstring const snippet_;
        ///
        double const ascent_frac_;
 };
 
 
 PreviewImage::PreviewImage(PreviewLoader & l,
-                          string const & s,
+                          docstring const & s,
                           FileName const & f,
                           double af)
        : pimpl_(new Impl(*this, l, s, f, af))
@@ -67,7 +67,7 @@ PreviewImage::~PreviewImage()
 }
 
 
-string const & PreviewImage::snippet() const
+docstring const & PreviewImage::snippet() const
 {
        return pimpl_->snippet_;
 }
@@ -86,7 +86,7 @@ Dimension PreviewImage::dim() const
        if (!image)
                return dim;
 
-       dim.asc = int(pimpl_->ascent_frac_ * double(image->height()) + 0.5);
+       dim.asc = support::iround(pimpl_->ascent_frac_ * double(image->height()));
        dim.des = image->height() - dim.asc;
        dim.wid = image->width();
        return dim;
@@ -105,15 +105,14 @@ PreviewLoader & PreviewImage::previewLoader() const
 }
 
 
-PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
-                        string const & s,
-                        FileName const & bf,
-                        double af)
+PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l, docstring const & s,
+                         FileName const & bf, double af)
        : parent_(p), ploader_(l), iloader_(l.buffer().fileName(), bf),
          snippet_(s), ascent_frac_(af)
 {
        iloader_.setDisplayPixelRatio(l.displayPixelRatio());
-       iloader_.connect(bind(&Impl::statusChanged, this));
+       // This connection is destroyed at the same time as this.
+       iloader_.connect([this](){ statusChanged(); });
 }
 
 
@@ -127,7 +126,7 @@ PreviewImage::Impl::~Impl()
 }
 
 
-Image const * PreviewImage::Impl::image()
+Image const * PreviewImage::Impl::image() const
 {
        if (iloader_.status() == WaitingToLoad)
                iloader_.startLoading();