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
31 using namespace lyx::support;
36 bool PreviewedInset::activated()
38 return Previews::activated();
42 BufferView * PreviewedInset::view() const
48 void PreviewedInset::generatePreview()
50 if (!Previews::activated() || !previewWanted() ||
51 !view() || !view()->buffer())
54 Previews & previews = Previews::get();
55 PreviewLoader & loader = previews.loader(view()->buffer());
57 if (!snippet_.empty())
58 loader.startLoading();
62 void PreviewedInset::addPreview(PreviewLoader & ploader)
64 if (!Previews::activated() || !previewWanted())
67 snippet_ = trim(latexString());
71 pimage_ = ploader.preview(snippet_);
75 // If this is the first time of calling, connect to the
76 // PreviewLoader signal that'll inform us when the preview image
77 // is ready for loading.
78 if (!connection_.connected()) {
79 connection_ = ploader.connect(
80 boost::bind(&PreviewedInset::imageReady, this, _1));
83 ploader.add(snippet_);
87 void PreviewedInset::removePreview()
89 if (!view() || !view()->buffer() || snippet_.empty())
92 Previews & previews = Previews::get();
93 PreviewLoader & loader = previews.loader(view()->buffer());
94 loader.remove(snippet_);
100 bool PreviewedInset::previewReady() const
102 if (!Previews::activated() || !previewWanted() ||
103 !view() || !view()->buffer())
106 if (!pimage_ || snippet_ != pimage_->snippet()) {
107 PreviewLoader & ploader =
108 Previews::get().loader(view()->buffer());
109 pimage_ = ploader.preview(snippet_);
115 return pimage_->image();
119 void PreviewedInset::imageReady(PreviewImage const & pimage) const
121 // Check snippet against the Inset's current contents
122 if (snippet_ != pimage.snippet())
128 view()->updateInset();
131 } // namespace graphics