scramble email addresses
[lyx.git] / src / graphics / GraphicsImage.h
blobdae4ecea64fd6e78ad8ce9004968d97d0ffef675
1 // -*- C++ -*-
2 /**
3 * \file GraphicsImage.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Baruch Even
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
12 * An abstract base class for the images themselves.
13 * Allows the user to retrieve the pixmap, once loaded and to issue commands
14 * to modify it.
16 * The boost::functions newImage and loadableFormats are connected to the
17 * appropriate derived classes elsewhere, allowing the graphics cache to
18 * access them without knowing anything about their instantiation.
20 * The loading process can be asynchronous, but cropping, rotating and
21 * scaling block execution.
24 #ifndef GRAPHICSIMAGE_H
25 #define GRAPHICSIMAGE_H
27 #include <boost/function.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/signal.hpp>
31 #include <vector>
32 #include <utility>
34 namespace lyx {
36 namespace support { class FileName; }
38 namespace graphics {
40 class Params;
42 class Image {
43 public:
44 /** This is to be connected to a function that will return a new
45 * instance of a viable derived class.
47 typedef boost::shared_ptr<Image> ImagePtr;
48 ///
49 static boost::function<ImagePtr()> newImage;
51 ///
52 typedef std::vector<std::string> FormatList;
53 /// Return the list of loadable formats.
54 static boost::function<FormatList()> loadableFormats;
56 ///
57 virtual ~Image() {}
59 /// Create a copy
60 Image * clone() const;
62 /// Get the image width
63 unsigned int getWidth() const;
65 /// Get the image height
66 unsigned int getHeight() const;
68 /// Is the image drawable ?
69 bool isDrawable() const;
71 /** At the end of the loading process inform the outside world
72 * by emitting a signal
74 typedef boost::signal<void(bool)> SignalType;
75 ///
76 SignalType finishedLoading;
78 /** Start loading the image file.
79 * The caller should expect this process to be asynchronous and
80 * so should connect to the "finished" signal above.
82 void load(support::FileName const & filename);
84 /** Generate the pixmap.
85 * Uses the params to decide on color, grayscale etc.
86 * Returns true if the pixmap is created.
88 bool setPixmap(Params const & params);
90 /// Clip the image using params.
91 void clip(Params const & params);
93 /// Rotate the image using params.
94 void rotate(Params const & params);
96 /// Scale the image using params.
97 void scale(Params const & params);
99 protected:
100 /// Must define default c-tor explicitly as we define a copy c-tor.
101 Image() {}
102 /// Don't copy the signal finishedLoading
103 Image(Image const &) {}
105 /** Uses the params to ascertain the dimensions of the scaled image.
106 * Returned as make_pair(width, height).
107 * If something goes wrong, returns make_pair(getWidth(), getHeight())
109 std::pair<unsigned int, unsigned int>
110 getScaledDimensions(Params const & params) const;
112 private:
113 /// Create a copy
114 virtual Image * clone_impl() const = 0;
115 /// Get the image width
116 virtual unsigned int getWidth_impl() const = 0;
118 /// Get the image height
119 virtual unsigned int getHeight_impl() const = 0;
121 /// is the image drawable ?
122 virtual bool isDrawable_impl() const = 0;
124 /** Start loading the image file.
125 * The caller should expect this process to be asynchronous and
126 * so should connect to the "finished" signal above.
128 virtual void load_impl(support::FileName const & filename) = 0;
130 /** Generate the pixmap.
131 * Uses the params to decide on color, grayscale etc.
132 * Returns true if the pixmap is created.
134 virtual bool setPixmap_impl(Params const & params) = 0;
136 /// Clip the image using params.
137 virtual void clip_impl(Params const & params) = 0;
139 /// Rotate the image using params.
140 virtual void rotate_impl(Params const & params) = 0;
142 /// Scale the image using params.
143 virtual void scale_impl(Params const & params) = 0;
147 inline
148 Image * Image::clone() const
150 return clone_impl();
154 inline
155 unsigned int Image::getWidth() const
157 return getWidth_impl();
161 inline
162 unsigned int Image::getHeight() const
164 return getHeight_impl();
168 inline
169 bool Image::isDrawable() const
171 return isDrawable_impl();
175 inline
176 void Image::load(support::FileName const & filename)
178 return load_impl(filename);
182 inline
183 bool Image::setPixmap(Params const & params)
185 return setPixmap_impl(params);
189 inline
190 void Image::clip(Params const & params)
192 return clip_impl(params);
196 inline
197 void Image::rotate(Params const & params)
199 return rotate_impl(params);
203 inline
204 void Image::scale(Params const & params)
206 return scale_impl(params);
209 } // namespace graphics
210 } // namespace lyx
212 #endif // GRAPHICSIMAGE_H