]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewedInset.h
Small clean-up of the PreviewedInset interface.
[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 "support/std_string.h"
20 #include <boost/signals/trackable.hpp>
21 #include <boost/signals/connection.hpp>
22
23 class InsetOld;
24 class BufferView;
25
26 namespace lyx {
27 namespace graphics {
28
29 class PreviewImage;
30 class PreviewLoader;
31
32 class PreviewedInset : public boost::signals::trackable {
33 public:
34         /// a wrapper for Previews::activated()
35         static bool activated();
36
37         ///
38         PreviewedInset(InsetOld & inset);
39
40         /** Find the PreviewLoader, add a LaTeX snippet to it and
41          *  start the loading process.
42          */
43         void generatePreview();
44
45         /** Add a LaTeX snippet to the PreviewLoader but do not start the
46          *  loading process.
47          */
48         void addPreview(PreviewLoader & ploader);
49
50         /** Remove a snippet from the cache of previews.
51          *  Useful if previewing the contents of a file that has changed.
52          */
53         void removePreview();
54
55         /// The preview has been generated and is ready to use.
56         bool previewReady() const;
57
58         /// If !previewReady() returns 0.
59         PreviewImage const * pimage() const;
60
61 protected:
62         ///
63         virtual ~PreviewedInset() {}
64         /// Allow the daughter classes to cast up to the parent inset.
65         InsetOld const & inset() const;
66         ///
67         BufferView * view() const;
68
69 private:
70         /// This method is connected to the PreviewLoader::imageReady signal.
71         void imageReady(PreviewImage const &) const;
72
73         /// Does the owning inset want a preview?
74         virtual bool previewWanted() const = 0;
75         /// a wrapper to Inset::latex
76         virtual string const latexString() const = 0;
77
78         ///
79         InsetOld & inset_;
80         ///
81         string snippet_;
82
83         /// We don't own this. Cached for efficiency reasons.
84         mutable PreviewImage const * pimage_;
85         ///
86         boost::signals::connection connection_;
87 };
88
89
90 inline
91 PreviewImage const * PreviewedInset::pimage() const
92 {
93         return pimage_;
94 }
95
96
97 inline
98 InsetOld const & PreviewedInset::inset() const
99 {
100         return inset_;
101 }
102
103 } // namespace graphics
104 } // namespace lyx
105
106 #endif // PREVIEWEDINSET_H