Not so soon, I guess, since that FIXME was from r6305.
[lyx.git] / src / graphics / PreviewImage.cpp
blob306c2bfb12c524822f8e27a8b33201eaca2ec675
1 /**
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.
9 */
11 #include <config.h>
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>
22 using namespace std;
23 using namespace lyx::support;
25 namespace lyx {
26 namespace graphics {
28 class PreviewImage::Impl : public boost::signals::trackable {
29 public:
30 ///
31 Impl(PreviewImage & p, PreviewLoader & l,
32 string const & s, FileName const & f, double af);
33 ///
34 ~Impl();
35 ///
36 Image const * image();
37 ///
38 void statusChanged();
40 ///
41 PreviewImage const & parent_;
42 ///
43 PreviewLoader & ploader_;
44 ///
45 Loader iloader_;
46 ///
47 string const snippet_;
48 ///
49 double const ascent_frac_;
53 PreviewImage::PreviewImage(PreviewLoader & l,
54 string const & s,
55 FileName const & f,
56 double af)
57 : pimpl_(new Impl(*this, l, s, f, af))
61 PreviewImage::~PreviewImage()
63 delete pimpl_;
67 string const & PreviewImage::snippet() const
69 return pimpl_->snippet_;
73 Dimension PreviewImage::dim() const
75 Dimension dim;
76 Image const * const image = pimpl_->iloader_.image();
77 if (!image)
78 return dim;
80 dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
81 dim.des = image->height() - dim.asc;
82 dim.wid = image->width();
83 return dim;
87 Image const * PreviewImage::image() const
89 return pimpl_->image();
93 PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
94 string const & s,
95 FileName const & bf,
96 double af)
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()) {
122 case WaitingToLoad:
123 case Loading:
124 case Converting:
125 case Loaded:
126 case ScalingEtc:
127 break;
129 case ErrorNoFile:
130 case ErrorConverting:
131 case ErrorLoading:
132 case ErrorGeneratingPixmap:
133 case ErrorUnknown:
134 //iloader_.filename().removeFile();
135 ploader_.remove(snippet_);
136 break;
138 case Ready:
139 iloader_.filename().removeFile();
140 break;
142 ploader_.emitSignal(parent_);
145 } // namespace graphics
146 } // namespace lyx