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