]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewedInset.h
add virtual destructor
[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         virtual ~PreviewedInset() {}
42
43         /** Find the PreviewLoader, add a LaTeX snippet to it and
44          *  start the loading process.
45          */
46         void generatePreview();
47
48         /** Add a LaTeX snippet to the PreviewLoader but do not start the
49          *  loading process.
50          */
51         void addPreview(PreviewLoader & ploader);
52
53         /// The preview has been generated and is ready to use.
54         bool previewReady() const;
55
56         /// If !previewReady() returns 0.
57         PreviewImage const * pimage() const { return pimage_; }
58
59 protected:
60         /// Allow the daughter classes to cast up to the parent inset.
61         Inset * inset() const { return &inset_; }
62
63 private:
64         /** This method is connected to the grfx::PreviewLoader::imageReady
65          *  signal.
66          */
67         void imageReady(PreviewImage const &) const;
68
69         /// Does the owning inset want a preview?
70         virtual bool previewWanted() const = 0;
71         ///
72         virtual BufferView * view() const = 0;
73         /// a wrapper to Inset::latex
74         virtual string const latexString() const = 0;
75
76         ///
77         Inset & inset_;
78         ///
79         string snippet_;
80         /// We don't own this. Cached for efficiency reasons.
81         mutable PreviewImage const * pimage_;
82         ///
83         boost::signals::connection connection_;
84 };
85
86 } // namespace grfx
87
88
89 #endif // PREVIEWEDINSET_H