]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCacheItem.h
02dd95897e8d035600e82cdf50c9c82d7aac9fd7
[lyx.git] / src / graphics / GraphicsCacheItem.h
1 // -*- C++ -*-
2 /*
3  * \file GraphicsCacheItem.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  * The graphics cache is a container of grfx::CacheItems.
11  * Each grfx::CacheItem, definedhere represents a separate image file.
12  *
13  * The routines here can be used to load the graphics file into memory at
14  * which point (status() == grfx::Loaded).
15  * The user is then free to access image() in order to copy it and to then
16  * transform the copy (rotate, scale, clip) and to generate the pixmap.
17  *
18  * The graphics cache supports fully asynchronous:
19  * file conversion to a loadable format;
20  * file loading.
21  *
22  * Whether you get that, of course, depends on grfx::Converter and on the
23  * grfx::Image-derived image class.
24  */
25
26 #ifndef GRAPHICSCACHEITEM_H
27 #define GRAPHICSCACHEITEM_H
28
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "GraphicsTypes.h"
34 #include "LString.h"
35
36 #include <boost/utility.hpp>
37 #include <boost/scoped_ptr.hpp>
38 #include <boost/signals/signal0.hpp>
39
40 class InsetGraphics;
41
42 namespace grfx {
43
44 class Image;
45 class Converter;
46
47 /// A grfx::Cache item holder.
48 class CacheItem : boost::noncopyable {
49 public:
50         ///
51         CacheItem(string const & file);
52
53         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
54         ~CacheItem();
55
56         ///
57         string const & filename() const;
58
59         /// It's in the cache. Now start the loading process.
60         void startLoading() const;
61
62         /** Get the image associated with filename_.
63          *  If the image is not yet loaded, returns 0.
64          *  This routine returns a pointer to const; if you want to modify it,
65          *  create a copy and modify that.
66          */
67         Image const * image() const;
68
69         /// How far have we got in loading the image?
70         ImageStatus status() const;
71
72         /** Connect and you'll be informed when the loading status of the image
73          *  changes.
74          */
75         typedef boost::signal0<void>::slot_type slot_type;
76         ///
77         boost::signals::connection connect(slot_type const &) const;
78
79 private:
80         /// Use the Pimpl idiom to hide the internals.
81         class Impl;
82
83         /// The pointer never changes although *pimpl_'s contents may.
84         boost::scoped_ptr<Impl> const pimpl_;
85 };
86
87 } // namespace grfx
88
89 #endif // GRAPHICSCACHEITEM_H