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"
19 #include "support/lyxlib.h"
21 #include <boost/bind.hpp>
27 using support::FileName;
31 class PreviewImage::Impl : public boost::signals::trackable {
34 Impl(PreviewImage & p, PreviewLoader & l,
35 string const & s, FileName const & f, double af);
39 Image const * image();
44 PreviewImage const & parent_;
46 PreviewLoader & ploader_;
50 string const snippet_;
52 double const ascent_frac_;
56 PreviewImage::PreviewImage(PreviewLoader & l,
60 : pimpl_(new Impl(*this, l, s, f, af))
64 PreviewImage::~PreviewImage()
70 string const & PreviewImage::snippet() const
72 return pimpl_->snippet_;
76 Dimension PreviewImage::dim() const
79 Image const * const image = pimpl_->iloader_.image();
83 dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
84 dim.des = image->height() - dim.asc;
85 dim.wid = image->width();
90 Image const * PreviewImage::image() const
92 return pimpl_->image();
96 PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
100 : parent_(p), ploader_(l), iloader_(bf),
101 snippet_(s), ascent_frac_(af)
103 iloader_.connect(boost::bind(&Impl::statusChanged, this));
107 PreviewImage::Impl::~Impl()
109 iloader_.filename().removeFile();
113 Image const * PreviewImage::Impl::image()
115 if (iloader_.status() == WaitingToLoad)
116 iloader_.startLoading();
118 return iloader_.image();
122 void PreviewImage::Impl::statusChanged()
124 switch (iloader_.status()) {
133 case ErrorConverting:
135 case ErrorGeneratingPixmap:
137 //iloader_.filename().removeFile();
138 ploader_.remove(snippet_);
142 iloader_.filename().removeFile();
145 ploader_.emitSignal(parent_);
148 } // namespace graphics