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