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 <boost/function.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/signal.hpp>
41 /** This is to be connected to a function that will return a new
42 * instance of a viable derived class.
44 typedef boost::shared_ptr<Image> ImagePtr;
46 static boost::function<ImagePtr()> newImage;
48 /// Return the list of loadable formats.
49 typedef std::vector<std::string> FormatList;
51 static boost::function<FormatList()> loadableFormats;
57 Image * clone() const;
59 /// Get the image width
60 unsigned int getWidth() const;
62 /// Get the image height
63 unsigned int getHeight() const;
65 /// Is the image drawable ?
66 bool isDrawable() const;
68 /** At the end of the loading process inform the outside world
69 * by emitting a signal
71 typedef boost::signal<void(bool)> SignalType;
73 SignalType finishedLoading;
75 /** Start loading the image file.
76 * The caller should expect this process to be asynchronous and
77 * so should connect to the "finished" signal above.
79 void load(std::string const & filename);
81 /** Generate the pixmap.
82 * Uses the params to decide on color, grayscale etc.
83 * Returns true if the pixmap is created.
85 bool setPixmap(Params const & params);
87 /// Clip the image using params.
88 void clip(Params const & params);
90 /// Rotate the image using params.
91 void rotate(Params const & params);
93 /// Scale the image using params.
94 void scale(Params const & params);
97 /// Must define default c-tor explicitly as we define a copy c-tor.
99 /// Don't copy the signal finishedLoading
100 Image(Image const &) {}
102 /** Uses the params to ascertain the dimensions of the scaled image.
103 * Returned as make_pair(width, height).
104 * If something goes wrong, returns make_pair(getWidth(), getHeight())
106 std::pair<unsigned int, unsigned int>
107 getScaledDimensions(Params const & params) const;
111 virtual Image * clone_impl() const = 0;
112 /// Get the image width
113 virtual unsigned int getWidth_impl() const = 0;
115 /// Get the image height
116 virtual unsigned int getHeight_impl() const = 0;
118 /// is the image drawable ?
119 virtual bool isDrawable_impl() const = 0;
121 /** Start loading the image file.
122 * The caller should expect this process to be asynchronous and
123 * so should connect to the "finished" signal above.
125 virtual void load_impl(std::string const & filename) = 0;
127 /** Generate the pixmap.
128 * Uses the params to decide on color, grayscale etc.
129 * Returns true if the pixmap is created.
131 virtual bool setPixmap_impl(Params const & params) = 0;
133 /// Clip the image using params.
134 virtual void clip_impl(Params const & params) = 0;
136 /// Rotate the image using params.
137 virtual void rotate_impl(Params const & params) = 0;
139 /// Scale the image using params.
140 virtual void scale_impl(Params const & params) = 0;
145 Image * Image::clone() const
152 unsigned int Image::getWidth() const
154 return getWidth_impl();
159 unsigned int Image::getHeight() const
161 return getHeight_impl();
166 bool Image::isDrawable() const
168 return isDrawable_impl();
173 void Image::load(std::string const & filename)
175 return load_impl(filename);
180 bool Image::setPixmap(Params const & params)
182 return setPixmap_impl(params);
187 void Image::clip(Params const & params)
189 return clip_impl(params);
194 void Image::rotate(Params const & params)
196 return rotate_impl(params);
201 void Image::scale(Params const & params)
203 return scale_impl(params);
206 } // namespace graphics
209 #endif // GRAPHICSIMAGE_H