]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsImage.h
d3ad5436ed3810aaae970988f4b8d5827ab7449e
[lyx.git] / src / graphics / GraphicsImage.h
1 // -*- C++ -*-
2 /**
3  *  \file GraphicsImage.h
4  *  Read the file COPYING
5  *
6  *  \author Baruch Even 
7  *  \author Angus Leeming 
8  *
9  * Full author contact details are available in file CREDITS
10  *
11  *  An abstract base class for the images themselves.
12  *  Allows the user to retrieve the pixmap, once loaded and to issue commands
13  *  to modify it.
14  *
15  *  The boost::functions newImage and loadableFormats are connected to the
16  *  appropriate derived classes elsewhere, allowing the graphics cache to
17  *  access them without knowing anything about their instantiation.
18  *
19  *  The loading process can be asynchronous, but cropping, rotating and
20  *  scaling block execution.
21  */
22
23 #ifndef GRAPHICSIMAGE_H
24 #define GRAPHICSIMAGE_H
25
26 #include "LString.h"
27
28 #include <boost/shared_ptr.hpp>
29 #include <boost/function/function0.hpp>
30 #include <boost/signals/signal1.hpp>
31
32 #include <vector>
33 #include <utility>
34
35 #ifdef __GNUG__
36 #pragma interface
37 #endif
38
39 namespace grfx {
40
41 class Params;
42
43 class Image {
44 public:
45         /** This is to be connected to a function that will return a new
46          *  instance of a viable derived class.
47          */
48         typedef boost::shared_ptr<Image> ImagePtr;
49         ///
50         static boost::function0<ImagePtr> newImage;
51
52         /// Return the list of loadable formats.
53         typedef std::vector<string> FormatList;
54         ///
55         static boost::function0<FormatList> loadableFormats;
56
57         /// Must define default c-tor explicitly as we define a copy c-tor.
58         Image() {}
59         /// Don't copy the signal finishedLoading
60         Image(Image const &) {}
61         ///
62         virtual ~Image() {}
63
64         /// Create a copy
65         virtual Image * clone() const = 0;
66
67         /// Get the image width
68         virtual unsigned int getWidth() const = 0;
69
70         /// Get the image height
71         virtual unsigned int getHeight() const = 0;
72
73         /// is the image drawable ?
74         virtual bool isDrawable() const = 0;
75
76         /** At the end of the loading process inform the outside world
77          *  by emitting a signal.
78          */
79         typedef boost::signal1<void, bool> SignalType;
80         ///
81         SignalType finishedLoading;
82
83         /** Start loading the image file.
84          *  The caller should expect this process to be asynchronous and
85          *  so should connect to the "finished" signal above.
86          */
87         virtual void load(string const & filename) = 0;
88
89         /** Generate the pixmap.
90          *  Uses the params to decide on color, grayscale etc.
91          *  Returns true if the pixmap is created.
92          */
93         virtual bool setPixmap(Params const & params) = 0;
94
95         /// Clip the image using params.
96         virtual void clip(Params const & params) = 0;
97
98         /// Rotate the image using params.
99         virtual void rotate(Params const & params) = 0;
100
101         /// Scale the image using params.
102         virtual void scale(Params const & params) = 0;
103
104 protected:
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())
108          */
109         std::pair<unsigned int, unsigned int>
110         getScaledDimensions(Params const & params) const;
111 };
112
113 } // namespace grfx
114
115 #endif // GRAPHICSIMAGE_H