]> git.lyx.org Git - features.git/blob - src/graphics/GraphicsLoader.h
Smart loading of image files for previews and for the graphics inset.
[features.git] / src / graphics / GraphicsLoader.h
1 // -*- C++ -*-
2 /**
3  *  \file GraphicsLoader.h
4  *  Copyright 2002 the LyX Team
5  *  Read the file COPYING
6  *
7  *  \author Angus Leeming <leeming@lyx.org>
8  *
9  *  The public face of the graphics cache.
10  *
11  *  * The user supplies an image file and the display parameters.
12  *  * He can change the file or the display parameters through a reset() method.
13  *  * He must start the loading process explicitly with startLoading().
14  *  * He receives a statusChanged signal when the loading status changes.
15  *  * When (status() == Ready), he uses image() to access the loaded image
16  *    and passes it to the Painter.
17  *
18  *  What could be simpler?
19  */
20
21 #ifndef GRAPHICSLOADER_H
22 #define GRAPHICSLOADER_H
23
24 #ifdef __GNUG__
25 #pragma interface
26 #endif
27
28 #include "GraphicsTypes.h"
29 #include "LString.h"
30
31 #include <boost/signals/signal0.hpp>
32 #include <boost/scoped_ptr.hpp>
33
34 class Inset;
35 class BufferView;
36
37 namespace grfx {
38
39 class Image;
40 class Params;
41
42 class Loader {
43 public:
44         /// Must use the reset methods to make this instance usable.
45         Loader();
46         /// The image is not transformed, just displayed as-is.
47         Loader(string const & file_with_path, DisplayType = ColorDisplay);
48         /// The image is transformed before display.
49         Loader(string const & file_with_path, Params const &);
50
51         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
52         ~Loader();
53
54         /// The file can be changed, or the display params, or both.
55         void reset(string const & file_with_path, DisplayType = ColorDisplay);
56         ///
57         void reset(string const & file_with_path, Params const &);
58         ///
59         void reset(Params 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         /// We are explicit about when we begin the loading process.
67         void startLoading();
68
69         /** starting loading of the image is conditional upon the
70          *  inset being visible or not.
71          */
72         void startLoading(Inset const &, BufferView const &);
73
74         /// How far have we got in loading the image?
75         ImageStatus status() const;
76
77         /// This signal is emitted when the image loading status changes.
78         boost::signal0<void> statusChanged;
79
80         /** The loaded image with Pixmap set.
81          *  If the Pixmap is not yet set (see status() for why...), returns 0.
82          */
83         Image const * image() const;
84
85 private:
86         /// Use the Pimpl idiom to hide the internals.
87         class Impl;
88         /// The pointer never changes although *pimpl_'s contents may.
89         boost::scoped_ptr<Impl> const pimpl_;
90 };
91
92 } // namespace grfx
93
94 #endif // GRAPHICSLOADER_H