3 * \file GraphicsImage.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
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
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 "support/std_string.h"
29 #include <boost/shared_ptr.hpp>
30 #include <boost/function/function0.hpp>
31 #include <boost/signals/signal1.hpp>
43 /** This is to be connected to a function that will return a new
44 * instance of a viable derived class.
46 typedef boost::shared_ptr<Image> ImagePtr;
48 static boost::function0<ImagePtr> newImage;
50 /// Return the list of loadable formats.
51 typedef std::vector<string> FormatList;
53 static boost::function0<FormatList> loadableFormats;
59 Image * clone() const;
61 /// Get the image width
62 unsigned int getWidth() const;
64 /// Get the image height
65 unsigned int getHeight() const;
67 /// Is the image drawable ?
68 bool isDrawable() const;
70 /** At the end of the loading process inform the outside world
71 * by emitting a signal.
73 typedef boost::signal1<void, bool> SignalType;
75 SignalType finishedLoading;
77 /** Start loading the image file.
78 * The caller should expect this process to be asynchronous and
79 * so should connect to the "finished" signal above.
81 void load(string const & filename);
83 /** Generate the pixmap.
84 * Uses the params to decide on color, grayscale etc.
85 * Returns true if the pixmap is created.
87 bool setPixmap(Params const & params);
89 /// Clip the image using params.
90 void clip(Params const & params);
92 /// Rotate the image using params.
93 void rotate(Params const & params);
95 /// Scale the image using params.
96 void scale(Params const & params);
99 /// Must define default c-tor explicitly as we define a copy c-tor.
101 /// Don't copy the signal finishedLoading
102 Image(Image const &) {}
104 /** Uses the params to ascertain the dimensions of the scaled image.
105 * Returned as make_pair(width, height).
106 * If something goes wrong, returns make_pair(getWidth(), getHeight())
108 std::pair<unsigned int, unsigned int>
109 getScaledDimensions(Params const & params) const;
113 virtual Image * clone_impl() const = 0;
114 /// Get the image width
115 virtual unsigned int getWidth_impl() const = 0;
117 /// Get the image height
118 virtual unsigned int getHeight_impl() const = 0;
120 /// is the image drawable ?
121 virtual bool isDrawable_impl() const = 0;
123 /** Start loading the image file.
124 * The caller should expect this process to be asynchronous and
125 * so should connect to the "finished" signal above.
127 virtual void load_impl(string const & filename) = 0;
129 /** Generate the pixmap.
130 * Uses the params to decide on color, grayscale etc.
131 * Returns true if the pixmap is created.
133 virtual bool setPixmap_impl(Params const & params) = 0;
135 /// Clip the image using params.
136 virtual void clip_impl(Params const & params) = 0;
138 /// Rotate the image using params.
139 virtual void rotate_impl(Params const & params) = 0;
141 /// Scale the image using params.
142 virtual void scale_impl(Params const & params) = 0;
147 Image * Image::clone() const
154 unsigned int Image::getWidth() const
156 return getWidth_impl();
161 unsigned int Image::getHeight() const
163 return getHeight_impl();
168 bool Image::isDrawable() const
170 return isDrawable_impl();
175 void Image::load(string const & filename)
177 return load_impl(filename);
182 bool Image::setPixmap(Params const & params)
184 return setPixmap_impl(params);
189 void Image::clip(Params const & params)
191 return clip_impl(params);
196 void Image::rotate(Params const & params)
198 return rotate_impl(params);
203 void Image::scale(Params const & params)
205 return scale_impl(params);
208 } // namespace graphics
211 #endif // GRAPHICSIMAGE_H