mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-20 15:01:58 +00:00
Basic Qt image loader support, clipboard support
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4609 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
909a631592
commit
f6587aecad
@ -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
|
||||
|
@ -32,6 +32,8 @@ libqt2_la_SOURCES = \
|
||||
Toolbar_pimpl.h \
|
||||
QContentPane.C \
|
||||
QContentPane.h \
|
||||
QLImage.C \
|
||||
QLImage.h \
|
||||
QLPainter.C \
|
||||
QLPainter.h \
|
||||
QLyXKeySym.C \
|
||||
|
258
src/frontends/qt2/QLImage.C
Normal file
258
src/frontends/qt2/QLImage.C
Normal file
@ -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
|
88
src/frontends/qt2/QLImage.h
Normal file
88
src/frontends/qt2/QLImage.h
Normal file
@ -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
|
@ -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"
|
||||
@ -24,13 +24,12 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user