]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCacheItem.h
b6d7d4164ca0411e7fd0b44503f0e69a7875348d
[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 graphics::CacheItems.
13  * Each 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() == 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 graphics::Converter and
25  * on the graphics::Image-derived image class.
26  */
27
28 #ifndef GRAPHICSCACHEITEM_H
29 #define GRAPHICSCACHEITEM_H
30
31 #include "GraphicsTypes.h"
32
33 #include <boost/signals2.hpp>
34
35
36 namespace lyx {
37
38 namespace support { class FileName; }
39
40 namespace graphics {
41
42 class Image;
43 class Converter;
44
45 /// A graphics::Cache item holder.
46 class CacheItem {
47 public:
48         ///
49         CacheItem(support::FileName const & file, support::FileName const & doc_file);
50         /// Needed for the pimpl
51         ~CacheItem();
52
53         ///
54         support::FileName const & filename() const;
55
56         /// Try to load a display format.
57         bool tryDisplayFormat() const;
58
59         /// It's in the cache. Now start the loading process.
60         void startLoading() const;
61
62         /** Monitor any changes to the file.
63          *  There is no point monitoring the file before startLoading() is
64          *  invoked.
65          */
66         void startMonitoring() const;
67         ///
68         bool monitoring() const;
69
70         /** Get the image associated with filename().
71          *  If the image is not yet loaded, returns 0.
72          *  This routine returns a pointer to const; if you want to modify it,
73          *  create a copy and modify that.
74          */
75         Image const * image() const;
76
77         /// How far have we got in loading the image?
78         ImageStatus status() const;
79
80         /** Connect and you'll be informed when the loading status of the image
81          *  changes.
82          */
83         typedef boost::signals2::signal<void()>::slot_type slot_type;
84         ///
85         boost::signals2::connection connect(slot_type const &) const;
86
87 private:
88         /// noncopyable
89         CacheItem(CacheItem const &);
90         void operator=(CacheItem const &);
91
92         /// Use the Pimpl idiom to hide the internals.
93         class Impl;
94         /// The pointer never changes although *pimpl_'s contents may.
95         Impl * const pimpl_;
96 };
97
98 } // namespace graphics
99 } // namespace lyx
100
101 #endif // GRAPHICSCACHEITEM_H