3 * \file PreviewedInset.h
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
11 * grfx::PreviewedInset is an abstract base class that can help insets to
12 * generate previews. The daughter class must instantiate three small
13 * methods. The Inset would own an instance of this daughter class.
16 #ifndef PREVIEWEDINSET_H
17 #define PREVIEWEDINSET_H
20 #include <boost/signals/trackable.hpp>
21 #include <boost/signals/connection.hpp>
31 class PreviewedInset : public boost::signals::trackable {
33 /// a wrapper for Previews::activated()
34 static bool activated();
37 PreviewedInset(Inset & inset) : inset_(inset), pimage_(0) {}
39 virtual ~PreviewedInset() {}
41 /** Find the PreviewLoader, add a LaTeX snippet to it and
42 * start the loading process.
44 void generatePreview();
46 /** Add a LaTeX snippet to the PreviewLoader but do not start the
49 void addPreview(PreviewLoader & ploader);
51 /** Remove a snippet from the cache of previews.
52 * Useful if previewing the contents of a file that has changed.
56 /// The preview has been generated and is ready to use.
57 bool previewReady() const;
59 /// If !previewReady() returns 0.
60 PreviewImage const * pimage() const { return pimage_; }
63 /// Allow the daughter classes to cast up to the parent inset.
64 Inset * inset() const { return &inset_; }
66 BufferView * view() const;
69 /** This method is connected to the grfx::PreviewLoader::imageReady
72 void imageReady(PreviewImage const &) const;
74 /// Does the owning inset want a preview?
75 virtual bool previewWanted() const = 0;
76 /// a wrapper to Inset::latex
77 virtual string const latexString() const = 0;
84 /// We don't own this. Cached for efficiency reasons.
85 mutable PreviewImage const * pimage_;
87 boost::signals::connection connection_;
93 #endif // PREVIEWEDINSET_H