2002-02-27 09:59:52 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2003-08-23 00:17:00 +00:00
|
|
|
* \file GraphicsImage.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-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Baruch Even
|
|
|
|
* \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-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* An abstract base class for the images themselves.
|
|
|
|
* Allows the user to retrieve the pixmap, once loaded and to issue commands
|
|
|
|
* to modify it.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* The boost::functions newImage and loadableFormats are connected to the
|
|
|
|
* appropriate derived classes elsewhere, allowing the graphics cache to
|
|
|
|
* access them without knowing anything about their instantiation.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* The loading process can be asynchronous, but cropping, rotating and
|
|
|
|
* scaling block execution.
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAPHICSIMAGE_H
|
|
|
|
#define GRAPHICSIMAGE_H
|
|
|
|
|
2007-11-23 22:15:17 +00:00
|
|
|
#include "Dimension.h"
|
|
|
|
|
2004-09-26 13:34:57 +00:00
|
|
|
#include <boost/function.hpp>
|
2004-09-26 14:19:47 +00:00
|
|
|
#include <boost/signal.hpp>
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
2006-11-26 21:30:39 +00:00
|
|
|
|
|
|
|
namespace support { class FileName; }
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace graphics {
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class Params;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class Image {
|
2002-02-27 09:59:52 +00:00
|
|
|
public:
|
2002-06-28 11:22:56 +00:00
|
|
|
/** This is to be connected to a function that will return a new
|
|
|
|
* instance of a viable derived class.
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
2007-11-22 00:03:18 +00:00
|
|
|
static boost::function<Image *()> newImage;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
///
|
2004-10-29 15:47:55 +00:00
|
|
|
typedef std::vector<std::string> FormatList;
|
|
|
|
/// Return the list of loadable formats.
|
2004-09-26 13:34:57 +00:00
|
|
|
static boost::function<FormatList()> loadableFormats;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual ~Image() {}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Create a copy
|
2007-11-21 22:54:10 +00:00
|
|
|
virtual Image * clone() const = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Get the image width
|
2007-11-23 22:15:17 +00:00
|
|
|
virtual unsigned int width() const = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Get the image height
|
2007-11-23 22:15:17 +00:00
|
|
|
virtual unsigned int height() const = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2003-09-16 15:34:39 +00:00
|
|
|
/// Is the image drawable ?
|
2007-11-21 22:54:10 +00:00
|
|
|
virtual bool isDrawable() const = 0;
|
2002-07-17 16:56:42 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/** At the end of the loading process inform the outside world
|
2004-09-26 14:19:47 +00:00
|
|
|
* by emitting a signal
|
2002-06-28 11:22:56 +00:00
|
|
|
*/
|
2004-09-26 14:19:47 +00:00
|
|
|
typedef boost::signal<void(bool)> SignalType;
|
2002-02-27 09:59:52 +00:00
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
SignalType finishedLoading;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/** Start loading the image file.
|
|
|
|
* The caller should expect this process to be asynchronous and
|
|
|
|
* so should connect to the "finished" signal above.
|
|
|
|
*/
|
2007-11-21 22:54:10 +00:00
|
|
|
virtual void load(support::FileName const & filename) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/** Generate the pixmap.
|
|
|
|
* Uses the params to decide on color, grayscale etc.
|
|
|
|
* Returns true if the pixmap is created.
|
|
|
|
*/
|
2007-11-21 22:54:10 +00:00
|
|
|
virtual bool setPixmap(Params const & params) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Clip the image using params.
|
2007-11-21 22:54:10 +00:00
|
|
|
virtual void clip(Params const & params) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Rotate the image using params.
|
2007-11-21 22:54:10 +00:00
|
|
|
virtual void rotate(Params const & params) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Scale the image using params.
|
2007-11-21 22:54:10 +00:00
|
|
|
virtual void scale(Params const & params) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
protected:
|
2003-09-16 15:34:39 +00:00
|
|
|
/// Must define default c-tor explicitly as we define a copy c-tor.
|
|
|
|
Image() {}
|
|
|
|
/// Don't copy the signal finishedLoading
|
|
|
|
Image(Image const &) {}
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Uses the params to ascertain the dimensions of the scaled image.
|
2007-11-23 22:15:17 +00:00
|
|
|
* Returned as Dimension(width, height, 0 descend).
|
|
|
|
* If something goes wrong, returns make_pair(getWidth(), getHeight(), 0)
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
2007-11-23 22:15:17 +00:00
|
|
|
Dimension scaledDimension(Params const & params) const;
|
2002-02-27 09:59:52 +00:00
|
|
|
};
|
|
|
|
|
2003-09-16 15:34:39 +00:00
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
#endif // GRAPHICSIMAGE_H
|