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();
48 RenderPreview(RenderPreview const &);
49 RenderBase * clone() 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, add a LaTeX snippet to it and
57 * start the loading process.
59 void generatePreview(std::string const & latex_snippet,
62 /** Add a LaTeX snippet to the PreviewLoader but do not start the
65 void addPreview(std::string const & latex_snippet,
66 lyx::graphics::PreviewLoader & ploader);
68 /** Remove a snippet from the cache of previews.
69 * Useful if previewing the contents of a file that has changed.
71 void removePreview(Buffer const &);
73 /// The preview has been generated and is ready to use.
74 bool previewReady() const;
76 /// Connect and you'll be informed when the preview is ready.
77 typedef boost::signal0<void>::slot_type slot_type;
78 boost::signals::connection connect(slot_type const &);
82 void operator=(RenderPreview const &);
84 /// This method is connected to the PreviewLoader::imageReady signal.
85 void imageReady(lyx::graphics::PreviewImage const &);
87 /// The thing that we're trying to generate a preview of.
90 /// We don't own this. Cached for efficiency reasons.
91 lyx::graphics::PreviewImage const * pimage_;
93 /** Store the connection to the preview loader so that we connect
96 boost::signals::connection ploader_connection_;
98 /// This signal is emitted when the preview is ready for display.
99 boost::signal0<void> preview_ready_signal_;
103 class RenderMonitoredPreview : public RenderPreview {
105 RenderMonitoredPreview() : monitor_(std::string(), 2000) {}
107 bool monitoring() const { return monitor_.monitoring(); }
109 void startMonitoring(std::string const & file);
111 void stopMonitoring() { monitor_.stop(); }
113 /// Connect and you'll be informed when the file changes.
114 boost::signals::connection fileChanged(slot_type const &);
118 lyx::support::FileMonitor monitor_;
121 #endif // RENDERPREVIEW_H