]> git.lyx.org Git - lyx.git/blob - src/insets/RenderPreview.h
Merge branch 'master' into biblatex2
[lyx.git] / src / insets / RenderPreview.h
1 // -*- C++ -*-
2 /**
3  * \file RenderPreview.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
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.
14  */
15
16 #ifndef RENDERPREVIEW_H
17 #define RENDERPREVIEW_H
18
19 #include "RenderBase.h"
20
21 #include "support/docstring.h"
22 #include "support/FileMonitor.h"
23
24 #include <boost/signals2.hpp>
25 #include <boost/signals2/trackable.hpp>
26 #include <boost/signals2/connection.hpp>
27
28 namespace lyx {
29
30 class Buffer;
31 class MetricsInfo;
32 class PainterInfo;
33
34 namespace support { class FileName; }
35
36 namespace graphics {
37
38 class PreviewImage;
39 class PreviewLoader;
40
41 } // namespace graphics
42
43
44 class RenderPreview : public RenderBase, public boost::signals2::trackable {
45 public:
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();
50
51         RenderPreview(Inset const *);
52         RenderPreview(RenderPreview const &, Inset const *);
53         ~RenderPreview();
54         RenderBase * clone(Inset const *) const;
55
56         /// Compute the size of the object, returned in dim
57         void metrics(MetricsInfo &, Dimension & dim) const;
58         ///
59         void draw(PainterInfo & pi, int x, int y) const;
60
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
64          */
65         void addPreview(docstring const & latex_snippet, Buffer const &,
66                         bool ignore_lyxrc = false);
67
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
71          */
72         void addPreview(docstring const & latex_snippet,
73                         graphics::PreviewLoader & ploader,
74                         bool ignore_lyxrc = false);
75
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;
80
81         /** Remove a snippet from the cache of previews.
82          *  Useful if previewing the contents of a file that has changed.
83          */
84         void removePreview(Buffer const &);
85
86         /** \returns a pointer to the PreviewImage associated with this snippet
87          *  of latex.
88          */
89         graphics::PreviewImage const *
90         getPreviewImage(Buffer const & buffer) const;
91
92         /// equivalent to dynamic_cast
93         virtual RenderPreview * asPreview() { return this; }
94
95 private:
96         /// Not implemented.
97         RenderPreview & operator=(RenderPreview const &);
98
99         /// This method is connected to the PreviewLoader::imageReady signal.
100         void imageReady(graphics::PreviewImage const &);
101
102         /// The thing that we're trying to generate a preview of.
103         std::string snippet_;
104
105         /** Store the connection to the preview loader so that we connect
106          *  only once.
107          */
108         boost::signals2::connection ploader_connection_;
109
110         /// Inform the core that the inset has changed.
111         Inset const * parent_;
112 };
113
114
115 class RenderMonitoredPreview : public RenderPreview {
116 public:
117         RenderMonitoredPreview(Inset const *);
118         ///
119         void draw(PainterInfo & pi, int x, int y) const;
120         ///
121         void setAbsFile(support::FileName const & file);
122         ///
123         bool monitoring() const { return monitor_.monitoring(); }
124         void startMonitoring() const { monitor_.start(); }
125         void stopMonitoring() const { monitor_.stop(); }
126
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 &);
130
131         /// equivalent to dynamic_cast
132         virtual RenderMonitoredPreview * asMonitoredPreview() { return this; }
133
134 private:
135         ///
136         mutable support::FileMonitor monitor_;
137 };
138
139 } // namespace lyx
140
141 #endif // RENDERPREVIEW_H