]> git.lyx.org Git - lyx.git/blob - src/insets/RenderPreview.h
Update my email and status.
[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/signal.hpp>
25 #include <boost/signals/trackable.hpp>
26 #include <boost/signals/connection.hpp>
27
28 namespace lyx {
29
30 class Buffer;
31 class LyXRC_PreviewStatus;
32 class MetricsInfo;
33 class PainterInfo;
34
35 namespace support { class FileName; }
36
37 namespace graphics {
38
39 class PreviewImage;
40 class PreviewLoader;
41
42 } // namespace graphics
43
44
45 class RenderPreview : public RenderBase, public boost::signals::trackable {
46 public:
47         /// a wrapper for lyxrc.preview
48         static LyXRC_PreviewStatus status();
49
50         RenderPreview(Inset const *);
51         RenderPreview(RenderPreview const &, Inset const *);
52         ~RenderPreview();
53         RenderBase * clone(Inset const *) const;
54
55         /// Compute the size of the object, returned in dim
56         void metrics(MetricsInfo &, Dimension & dim) const;
57         ///
58         void draw(PainterInfo & pi, int x, int y) const;
59
60         /** Find the PreviewLoader and add a LaTeX snippet to it.
61          *  Do not start the loading process.
62          *  \param ignore_lyxrc: generate the preview no matter what LyXRC says
63          */
64         void addPreview(docstring const & latex_snippet, Buffer const &,
65                         bool ignore_lyxrc = false);
66
67         /** Add a LaTeX snippet to the PreviewLoader.
68          *  Do not start the loading process.
69          *  \param ignore_lyxrc: generate the preview no matter what LyXRC says
70          */
71         void addPreview(docstring const & latex_snippet,
72                         graphics::PreviewLoader & ploader,
73                         bool ignore_lyxrc = false);
74
75         /// Begin the loading process.
76         /// \param forexport : whether this is intended for export. if so,
77         /// then we ignore LyXRC and wait for the image to be generated.
78         void startLoading(Buffer const & buffer, bool forexport = false) const;
79
80         /** Remove a snippet from the cache of previews.
81          *  Useful if previewing the contents of a file that has changed.
82          */
83         void removePreview(Buffer const &);
84
85         /** \returns a pointer to the PreviewImage associated with this snippet
86          *  of latex.
87          */
88         graphics::PreviewImage const *
89         getPreviewImage(Buffer const & buffer) const;
90
91         /// equivalent to dynamic_cast
92         virtual RenderPreview * asPreview() { return this; }
93
94 private:
95         /// Not implemented.
96         RenderPreview & operator=(RenderPreview const &);
97
98         /// This method is connected to the PreviewLoader::imageReady signal.
99         void imageReady(graphics::PreviewImage const &);
100
101         /// The thing that we're trying to generate a preview of.
102         std::string snippet_;
103
104         /** Store the connection to the preview loader so that we connect
105          *  only once.
106          */
107         boost::signals::connection ploader_connection_;
108
109         /// Inform the core that the inset has changed.
110         Inset const * parent_;
111 };
112
113
114 class RenderMonitoredPreview : public RenderPreview {
115 public:
116         RenderMonitoredPreview(Inset const *);
117         ///
118         void draw(PainterInfo & pi, int x, int y) const;
119         ///
120         void setAbsFile(support::FileName const & file);
121         ///
122         bool monitoring() const { return monitor_.monitoring(); }
123         void startMonitoring() const { monitor_.start(); }
124         void stopMonitoring() const { monitor_.stop(); }
125
126         /// Connect and you'll be informed when the file changes.
127         typedef support::FileMonitor::slot_type slot_type;
128         boost::signals::connection fileChanged(slot_type const &);
129
130         /// equivalent to dynamic_cast
131         virtual RenderMonitoredPreview * asMonitoredPreview() { return this; }
132
133 private:
134         ///
135         mutable support::FileMonitor monitor_;
136 };
137
138 } // namespace lyx
139
140 #endif // RENDERPREVIEW_H