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>
28 using support::FileName;
32 class PreviewImage::Impl : public boost::signals::trackable {
35 Impl(PreviewImage & p, PreviewLoader & l,
36 string const & s, FileName const & f, double af);
40 Image const * image();
45 PreviewImage const & parent_;
47 PreviewLoader & ploader_;
51 string const snippet_;
53 double const ascent_frac_;
57 PreviewImage::PreviewImage(PreviewLoader & l,
61 : pimpl_(new Impl(*this, l, s, f, af))
65 PreviewImage::~PreviewImage()
71 string const & PreviewImage::snippet() const
73 return pimpl_->snippet_;
77 Dimension PreviewImage::dim() const
80 Image const * const image = pimpl_->iloader_.image();
84 dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
85 dim.des = image->height() - dim.asc;
86 dim.wid = image->width();
91 Image const * PreviewImage::image() const
93 return pimpl_->image();
97 PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
101 : parent_(p), ploader_(l), iloader_(bf),
102 snippet_(s), ascent_frac_(af)
104 iloader_.connect(boost::bind(&Impl::statusChanged, this));
108 PreviewImage::Impl::~Impl()
110 iloader_.filename().removeFile();
114 Image const * PreviewImage::Impl::image()
116 if (iloader_.status() == WaitingToLoad)
117 iloader_.startLoading();
119 return iloader_.image();
123 void PreviewImage::Impl::statusChanged()
125 switch (iloader_.status()) {
134 case ErrorConverting:
136 case ErrorGeneratingPixmap:
138 //iloader_.filename().removeFile();
139 ploader_.remove(snippet_);
143 iloader_.filename().removeFile();
146 ploader_.emitSignal(parent_);
149 } // namespace graphics