4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Vincent van Ravesteijn
9 * Full author contact details are available in file CREDITS.
12 #ifndef INSETPREVIEW_H
13 #define INSETPREVIEW_H
15 #include "InsetText.h"
17 #include "support/unique_ptr.h"
29 /// An inset with an instant preview
30 class InsetPreview : public InsetText {
34 explicit InsetPreview(Buffer *);
38 InsetPreview(InsetPreview const & other);
40 InsetPreview & operator=(InsetPreview const & other);
42 /// \name Methods inherited from Inset class
44 Inset * clone() const override { return new InsetPreview(*this); }
46 bool neverIndent() const override { return true; }
48 InsetCode lyxCode() const override { return PREVIEW_CODE; }
50 docstring layoutName() const override { return from_ascii("Preview"); }
52 bool descendable(BufferView const & /*bv*/) const override { return true; }
54 std::string contextMenuName() const override
55 { return "context-preview"; }
57 void metrics(MetricsInfo & mi, Dimension & dim) const override;
59 Inset * editXY(Cursor & cur, int x, int y) override;
61 void draw(PainterInfo & pi, int x, int y) const override;
63 void addPreview(DocIterator const & inset_pos,
64 graphics::PreviewLoader & ploader) const override;
66 bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
68 void write(std::ostream & os) const override;
70 void edit(Cursor & cur, bool front, EntryDirection entry_from) override;
72 bool canPaintChange(BufferView const &) const override { return true; };
76 /// Retrieves the preview state. Returns true if preview
77 /// is enabled and the preview image is available.
78 bool previewState(BufferView * bv) const;
79 /// Recreates the preview if preview is enabled.
80 void reloadPreview(DocIterator const & pos) const;
81 /// Prepare the preview if preview is enabled.
82 void preparePreview(DocIterator const & pos) const;
85 unique_ptr<RenderPreview> preview_;