]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsImage.h
Enable compilation with lyxstring again.
[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 <a.leeming@ic.ac.uk>
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 #include "GraphicsTypes.h"
27
28 #include <boost/shared_ptr.hpp>
29
30 #include <sigc++/signal_system.h>
31
32 #include <X11/X.h>
33
34 #include <vector>
35 #include <utility>
36
37 #ifdef __GNUG__
38 #pragma interface
39 #endif
40
41 namespace grfx {
42
43 class GParams;
44
45 class GImage
46 {
47 public:
48         /// A list of supported formats.
49         typedef std::vector<string> FormatList;
50         /** This will be connected to a function that will return whichever
51          *  derived class we desire.
52          */
53         static SigC::Signal0<ImagePtr> newImage;
54
55         /// Return the list of loadable formats.
56         static SigC::Signal0<FormatList> loadableFormats;
57
58         ///
59         virtual ~GImage() {}
60
61         /// Create a copy
62         virtual GImage * clone() const = 0;
63
64         ///
65         virtual Pixmap getPixmap() 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         /** At the end of the loading or modification process, return the new
74          *  image by emitting this signal */
75         typedef SigC::Signal1<void, bool> SignalType;
76         ///
77         typedef boost::shared_ptr<SignalType> SignalTypePtr;
78
79         /// Start loading the image file.
80         virtual void load(string const & filename, SignalTypePtr) = 0;
81
82         /** Generate the pixmap.
83          *  Uses the params to decide on color, grayscale etc.
84          *  Returns true if the pixmap is created.
85          */
86         virtual bool setPixmap(GParams const & params) = 0;
87
88         /// Clip the image using params.
89         virtual void clip(GParams const & params) = 0;
90
91         /// Rotate the image using params.
92         virtual void rotate(GParams const & params) = 0;
93
94         /// Scale the image using params.
95         virtual void scale(GParams const & params) = 0;
96
97 protected:
98         /** Uses the params to ascertain the dimensions of the scaled image.
99          *  Returned as make_pair(width, height).
100          *  If something geso wrong, returns make_pair(getWidth(), getHeight())
101          */
102         std::pair<unsigned int, unsigned int>
103         getScaledDimensions(GParams const & params) const;
104 };
105
106 } // namespace grfx
107
108 #endif // GRAPHICSIMAGE_H