X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fgraphics%2FPreviewImage.C;h=75d41634ced7a43394d54dc6f2bf9d2fccf2633e;hb=005545f28100fd30afa22313d6e3b1b67aa9a857;hp=8f90b203799a1115383b06eb2e6ff6a8374acb75;hpb=f68a2bfb915bf590b9dd11061750b7922e5c1deb;p=lyx.git diff --git a/src/graphics/PreviewImage.C b/src/graphics/PreviewImage.C index 8f90b20379..75d41634ce 100644 --- a/src/graphics/PreviewImage.C +++ b/src/graphics/PreviewImage.C @@ -1,40 +1,40 @@ /** - * \file PreviewImage.C - * Copyright 2002 the LyX Team - * Read the file COPYING + * \file PreviewImage.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * \author Angus Leeming + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS. */ #include -#ifdef __GNUG__ -#pragma implementation -#endif - #include "PreviewImage.h" -#include "PreviewLoader.h" #include "GraphicsImage.h" #include "GraphicsLoader.h" - -#include "debug.h" +#include "PreviewLoader.h" #include "support/lyxlib.h" #include -#include +namespace support = lyx::support; -namespace grfx { +using std::string; + + +namespace lyx { +namespace graphics { struct PreviewImage::Impl : public boost::signals::trackable { /// Impl(PreviewImage & p, PreviewLoader & l, string const & s, string const & f, double af); /// - void startLoading(); + ~Impl(); /// - Image const * image() const { return iloader_->image(); } + Image const * image(); /// void statusChanged(); @@ -43,7 +43,7 @@ struct PreviewImage::Impl : public boost::signals::trackable { /// PreviewLoader & ploader_; /// - boost::scoped_ptr const iloader_; + Loader iloader_; /// string const snippet_; /// @@ -63,20 +63,15 @@ PreviewImage::~PreviewImage() {} -void PreviewImage::startLoading() -{ - return pimpl_->startLoading(); -} - - string const & PreviewImage::snippet() const { return pimpl_->snippet_; } + int PreviewImage::ascent() const { - Image const * const image = pimpl_->image(); + Image const * const image = pimpl_->iloader_.image(); if (!image) return 0; @@ -86,17 +81,18 @@ int PreviewImage::ascent() const int PreviewImage::descent() const { - Image const * const image = pimpl_->image(); + Image const * const image = pimpl_->iloader_.image(); if (!image) return 0; - return int((1.0 - pimpl_->ascent_frac_) * double(image->getHeight())); + // Avoids rounding errors. + return image->getHeight() - ascent(); } int PreviewImage::width() const { - Image const * const image = pimpl_->image(); + Image const * const image = pimpl_->iloader_.image(); return image ? image->getWidth() : 0; } @@ -111,25 +107,31 @@ PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l, string const & s, string const & bf, double af) - : parent_(p), ploader_(l), iloader_(new Loader(bf)), + : parent_(p), ploader_(l), iloader_(bf), snippet_(s), ascent_frac_(af) -{} +{ + iloader_.connect(boost::bind(&Impl::statusChanged, this)); +} + + +PreviewImage::Impl::~Impl() +{ + support::unlink(iloader_.filename()); +} -void PreviewImage::Impl::startLoading() +Image const * PreviewImage::Impl::image() { - if (iloader_->status() != WaitingToLoad) - return; + if (iloader_.status() == WaitingToLoad) + iloader_.startLoading(); - iloader_->statusChanged.connect( - boost::bind(&Impl::statusChanged, this)); - iloader_->startLoading(); + return iloader_.image(); } void PreviewImage::Impl::statusChanged() { - switch (iloader_->status()) { + switch (iloader_.status()) { case WaitingToLoad: case Loading: case Converting: @@ -142,15 +144,16 @@ void PreviewImage::Impl::statusChanged() case ErrorLoading: case ErrorGeneratingPixmap: case ErrorUnknown: - //lyx::unlink(iloader_->filename()); + //lyx::unlink(iloader_.filename()); ploader_.remove(snippet_); break; case Ready: - lyx::unlink(iloader_->filename()); - ploader_.imageReady(parent_); + support::unlink(iloader_.filename()); break; } + ploader_.emitSignal(parent_); } -} // namespace grfx +} // namespace graphics +} // namespace lyx