3 * \file PreviewedInset.C
4 * Read the file COPYING
6 * \author Angus Leeming
8 * Full author contact details available in file CREDITS
12 #pragma implementation
17 #include "PreviewedInset.h"
18 #include "GraphicsImage.h"
19 #include "PreviewLoader.h"
20 #include "PreviewImage.h"
24 #include "BufferView.h"
26 #include "frontends/LyXView.h"
28 #include "support/lstrings.h"
30 #include <boost/bind.hpp>
32 #include "debug.h" // temporary
36 bool PreviewedInset::activated()
38 return Previews::activated();
42 void PreviewedInset::generatePreview()
44 if (!Previews::activated() || !previewWanted() ||
45 !view() || !view()->buffer())
48 grfx::Previews & previews = grfx::Previews::get();
49 grfx::PreviewLoader & loader = previews.loader(view()->buffer());
51 if (!snippet_.empty())
52 loader.startLoading();
56 void PreviewedInset::addPreview(grfx::PreviewLoader & ploader)
58 if (!Previews::activated() || !previewWanted())
61 setView(ploader.buffer().getUser());
63 snippet_ = trim(latexString());
67 pimage_ = ploader.preview(snippet_);
71 // If this is the first time of calling, connect to the
72 // grfx::PreviewLoader signal that'll inform us when the preview image
73 // is ready for loading.
74 if (!connection_.connected()) {
75 connection_ = ploader.connect(
76 boost::bind(&PreviewedInset::imageReady, this, _1));
79 ploader.add(snippet_);
83 void PreviewedInset::removePreview()
85 if (!view() || !view()->buffer() || snippet_.empty())
88 grfx::Previews & previews = grfx::Previews::get();
89 grfx::PreviewLoader & loader = previews.loader(view()->buffer());
90 loader.remove(snippet_);
96 bool PreviewedInset::previewReady() const
98 if (!Previews::activated() || !previewWanted() ||
99 !view() || !view()->buffer())
102 if (!pimage_ || snippet_ != pimage_->snippet()) {
103 grfx::PreviewLoader & ploader =
104 grfx::Previews::get().loader(view()->buffer());
105 pimage_ = ploader.preview(snippet_);
111 return pimage_->image(inset_, *view());
115 void PreviewedInset::setView(BufferView * bv)
120 view_ = bv->owner()->view();
123 void PreviewedInset::imageReady(grfx::PreviewImage const & pimage) const
125 // Check snippet against the Inset's current contents
126 if (snippet_ != pimage.snippet())
132 view()->updateInset(&inset_, false);