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