]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewLoader.h
Merge branch 'master' of git.lyx.org:lyx
[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 "ColorCode.h"
22 #include "support/signals.h"
23
24 #include <QObject>
25
26 #include <memory>
27
28 namespace lyx {
29
30 class Buffer;
31
32 namespace graphics {
33
34 class PreviewImage;
35
36 class PreviewLoader : public QObject {
37         Q_OBJECT
38 public:
39         /** We need buffer because we require the preamble to the
40          *  LaTeX file.
41          */
42         PreviewLoader(Buffer const & buffer);
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(std::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(std::string const & latex_snippet) const;
63
64         /// Add a snippet of LaTeX to the queue for processing.
65         void add(std::string const & latex_snippet) const;
66
67         /// Remove this snippet of LaTeX from the PreviewLoader.
68         void remove(std::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(bool wait = false) 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          *  lyx::graphics::PreviewImage::image().
78          */
79         typedef signal<void(PreviewImage const &)> sig;
80         typedef sig::slot_type slot;
81         ///
82         connection connect(slot const &) const;
83
84         /** When PreviewImage has finished loading the image file into memory,
85          *  it tells the PreviewLoader to tell the outside world
86          */
87         void emitSignal(PreviewImage const &) const;
88
89         /// Which buffer owns this loader.
90         Buffer const & buffer() const;
91         /// The background color used
92         static ColorCode backgroundColor() { return Color_background; }
93         /// The foreground color used
94         static ColorCode foregroundColor() { return Color_preview; }
95
96         double displayPixelRatio() const ;
97
98 public Q_SLOTS:
99         ///
100         void refreshPreviews();
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         std::shared_ptr<Impl> const pimpl_;
111 };
112
113 } // namespace graphics
114 } // namespace lyx
115
116 #endif // PREVIEWLOADER_H