[prev in list] [next in list] [prev in thread] [next in thread]
List: lyx-devel
Subject: Drag-n-drop image files (QT)
From: Johnathan Burchill <jkerrb () users ! sourceforge ! net>
Date: 2005-01-28 4:34:35
Message-ID: 200501272134.42178.jkerrb () users ! sourceforge ! net
[Download RAW message or body]
Howdy,
A colleague asked me if there was anything that MS word could do well, that
LyX couldn't, and all I could think of was drag-n-dropping image files
into the document. That got me to thinking what it would take to implement
it in LyX. Here's one solution, albeit somewhat naive perhaps, as I've not
been hacking LyX for quite some time, so there may be unaccounted
side-effects.
The strategy was to build on the current drag-n-drop support, which allows
you to open a lyx file by dropping it in the main window. Now
QWorkArea::dropEvent() checks each entry in the QStringList::Iterator, and
if it represents an image file, dispatch sends an LFUN_INSET_INSERT
graphics request. If it isn't a graphics file, then dispatch requests an
LFUN_FILE_OPEN.
Then in factory.C, createInset() handles the LFUN_INSET_INSERT "graphics"
by adding the filename obtained from the dropEvent to the
InsetGraphicsParams structure before InsetGraphics::setParams() is called.
I've patched 1.3.5-qt (3.3.3) for drag-n-drop of graphics files, and it
works great. Also have a patch for 1.4.0 cvs, but it's buggy, and I'm not
sure whether it's my doing or just a result of the current state of cvs.
In 1.3.5, the image is placed at the cursor, already showing, and clipped.
But in 1.4.0, the image is always inserted at the top of the document, and
there are bizarre redraws with multiple images (e.g. some are missing
until you resize the window a certain way).
Is anyone working on dnd image support?
The 1.4.0 current cvs patch follows. Let me know if you want the patch for
1.3.5.
JB
--
Johnathan K. Burchill, Ph.D.
jkerrb@users.sourceforge.net
Patch for 1.4.0 current cvs:
Index: src/frontends/qt2/QWorkArea.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QWorkArea.h,v
retrieving revision 1.15
diff -u -3 -p -u -r1.15 QWorkArea.h
--- src/frontends/qt2/QWorkArea.h 2004/04/28 17:22:04 1.15
+++ src/frontends/qt2/QWorkArea.h 2005/01/28 04:29:20
@@ -64,6 +64,8 @@ public:
/// get the content pane widget
QWidget * getContent() const { return content_; }
private:
+ /// Test whether str is a loadable image
+ bool decodeGraphics( QString const & str );
/// scroll bar
QScrollBar * scrollbar_;
/// content
Index: src/frontends/qt2/QWorkArea.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QWorkArea.C,v
retrieving revision 1.28
diff -u -3 -p -u -r1.28 QWorkArea.C
--- src/frontends/qt2/QWorkArea.C 2004/05/20 09:36:28 1.28
+++ src/frontends/qt2/QWorkArea.C 2005/01/28 04:29:20
@@ -225,7 +225,24 @@ void QWorkArea::dropEvent(QDropEvent* ev
lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!"
<< endl;
for (QStringList::Iterator i = files.begin();
- i!=files.end(); ++i)
- dispatch(FuncRequest(LFUN_FILE_OPEN,
fromqstr(*i)));
+ i!=files.end(); ++i) {
+ //First see if a graphic was dropped
+ if ( decodeGraphics(*i) ) {
+ dispatch(FuncRequest(LFUN_INSET_INSERT,
+ "graphics \"" + fromqstr(*i) + "\""));
+ } else {
+ dispatch(FuncRequest(LFUN_FILE_OPEN,
fromqstr(*i)));
+ }
+ }
}
}
+
+bool QWorkArea::decodeGraphics( QString const & str )
+{
+ //Allow ps, eps, and allowable QT formats
+ QString name(str);
+ return (name.endsWith(".ps", false) ||
+ name.endsWith(".eps", false) ||
+ (QImageIO::imageFormat(name) != 0));
+}
+
Index: src/factory.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/factory.C,v
retrieving revision 1.95
diff -u -3 -p -u -r1.95 factory.C
--- src/factory.C 2004/08/14 15:55:17 1.95
+++ src/factory.C 2005/01/28 04:29:20
@@ -252,6 +252,12 @@ InsetBase * createInset(BufferView * bv,
InsetGraphicsMailer::string2params(cmd.argument,
buffer, igp);
auto_ptr<InsetGraphics> inset(new InsetGraphics);
+ string const & filename = cmd.getArg( 1 );
+ if (!filename.empty()) {
+ igp.filename = filename;
+ //automatically clip the image
+ igp.clip = true;
+ }
inset->setParams(igp);
return inset.release();
[Attachment #3 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic