]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QLImage.C
better selection and scrolling behaviour
[lyx.git] / src / frontends / qt2 / QLImage.C
index 7ff7a00f62365a1f41822932d6c19dcfafa8bed4..1d70b20ea67066e1351284be0366cc0192f46892 100644 (file)
@@ -1,10 +1,12 @@
-/*
+/**
  * \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>
@@ -44,7 +46,7 @@ Image::ImagePtr QLImage::newImage()
 Image::FormatList QLImage::loadableFormats()
 {
        static FormatList fmts;
+
        if (!fmts.empty())
                return fmts;
 
@@ -56,14 +58,14 @@ Image::FormatList QLImage::loadableFormats()
                << "\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() << endl;
 
                string ext = lowercase(it.current());
-        
+
                // special case
                if (ext == "jpeg")
                        ext = "jpg";
@@ -97,7 +99,8 @@ QLImage::QLImage()
 
 
 QLImage::QLImage(QLImage const & other)
-       : Image(other), pixmap_(other.pixmap_), xformed_pixmap_(other.xformed_pixmap_)
+       : Image(other), pixmap_(other.pixmap_),
+         xformed_pixmap_(other.xformed_pixmap_)
 {
 }
 
@@ -140,11 +143,11 @@ void QLImage::load(string const & filename)
                finishedLoading(false);
                return;
        }
-       lyxerr[Debug::GRAPHICS] << "just Loaded." << endl; 
+       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); 
+       finishedLoading(true);
 }
 
 
@@ -156,27 +159,22 @@ bool QLImage::setPixmap(Params const & params)
                return false;
 
        lyxerr[Debug::GRAPHICS] << "setPixmap()" << endl;
-// 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;
-       }
 
-       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.
@@ -185,7 +183,7 @@ bool QLImage::setPixmap(Params const & params)
                flimage_replace_pixel(image_, image_->fill_color, fill);
                image_->fill_color = fill;
        }
-#endif 
+#endif
 
        return true;
 }
@@ -193,7 +191,6 @@ bool QLImage::setPixmap(Params const & params)
 
 void QLImage::clip(Params const & params)
 {
-       lyxerr << "clip isNull " << pixmap_.isNull() << ", " <<xformed_pixmap_.isNull() << endl; 
        if (xformed_pixmap_.isNull())
                return;
 
@@ -214,8 +211,9 @@ void QLImage::clip(Params const & params)
        if (new_width == pixmap_.width() && new_height == pixmap_.height())
                return;
 
-       int const xoffset_l = std::max(0, int(params.bb.xl));
-       int const yoffset_t = std::max(0, pixmap_.height() - int(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;
@@ -227,7 +225,6 @@ void QLImage::clip(Params const & params)
 
 void QLImage::rotate(Params const & params)
 {
-       lyxerr << "rotate isNull " << pixmap_.isNull() << ", " <<xformed_pixmap_.isNull() << endl; 
        if (xformed_pixmap_.isNull())
                return;
 
@@ -238,7 +235,7 @@ void QLImage::rotate(Params const & params)
        // degree units.
 
        lyxerr[Debug::GRAPHICS] << "rotating image by " << params.angle << " degrees" << endl;
+
        QWMatrix m;
        m.rotate(-params.angle);
        xformed_pixmap_ = xformed_pixmap_.xForm(m);
@@ -247,7 +244,6 @@ void QLImage::rotate(Params const & params)
 
 void QLImage::scale(Params const & params)
 {
-       lyxerr << "scale isNull " << pixmap_.isNull() << ", " <<xformed_pixmap_.isNull() << endl; 
        if (xformed_pixmap_.isNull())
                return;
 
@@ -258,9 +254,10 @@ void QLImage::scale(Params const & params)
        if (width == getWidth() && height == getHeight())
                return;
 
-       lyxerr[Debug::GRAPHICS] << "resizing image to " << width << "(" <<
-               (double(width)/getWidth()) << ")," << height << "(" <<
-               (double(height)/getHeight()) << ")" << endl;
+       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);