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