2002-08-01 17:28:59 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file PreviewedInset.h
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-08-01 17:28:59 +00:00
|
|
|
*
|
2002-09-05 11:31:30 +00:00
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* Full author contact details are available in file CREDITS
|
2002-08-01 17:28:59 +00:00
|
|
|
*
|
|
|
|
* grfx::PreviewedInset is an abstract base class that can help insets to
|
|
|
|
* generate previews. The daughter class must instantiate three small
|
|
|
|
* methods. The Inset would own an instance of this daughter class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PREVIEWEDINSET_H
|
|
|
|
#define PREVIEWEDINSET_H
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LString.h"
|
2002-08-02 16:30:58 +00:00
|
|
|
#include <boost/weak_ptr.hpp>
|
2002-08-01 17:28:59 +00:00
|
|
|
#include <boost/signals/trackable.hpp>
|
|
|
|
#include <boost/signals/connection.hpp>
|
|
|
|
|
|
|
|
class Inset;
|
|
|
|
class BufferView;
|
|
|
|
|
|
|
|
namespace grfx {
|
|
|
|
|
|
|
|
class PreviewImage;
|
|
|
|
class PreviewLoader;
|
|
|
|
|
|
|
|
class PreviewedInset : public boost::signals::trackable {
|
|
|
|
public:
|
|
|
|
/// a wrapper for Previews::activated()
|
|
|
|
static bool activated();
|
|
|
|
|
|
|
|
///
|
|
|
|
PreviewedInset(Inset & inset) : inset_(inset), pimage_(0) {}
|
2002-08-02 13:34:14 +00:00
|
|
|
///
|
|
|
|
virtual ~PreviewedInset() {}
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
/** Find the PreviewLoader, add a LaTeX snippet to it and
|
|
|
|
* start the loading process.
|
|
|
|
*/
|
2002-08-02 12:38:20 +00:00
|
|
|
void generatePreview();
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
/** Add a LaTeX snippet to the PreviewLoader but do not start the
|
|
|
|
* loading process.
|
|
|
|
*/
|
2002-08-02 12:38:20 +00:00
|
|
|
void addPreview(PreviewLoader & ploader);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
/** Remove a snippet from the cache of previews.
|
|
|
|
* Useful if previewing the contents of a file that has changed.
|
|
|
|
*/
|
|
|
|
void removePreview();
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
/// The preview has been generated and is ready to use.
|
|
|
|
bool previewReady() const;
|
|
|
|
|
|
|
|
/// If !previewReady() returns 0.
|
|
|
|
PreviewImage const * pimage() const { return pimage_; }
|
|
|
|
|
2002-08-02 16:30:58 +00:00
|
|
|
///
|
|
|
|
void setView(BufferView *);
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
protected:
|
|
|
|
/// Allow the daughter classes to cast up to the parent inset.
|
|
|
|
Inset * inset() const { return &inset_; }
|
2002-08-02 16:30:58 +00:00
|
|
|
///
|
|
|
|
BufferView * view() const { return view_.get(); }
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/** This method is connected to the grfx::PreviewLoader::imageReady
|
|
|
|
* signal.
|
|
|
|
*/
|
|
|
|
void imageReady(PreviewImage const &) const;
|
|
|
|
|
|
|
|
/// Does the owning inset want a preview?
|
|
|
|
virtual bool previewWanted() const = 0;
|
|
|
|
/// a wrapper to Inset::latex
|
|
|
|
virtual string const latexString() const = 0;
|
|
|
|
|
|
|
|
///
|
|
|
|
Inset & inset_;
|
2002-08-02 12:38:20 +00:00
|
|
|
///
|
|
|
|
string snippet_;
|
2002-08-02 16:30:58 +00:00
|
|
|
///
|
|
|
|
boost::weak_ptr<BufferView> view_;
|
|
|
|
|
2002-08-02 12:38:20 +00:00
|
|
|
/// We don't own this. Cached for efficiency reasons.
|
2002-08-01 17:28:59 +00:00
|
|
|
mutable PreviewImage const * pimage_;
|
|
|
|
///
|
2002-08-02 12:38:20 +00:00
|
|
|
boost::signals::connection connection_;
|
2002-08-01 17:28:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace grfx
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PREVIEWEDINSET_H
|