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