2 * \file PreviewImage.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
13 #include "PreviewImage.h"
15 #include "Dimension.h"
16 #include "GraphicsImage.h"
17 #include "GraphicsLoader.h"
18 #include "PreviewLoader.h"
20 #include "support/FileName.h"
22 #include "support/bind.h"
25 using namespace lyx::support;
30 class PreviewImage::Impl : public boost::signals::trackable {
33 Impl(PreviewImage & p, PreviewLoader & l,
34 string const & s, FileName const & f, double af);
38 Image const * image();
43 PreviewImage const & parent_;
45 PreviewLoader & ploader_;
49 string const snippet_;
51 double const ascent_frac_;
55 PreviewImage::PreviewImage(PreviewLoader & l,
59 : pimpl_(new Impl(*this, l, s, f, af))
63 PreviewImage::~PreviewImage()
69 string const & PreviewImage::snippet() const
71 return pimpl_->snippet_;
75 support::FileName const & PreviewImage::filename() const
77 return pimpl_->iloader_.filename();
81 Dimension PreviewImage::dim() const
84 Image const * const image = pimpl_->iloader_.image();
88 dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
89 dim.des = image->height() - dim.asc;
90 dim.wid = image->width();
95 Image const * PreviewImage::image() const
97 return pimpl_->image();
101 PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
105 : parent_(p), ploader_(l), iloader_(bf),
106 snippet_(s), ascent_frac_(af)
108 iloader_.connect(bind(&Impl::statusChanged, this));
112 PreviewImage::Impl::~Impl()
114 iloader_.filename().removeFile();
118 Image const * PreviewImage::Impl::image()
120 if (iloader_.status() == WaitingToLoad)
121 iloader_.startLoading();
123 return iloader_.image();
127 void PreviewImage::Impl::statusChanged()
129 switch (iloader_.status()) {
138 case ErrorConverting:
140 case ErrorGeneratingPixmap:
142 //iloader_.filename().removeFile();
143 ploader_.remove(snippet_);
144 // FIXME: We need to return here, because PreviewLoader::remove
145 // removes the preview image from the cache, which deletes this
146 // object, so we should not try to do anything here.
150 iloader_.filename().removeFile();
153 ploader_.emitSignal(parent_);
156 } // namespace graphics