]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsLoader.h
ab3d686c24c44e689de21ead5bfd8bda7ef4ccff
[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
29 #include <boost/scoped_ptr.hpp>
30 #include <boost/signal.hpp>
31
32 namespace lyx {
33 namespace graphics {
34
35 class Image;
36 class Params;
37
38 class Loader {
39 public:
40         /// Must use the reset methods to make this instance usable.
41         Loader();
42         /// The image is not transformed, just displayed as-is.
43         Loader(std::string const & file_with_path, DisplayType = ColorDisplay);
44         /// The image is transformed before display.
45         Loader(std::string const & file_with_path, Params const &);
46         ///
47         Loader(Loader const &);
48
49         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
50         ~Loader();
51
52         Loader & operator=(Loader const &);
53
54         /// The file can be changed, or the display params, or both.
55         void reset(std::string const & file_with_path,
56                    DisplayType = ColorDisplay) const;
57         ///
58         void reset(std::string const & file_with_path, Params const &) const;
59         ///
60         void reset(Params const &) const;
61
62         /// Returns the absolute path of the loaded (loading?) file.
63         std::string const & filename() const;
64         ///
65         bool empty() const { return filename().empty(); }
66
67         /** starting loading of the image is done by a urgency-based
68          *  decision. Here we only call LoaderQueue::touch to request it.
69          */
70         void startLoading() const;
71
72         /** Monitor any changes to the file.
73          *  There is no point monitoring the file before startLoading() is
74          *  invoked.
75          */
76         void startMonitoring() const;
77         ///
78         bool monitoring() const;
79         /** Returns the check sum of filename() so that, for example, you can
80          *  ascertain whether to output a new PostScript version of the file
81          *  for a LaTeX run.
82          */
83         unsigned long checksum() const;
84
85         /// How far have we got in loading the image?
86         ImageStatus status() const;
87
88         /** Connect and you'll be informed when the loading status of the image
89          *  changes.
90          */
91         typedef boost::signal<void()> sig_type;
92         typedef sig_type::slot_type slot_type;
93         ///
94         boost::signals::connection connect(slot_type const &) const;
95
96         /** The loaded image with Pixmap set.
97          *  If the Pixmap is not yet set (see status() for why...), returns 0.
98          */
99         Image const * image() const;
100
101 private:
102         /// Use the Pimpl idiom to hide the internals.
103         class Impl;
104         /// The pointer never changes although *pimpl_'s contents may.
105         boost::scoped_ptr<Impl> const pimpl_;
106 };
107
108 } // namespace graphics
109 } // namespace lyx
110
111 #endif // GRAPHICSLOADER_H