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