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 <boost/bind.hpp>
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 Dimension PreviewImage::dim() const
76 Image const * const image = pimpl_->iloader_.image();
80 dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
81 dim.des = image->height() - dim.asc;
82 dim.wid = image->width();
87 Image const * PreviewImage::image() const
89 return pimpl_->image();
93 PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
97 : parent_(p), ploader_(l), iloader_(bf),
98 snippet_(s), ascent_frac_(af)
100 iloader_.connect(boost::bind(&Impl::statusChanged, this));
104 PreviewImage::Impl::~Impl()
106 iloader_.filename().removeFile();
110 Image const * PreviewImage::Impl::image()
112 if (iloader_.status() == WaitingToLoad)
113 iloader_.startLoading();
115 return iloader_.image();
119 void PreviewImage::Impl::statusChanged()
121 switch (iloader_.status()) {
130 case ErrorConverting:
132 case ErrorGeneratingPixmap:
134 //iloader_.filename().removeFile();
135 ploader_.remove(snippet_);
139 iloader_.filename().removeFile();
142 ploader_.emitSignal(parent_);
145 } // namespace graphics