3 * \file render_preview.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 * lyx::graphics::RenderPreview is an abstract base class that can help
12 * insets to generate previews. The daughter class must instantiate two small
13 * methods. The Inset would own an instance of this daughter class.
16 #ifndef RENDER_PREVIEW_H
17 #define RENDER_PREVIEW_H
19 #include "render_base.h"
21 #include "support/FileMonitor.h"
23 #include <boost/signals/signal0.hpp>
24 #include <boost/signals/trackable.hpp>
25 #include <boost/signals/connection.hpp>
38 } // namespace graphics
42 class RenderPreview : public RenderBase, public boost::signals::trackable {
44 /// a wrapper for Previews::activated()
45 static bool activated();
47 RenderPreview(InsetBase const *);
48 RenderPreview(RenderPreview const &, InsetBase const *);
49 std::auto_ptr<RenderBase> clone(InsetBase const *) const;
51 /// Compute the size of the object, returned in dim
52 void metrics(MetricsInfo &, Dimension & dim) const;
54 void draw(PainterInfo & pi, int x, int y) const;
56 /** Find the PreviewLoader and add a LaTeX snippet to it.
57 * Do not start the loading process.
59 void addPreview(std::string const & latex_snippet, Buffer const &);
61 /** Add a LaTeX snippet to the PreviewLoader.
62 * Do not start the loading process.
64 void addPreview(std::string const & latex_snippet,
65 lyx::graphics::PreviewLoader & ploader);
67 /// Begin the loading process.
68 void startLoading(Buffer const & buffer) const;
70 /** Remove a snippet from the cache of previews.
71 * Useful if previewing the contents of a file that has changed.
73 void removePreview(Buffer const &);
75 /// The preview has been generated and is ready to use.
76 bool previewReady() const;
78 /// equivalent to dynamic_cast
79 virtual RenderPreview * asPreview() { return this; }
83 void operator=(RenderPreview const &);
85 /// This method is connected to the PreviewLoader::imageReady signal.
86 void imageReady(lyx::graphics::PreviewImage const &);
88 /// The thing that we're trying to generate a preview of.
91 /// We don't own this. Cached for efficiency reasons.
92 lyx::graphics::PreviewImage const * pimage_;
94 /** Store the connection to the preview loader so that we connect
97 boost::signals::connection ploader_connection_;
99 /// Inform the core that the inset has changed.
100 InsetBase const * parent_;
104 class RenderMonitoredPreview : public RenderPreview {
106 RenderMonitoredPreview(InsetBase const *);
108 void draw(PainterInfo & pi, int x, int y) const;
110 void setAbsFile(std::string const & file);
112 bool monitoring() const { return monitor_.monitoring(); }
113 void startMonitoring() const { monitor_.start(); }
114 void stopMonitoring() const { monitor_.stop(); }
117 /// Connect and you'll be informed when the file changes.
118 typedef boost::signal0<void>::slot_type slot_type;
119 boost::signals::connection fileChanged(slot_type const &);
121 /// equivalent to dynamic_cast
122 virtual RenderMonitoredPreview * asMonitoredPreview() { return this; }
126 mutable lyx::support::FileMonitor monitor_;
129 #endif // RENDERPREVIEW_H