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