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/signal.hpp>
24 #include <boost/signals/trackable.hpp>
25 #include <boost/signals/connection.hpp>
29 class LyXRC_PreviewStatus;
39 } // namespace graphics
43 class RenderPreview : public RenderBase, public boost::signals::trackable {
45 /// a wrapper for Previews::status()
46 static LyXRC_PreviewStatus status();
48 RenderPreview(InsetBase const *);
49 RenderPreview(RenderPreview const &, InsetBase const *);
50 std::auto_ptr<RenderBase> clone(InsetBase const *) const;
52 /// Compute the size of the object, returned in dim
53 void metrics(MetricsInfo &, Dimension & dim) const;
55 void draw(PainterInfo & pi, int x, int y) const;
57 /** Find the PreviewLoader and add a LaTeX snippet to it.
58 * Do not start the loading process.
60 void addPreview(std::string const & latex_snippet, Buffer const &);
62 /** Add a LaTeX snippet to the PreviewLoader.
63 * Do not start the loading process.
65 void addPreview(std::string const & latex_snippet,
66 lyx::graphics::PreviewLoader & ploader);
68 /// Begin the loading process.
69 void startLoading(Buffer const & buffer) const;
71 /** Remove a snippet from the cache of previews.
72 * Useful if previewing the contents of a file that has changed.
74 void removePreview(Buffer const &);
76 /** \returns a pointer to the PreviewImage associated with this snippet
79 lyx::graphics::PreviewImage const *
80 getPreviewImage(Buffer const & buffer) const;
82 /// equivalent to dynamic_cast
83 virtual RenderPreview * asPreview() { return this; }
87 void operator=(RenderPreview const &);
89 /// This method is connected to the PreviewLoader::imageReady signal.
90 void imageReady(lyx::graphics::PreviewImage const &);
92 /// The thing that we're trying to generate a preview of.
95 /** Store the connection to the preview loader so that we connect
98 boost::signals::connection ploader_connection_;
100 /// Inform the core that the inset has changed.
101 InsetBase const * parent_;
105 class RenderMonitoredPreview : public RenderPreview {
107 RenderMonitoredPreview(InsetBase const *);
109 void draw(PainterInfo & pi, int x, int y) const;
111 void setAbsFile(std::string const & file);
113 bool monitoring() const { return monitor_.monitoring(); }
114 void startMonitoring() const { monitor_.start(); }
115 void stopMonitoring() const { monitor_.stop(); }
118 /// Connect and you'll be informed when the file changes.
119 typedef lyx::support::FileMonitor::slot_type slot_type;
120 boost::signals::connection fileChanged(slot_type const &);
122 /// equivalent to dynamic_cast
123 virtual RenderMonitoredPreview * asMonitoredPreview() { return this; }
127 mutable lyx::support::FileMonitor monitor_;
130 #endif // RENDERPREVIEW_H