]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewLoader.h
PDF-form.lyx: add a note
[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  * 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/signal.hpp>
22 #include "support/docstring.h"
23
24 #include "ColorCode.h"
25
26 namespace lyx {
27
28 class Buffer;
29
30 namespace graphics {
31
32 class PreviewImage;
33
34 class PreviewLoader {
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(std::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(std::string const & latex_snippet) const;
62
63         /// Add a snippet of LaTeX to the queue for processing.
64         void add(std::string const & latex_snippet) const;
65
66         /// Remove this snippet of LaTeX from the PreviewLoader.
67         void remove(std::string const & latex_snippet) const;
68
69         /// Record math macro definitions added to the loader
70         void addMacroDef(docstring const & latex_snippet) const;
71         /// Has a math macro definition already been added to the loader?
72         bool hasMacroDef(docstring const & latex_snippet) const;
73
74         /** We have accumulated several latex snippets with status "InQueue".
75          *  Initiate their transformation into bitmap images.
76          */
77         void startLoading(bool wait = false) const;
78
79         /** Connect and you'll be informed when the bitmap image file
80          *  has been created and is ready for loading through
81          *  lyx::graphics::PreviewImage::image().
82          */
83         typedef boost::signal<void(PreviewImage const &)> sig_type;
84         typedef sig_type::slot_type slot_type;
85         ///
86         boost::signals::connection connect(slot_type const &) const;
87
88         /** When PreviewImage has finished loading the image file into memory,
89          *  it tells the PreviewLoader to tell the outside world
90          */
91         void emitSignal(PreviewImage const &) const;
92
93         /// Which buffer owns this loader.
94         Buffer const & buffer() const;
95         /// The background color used
96         static ColorCode backgroundColor() { return Color_background; }
97         /// The foreground color used
98         static ColorCode foregroundColor() { return Color_preview; }
99
100         double displayPixelRatio() const ;
101
102 private:
103         /// noncopyable
104         PreviewLoader(PreviewLoader const &);
105         void operator=(PreviewLoader const &);
106
107         /// Use the Pimpl idiom to hide the internals.
108         class Impl;
109         /// The pointer never changes although *pimpl_'s contents may.
110         Impl * const pimpl_;
111 };
112
113 } // namespace graphics
114 } // namespace lyx
115
116 #endif // PREVIEWLOADER_H