3 * \file PreviewedInset.h
4 * Read the file COPYING
6 * \author Angus Leeming
8 * Full author contact details available in file CREDITS
10 * grfx::PreviewedInset is an abstract base class that can help insets to
11 * generate previews. The daughter class must instantiate three small
12 * methods. The Inset would own an instance of this daughter class.
15 #ifndef PREVIEWEDINSET_H
16 #define PREVIEWEDINSET_H
23 #include <boost/weak_ptr.hpp>
24 #include <boost/signals/trackable.hpp>
25 #include <boost/signals/connection.hpp>
35 class PreviewedInset : public boost::signals::trackable {
37 /// a wrapper for Previews::activated()
38 static bool activated();
41 PreviewedInset(Inset & inset) : inset_(inset), pimage_(0) {}
43 virtual ~PreviewedInset() {}
45 /** Find the PreviewLoader, add a LaTeX snippet to it and
46 * start the loading process.
48 void generatePreview();
50 /** Add a LaTeX snippet to the PreviewLoader but do not start the
53 void addPreview(PreviewLoader & ploader);
55 /** Remove a snippet from the cache of previews.
56 * Useful if previewing the contents of a file that has changed.
60 /// The preview has been generated and is ready to use.
61 bool previewReady() const;
63 /// If !previewReady() returns 0.
64 PreviewImage const * pimage() const { return pimage_; }
67 void setView(BufferView *);
70 /// Allow the daughter classes to cast up to the parent inset.
71 Inset * inset() const { return &inset_; }
73 BufferView * view() const { return view_.get(); }
76 /** This method is connected to the grfx::PreviewLoader::imageReady
79 void imageReady(PreviewImage const &) const;
81 /// Does the owning inset want a preview?
82 virtual bool previewWanted() const = 0;
83 /// a wrapper to Inset::latex
84 virtual string const latexString() const = 0;
91 boost::weak_ptr<BufferView> view_;
93 /// We don't own this. Cached for efficiency reasons.
94 mutable PreviewImage const * pimage_;
96 boost::signals::connection connection_;
102 #endif // PREVIEWEDINSET_H