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>
24 using namespace lyx::support;
29 class PreviewImage::Impl : public boost::signals::trackable {
32 Impl(PreviewImage & p, PreviewLoader & l,
33 string const & s, FileName const & f, double af);
37 Image const * image();
42 PreviewImage const & parent_;
44 PreviewLoader & ploader_;
48 string const snippet_;
50 double const ascent_frac_;
54 PreviewImage::PreviewImage(PreviewLoader & l,
58 : pimpl_(new Impl(*this, l, s, f, af))
62 PreviewImage::~PreviewImage()
68 string const & PreviewImage::snippet() const
70 return pimpl_->snippet_;
74 Dimension PreviewImage::dim() const
77 Image const * const image = pimpl_->iloader_.image();
81 dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
82 dim.des = image->height() - dim.asc;
83 dim.wid = image->width();
88 Image const * PreviewImage::image() const
90 return pimpl_->image();
94 PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
98 : parent_(p), ploader_(l), iloader_(bf),
99 snippet_(s), ascent_frac_(af)
101 iloader_.connect(boost::bind(&Impl::statusChanged, this));
105 PreviewImage::Impl::~Impl()
107 iloader_.filename().removeFile();
111 Image const * PreviewImage::Impl::image()
113 if (iloader_.status() == WaitingToLoad)
114 iloader_.startLoading();
116 return iloader_.image();
120 void PreviewImage::Impl::statusChanged()
122 switch (iloader_.status()) {
131 case ErrorConverting:
133 case ErrorGeneratingPixmap:
135 //iloader_.filename().removeFile();
136 ploader_.remove(snippet_);
140 iloader_.filename().removeFile();
143 ploader_.emitSignal(parent_);
146 } // namespace graphics