-/*
+/**
* \file QLImage.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author Angus Leeming, a.leeming@ic.ac.uk
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author Angus Leeming
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
Image::FormatList QLImage::loadableFormats()
{
static FormatList fmts;
-
+
if (!fmts.empty())
return fmts;
<< "\nThe image loader can load the following directly:\n";
QStrList qt_formats = QImageIO::inputFormats();
-
+
QStrListIterator it(qt_formats);
for (; it.current(); ++it) {
- lyxerr[Debug::GRAPHICS] << it.current() << std::endl;
+ lyxerr[Debug::GRAPHICS] << it.current() << endl;
string ext = lowercase(it.current());
-
+
// special case
if (ext == "jpeg")
ext = "jpg";
lyxerr[Debug::GRAPHICS] << ", ";
lyxerr[Debug::GRAPHICS] << *fit;
}
- lyxerr[Debug::GRAPHICS] << '\n' << std::endl;
+ lyxerr[Debug::GRAPHICS] << '\n' << endl;
return fmts;
}
QLImage::QLImage(QLImage const & other)
- : Image(other), pixmap_(other.pixmap_)
+ : Image(other), pixmap_(other.pixmap_),
+ xformed_pixmap_(other.xformed_pixmap_)
{
}
unsigned int QLImage::getWidth() const
{
- return pixmap_.width();
+ return xformed_pixmap_.width();
}
unsigned int QLImage::getHeight() const
{
- return pixmap_.height();
+ return xformed_pixmap_.height();
}
{
if (!pixmap_.isNull()) {
lyxerr[Debug::GRAPHICS]
- << "Image is loaded already!" << std::endl;
+ << "Image is loaded already!" << endl;
finishedLoading(false);
return;
}
if (!pixmap_.load(filename.c_str())) {
lyxerr[Debug::GRAPHICS]
- << "Unable to open image" << std::endl;
+ << "Unable to open image" << endl;
finishedLoading(false);
return;
}
- finishedLoading(true);
+ lyxerr[Debug::GRAPHICS] << "just Loaded." << endl;
+ xformed_pixmap_ = pixmap_;
+ lyxerr[Debug::GRAPHICS] << "pixmap isNull " << pixmap_.isNull()
+ << " xformed_pixmap_ isNull " << xformed_pixmap_.isNull() << endl;
+ finishedLoading(true);
}
bool QLImage::setPixmap(Params const & params)
{
+ lyxerr[Debug::GRAPHICS] << "pixmap isNull " << pixmap_.isNull()
+ << " xformed_pixmap_ isNull " << xformed_pixmap_.isNull() << endl;
if (pixmap_.isNull() || params.display == NoDisplay)
return false;
-// FIXME
-#if 0
- int color_key;
- switch (params.display) {
- case MonochromeDisplay:
- color_key = FL_IMAGE_MONO;
- break;
- case GrayscaleDisplay:
- color_key = FL_IMAGE_GRAY;
- break;
- case ColorDisplay:
- default: // NoDisplay cannot happen!
- color_key = FL_IMAGE_RGB;
- break;
- }
+ lyxerr[Debug::GRAPHICS] << "setPixmap()" << endl;
- if (color_key != FL_IMAGE_RGB) {
- flimage_convert(image_, color_key, 0);
- }
+ // FIXME: it's a fake kind of grayscale !
+ switch (params.display) {
+ case GrayscaleDisplay:
+ case MonochromeDisplay: {
+ QImage i(xformed_pixmap_.convertToImage());
+ xformed_pixmap_.convertFromImage(i, QPixmap::Mono);
+ break;
+ }
+
+ default:
+ break;
+ }
+// FIXME
+#if 0
unsigned int fill = packedcolor(LColor::graphicsbg);
if (fill != image_->fill_color) {
// the background color has changed.
flimage_replace_pixel(image_, image_->fill_color, fill);
image_->fill_color = fill;
}
-#endif
+#endif
- xformed_pixmap_ = pixmap_;
return true;
}
void QLImage::clip(Params const & params)
{
- if (pixmap_.isNull())
+ if (xformed_pixmap_.isNull())
return;
if (params.bb.empty())
if (new_width == pixmap_.width() && new_height == pixmap_.height())
return;
- int const xoffset_l = std::max(0, params.bb.xl);
- int const yoffset_t = std::max(0, pixmap_.height() - params.bb.yt);
+ int const xoffset_l = params.bb.xl;
+ int const yoffset_t = (pixmap_.height() > params.bb.yt ?
+ pixmap_.height() - params.bb.yt : 0);
xformed_pixmap_.resize(new_width, new_height);
QPainter p;
// The angle passed to flimage_rotate is the angle in one-tenth of a
// degree units.
+ lyxerr[Debug::GRAPHICS] << "rotating image by " << params.angle << " degrees" << endl;
+
QWMatrix m;
- m.rotate(params.angle / 10.0);
- xformed_pixmap_.xForm(m);
+ m.rotate(-params.angle);
+ xformed_pixmap_ = xformed_pixmap_.xForm(m);
}
if (width == getWidth() && height == getHeight())
return;
- xformed_pixmap_.resize(width, height);
+ lyxerr[Debug::GRAPHICS] << "resizing image to " << width << '('
+ << (double(width)/getWidth()) << "),"
+ << height << '('
+ << (double(height)/getHeight()) << ')' << endl;
+ QWMatrix m;
+ m.scale(double(width) / getWidth(), double(height) / getHeight());
+ xformed_pixmap_ = xformed_pixmap_.xForm(m);
}
} // namespace grfx