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/docstring.h"
22 #include "support/FileMonitor.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 /// Return true if preview is enabled in text (from LyXRC::preview)
48 static bool previewText();
49 /// Return true if preview is enabled in mathed (from LyXRC::preview)
50 static bool previewMath();
52 RenderPreview(Inset const *);
53 RenderPreview(RenderPreview const &, Inset const *);
55 RenderBase * clone(Inset const *) const;
57 /// Compute the size of the object, returned in dim
58 void metrics(MetricsInfo &, Dimension & dim) const;
60 void draw(PainterInfo & pi, int x, int y) const;
62 /** Find the PreviewLoader and add a LaTeX snippet to it.
63 * Do not start the loading process.
64 * \param ignore_lyxrc: generate the preview no matter what LyXRC says
66 void addPreview(docstring const & latex_snippet, Buffer const &,
67 bool ignore_lyxrc = false);
69 /** Add a LaTeX snippet to the PreviewLoader.
70 * Do not start the loading process.
71 * \param ignore_lyxrc: generate the preview no matter what LyXRC says
73 void addPreview(docstring const & latex_snippet,
74 graphics::PreviewLoader & ploader,
75 bool ignore_lyxrc = false);
77 /// Begin the loading process.
78 /// \param forexport : whether this is intended for export. if so,
79 /// then we ignore LyXRC and wait for the image to be generated.
80 void startLoading(Buffer const & buffer, bool forexport = false) const;
82 /** Remove a snippet from the cache of previews.
83 * Useful if previewing the contents of a file that has changed.
85 void removePreview(Buffer const &);
87 /** \returns a pointer to the PreviewImage associated with this snippet
90 graphics::PreviewImage const *
91 getPreviewImage(Buffer const & buffer) const;
93 /// equivalent to dynamic_cast
94 virtual RenderPreview * asPreview() { return this; }
98 RenderPreview & operator=(RenderPreview const &);
100 /// This method is connected to the PreviewLoader::imageReady signal.
101 void imageReady(graphics::PreviewImage const &);
103 /// The thing that we're trying to generate a preview of.
104 std::string snippet_;
106 /** Store the connection to the preview loader so that we connect
109 boost::signals::connection ploader_connection_;
111 /// Inform the core that the inset has changed.
112 Inset const * parent_;
116 class RenderMonitoredPreview : public RenderPreview {
118 RenderMonitoredPreview(Inset const *);
120 void draw(PainterInfo & pi, int x, int y) const;
122 void setAbsFile(support::FileName const & file);
124 bool monitoring() const { return monitor_.monitoring(); }
125 void startMonitoring() const { monitor_.start(); }
126 void stopMonitoring() const { monitor_.stop(); }
128 /// Connect and you'll be informed when the file changes.
129 typedef support::FileMonitor::slot_type slot_type;
130 boost::signals::connection fileChanged(slot_type const &);
132 /// equivalent to dynamic_cast
133 virtual RenderMonitoredPreview * asMonitoredPreview() { return this; }
137 mutable support::FileMonitor monitor_;
142 #endif // RENDERPREVIEW_H