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/signals2.hpp>
25 #include <boost/signals2/trackable.hpp>
26 #include <boost/signals2/connection.hpp>
34 namespace support { class FileName; }
41 } // namespace graphics
44 class RenderPreview : public RenderBase, public boost::signals2::trackable {
46 /// Return true if preview is enabled in text (from LyXRC::preview)
47 static bool previewText();
48 /// Return true if preview is enabled in mathed (from LyXRC::preview)
49 static bool previewMath();
51 RenderPreview(Inset const *);
52 RenderPreview(RenderPreview const &, Inset const *);
54 RenderBase * clone(Inset const *) const;
56 /// Compute the size of the object, returned in dim
57 void metrics(MetricsInfo &, Dimension & dim) const;
59 void draw(PainterInfo & pi, int x, int y) const;
61 /** Find the PreviewLoader and add a LaTeX snippet to it.
62 * Do not start the loading process.
63 * \param ignore_lyxrc: generate the preview no matter what LyXRC says
65 void addPreview(docstring const & latex_snippet, Buffer const &,
66 bool ignore_lyxrc = false);
68 /** Add a LaTeX snippet to the PreviewLoader.
69 * Do not start the loading process.
70 * \param ignore_lyxrc: generate the preview no matter what LyXRC says
72 void addPreview(docstring const & latex_snippet,
73 graphics::PreviewLoader & ploader,
74 bool ignore_lyxrc = false);
76 /// Begin the loading process.
77 /// \param forexport : whether this is intended for export. if so,
78 /// then we ignore LyXRC and wait for the image to be generated.
79 void startLoading(Buffer const & buffer, bool forexport = false) const;
81 /** Remove a snippet from the cache of previews.
82 * Useful if previewing the contents of a file that has changed.
84 void removePreview(Buffer const &);
86 /** \returns a pointer to the PreviewImage associated with this snippet
89 graphics::PreviewImage const *
90 getPreviewImage(Buffer const & buffer) const;
92 /// equivalent to dynamic_cast
93 virtual RenderPreview * asPreview() { return this; }
97 RenderPreview & operator=(RenderPreview const &);
99 /// This method is connected to the PreviewLoader::imageReady signal.
100 void imageReady(graphics::PreviewImage const &);
102 /// The thing that we're trying to generate a preview of.
103 std::string snippet_;
105 /** Store the connection to the preview loader so that we connect
108 boost::signals2::connection ploader_connection_;
110 /// Inform the core that the inset has changed.
111 Inset const * parent_;
115 class RenderMonitoredPreview : public RenderPreview {
117 RenderMonitoredPreview(Inset const *);
119 void draw(PainterInfo & pi, int x, int y) const;
121 void setAbsFile(support::FileName const & file);
123 bool monitoring() const { return monitor_.monitoring(); }
124 void startMonitoring() const { monitor_.start(); }
125 void stopMonitoring() const { monitor_.stop(); }
127 /// Connect and you'll be informed when the file changes.
128 typedef support::FileMonitor::slot_type slot_type;
129 boost::signals2::connection fileChanged(slot_type const &);
131 /// equivalent to dynamic_cast
132 virtual RenderMonitoredPreview * asMonitoredPreview() { return this; }
136 mutable support::FileMonitor monitor_;
141 #endif // RENDERPREVIEW_H