2 * \file PreviewedInset.C
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 "PreviewedInset.h"
14 #include "GraphicsImage.h"
15 #include "PreviewLoader.h"
16 #include "PreviewImage.h"
20 #include "BufferView.h"
22 #include "frontends/LyXView.h"
24 #include "support/lstrings.h"
26 #include <boost/bind.hpp>
28 #include "debug.h" // temporary
30 using namespace lyx::support;
35 bool PreviewedInset::activated()
37 return Previews::activated();
41 BufferView * PreviewedInset::view() const
47 void PreviewedInset::generatePreview()
49 if (!Previews::activated() || !previewWanted() ||
50 !view() || !view()->buffer())
53 Previews & previews = Previews::get();
54 PreviewLoader & loader = previews.loader(*view()->buffer());
56 if (!snippet_.empty())
57 loader.startLoading();
61 void PreviewedInset::addPreview(PreviewLoader & ploader)
63 if (!Previews::activated() || !previewWanted())
66 snippet_ = trim(latexString());
70 pimage_ = ploader.preview(snippet_);
74 // If this is the first time of calling, connect to the
75 // PreviewLoader signal that'll inform us when the preview image
76 // is ready for loading.
77 if (!connection_.connected()) {
78 connection_ = ploader.connect(
79 boost::bind(&PreviewedInset::imageReady, this, _1));
82 ploader.add(snippet_);
86 void PreviewedInset::removePreview()
88 if (!view() || !view()->buffer() || snippet_.empty())
91 Previews & previews = Previews::get();
92 PreviewLoader & loader = previews.loader(*view()->buffer());
93 loader.remove(snippet_);
99 bool PreviewedInset::previewReady() const
101 if (!Previews::activated() || !previewWanted() ||
102 !view() || !view()->buffer())
105 if (!pimage_ || snippet_ != pimage_->snippet()) {
106 PreviewLoader & ploader =
107 Previews::get().loader(*view()->buffer());
108 pimage_ = ploader.preview(snippet_);
114 return pimage_->image();
118 void PreviewedInset::imageReady(PreviewImage const & pimage) const
120 // Check snippet against the Inset's current contents
121 if (snippet_ != pimage.snippet())
127 view()->updateInset(inset());
130 } // namespace graphics