]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewedInset.h
The std::string mammoth path.
[lyx.git] / src / graphics / PreviewedInset.h
1 // -*- C++ -*-
2 /**
3  * \file PreviewedInset.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * lyx::graphics::PreviewedInset is an abstract base class that can help
12  * insets to generate previews. The daughter class must instantiate two small
13  * methods. The Inset would own an instance of this daughter class.
14  */
15
16 #ifndef PREVIEWEDINSET_H
17 #define PREVIEWEDINSET_H
18
19 #include <boost/signals/trackable.hpp>
20 #include <boost/signals/connection.hpp>
21
22 class Buffer;
23 class BufferView;
24 class InsetOld;
25
26
27 namespace lyx {
28 namespace graphics {
29
30 class PreviewImage;
31 class PreviewLoader;
32
33 class PreviewedInset : public boost::signals::trackable {
34 public:
35         /// a wrapper for Previews::activated()
36         static bool activated();
37
38         ///
39         PreviewedInset(InsetOld & inset);
40
41         /** Find the PreviewLoader, add a LaTeX snippet to it and
42          *  start the loading process.
43          */
44         void generatePreview(Buffer const &);
45
46         /** Add a LaTeX snippet to the PreviewLoader but do not start the
47          *  loading process.
48          */
49         void addPreview(PreviewLoader & ploader);
50
51         /** Remove a snippet from the cache of previews.
52          *  Useful if previewing the contents of a file that has changed.
53          */
54         void removePreview();
55
56         /// The preview has been generated and is ready to use.
57         bool previewReady() const;
58
59         /// If !previewReady() returns 0.
60         PreviewImage const * pimage() const;
61
62 protected:
63         ///
64         virtual ~PreviewedInset() {}
65         /// Allow the daughter classes to cast up to the parent inset.
66         InsetOld const & inset() const;
67         ///
68         BufferView * view() const;
69
70 private:
71         /// This method is connected to the PreviewLoader::imageReady signal.
72         void imageReady(PreviewImage const &) const;
73
74         /// Does the owning inset want a preview?
75         virtual bool previewWanted(Buffer const &) const = 0;
76         /// a wrapper to Inset::latex
77         virtual std::string const latexString(Buffer const &) const = 0;
78
79         ///
80         InsetOld & inset_;
81         ///
82         std::string snippet_;
83
84         /// We don't own this. Cached for efficiency reasons.
85         mutable PreviewImage const * pimage_;
86         ///
87         boost::signals::connection connection_;
88 };
89
90
91 inline
92 PreviewImage const * PreviewedInset::pimage() const
93 {
94         return pimage_;
95 }
96
97
98 inline
99 InsetOld const & PreviewedInset::inset() const
100 {
101         return inset_;
102 }
103
104 } // namespace graphics
105 } // namespace lyx
106
107 #endif // PREVIEWEDINSET_H