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