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