2002-07-05 21:24:15 +00:00
|
|
|
/**
|
|
|
|
* \file PreviewImage.C
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
2002-07-15 11:08:46 +00:00
|
|
|
* \author Angus Leeming <leeming@lyx.org>
|
2002-07-05 21:24:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "PreviewImage.h"
|
|
|
|
#include "PreviewLoader.h"
|
|
|
|
#include "GraphicsImage.h"
|
|
|
|
#include "GraphicsLoader.h"
|
|
|
|
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
#include <boost/signals/trackable.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
namespace grfx {
|
|
|
|
|
|
|
|
struct PreviewImage::Impl : public boost::signals::trackable {
|
|
|
|
///
|
|
|
|
Impl(PreviewImage & p, PreviewLoader & l,
|
|
|
|
string const & s, string const & f, double af);
|
|
|
|
///
|
2002-07-06 12:38:44 +00:00
|
|
|
~Impl();
|
|
|
|
///
|
2002-07-15 11:08:46 +00:00
|
|
|
Image const * image(Inset const &, BufferView const &);
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
|
|
|
void statusChanged();
|
|
|
|
|
|
|
|
///
|
|
|
|
PreviewImage const & parent_;
|
|
|
|
///
|
|
|
|
PreviewLoader & ploader_;
|
|
|
|
///
|
2002-07-15 11:08:46 +00:00
|
|
|
Loader iloader_;
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
|
|
|
string const snippet_;
|
|
|
|
///
|
|
|
|
double const ascent_frac_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PreviewImage::PreviewImage(PreviewLoader & l,
|
|
|
|
string const & s,
|
|
|
|
string const & f,
|
|
|
|
double af)
|
|
|
|
: pimpl_(new Impl(*this, l, s, f, af))
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
PreviewImage::~PreviewImage()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
string const & PreviewImage::snippet() const
|
|
|
|
{
|
|
|
|
return pimpl_->snippet_;
|
|
|
|
}
|
|
|
|
|
2002-07-15 11:08:46 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
int PreviewImage::ascent() const
|
|
|
|
{
|
2002-07-15 11:08:46 +00:00
|
|
|
Image const * const image = pimpl_->iloader_.image();
|
2002-07-05 21:24:15 +00:00
|
|
|
if (!image)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return int(pimpl_->ascent_frac_ * double(image->getHeight()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PreviewImage::descent() const
|
|
|
|
{
|
2002-07-15 11:08:46 +00:00
|
|
|
Image const * const image = pimpl_->iloader_.image();
|
2002-07-05 21:24:15 +00:00
|
|
|
if (!image)
|
|
|
|
return 0;
|
|
|
|
|
2002-07-09 09:30:54 +00:00
|
|
|
// Avoids rounding errors.
|
|
|
|
return image->getHeight() - ascent();
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PreviewImage::width() const
|
|
|
|
{
|
2002-07-15 11:08:46 +00:00
|
|
|
Image const * const image = pimpl_->iloader_.image();
|
2002-07-05 21:24:15 +00:00
|
|
|
return image ? image->getWidth() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-15 11:08:46 +00:00
|
|
|
Image const * PreviewImage::image(Inset const & inset,
|
|
|
|
BufferView const & bv) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2002-07-15 11:08:46 +00:00
|
|
|
return pimpl_->image(inset, bv);
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
|
|
|
|
string const & s,
|
|
|
|
string const & bf,
|
|
|
|
double af)
|
2002-07-15 11:08:46 +00:00
|
|
|
: parent_(p), ploader_(l), iloader_(bf),
|
2002-07-05 21:24:15 +00:00
|
|
|
snippet_(s), ascent_frac_(af)
|
2002-07-15 11:08:46 +00:00
|
|
|
{
|
|
|
|
iloader_.statusChanged.connect(
|
|
|
|
boost::bind(&Impl::statusChanged, this));
|
|
|
|
}
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
|
2002-07-06 12:38:44 +00:00
|
|
|
PreviewImage::Impl::~Impl()
|
|
|
|
{
|
2002-07-15 11:08:46 +00:00
|
|
|
lyx::unlink(iloader_.filename());
|
2002-07-06 12:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-15 11:08:46 +00:00
|
|
|
Image const * PreviewImage::Impl::image(Inset const & inset,
|
|
|
|
BufferView const & bv)
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2002-07-15 11:08:46 +00:00
|
|
|
if (iloader_.status() == WaitingToLoad)
|
|
|
|
iloader_.startLoading(inset, bv);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-15 11:08:46 +00:00
|
|
|
return iloader_.image();
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PreviewImage::Impl::statusChanged()
|
|
|
|
{
|
2002-07-15 11:08:46 +00:00
|
|
|
switch (iloader_.status()) {
|
2002-07-05 21:24:15 +00:00
|
|
|
case WaitingToLoad:
|
|
|
|
case Loading:
|
|
|
|
case Converting:
|
|
|
|
case Loaded:
|
|
|
|
case ScalingEtc:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ErrorNoFile:
|
|
|
|
case ErrorConverting:
|
|
|
|
case ErrorLoading:
|
|
|
|
case ErrorGeneratingPixmap:
|
|
|
|
case ErrorUnknown:
|
2002-07-15 11:08:46 +00:00
|
|
|
//lyx::unlink(iloader_.filename());
|
2002-07-05 21:24:15 +00:00
|
|
|
ploader_.remove(snippet_);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Ready:
|
2002-07-15 11:08:46 +00:00
|
|
|
lyx::unlink(iloader_.filename());
|
2002-07-05 21:24:15 +00:00
|
|
|
ploader_.imageReady(parent_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace grfx
|