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