2000-07-31 12:30:10 +00:00
|
|
|
// -*- C++ -*-
|
2002-02-27 09:59:52 +00:00
|
|
|
/*
|
|
|
|
* \file GraphicsCacheItem.h
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
2002-02-27 09:59:52 +00:00
|
|
|
* \author Baruch Even <baruch.even@writeme.com>
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
|
|
|
*
|
|
|
|
* The graphics cache is a container of GCacheItems. Each GCacheItem, defined
|
2002-06-26 14:15:08 +00:00
|
|
|
* here represents a separate image file. The routines here can be used to
|
|
|
|
* load the graphics file into memory at which point (status() == grfx::Loaded).
|
|
|
|
* The user is then free to access image() in order to transform the image
|
|
|
|
* (rotate, scale, clip) and to generate the pixmap.
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
|
|
|
* The graphics cache supports fully asynchronous:
|
|
|
|
* file conversion to a loadable format;
|
|
|
|
* file loading.
|
|
|
|
*
|
|
|
|
* Whether you get that, of course, depends on grfx::GConverter and on the
|
|
|
|
* grfx::GImage-derived image class.
|
|
|
|
*/
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
#ifndef GRAPHICSCACHEITEM_H
|
|
|
|
#define GRAPHICSCACHEITEM_H
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
#include "GraphicsTypes.h"
|
2000-08-08 09:18:39 +00:00
|
|
|
#include "LString.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
#include <boost/utility.hpp>
|
2002-05-22 01:16:37 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
#include <boost/signals/signal0.hpp>
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <boost/signals/signal1.hpp>
|
|
|
|
#include <boost/signals/connection.hpp>
|
|
|
|
#include <boost/signals/trackable.hpp>
|
2000-08-10 13:15:05 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
class InsetGraphics;
|
|
|
|
|
|
|
|
namespace grfx {
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// A grfx::GCache item holder.
|
2002-05-29 16:21:03 +00:00
|
|
|
class GCacheItem : boost::noncopyable, public boost::signals::trackable {
|
2000-07-31 12:30:10 +00:00
|
|
|
public:
|
2000-08-14 15:31:16 +00:00
|
|
|
///
|
2002-06-25 15:59:10 +00:00
|
|
|
GCacheItem(string const & file);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// It's in the cache. Now start the loading process.
|
2002-06-25 15:59:10 +00:00
|
|
|
void startLoading();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
/** Get the image associated with filename_.
|
|
|
|
If the image is not yet loaded, return a null pointer.
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
2002-06-25 15:59:10 +00:00
|
|
|
ImagePtr const image() const { return image_; }
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
/// How far have we got in loading the image?
|
|
|
|
ImageStatus status() const { return status_; }
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
/// This signal is emitted when the image loading status changes.
|
|
|
|
boost::signal0<void> statusChanged;
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2002-04-11 17:40:44 +00:00
|
|
|
///
|
2002-06-25 15:59:10 +00:00
|
|
|
string const & filename() const { return filename_; }
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
private:
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Start the image conversion process, checking first that it is
|
|
|
|
* necessary. If it is necessary, then a conversion task is started.
|
|
|
|
* GCacheItem asumes that the conversion is asynchronous and so
|
|
|
|
* passes a Signal to the converting routine. When the conversion
|
|
|
|
* is finished, this Signal is emitted, returning the converted
|
|
|
|
* file to this->imageConverted.
|
2001-07-17 00:38:04 +00:00
|
|
|
*
|
2002-02-27 09:59:52 +00:00
|
|
|
* If no file conversion is needed, then convertToDisplayFormat() calls
|
|
|
|
* loadImage() directly.
|
|
|
|
*
|
|
|
|
* convertToDisplayFormat() will set the loading status flag as
|
|
|
|
* approriate through calls to setStatus().
|
2001-07-17 00:38:04 +00:00
|
|
|
*/
|
2002-02-27 09:59:52 +00:00
|
|
|
void convertToDisplayFormat();
|
2001-07-17 00:38:04 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Load the image into memory. This is called either from
|
|
|
|
* convertToDisplayFormat() direct or from imageConverted().
|
|
|
|
*/
|
2001-04-02 19:56:48 +00:00
|
|
|
void loadImage();
|
2000-08-10 13:15:05 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Get a notification when the image conversion is done.
|
|
|
|
* Connected to a signal on_finish_ which is passed to
|
|
|
|
* GConverter::convert.
|
|
|
|
*/
|
|
|
|
void imageConverted(string const & file_to_load);
|
|
|
|
|
|
|
|
/** Get a notification when the image loading is done.
|
|
|
|
* Connected to a signal on_finish_ which is passed to
|
|
|
|
* GImage::loadImage.
|
|
|
|
*/
|
|
|
|
void imageLoaded(bool);
|
|
|
|
|
|
|
|
/** Sets the status of the loading process. Also notifies
|
|
|
|
* listeners that the status has chacnged.
|
|
|
|
*/
|
2001-07-17 00:38:04 +00:00
|
|
|
void setStatus(ImageStatus new_status);
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// The filename we refer too.
|
2000-08-10 13:15:05 +00:00
|
|
|
string filename_;
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Is the file compressed?
|
|
|
|
bool zipped_;
|
|
|
|
/// If so, store the uncompressed file in this temporary file.
|
|
|
|
string unzipped_filename_;
|
|
|
|
/// What file are we trying to load?
|
|
|
|
string file_to_load_;
|
|
|
|
/** Should we delete the file after loading? True if the file is
|
|
|
|
* the result of a conversion process.
|
|
|
|
*/
|
|
|
|
bool remove_loaded_file_;
|
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
/// The image and its loading status.
|
2002-02-27 09:59:52 +00:00
|
|
|
ImagePtr image_;
|
|
|
|
///
|
|
|
|
ImageStatus status_;
|
|
|
|
|
|
|
|
/** A SignalLoadTypePtr is connected to this->imageLoaded and
|
|
|
|
* then passed to ImagePtr::load.
|
|
|
|
* When the image has been loaded, the signal is emitted.
|
|
|
|
*
|
|
|
|
* We pass a shared_ptr because it is eminently possible for the
|
2002-06-25 15:59:10 +00:00
|
|
|
* GCacheItem to be destructed before the loading is complete and
|
2002-02-27 09:59:52 +00:00
|
|
|
* the signal must remain in scope. It doesn't matter if the slot
|
|
|
|
* disappears, SigC takes care of that.
|
|
|
|
*/
|
2002-05-29 16:21:03 +00:00
|
|
|
typedef boost::signal1<void, bool> SignalLoadType;
|
2002-02-27 09:59:52 +00:00
|
|
|
///
|
|
|
|
typedef boost::shared_ptr<SignalLoadType> SignalLoadTypePtr;
|
|
|
|
|
|
|
|
/// The connection of the signal passed to ImagePtr::loadImage.
|
2002-05-29 16:21:03 +00:00
|
|
|
boost::signals::connection cl_;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/** A SignalConvertTypePtr is connected to this->imageConverted and
|
|
|
|
* then passed to GConverter::convert.
|
|
|
|
* When the image has been converted to a loadable format, the signal
|
|
|
|
* is emitted, returning the name of the loadable file to
|
|
|
|
* imageConverted.
|
|
|
|
*/
|
2002-05-29 16:21:03 +00:00
|
|
|
typedef boost::signal1<void, string const &> SignalConvertType;
|
2002-02-27 09:59:52 +00:00
|
|
|
///
|
|
|
|
typedef boost::shared_ptr<SignalConvertType> SignalConvertTypePtr;
|
|
|
|
|
|
|
|
/// The connection of the signal passed to GConverter::convert.
|
2002-05-29 16:21:03 +00:00
|
|
|
boost::signals::connection cc_;
|
2002-02-27 09:59:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace grfx
|
|
|
|
|
|
|
|
#endif // GRAPHICSCACHEITEM_H
|