2002-08-01 17:28:59 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2003-10-10 21:08:55 +00:00
|
|
|
* \file render_preview.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-10-10 21:08:55 +00:00
|
|
|
* lyx::graphics::RenderPreview 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
|
|
|
*/
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
#ifndef RENDER_PREVIEW_H
|
|
|
|
#define RENDER_PREVIEW_H
|
|
|
|
|
|
|
|
#include "render_base.h"
|
|
|
|
|
|
|
|
#include "support/FileMonitor.h"
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-09 19:27:07 +00:00
|
|
|
#include <boost/signals/signal0.hpp>
|
2002-08-01 17:28:59 +00:00
|
|
|
#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-10-10 21:08:55 +00:00
|
|
|
class MetricsInfo;
|
|
|
|
class PainterInfo;
|
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;
|
|
|
|
|
2003-10-09 19:27:07 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
|
|
|
class RenderPreview : public RenderBase, public boost::signals::trackable {
|
2002-08-01 17:28:59 +00:00
|
|
|
public:
|
|
|
|
/// a wrapper for Previews::activated()
|
|
|
|
static bool activated();
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
RenderPreview();
|
|
|
|
RenderPreview(RenderPreview const &);
|
|
|
|
RenderBase * clone() const;
|
|
|
|
|
|
|
|
/// Compute the size of the object, returned in dim
|
|
|
|
void metrics(MetricsInfo &, Dimension & dim) const;
|
2002-08-01 17:28:59 +00:00
|
|
|
///
|
2003-10-10 21:08:55 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
/** Find the PreviewLoader and add a LaTeX snippet to it.
|
|
|
|
* Do not start the loading process.
|
2002-08-01 17:28:59 +00:00
|
|
|
*/
|
2003-10-22 22:26:47 +00:00
|
|
|
void addPreview(std::string const & latex_snippet, Buffer const &);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
/** Add a LaTeX snippet to the PreviewLoader.
|
|
|
|
* Do not start the loading process.
|
2002-08-01 17:28:59 +00:00
|
|
|
*/
|
2003-10-10 21:08:55 +00:00
|
|
|
void addPreview(std::string const & latex_snippet,
|
|
|
|
lyx::graphics::PreviewLoader & ploader);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
/// Begin the loading process.
|
|
|
|
void startLoading(Buffer const & buffer) const;
|
|
|
|
|
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 23:14:30 +00:00
|
|
|
bool previewReady() const;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-09 19:27:07 +00:00
|
|
|
/// Connect and you'll be informed when the preview is ready.
|
|
|
|
typedef boost::signal0<void>::slot_type slot_type;
|
|
|
|
boost::signals::connection connect(slot_type const &);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
private:
|
2003-10-10 21:08:55 +00:00
|
|
|
/// Not implemented.
|
|
|
|
void operator=(RenderPreview const &);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
/// This method is connected to the PreviewLoader::imageReady signal.
|
|
|
|
void imageReady(lyx::graphics::PreviewImage const &);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-09 19:27:07 +00:00
|
|
|
/// The thing that we're trying to generate a preview of.
|
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.
|
2003-10-10 21:08:55 +00:00
|
|
|
lyx::graphics::PreviewImage const * pimage_;
|
2003-10-09 19:27:07 +00:00
|
|
|
|
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_;
|
2003-09-16 15:43:00 +00:00
|
|
|
|
2003-10-09 19:27:07 +00:00
|
|
|
/// This signal is emitted when the preview is ready for display.
|
|
|
|
boost::signal0<void> preview_ready_signal_;
|
|
|
|
};
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
|
|
|
class RenderMonitoredPreview : public RenderPreview {
|
|
|
|
public:
|
|
|
|
RenderMonitoredPreview() : monitor_(std::string(), 2000) {}
|
|
|
|
///
|
2003-10-22 22:26:47 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const;
|
2003-10-10 21:08:55 +00:00
|
|
|
///
|
2003-10-22 22:26:47 +00:00
|
|
|
void setAbsFile(std::string const & file);
|
2003-10-10 21:08:55 +00:00
|
|
|
///
|
2003-10-22 22:26:47 +00:00
|
|
|
bool monitoring() const { return monitor_.monitoring(); }
|
|
|
|
void startMonitoring() const { monitor_.start(); }
|
|
|
|
void stopMonitoring() const { monitor_.stop(); }
|
2003-10-10 21:08:55 +00:00
|
|
|
|
|
|
|
/// Connect and you'll be informed when the file changes.
|
|
|
|
boost::signals::connection fileChanged(slot_type const &);
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
2003-10-22 22:26:47 +00:00
|
|
|
mutable lyx::support::FileMonitor monitor_;
|
2003-10-10 21:08:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RENDERPREVIEW_H
|