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"
14 #include "GraphicsImage.h"
15 #include "GraphicsLoader.h"
16 #include "PreviewLoader.h"
18 #include "support/FileName.h"
20 #include "support/bind.h"
23 using namespace lyx::support;
28 class PreviewImage::Impl : public boost::signals::trackable {
31 Impl(PreviewImage & p, PreviewLoader & l,
32 string const & s, FileName const & f, double af);
36 Image const * image();
41 PreviewImage const & parent_;
43 PreviewLoader & ploader_;
47 string const snippet_;
49 double const ascent_frac_;
53 PreviewImage::PreviewImage(PreviewLoader & l,
57 : pimpl_(new Impl(*this, l, s, f, af))
61 PreviewImage::~PreviewImage()
67 string const & PreviewImage::snippet() const
69 return pimpl_->snippet_;
73 support::FileName const & PreviewImage::filename() const
75 return pimpl_->iloader_.filename();
79 Dimension PreviewImage::dim() const
82 Image const * const image = pimpl_->iloader_.image();
86 dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
87 dim.des = image->height() - dim.asc;
88 dim.wid = image->width();
93 Image const * PreviewImage::image() const
95 return pimpl_->image();
99 PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
103 : parent_(p), ploader_(l), iloader_(bf),
104 snippet_(s), ascent_frac_(af)
106 iloader_.connect(bind(&Impl::statusChanged, this));
110 PreviewImage::Impl::~Impl()
112 iloader_.filename().removeFile();
116 Image const * PreviewImage::Impl::image()
118 if (iloader_.status() == WaitingToLoad)
119 iloader_.startLoading();
121 return iloader_.image();
125 void PreviewImage::Impl::statusChanged()
127 switch (iloader_.status()) {
136 case ErrorConverting:
138 case ErrorGeneratingPixmap:
140 //iloader_.filename().removeFile();
141 ploader_.remove(snippet_);
142 // FIXME: We need to return here, because PreviewLoader::remove
143 // removes the preview image from the cache, which deletes this
144 // object, so we should not try to do anything here.
148 iloader_.filename().removeFile();
151 ploader_.emitSignal(parent_);
154 } // namespace graphics