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