3 * \file RenderPreview.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 * 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 RENDERPREVIEW_H
17 #define RENDERPREVIEW_H
19 #include "RenderBase.h"
21 #include "support/FileMonitor.h"
22 #include "support/docstring.h"
24 #include <boost/signal.hpp>
25 #include <boost/signals/trackable.hpp>
26 #include <boost/signals/connection.hpp>
31 class LyXRC_PreviewStatus;
35 namespace support { class FileName; }
42 } // namespace graphics
45 class RenderPreview : public RenderBase, public boost::signals::trackable {
47 /// a wrapper for Previews::status()
48 static LyXRC_PreviewStatus status();
50 RenderPreview(Inset const *);
51 RenderPreview(RenderPreview const &, Inset const *);
53 RenderBase * clone(Inset const *) const;
55 /// Compute the size of the object, returned in dim
56 void metrics(MetricsInfo &, Dimension & dim) const;
58 void draw(PainterInfo & pi, int x, int y) const;
60 /** Find the PreviewLoader and add a LaTeX snippet to it.
61 * Do not start the loading process.
63 void addPreview(docstring const & latex_snippet, Buffer const &);
65 /** Add a LaTeX snippet to the PreviewLoader.
66 * Do not start the loading process.
68 void addPreview(docstring const & latex_snippet,
69 graphics::PreviewLoader & ploader);
71 /// Begin the loading process.
72 void startLoading(Buffer const & buffer) const;
74 /** Remove a snippet from the cache of previews.
75 * Useful if previewing the contents of a file that has changed.
77 void removePreview(Buffer const &);
79 /** \returns a pointer to the PreviewImage associated with this snippet
82 graphics::PreviewImage const *
83 getPreviewImage(Buffer const & buffer) const;
85 /// equivalent to dynamic_cast
86 virtual RenderPreview * asPreview() { return this; }
90 RenderPreview & operator=(RenderPreview const &);
92 /// This method is connected to the PreviewLoader::imageReady signal.
93 void imageReady(graphics::PreviewImage const &);
95 /// The thing that we're trying to generate a preview of.
98 /** Store the connection to the preview loader so that we connect
101 boost::signals::connection ploader_connection_;
103 /// Inform the core that the inset has changed.
104 Inset const * parent_;
108 class RenderMonitoredPreview : public RenderPreview {
110 RenderMonitoredPreview(Inset const *);
112 void draw(PainterInfo & pi, int x, int y) const;
114 void setAbsFile(support::FileName const & file);
116 bool monitoring() const { return monitor_.monitoring(); }
117 void startMonitoring() const { monitor_.start(); }
118 void stopMonitoring() const { monitor_.stop(); }
120 /// Connect and you'll be informed when the file changes.
121 typedef support::FileMonitor::slot_type slot_type;
122 boost::signals::connection fileChanged(slot_type const &);
124 /// equivalent to dynamic_cast
125 virtual RenderMonitoredPreview * asMonitoredPreview() { return this; }
129 mutable support::FileMonitor monitor_;
134 #endif // RENDERPREVIEW_H