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
|
|
|
|
|
|
|
|
#include "LString.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2002-07-04 17:45:35 +00:00
|
|
|
#include <boost/function/function0.hpp>
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <boost/signals/signal1.hpp>
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
|
|
|
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
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
typedef boost::shared_ptr<Image> ImagePtr;
|
|
|
|
///
|
2002-07-04 17:45:35 +00:00
|
|
|
static boost::function0<ImagePtr> newImage;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Return the list of loadable formats.
|
2002-06-28 11:22:56 +00:00
|
|
|
typedef std::vector<string> FormatList;
|
|
|
|
///
|
2002-07-04 17:45:35 +00:00
|
|
|
static boost::function0<FormatList> loadableFormats;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +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
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual ~Image() {}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Create a copy
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual Image * clone() const = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Get the image width
|
|
|
|
virtual unsigned int getWidth() const = 0;
|
|
|
|
|
|
|
|
/// Get the image height
|
|
|
|
virtual unsigned int getHeight() const = 0;
|
|
|
|
|
2002-07-15 17:17:57 +00:00
|
|
|
/// is the image drawable ?
|
|
|
|
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
|
|
|
|
* by emitting a signal.
|
|
|
|
*/
|
2002-05-29 16:21:03 +00:00
|
|
|
typedef boost::signal1<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.
|
|
|
|
*/
|
|
|
|
virtual void load(string 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.
|
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual bool setPixmap(Params const & params) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Clip the image using params.
|
2002-06-28 11:22:56 +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.
|
2002-06-28 11:22:56 +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.
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual void scale(Params const & params) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Uses the params to ascertain the dimensions of the scaled image.
|
|
|
|
* Returned as make_pair(width, height).
|
2002-06-28 11:22:56 +00:00
|
|
|
* If something goes wrong, returns make_pair(getWidth(), getHeight())
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
|
|
|
std::pair<unsigned int, unsigned int>
|
2002-06-28 11:22:56 +00:00
|
|
|
getScaledDimensions(Params const & params) const;
|
2002-02-27 09:59:52 +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
|