3 * \file PreviewedInset.C
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
14 #include "PreviewedInset.h"
15 #include "GraphicsImage.h"
16 #include "PreviewLoader.h"
17 #include "PreviewImage.h"
21 #include "BufferView.h"
23 #include "frontends/LyXView.h"
25 #include "support/lstrings.h"
27 #include <boost/bind.hpp>
29 #include "debug.h" // temporary
33 bool PreviewedInset::activated()
35 return Previews::activated();
39 BufferView * PreviewedInset::view() const
45 void PreviewedInset::generatePreview()
47 if (!Previews::activated() || !previewWanted() ||
48 !view() || !view()->buffer())
51 grfx::Previews & previews = grfx::Previews::get();
52 grfx::PreviewLoader & loader = previews.loader(view()->buffer());
54 if (!snippet_.empty())
55 loader.startLoading();
59 void PreviewedInset::addPreview(grfx::PreviewLoader & ploader)
61 if (!Previews::activated() || !previewWanted())
64 snippet_ = trim(latexString());
68 pimage_ = ploader.preview(snippet_);
72 // If this is the first time of calling, connect to the
73 // grfx::PreviewLoader signal that'll inform us when the preview image
74 // is ready for loading.
75 if (!connection_.connected()) {
76 connection_ = ploader.connect(
77 boost::bind(&PreviewedInset::imageReady, this, _1));
80 ploader.add(snippet_);
84 void PreviewedInset::removePreview()
86 if (!view() || !view()->buffer() || snippet_.empty())
89 grfx::Previews & previews = grfx::Previews::get();
90 grfx::PreviewLoader & loader = previews.loader(view()->buffer());
91 loader.remove(snippet_);
97 bool PreviewedInset::previewReady() const
99 if (!Previews::activated() || !previewWanted() ||
100 !view() || !view()->buffer())
103 if (!pimage_ || snippet_ != pimage_->snippet()) {
104 grfx::PreviewLoader & ploader =
105 grfx::Previews::get().loader(view()->buffer());
106 pimage_ = ploader.preview(snippet_);
112 return pimage_->image();
116 void PreviewedInset::imageReady(grfx::PreviewImage const & pimage) const
118 // Check snippet against the Inset's current contents
119 if (snippet_ != pimage.snippet())
125 view()->updateInset(&inset_);