]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsLoader.h
Create a grfx::Loader class and so move large chunks of code out of
[lyx.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 view of the graphics cache.
10  *  * The user supplies an image file and the display parameters.
11  *  * He can change the file or the display parameters through a reset() method.
12  *  * He must start the loading process explicitly with startLoading().
13  *  * He receives a statusChanged signal when the loading status changes.
14  *  * When (status() == Ready), he uses image() to access the loaded image
15  *    and passes it to the Painter.
16  *
17  *  What could be simpler?
18  */
19
20 #ifndef GRAPHICSLOADER_H
21 #define GRAPHICSLOADER_H
22
23 #ifdef __GNUG__
24 #pragma interface
25 #endif
26
27 #include "GraphicsTypes.h"
28 #include "LString.h"
29
30 #include <boost/signals/signal0.hpp>
31 #include <memory>
32
33 namespace grfx {
34
35 class GParams;
36
37 /** One image, one instance of grfx::Loader, although the image can be
38  *  changed.
39  */
40 class Loader {
41 public:
42         /// Must use the reset methods to make this instance usable.
43         Loader();
44         /// The image is not transformed, just displayed as-is.
45         Loader(string const & file_with_path, DisplayType = ColorDisplay);
46         /// The image is transformed before display.
47         Loader(string const & file_with_path, GParams const &);
48
49         /// The file can be changed, or the display params, or both.
50         void reset(string const & file_with_path, DisplayType = ColorDisplay);
51         ///
52         void reset(string const & file_with_path, GParams const &);
53         ///
54         void reset(GParams const &);
55
56         /// Returns the absolute path of the loaded (loading?) file.
57         string const & filename() const;
58         ///
59         bool empty() const { return filename().empty(); }
60
61         /// We are explicit about when we begin the loading process.
62         void startLoading();
63
64         ///  How far have we got in loading the image?
65         ImageStatus status() const;
66
67         /// This signal is emitted when the image loading status changes.
68         boost::signal0<void> statusChanged;
69
70         /** The loaded image with Pixmap set.
71          *  If the Pixmap is not yet set (see status() for why...), returns 0.
72          */
73         GImage const * image() const;
74
75 private:
76         /// Use the Pimpl idiom to hide the internals.
77         class Impl;
78         /// The pointer never changes although *pimpl_'s contents may.
79         std::auto_ptr<Impl> const pimpl_;
80 };
81
82 } // namespace grfx
83
84 #endif // GRAPHICSLOADER_H