]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsLoader.h
Purely mechanical: move fragile into LatexRunParams.
[lyx.git] / src / graphics / GraphicsLoader.h
1 // -*- C++ -*-
2 /**
3  *  \file GraphicsLoader.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  *  The public face of the graphics cache.
12  *
13  *  * The user supplies an image file and the display parameters.
14  *  * He can change the file or the display parameters through a reset() method.
15  *  * He must start the loading process explicitly with startLoading().
16  *  * If he is connected through the connect() method, then he'll be informed
17  *    when the loading status changes.
18  *  * When (status() == Ready), he can use image() to access the loaded image
19  *    and pass it to the Painter.
20  *
21  *  What could be simpler?
22  */
23
24 #ifndef GRAPHICSLOADER_H
25 #define GRAPHICSLOADER_H
26
27 #include "GraphicsTypes.h"
28 #include "LString.h"
29
30 #include <boost/signals/signal0.hpp>
31 #include <boost/scoped_ptr.hpp>
32
33 class Inset;
34 class BufferView;
35
36 namespace grfx {
37
38 class Image;
39 class Params;
40
41 class Loader {
42 public:
43         /// Must use the reset methods to make this instance usable.
44         Loader();
45         /// The image is not transformed, just displayed as-is.
46         Loader(string const & file_with_path, DisplayType = ColorDisplay);
47         /// The image is transformed before display.
48         Loader(string const & file_with_path, Params const &);
49
50         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
51         ~Loader();
52
53         /// The file can be changed, or the display params, or both.
54         void reset(string const & file_with_path,
55                    DisplayType = ColorDisplay) const;
56         ///
57         void reset(string const & file_with_path, Params const &) const;
58         ///
59         void reset(Params const &) const;
60
61         /// Returns the absolute path of the loaded (loading?) file.
62         string const & filename() const;
63         ///
64         bool empty() const { return filename().empty(); }
65
66         /** starting loading of the image is done by a urgency-based
67          *  decision. Here we only call LoaderQueue::touch to request it.
68          */
69         void startLoading() const;
70
71         /** Monitor any changes to the file.
72          *  There is no point monitoring the file before startLoading() is
73          *  invoked.
74          */
75         void startMonitoring() const;
76         ///
77         bool monitoring() const;
78         /** Returns the check sum of filename() so that, for example, you can
79          *  ascertain whether to output a new PostScript version of the file
80          *  for a LaTeX run.
81          */
82         unsigned long checksum() const;
83
84         /// How far have we got in loading the image?
85         ImageStatus status() const;
86
87         /** Connect and you'll be informed when the loading status of the image
88          *  changes.
89          */
90         typedef boost::signal0<void>::slot_type slot_type;
91         ///
92         boost::signals::connection connect(slot_type const &) const;
93
94         /** The loaded image with Pixmap set.
95          *  If the Pixmap is not yet set (see status() for why...), returns 0.
96          */
97         Image const * image() const;
98
99 private:
100         /// Use the Pimpl idiom to hide the internals.
101         class Impl;
102         /// The pointer never changes although *pimpl_'s contents may.
103         boost::scoped_ptr<Impl> const pimpl_;
104 };
105
106 } // namespace grfx
107
108 #endif // GRAPHICSLOADER_H