]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsImage.h
remove one <boost/shared_ptr.hpp>
[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 <boost/function.hpp>
28 #include <boost/signal.hpp>
29
30 #include <vector>
31 #include <utility>
32
33 namespace lyx {
34
35 namespace support { class FileName; }
36
37 namespace graphics {
38
39 class Params;
40
41 class Image {
42 public:
43         /** This is to be connected to a function that will return a new
44          *  instance of a viable derived class.
45          */
46         static boost::function<Image *()> newImage;
47
48         ///
49         typedef std::vector<std::string> FormatList;
50         /// Return the list of loadable formats.
51         static boost::function<FormatList()> loadableFormats;
52
53         ///
54         virtual ~Image() {}
55
56         /// Create a copy
57         virtual Image * clone() const = 0;
58
59         /// Get the image width
60         virtual unsigned int getWidth() const = 0;
61
62         /// Get the image height
63         virtual unsigned int getHeight() const = 0;
64
65         /// Is the image drawable ?
66         virtual bool isDrawable() const = 0;
67
68         /** At the end of the loading process inform the outside world
69          *  by emitting a signal
70          */
71         typedef boost::signal<void(bool)> SignalType;
72         ///
73         SignalType finishedLoading;
74
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.
78          */
79         virtual void load(support::FileName const & filename) = 0;
80
81         /** Generate the pixmap.
82          *  Uses the params to decide on color, grayscale etc.
83          *  Returns true if the pixmap is created.
84          */
85         virtual bool setPixmap(Params const & params) = 0;
86
87         /// Clip the image using params.
88         virtual void clip(Params const & params) = 0;
89
90         /// Rotate the image using params.
91         virtual void rotate(Params const & params) = 0;
92
93         /// Scale the image using params.
94         virtual void scale(Params const & params) = 0;
95
96 protected:
97         /// Must define default c-tor explicitly as we define a copy c-tor.
98         Image() {}
99         /// Don't copy the signal finishedLoading
100         Image(Image const &) {}
101
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())
105          */
106         std::pair<unsigned int, unsigned int>
107         getScaledDimensions(Params const & params) const;
108 };
109
110
111 } // namespace graphics
112 } // namespace lyx
113
114 #endif // GRAPHICSIMAGE_H