3 * \file GraphicsImage.h
4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author Baruch Even <baruch.even@writeme.com>
8 * \author Angus Leeming <leeming@lyx.org>
10 * An abstract base class for the images themselves.
11 * Allows the user to retrieve the pixmap, once loaded and to issue commands
14 * The signals newImage and loadableFormats are connected to the approriate
15 * derived classes elsewhere, allowing the graphics cache to access them
16 * without knowing anything about their instantiation.
18 * The loading process can be asynchronous, but cropping, rotating and
19 * scaling block execution.
22 #ifndef GRAPHICSIMAGE_H
23 #define GRAPHICSIMAGE_H
27 #include <boost/shared_ptr.hpp>
28 #include <boost/function/function0.hpp>
29 #include <boost/signals/signal1.hpp>
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;
49 static boost::function0<ImagePtr> newImage;
51 /// Return the list of loadable formats.
52 typedef std::vector<string> FormatList;
54 static boost::function0<FormatList> loadableFormats;
56 /// Must define default c-tor explicitly as we define a copy c-tor.
58 /// Don't copy the signal finishedLoading
59 Image(Image const &) {}
64 virtual Image * clone() const = 0;
66 /// Get the image width
67 virtual unsigned int getWidth() const = 0;
69 /// Get the image height
70 virtual unsigned int getHeight() const = 0;
72 /// is the image drawable ?
73 virtual bool isDrawable() const = 0;
75 /** At the end of the loading process inform the outside world
76 * by emitting a signal.
78 typedef boost::signal1<void, bool> SignalType;
80 SignalType finishedLoading;
82 /** Start loading the image file.
83 * The caller should expect this process to be asynchronous and
84 * so should connect to the "finished" signal above.
86 virtual void load(string const & filename) = 0;
88 /** Generate the pixmap.
89 * Uses the params to decide on color, grayscale etc.
90 * Returns true if the pixmap is created.
92 virtual bool setPixmap(Params const & params) = 0;
94 /// Clip the image using params.
95 virtual void clip(Params const & params) = 0;
97 /// Rotate the image using params.
98 virtual void rotate(Params const & params) = 0;
100 /// Scale the image using params.
101 virtual void scale(Params const & params) = 0;
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;
114 #endif // GRAPHICSIMAGE_H