2002-08-01 17:28:59 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2003-07-21 21:30:57 +00:00
|
|
|
* \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-12-01 22:59:25 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 11:31:30 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-08-01 17:28:59 +00:00
|
|
|
*
|
2003-07-21 21:30:57 +00:00
|
|
|
* lyx::graphics::PreviewedInset is an abstract base class that can help
|
2003-09-16 15:43:00 +00:00
|
|
|
* insets to generate previews. The daughter class must instantiate two small
|
2003-07-21 21:30:57 +00:00
|
|
|
* methods. The Inset would own an instance of this daughter class.
|
2002-08-01 17:28:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PREVIEWEDINSET_H
|
|
|
|
#define PREVIEWEDINSET_H
|
|
|
|
|
|
|
|
#include <boost/signals/trackable.hpp>
|
|
|
|
#include <boost/signals/connection.hpp>
|
|
|
|
|
2003-09-18 13:13:49 +00:00
|
|
|
class Buffer;
|
2002-08-01 17:28:59 +00:00
|
|
|
class BufferView;
|
2003-09-18 13:13:49 +00:00
|
|
|
class InsetOld;
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace graphics {
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
class PreviewImage;
|
|
|
|
class PreviewLoader;
|
|
|
|
|
|
|
|
class PreviewedInset : public boost::signals::trackable {
|
|
|
|
public:
|
|
|
|
/// a wrapper for Previews::activated()
|
|
|
|
static bool activated();
|
|
|
|
|
|
|
|
///
|
2003-09-16 15:43:00 +00:00
|
|
|
PreviewedInset(InsetOld & inset);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
/** Find the PreviewLoader, add a LaTeX snippet to it and
|
|
|
|
* start the loading process.
|
|
|
|
*/
|
2003-09-19 10:16:33 +00:00
|
|
|
void generatePreview(Buffer const &);
|
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.
|
|
|
|
*/
|
2003-10-09 14:36:16 +00:00
|
|
|
void removePreview(Buffer const &);
|
2002-08-06 14:02:59 +00:00
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
/// The preview has been generated and is ready to use.
|
2003-10-09 14:36:16 +00:00
|
|
|
bool previewReady(Buffer const &) const;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
/// If !previewReady() returns 0.
|
2003-09-16 15:43:00 +00:00
|
|
|
PreviewImage const * pimage() const;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
protected:
|
2003-09-16 15:43:00 +00:00
|
|
|
///
|
|
|
|
virtual ~PreviewedInset() {}
|
2002-08-01 17:28:59 +00:00
|
|
|
/// Allow the daughter classes to cast up to the parent inset.
|
2003-09-16 15:43:00 +00:00
|
|
|
InsetOld const & inset() const;
|
2002-08-02 16:30:58 +00:00
|
|
|
///
|
2003-02-26 13:10:16 +00:00
|
|
|
BufferView * view() const;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
private:
|
2003-07-21 21:30:57 +00:00
|
|
|
/// This method is connected to the PreviewLoader::imageReady signal.
|
2002-08-01 17:28:59 +00:00
|
|
|
void imageReady(PreviewImage const &) const;
|
|
|
|
|
|
|
|
/// Does the owning inset want a preview?
|
2003-09-19 10:16:33 +00:00
|
|
|
virtual bool previewWanted(Buffer const &) const = 0;
|
2002-08-01 17:28:59 +00:00
|
|
|
/// a wrapper to Inset::latex
|
2003-10-06 15:43:21 +00:00
|
|
|
virtual std::string const latexString(Buffer const &) const = 0;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
///
|
2003-07-25 21:20:24 +00:00
|
|
|
InsetOld & inset_;
|
2002-08-02 12:38:20 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string snippet_;
|
2002-12-01 22:59:25 +00:00
|
|
|
|
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_;
|
2003-10-09 14:36:16 +00:00
|
|
|
/** Store the connection to the preview loader so that we connect
|
|
|
|
* only once.
|
|
|
|
*/
|
|
|
|
boost::signals::connection ploader_connection_;
|
2002-08-01 17:28:59 +00:00
|
|
|
};
|
|
|
|
|
2003-09-16 15:43:00 +00:00
|
|
|
|
|
|
|
inline
|
|
|
|
PreviewImage const * PreviewedInset::pimage() const
|
|
|
|
{
|
|
|
|
return pimage_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
InsetOld const & PreviewedInset::inset() const
|
|
|
|
{
|
|
|
|
return inset_;
|
|
|
|
}
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
#endif // PREVIEWEDINSET_H
|