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