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