]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewLoader.h
Preview code
[lyx.git] / src / graphics / PreviewLoader.h
1 // -*- C++ -*-
2 /**
3  *  \file PreviewLoader.h
4  *  Copyright 2002 the LyX Team
5  *  Read the file COPYING
6  *
7  * \author Angus Leeming <a.leeming@ic.ac.uk>
8  *
9  *  grfx::PreviewLoader collects latex snippets together. Then, on a
10  *  startLoading() call, these are dumped to file and processed, converting
11  *  each snippet to a separate bitmap image file. Once a bitmap file is ready
12  *  to be loaded back into LyX, the PreviewLoader emits a readyToDisplay signal
13  *  to inform the initiating process.
14  */
15
16 #ifndef PREVIEWLOADER_H
17 #define PREVIEWLOADER_H
18
19 #ifdef __GNUG__
20 #pragma interface
21 #endif
22
23 #include "LString.h"
24 #include <boost/utility.hpp>
25 #include <boost/scoped_ptr.hpp>
26 #include <boost/signals/signal1.hpp>
27
28 class Buffer;
29
30 namespace grfx {
31
32 class PreviewImage;
33
34 class PreviewLoader : boost::noncopyable {
35 public:
36         /** We need buffer because we require the preamble to the
37          *  LaTeX file.
38          */
39         PreviewLoader(Buffer const & buffer);
40         ///
41         ~PreviewLoader();
42
43         /** Is there an image already associated with this snippet of LaTeX?
44          *  If so, returns a pointer to it, else returns 0.
45          */
46         PreviewImage const * preview(string const & latex_snippet) const;
47
48         ///
49         enum Status {
50                 ///
51                 NotFound,
52                 ///
53                 InQueue,
54                 ///
55                 Processing,
56                 ///
57                 Ready
58         };
59
60         /// How far have we got in loading the image?
61         Status status(string const & latex_snippet) const;
62         
63         /// Add a snippet of LaTeX to the queue for processing.
64         void add(string const & latex_snippet);
65
66         /// Remove this snippet of LaTeX from the PreviewLoader.
67         void remove(string const & latex_snippet);
68         
69         /** We have accumulated several latex snippets with status "InQueue".
70          *  Initiate their transformation into bitmap images.
71          */
72         void startLoading();
73
74         /// Emit this signal when an image is ready for display.
75         boost::signal1<void, PreviewImage const &> imageReady;
76
77 private:
78         /// Use the Pimpl idiom to hide the internals.
79         class Impl;
80         /// The pointer never changes although *pimpl_'s contents may.
81         boost::scoped_ptr<Impl> const pimpl_;
82 };
83
84 } // namespace grfx
85
86 #endif // PREVIEWLOADER_H