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