2002-08-01 17:28:59 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file RenderPreview.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
|
|
|
*
|
2006-10-21 00:16:43 +00:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#ifndef RENDERPREVIEW_H
|
|
|
|
#define RENDERPREVIEW_H
|
2003-10-10 21:08:55 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "RenderBase.h"
|
2003-10-10 21:08:55 +00:00
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
#include "support/docstring.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/FileMonitor.h"
|
2017-03-09 21:44:07 +00:00
|
|
|
#include "support/FileName.h"
|
2017-05-28 11:25:53 +00:00
|
|
|
#include "support/signals.h"
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2003-09-18 13:13:49 +00:00
|
|
|
class Buffer;
|
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 graphics {
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
class PreviewImage;
|
|
|
|
class PreviewLoader;
|
|
|
|
|
2003-10-09 19:27:07 +00:00
|
|
|
} // namespace graphics
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
2017-05-28 11:25:53 +00:00
|
|
|
class RenderPreview : public RenderBase {
|
2002-08-01 17:28:59 +00:00
|
|
|
public:
|
2014-05-20 10:19:26 +00:00
|
|
|
/// Return true if preview is enabled in text (from LyXRC::preview)
|
|
|
|
static bool previewText();
|
|
|
|
/// Return true if preview is enabled in mathed (from LyXRC::preview)
|
|
|
|
static bool previewMath();
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit RenderPreview(Inset const *);
|
2007-04-29 13:39:47 +00:00
|
|
|
RenderPreview(RenderPreview const &, Inset const *);
|
2020-10-01 07:42:11 +00:00
|
|
|
RenderBase * clone(Inset const *) const override;
|
2003-10-10 21:08:55 +00:00
|
|
|
|
|
|
|
/// Compute the size of the object, returned in dim
|
2020-10-01 07:42:11 +00:00
|
|
|
void metrics(MetricsInfo &, Dimension & dim) const override;
|
2002-08-01 17:28:59 +00:00
|
|
|
///
|
2020-12-13 08:51:32 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const override;
|
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.
|
2010-07-29 15:17:58 +00:00
|
|
|
* \param ignore_lyxrc: generate the preview no matter what LyXRC says
|
2002-08-01 17:28:59 +00:00
|
|
|
*/
|
2010-07-29 15:17:58 +00:00
|
|
|
void addPreview(docstring const & latex_snippet, Buffer const &,
|
|
|
|
bool ignore_lyxrc = false);
|
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.
|
2010-07-29 15:17:58 +00:00
|
|
|
* \param ignore_lyxrc: generate the preview no matter what LyXRC says
|
2002-08-01 17:28:59 +00:00
|
|
|
*/
|
2006-10-21 00:16:43 +00:00
|
|
|
void addPreview(docstring const & latex_snippet,
|
2010-07-29 15:17:58 +00:00
|
|
|
graphics::PreviewLoader & ploader,
|
|
|
|
bool ignore_lyxrc = false);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
/// Begin the loading process.
|
2010-07-29 15:17:58 +00:00
|
|
|
/// \param forexport : whether this is intended for export. if so,
|
|
|
|
/// then we ignore LyXRC and wait for the image to be generated.
|
|
|
|
void startLoading(Buffer const & buffer, bool forexport = false) const;
|
2003-10-22 22:26:47 +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
|
|
|
|
2004-04-19 13:05:36 +00:00
|
|
|
/** \returns a pointer to the PreviewImage associated with this snippet
|
|
|
|
* of latex.
|
|
|
|
*/
|
2006-10-21 00:16:43 +00:00
|
|
|
graphics::PreviewImage const *
|
2004-04-19 13:05:36 +00:00
|
|
|
getPreviewImage(Buffer const & buffer) const;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-25 20:09:52 +00:00
|
|
|
/// equivalent to dynamic_cast
|
2020-10-01 07:42:11 +00:00
|
|
|
RenderPreview * asPreview() override { return this; }
|
2003-10-25 20:09:52 +00:00
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
private:
|
2003-10-10 21:08:55 +00:00
|
|
|
/// Not implemented.
|
2004-11-23 23:04:52 +00:00
|
|
|
RenderPreview & 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.
|
2006-10-21 00:16:43 +00:00
|
|
|
void imageReady(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
|
|
|
|
2003-10-09 14:36:16 +00:00
|
|
|
/** Store the connection to the preview loader so that we connect
|
|
|
|
* only once.
|
|
|
|
*/
|
2020-12-14 18:46:39 +00:00
|
|
|
scoped_connection ploader_connection_;
|
2003-09-16 15:43:00 +00:00
|
|
|
|
2004-04-13 17:25:23 +00:00
|
|
|
/// Inform the core that the inset has changed.
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset const * parent_;
|
2003-10-09 19:27:07 +00:00
|
|
|
};
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
|
|
|
class RenderMonitoredPreview : public RenderPreview {
|
|
|
|
public:
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit RenderMonitoredPreview(Inset const *);
|
2003-10-10 21:08:55 +00:00
|
|
|
///
|
2020-12-13 08:51:32 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const override;
|
2003-10-10 21:08:55 +00:00
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
void setAbsFile(support::FileName const & file);
|
2003-10-10 21:08:55 +00:00
|
|
|
///
|
2017-03-09 21:44:07 +00:00
|
|
|
bool monitoring() const;
|
|
|
|
void startMonitoring() const;
|
|
|
|
void stopMonitoring() const;
|
2003-10-10 21:08:55 +00:00
|
|
|
|
|
|
|
/// Connect and you'll be informed when the file changes.
|
2017-05-28 11:25:53 +00:00
|
|
|
/// Do not forget to track objects used by the slot.
|
2020-12-14 18:46:39 +00:00
|
|
|
typedef signal<void()> sig;
|
2017-05-28 11:25:53 +00:00
|
|
|
typedef sig::slot_type slot;
|
2020-12-14 18:46:39 +00:00
|
|
|
connection connect(slot const & slot);
|
2003-10-10 21:08:55 +00:00
|
|
|
|
2003-10-25 20:09:52 +00:00
|
|
|
/// equivalent to dynamic_cast
|
2020-10-01 07:42:11 +00:00
|
|
|
RenderMonitoredPreview * asMonitoredPreview() override { return this; }
|
2003-10-25 20:09:52 +00:00
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
private:
|
2017-03-09 21:44:07 +00:00
|
|
|
/// This signal is emitted if the file is modified
|
2017-05-28 11:25:53 +00:00
|
|
|
sig changed_;
|
2017-03-09 21:44:07 +00:00
|
|
|
///
|
2017-03-19 13:41:54 +00:00
|
|
|
mutable support::ActiveFileMonitorPtr monitor_;
|
2003-10-10 21:08:55 +00:00
|
|
|
///
|
2017-03-09 21:44:07 +00:00
|
|
|
support::FileName filename_;
|
2003-10-10 21:08:55 +00:00
|
|
|
};
|
|
|
|
|
2017-03-09 21:44:07 +00:00
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
#endif // RENDERPREVIEW_H
|