QLImage::QLImage(QLImage const & other)
- : Image(other), pixmap_(other.pixmap_),
- xformed_pixmap_(other.pixmap_)
-{
-}
+ : Image(other), original_(other.original_),
+ transformed_(other.original_)
+{}
QLImage::~QLImage()
unsigned int QLImage::getWidth_impl() const
{
- return xformed_pixmap_.width();
+ return transformed_.width();
}
unsigned int QLImage::getHeight_impl() const
{
- return xformed_pixmap_.height();
+ return transformed_.height();
}
void QLImage::load_impl(string const & filename)
{
- if (!pixmap_.isNull()) {
+ if (!original_.isNull()) {
lyxerr[Debug::GRAPHICS]
<< "Image is loaded already!" << endl;
finishedLoading(false);
return;
}
- if (!pixmap_.load(toqstr(filename))) {
+ if (!original_.load(toqstr(filename))) {
lyxerr[Debug::GRAPHICS]
<< "Unable to open image" << endl;
finishedLoading(false);
return;
}
- xformed_pixmap_ = pixmap_;
+ transformed_ = original_;
finishedLoading(true);
}
bool QLImage::setPixmap_impl(Params const & params)
{
- if (pixmap_.isNull() || params.display == NoDisplay)
+ if (original_.isNull() || params.display == NoDisplay)
return false;
switch (params.display) {
case GrayscaleDisplay: {
- QImage i(xformed_pixmap_.convertToImage());
- xformed_pixmap_.convertFromImage(toGray(i));
+ toGray(transformed_);
break;
}
case MonochromeDisplay: {
- QImage i(xformed_pixmap_.convertToImage());
- xformed_pixmap_.convertFromImage(i, QPixmap::Mono);
- break;
- }
+ transformed_.convertDepth(transformed_.depth(), Qt::MonoOnly);
+ break;
+ }
- default:
- break;
+ default:
+ break;
}
return true;
void QLImage::clip_impl(Params const & params)
{
- if (xformed_pixmap_.isNull())
+ if (transformed_.isNull())
return;
if (params.bb.empty())
// No need to check if the width, height are > 0 because the
// Bounding Box would be empty() in this case.
- if (new_width > pixmap_.width() || new_height > pixmap_.height()) {
+ if (new_width > original_.width() || new_height > original_.height()) {
// Bounds are invalid.
return;
}
- if (new_width == pixmap_.width() && new_height == pixmap_.height())
+ if (new_width == original_.width() && new_height == original_.height())
return;
int const xoffset_l = params.bb.xl;
- int const yoffset_t = (pixmap_.height() > int(params.bb.yt) ?
- pixmap_.height() - params.bb.yt : 0);
-
- xformed_pixmap_.resize(new_width, new_height);
- QPainter p;
- p.begin(&xformed_pixmap_);
- p.drawPixmap(0, 0, pixmap_, xoffset_l, yoffset_t, new_width, new_height);
- p.end();
+ int const yoffset_t = (original_.height() > int(params.bb.yt) ?
+ original_.height() - params.bb.yt : 0);
+
+ transformed_ = original_.copy(xoffset_l, yoffset_t,
+ new_width, new_height);
}
void QLImage::rotate_impl(Params const & params)
{
- if (xformed_pixmap_.isNull())
+ if (transformed_.isNull())
return;
if (!params.angle)
return;
- // The angle passed to flimage_rotate is the angle in one-tenth of a
- // degree units.
-
QWMatrix m;
m.rotate(-params.angle);
- xformed_pixmap_ = xformed_pixmap_.xForm(m);
+
+ transformed_.setAlphaBuffer(true);
+ transformed_ = transformed_.xForm(m);
}
void QLImage::scale_impl(Params const & params)
{
- if (xformed_pixmap_.isNull())
+ if (transformed_.isNull())
return;
unsigned int width;
QWMatrix m;
m.scale(double(width) / getWidth(), double(height) / getHeight());
- xformed_pixmap_ = xformed_pixmap_.xForm(m);
+ transformed_ = transformed_.xForm(m);
}
} // namespace graphics
#include "graphics/GraphicsImage.h"
-#include <qpixmap.h>
+#include <qimage.h>
namespace lyx {
namespace graphics {
static FormatList loadableFormats();
~QLImage();
- QPixmap const & qpixmap() const { return xformed_pixmap_; }
+ QImage const & qimage() const { return transformed_; }
private:
/// Create a copy
*/
virtual void load_impl(std::string const & filename);
/**
- * Generate the pixmap, based on the current state of
- * image_ (clipped, rotated, scaled etc).
- * Uses the params to decide on color, grayscale etc.
- * Returns true if the pixmap is created.
+ * Finishes the process of modifying transformed_, using
+ * \c params to decide on color, grayscale etc.
+ * \returns true if successful.
*/
virtual bool setPixmap_impl(Params const & params);
/// Clip the image using params.
///
QLImage(QLImage const &);
- /// the original loaded image
- QPixmap pixmap_;
+ /// The original loaded image.
+ QImage original_;
- /// the transformed pixmap for display
- QPixmap xformed_pixmap_;
+ /// The transformed image for display.
+ QImage transformed_;
};
} // namespace graphics