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"
23 #include "support/FileName.h"
24 #include "support/signals.h"
38 } // namespace graphics
41 class RenderPreview : public RenderBase {
43 /// Return true if preview is enabled in text (from LyXRC::preview)
44 static bool previewText();
45 /// Return true if preview is enabled in mathed (from LyXRC::preview)
46 static bool previewMath();
48 explicit RenderPreview(Inset const *);
49 RenderPreview(RenderPreview const &, Inset const *);
50 RenderBase * clone(Inset const *) const override;
52 /// Compute the size of the object, returned in dim
53 void metrics(MetricsInfo &, Dimension & dim) const override;
55 void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const override;
57 /** Find the PreviewLoader and add a LaTeX snippet to it.
58 * Do not start the loading process.
59 * \param ignore_lyxrc: generate the preview no matter what LyXRC says
61 void addPreview(docstring const & latex_snippet, Buffer const &,
62 bool ignore_lyxrc = false);
64 /** Add a LaTeX snippet to the PreviewLoader.
65 * Do not start the loading process.
66 * \param ignore_lyxrc: generate the preview no matter what LyXRC says
68 void addPreview(docstring const & latex_snippet,
69 graphics::PreviewLoader & ploader,
70 bool ignore_lyxrc = false);
72 /// Begin the loading process.
73 /// \param forexport : whether this is intended for export. if so,
74 /// then we ignore LyXRC and wait for the image to be generated.
75 void startLoading(Buffer const & buffer, bool forexport = false) const;
77 /** Remove a snippet from the cache of previews.
78 * Useful if previewing the contents of a file that has changed.
80 void removePreview(Buffer const &);
82 /** \returns a pointer to the PreviewImage associated with this snippet
85 graphics::PreviewImage const *
86 getPreviewImage(Buffer const & buffer) const;
88 /// equivalent to dynamic_cast
89 RenderPreview * asPreview() override { return this; }
93 RenderPreview & operator=(RenderPreview const &);
95 /// This method is connected to the PreviewLoader::imageReady signal.
96 void imageReady(graphics::PreviewImage const &);
98 /// The thing that we're trying to generate a preview of.
101 /** Store the connection to the preview loader so that we connect
104 scoped_connection ploader_connection_;
106 /// Inform the core that the inset has changed.
107 Inset const * parent_;
111 class RenderMonitoredPreview : public RenderPreview {
113 explicit RenderMonitoredPreview(Inset const *);
115 void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const override;
117 void setAbsFile(support::FileName const & file);
119 bool monitoring() const;
120 void startMonitoring() const;
121 void stopMonitoring() const;
123 /// Connect and you'll be informed when the file changes.
124 /// Do not forget to track objects used by the slot.
125 typedef signal<void()> sig;
126 typedef sig::slot_type slot;
127 connection connect(slot const & slot);
129 /// equivalent to dynamic_cast
130 RenderMonitoredPreview * asMonitoredPreview() override { return this; }
133 /// This signal is emitted if the file is modified
136 mutable support::ActiveFileMonitorPtr monitor_;
138 support::FileName filename_;
145 #endif // RENDERPREVIEW_H