From: John Levon Date: Fri, 12 Jul 2002 01:48:53 +0000 (+0000) Subject: Basic Qt image loader support, clipboard support X-Git-Tag: 1.6.10~18898 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f6587aecad0693e82cc7e85f300d794641806e7c;p=features.git Basic Qt image loader support, clipboard support git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4609 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index de5608ec1a..8f74431df9 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,15 @@ +2002-07-12 John Levon + + * 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 * dialog files: add unused Dialogs paramater to allow compile diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 3176b191e2..d3099353d0 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -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 index 0000000000..124beb80b6 --- /dev/null +++ b/src/frontends/qt2/QLImage.C @@ -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 + */ + +#include + +#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 +#include +#include + +#include + +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 index 0000000000..ec30c356a5 --- /dev/null +++ b/src/frontends/qt2/QLImage.h @@ -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 + */ + +#ifndef QLIMAGE_H +#define QLIMAGE_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "graphics/GraphicsImage.h" + +#include + +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 diff --git a/src/frontends/qt2/QLPainter.C b/src/frontends/qt2/QLPainter.C index d8faacf942..999b5794cb 100644 --- a/src/frontends/qt2/QLPainter.C +++ b/src/frontends/qt2/QLPainter.C @@ -13,8 +13,8 @@ #endif #include +#include -//#include "graphics/GraphicsImage.h" #include "font_metrics.h" #include "support/lstrings.h" #include "lyxrc.h" @@ -24,13 +24,12 @@ #include "QWorkArea.h" #include "qfont_loader.h" #include "QLPainter.h" +#include "QLImage.h" #include #include #include -#include - 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(i).qpixmap(), 0, 0, w, h); return *this; } diff --git a/src/frontends/qt2/QWorkArea.C b/src/frontends/qt2/QWorkArea.C index 028e72fe73..b14372c1c0 100644 --- a/src/frontends/qt2/QWorkArea.C +++ b/src/frontends/qt2/QWorkArea.C @@ -31,6 +31,7 @@ #include #include #include +#include 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()); } diff --git a/src/frontends/qt2/TODO b/src/frontends/qt2/TODO index 757aba7347..0c6d6d1806 100644 --- a/src/frontends/qt2/TODO +++ b/src/frontends/qt2/TODO @@ -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 diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index e5700a12de..e8a7e766be 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -9,28 +9,33 @@ #include -#include "lyx_gui.h" - #include "support/lyxlib.h" #include "support/os.h" #include "support/filetools.h" - #include "debug.h" #include "gettext.h" +#include +#include + +#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 -#include +// Dear Lord, deliver us from Evil, +// aka the Qt headers +#include +#include +#include + +#include "QtView.h" +#include "QLImage.h" #include @@ -109,7 +114,10 @@ void lyx_gui::start(string const & batch, vector files) void lyx_gui::init_graphics() { - // FIXME + using namespace grfx; + + Image::newImage = boost::bind(&QLImage::newImage); + Image::loadableFormats = boost::bind(&QLImage::loadableFormats); } diff --git a/src/frontends/qt2/xforms/Makefile.am b/src/frontends/qt2/xforms/Makefile.am index 9a53422398..4acca16703 100644 --- a/src/frontends/qt2/xforms/Makefile.am +++ b/src/frontends/qt2/xforms/Makefile.am @@ -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