]> git.lyx.org Git - features.git/commitdiff
Basic Qt image loader support, clipboard support
authorJohn Levon <levon@movementarian.org>
Fri, 12 Jul 2002 01:48:53 +0000 (01:48 +0000)
committerJohn Levon <levon@movementarian.org>
Fri, 12 Jul 2002 01:48:53 +0000 (01:48 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4609 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/Makefile.am
src/frontends/qt2/QLImage.C [new file with mode: 0644]
src/frontends/qt2/QLImage.h [new file with mode: 0644]
src/frontends/qt2/QLPainter.C
src/frontends/qt2/QWorkArea.C
src/frontends/qt2/TODO
src/frontends/qt2/lyx_gui.C
src/frontends/qt2/xforms/Makefile.am

index de5608ec1a8604a7ee649adb482069a9f987f8f0..8f74431df9754d6ae59f6b3ab1d2b71204494220 100644 (file)
@@ -1,3 +1,15 @@
+2002-07-12  John Levon  <moz@compsoc.man.ac.uk>
+
+       * Makefile.am:
+       * QLImage.h:
+       * QLImage.C: initial image loader
+
+       * lyx_gui.C: initialise graphics
+
+       * QLPainter.C: draw images
+
+       * QWorkArea.C: implement clipboard as much as possible
 2002-07-11  John Levon  <moz@compsoc.man.ac.uk>
 
        * dialog files: add unused Dialogs paramater to allow compile
index 3176b191e2cda4b9395ec1ba3290c0d872c509ca..d3099353d09a335693d454412d3a635fbc7be40a 100644 (file)
@@ -32,6 +32,8 @@ libqt2_la_SOURCES = \
        Toolbar_pimpl.h \
        QContentPane.C \
        QContentPane.h \
+       QLImage.C \
+       QLImage.h \
        QLPainter.C \
        QLPainter.h \
        QLyXKeySym.C \
diff --git a/src/frontends/qt2/QLImage.C b/src/frontends/qt2/QLImage.C
new file mode 100644 (file)
index 0000000..124beb8
--- /dev/null
@@ -0,0 +1,258 @@
+/*
+ * \file QLImage.C
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author John Levon <moz@compsoc.man.ac.uk>
+ */
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "QLImage.h"
+#include "graphics/GraphicsParams.h"
+#include "converter.h"
+#include "debug.h"
+#include "support/LAssert.h"
+#include "support/lyxfunctional.h"  // compare_memfun
+
+#include <qimage.h>
+#include <qwmatrix.h>
+#include <qpainter.h>
+
+#include <boost/tuple/tuple.hpp>
+
+using std::find_if;
+
+namespace grfx {
+
+/// Access to this class is through this static method.
+Image::ImagePtr QLImage::newImage()
+{
+       ImagePtr ptr;
+       ptr.reset(new QLImage);
+       return ptr;
+}
+
+
+/// Return the list of loadable formats.
+Image::FormatList QLImage::loadableFormats()
+{
+       static FormatList fmts;
+       if (!fmts.empty())
+               return fmts;
+
+       // The formats recognised by LyX
+       Formats::const_iterator begin = formats.begin();
+       Formats::const_iterator end   = formats.end();
+
+       lyxerr[Debug::GRAPHICS]
+               << "\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";
+
+               Formats::const_iterator fit =
+                       find_if(begin, end, lyx::compare_memfun(&Format::extension, ext));
+               if (fit != end)
+                       fmts.push_back(fit->name());
+       }
+
+       lyxerr[Debug::GRAPHICS]
+               << "\nOf these, LyX recognises the following formats:\n";
+
+       FormatList::const_iterator fbegin = fmts.begin();
+       FormatList::const_iterator fend   = fmts.end();
+       for (FormatList::const_iterator fit = fbegin; fit != fend; ++fit) {
+               if (fit != fbegin)
+                       lyxerr[Debug::GRAPHICS] << ", ";
+               lyxerr[Debug::GRAPHICS] << *fit;
+       }
+       lyxerr[Debug::GRAPHICS] << '\n' << std::endl;
+
+       return fmts;
+}
+
+
+QLImage::QLImage()
+       : Image()
+{
+}
+
+
+QLImage::QLImage(QLImage const & other)
+       : Image(other), pixmap_(other.pixmap_)
+{
+}
+
+
+QLImage::~QLImage()
+{
+}
+
+
+Image * QLImage::clone() const
+{
+       return new QLImage(*this);
+}
+
+
+unsigned int QLImage::getWidth() const
+{
+       return pixmap_.width();
+}
+
+
+unsigned int QLImage::getHeight() const
+{
+       return pixmap_.height();
+}
+
+
+// FIXME 
+Pixmap QLImage::getPixmap() const
+{
+       return 1;
+}
+
+
+void QLImage::load(string const & filename)
+{
+       if (!pixmap_.isNull()) {
+               lyxerr[Debug::GRAPHICS]
+                       << "Image is loaded already!" << std::endl;
+               finishedLoading(false);
+               return;
+       }
+
+       if (!pixmap_.load(filename.c_str())) {
+               lyxerr[Debug::GRAPHICS]
+                       << "Unable to open image" << std::endl;
+               finishedLoading(false);
+               return;
+       }
+       finishedLoading(true); 
+}
+
+
+bool QLImage::setPixmap(Params const & params)
+{
+       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;
+       }
+
+       if (color_key != FL_IMAGE_RGB) {
+               flimage_convert(image_, color_key, 0);
+       }
+
+       unsigned int fill = packedcolor(LColor::graphicsbg);
+       if (fill != image_->fill_color) {
+               // the background color has changed.
+               // Note that in grayscale/monochrome images the background is
+               // grayed also, so this call will have no visible effect. Sorry!
+               flimage_replace_pixel(image_, image_->fill_color, fill);
+               image_->fill_color = fill;
+       }
+#endif 
+
+       xformed_pixmap_ = pixmap_;
+       return true;
+}
+
+
+void QLImage::clip(Params const & params)
+{
+       if (pixmap_.isNull())
+               return;
+
+       if (params.bb.empty())
+               // No clipping is necessary.
+               return;
+
+       int const new_width  = params.bb.xr - params.bb.xl;
+       int const new_height = params.bb.yt - params.bb.yb;
+
+       // 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()) {
+               // Bounds are invalid.
+               return;
+       }
+
+       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);
+
+       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();
+}
+
+
+void QLImage::rotate(Params const & params)
+{
+       if (xformed_pixmap_.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 / 10.0);
+       xformed_pixmap_.xForm(m);
+}
+
+
+void QLImage::scale(Params const & params)
+{
+       if (xformed_pixmap_.isNull())
+               return;
+
+       unsigned int width;
+       unsigned int height;
+       boost::tie(width, height) = getScaledDimensions(params);
+
+       if (width == getWidth() && height == getHeight())
+               return;
+
+       xformed_pixmap_.resize(width, height);
+}
+
+} // namespace grfx
diff --git a/src/frontends/qt2/QLImage.h b/src/frontends/qt2/QLImage.h
new file mode 100644 (file)
index 0000000..ec30c35
--- /dev/null
@@ -0,0 +1,88 @@
+// -*- C++ -*-
+/**
+ * \file QLImage.h
+ * Copyright 2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author John Levon <moz@compsoc.man.ac.uk>
+ */
+
+#ifndef QLIMAGE_H
+#define QLIMAGE_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "graphics/GraphicsImage.h"
+#include <qpixmap.h>
+namespace grfx {
+
+class QLImage : public Image
+{
+public:
+       /// Access to this class is through this static method.
+       static ImagePtr newImage();
+
+       /// Return the list of loadable formats.
+       static FormatList loadableFormats();
+
+       ~QLImage();
+
+       /// Create a copy
+       virtual Image * clone() const;
+
+       /// FIXME
+       virtual Pixmap getPixmap() const;
+
+       QPixmap const & qpixmap() const { return xformed_pixmap_; }
+
+       /// Get the image width
+       virtual unsigned int getWidth() const;
+
+       /// Get the image height
+       virtual unsigned int getHeight() const;
+
+       /** 
+        * Load the image file into memory.
+        * The process is asynchronous, so this method starts the loading.
+        * When finished, the Image::finishedLoading signal is emitted.
+        */
+       virtual void load(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.
+        */
+       virtual bool setPixmap(Params const & params);
+
+       /// Clip the image using params.
+       virtual void clip(Params const & params);
+
+       /// Rotate the image using params.
+       virtual void rotate(Params const & params);
+
+       /// Scale the image using params.
+       virtual void scale(Params const & params);
+
+private:
+       /// Access to the class is through newImage() and clone.
+       QLImage();
+       ///
+       QLImage(QLImage const &);
+
+       /// the original loaded image
+       QPixmap pixmap_;
+
+       /// the transformed pixmap for display
+       QPixmap xformed_pixmap_;
+};
+
+} // namespace grfx
+
+#endif // QLIMAGE_H
index d8faacf94295d5d07a80e43544fb3d1ee84b0551..999b5794cb66fc456dc52bbe4430d01b2ae763d3 100644 (file)
@@ -13,8 +13,8 @@
 #endif
 
 #include <iostream>
+#include <boost/scoped_array.hpp>
  
-//#include "graphics/GraphicsImage.h"
 #include "font_metrics.h"
 #include "support/lstrings.h" 
 #include "lyxrc.h"
 #include "QWorkArea.h"
 #include "qfont_loader.h"
 #include "QLPainter.h"
+#include "QLImage.h"
  
 #include <qpainter.h>
 #include <qbrush.h> 
 #include <qcolor.h>
 
-#include <boost/scoped_array.hpp>
-
 using std::endl;
 
 QLPainter::QLPainter(QWorkArea & qwa)
@@ -184,19 +183,11 @@ Painter & QLPainter::arc(int x, int y,
 }
 
  
-Painter & QLPainter::image(int , int 
-       int , int ,
-       grfx::Image const & )
+Painter & QLPainter::image(int x, int y
+       int w, int h,
+       grfx::Image const & i)
 {
-#if 0 // FIXME
-       XGCValues val;
-       val.function = GXcopy;
-       GC gc = XCreateGC(display(), owner_.getPixmap(),
-               GCFunction, &val);
-       XCopyArea(display(), image.getPixmap(), owner_.getPixmap(), 
-               gc, 0, 0, w, h, x, y);
-       XFreeGC(display(), gc);
-#endif
+       qp_->drawPixmap(x, y, static_cast<grfx::QLImage const &>(i).qpixmap(), 0, 0, w, h);
        return *this;
 }
 
index 028e72fe730845585c77e04054c2763fa19feb69..b14372c1c0f4e81f8830c31848fa5acd80d2ee0a 100644 (file)
@@ -31,6 +31,7 @@
 #include <qpainter.h>
 #include <qmainwindow.h>
 #include <qlayout.h>
+#include <qclipboard.h>
  
 using std::endl;
 using std::abs;
@@ -77,20 +78,22 @@ void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
 }
 
 
-void QWorkArea::haveSelection(bool ) const
+void QWorkArea::haveSelection(bool) const
 {
-       // FIXME 
+       // not possible in Qt !
 }
 
  
 string const QWorkArea::getClipboard() const 
 {
-       // FIXME 
-       return "nothing"; 
+       QString str = QApplication::clipboard()->text(); 
+       if (str.isNull())
+               return string();
+       return str.latin1();
 }
 
        
-void QWorkArea::putClipboard(string const &) const
+void QWorkArea::putClipboard(string const & str) const
 {
-       // FIXME
+       QApplication::clipboard()->setText(str.c_str());
 }
index 757aba73479b2718174fe174e9c8659db40b1fd3..0c6d6d18063c07104d8952c4a7f235c44993e97a 100644 (file)
@@ -14,7 +14,7 @@ FileDialog
  
 GraphicsImage
 
-       - remove X dependencies here (?) (*)
+       - remove getPixmap() 
  
 LyXServer
 
@@ -24,7 +24,6 @@ lyx_gui (qt)
 
        - move out lyxserver
        - do dpi
-       - initialise graphics
  
 Menubar_pimpl
 
@@ -85,11 +84,18 @@ qlkey
 
        - finish off the lists
  
+QLImage
+
+       - get jpeg etc. to work
+       - get rotation etc. to work
+       - get mono/color to work
+       - get bgcolor and clipping to work 
+
 QLPainter
 
        - work out why buttons look ugly and fix
        - check ::arc() works
-       - implement ::image + image loader grfx stuff etc. (*)(*)
 
 QLyXKeySym
 
@@ -103,7 +109,7 @@ QMiniBuffer
 
 QParagraph
 
-       - implement me (MVCed already) (*)
+       - implement me (MVCed already) (*) [Edwin is working on this]
 
 QPreferences
 
@@ -129,10 +135,6 @@ QTexinfo
 
        - fix "View" when path not shown
 
-QWorkArea
-
-       - clipboard code missing
-
 QtView
 
        - decide what to do about prohibit/allowInput 
index e5700a12de63b5decabc5358790c630b4a5b6f92..e8a7e766becff4d6c65319e7b0b5f7a00bb58339 100644 (file)
@@ -9,28 +9,33 @@
 
 #include <config.h>
  
-#include "lyx_gui.h"
 #include "support/lyxlib.h"
 #include "support/os.h"
 #include "support/filetools.h"
 #include "debug.h"
 #include "gettext.h"
  
+#include <fcntl.h>
+#include <boost/bind.hpp>
+#include "lyx_gui.h"
 #include "lyx_main.h"
 #include "lyxrc.h"
-
 // FIXME: move this stuff out again
 #include "bufferlist.h"
 #include "lyxfunc.h"
 #include "lyxserver.h"
 #include "BufferView.h"
-#include "QtView.h"
-#include <fcntl.h>
 
-#include <boost/bind.hpp>
+// Dear Lord, deliver us from Evil,
+// aka the Qt headers
+#include <boost/shared_ptr.hpp>
+#include <boost/function/function0.hpp>
+#include <boost/signals/signal1.hpp>
+#include "QtView.h"
+#include "QLImage.h"
  
 #include <qapplication.h>
  
@@ -109,7 +114,10 @@ void lyx_gui::start(string const & batch, vector<string> files)
  
 void lyx_gui::init_graphics()
 {
-       // FIXME
+       using namespace grfx;
+
+       Image::newImage = boost::bind(&QLImage::newImage);
+       Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
 }
 
 
index 9a53422398248836ee71a5c64fad4555930bac7a..4acca16703e5b9212b4b738d69388a41386e83b7 100644 (file)
@@ -7,11 +7,6 @@ INCLUDES = -I$(top_srcdir)/src/ -I$(top_srcdir)/src/frontends/ \
        $(FRONTEND_INCLUDES) $(BOOST_INCLUDES) \
        -I$(top_srcdir)/src/frontends/controllers
 
-if USE_BASIC_IMAGE_LOADER
-else
-XFORMSIMAGE = xformsImage.C xformsImage.h
-endif
-
 nodist_libqt2xforms_la_SOURCES = \
        Color.h \
        Color.C \
@@ -19,7 +14,6 @@ nodist_libqt2xforms_la_SOURCES = \
        DropDown.C \
        Tooltips.h \
        Tooltips.C \
-       $(XFORMSIMAGE) \
        xforms_helpers.h \
        xforms_helpers.C