]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewedInset.h
Previews for \input insets.
[lyx.git] / src / graphics / PreviewedInset.h
1 // -*- C++ -*-
2 /**
3  *  \file PreviewedInset.h
4  *  Copyright 2002 the LyX Team
5  *  Read the file COPYING
6  *
7  * \author Angus Leeming <leeming@lyx.org>
8  *
9  *  grfx::PreviewedInset is an abstract base class that can help insets to
10  *  generate previews. The daughter class must instantiate three small
11  *  methods. The Inset would own an instance of this daughter class.
12  */
13
14 #ifndef PREVIEWEDINSET_H
15 #define PREVIEWEDINSET_H
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "LString.h"
22 #include <boost/signals/trackable.hpp>
23 #include <boost/signals/connection.hpp>
24
25 class Inset;
26 class BufferView;
27
28 namespace grfx {
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(Inset & inset) : inset_(inset), pimage_(0) {}
40
41         /** Find the PreviewLoader, add a LaTeX snippet to it and
42          *  start the loading process.
43          */
44         void generatePreview() const;
45
46         /** Add a LaTeX snippet to the PreviewLoader but do not start the
47          *  loading process.
48          */
49         void addPreview(PreviewLoader & ploader) const;
50
51         /// The preview has been generated and is ready to use.
52         bool previewReady() const;
53
54         /// If !previewReady() returns 0.
55         PreviewImage const * pimage() const { return pimage_; }
56
57 protected:
58         /// Allow the daughter classes to cast up to the parent inset.
59         Inset * inset() const { return &inset_; }
60
61 private:
62         /** This method is connected to the grfx::PreviewLoader::imageReady
63          *  signal.
64          */
65         void imageReady(PreviewImage const &) const;
66
67         /// Does the owning inset want a preview?
68         virtual bool previewWanted() const = 0;
69         ///
70         virtual BufferView * view() const = 0;
71         /// a wrapper to Inset::latex
72         virtual string const latexString() const = 0;
73
74         ///
75         Inset & inset_;
76         /// We don't own this
77         mutable PreviewImage const * pimage_;
78         ///
79         mutable boost::signals::connection connection_;
80 };
81
82 } // namespace grfx
83
84
85 #endif // PREVIEWEDINSET_H