The following patch aims at making drag and drop of lyx files work on Qt. The main code (in QWorkarea) is trivial, but I need Bufferview_pimpl::workareaDispatch to call LyXView::dispatch instead of its own.
So I did that and the thing works (wow!) *but* selection is broken...
So this is the place in my message where I say: ``John, I need your help!''
JMarc
PS: the changes in text2.C are just here to compile because of Andre's latest changes.
Index: src/BufferView_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v retrieving revision 1.408 diff -u -r1.408 BufferView_pimpl.C --- src/BufferView_pimpl.C 4 Aug 2003 09:06:29 -0000 1.408 +++ src/BufferView_pimpl.C 4 Aug 2003 21:00:18 -0000 @@ -959,6 +959,7 @@ // layout choice etc. ourselves bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in) { +#if 0 // e.g. Qt mouse press when no buffer if (!available()) return false; @@ -970,22 +971,29 @@ ev.setView(bv_); bool const res = dispatch(ev); - +#else + owner_->dispatch(ev_in); +#endif + // see workAreaKeyPress cursor_timeout.restart(); screen().showCursor(*bv_); // FIXME: we should skip these when selecting +#if 0 bv_->owner()->updateLayoutChoice(); bv_->owner()->updateToolbar(); bv_->fitCursor(); +#endif // slight hack: this is only called currently when // we clicked somewhere, so we force through the display // of the new status here. bv_->owner()->clearMessage(); +#if 0 return res; +#endif } Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.1488 diff -u -r1.1488 ChangeLog --- src/ChangeLog 4 Aug 2003 14:36:51 -0000 1.1488 +++ src/ChangeLog 4 Aug 2003 21:00:47 -0000 @@ -1,3 +1,9 @@ +2003-08-04 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> + + * LyXAction.C (init): add tthe LFUN_MOUSE lfuns + + * BufferView_pimpl.C (workAreaDispatch): change to use + LyXView::dispatch instead of BufferView::Pimpl::dispatch 2003-08-04 André Pönitz <[EMAIL PROTECTED]> Index: src/LyXAction.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v retrieving revision 1.175 diff -u -r1.175 LyXAction.C --- src/LyXAction.C 2 Aug 2003 11:30:23 -0000 1.175 +++ src/LyXAction.C 4 Aug 2003 21:00:50 -0000 @@ -316,6 +316,11 @@ { LFUN_PARAGRAPH_APPLY, "paragraph-params-apply", Noop }, { LFUN_PARAGRAPH_UPDATE, "", Noop }, { LFUN_EXTERNAL_EDIT, "external-edit", Noop }, + { LFUN_MOUSE_PRESS, "mouse-press", ReadOnly}, + { LFUN_MOUSE_MOTION, "mouse-motion", ReadOnly}, + { LFUN_MOUSE_RELEASE, "mouse-release", ReadOnly}, + { LFUN_MOUSE_DOUBLE, "mouse-double", ReadOnly}, + { LFUN_MOUSE_TRIPLE, "mouse-triple", ReadOnly}, { LFUN_NOACTION, "", Noop } }; Index: src/text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.417 diff -u -r1.417 text2.C --- src/text2.C 4 Aug 2003 09:48:23 -0000 1.417 +++ src/text2.C 4 Aug 2003 21:00:56 -0000 @@ -762,8 +762,8 @@ { bool const lsel = TextCursor::setSelection(); - if (inset_owner && (selection.set() || lsel)) - inset_owner->setUpdateStatus(InsetText::SELECTION); +// if (inset_owner && (selection.set() || lsel)) +// inset_owner->setUpdateStatus(InsetText::SELECTION); } @@ -849,8 +849,8 @@ setCursor(cursor.par(), cursor.pos()); selection.cursor = cursor; } - if (inset_owner) - inset_owner->setUpdateStatus(InsetText::CURSOR_PAR); +// if (inset_owner) +// inset_owner->setUpdateStatus(InsetText::CURSOR_PAR); } Index: src/frontends/qt2/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v retrieving revision 1.562 diff -u -r1.562 ChangeLog --- src/frontends/qt2/ChangeLog 3 Aug 2003 18:07:50 -0000 1.562 +++ src/frontends/qt2/ChangeLog 4 Aug 2003 21:01:11 -0000 @@ -1,3 +1,9 @@ +2003-08-04 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> + + * QWorkArea.C (QWorkArea): + (dragEnterEvent): + (dropEvent): add support for drag and drop of URIs + 2003-08-03 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> * ui/moc/Makefile.am (INCLUDES): forgot to use QT_INCLUDES Index: src/frontends/qt2/QWorkArea.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QWorkArea.C,v retrieving revision 1.13 diff -u -r1.13 QWorkArea.C --- src/frontends/qt2/QWorkArea.C 24 May 2003 15:19:05 -0000 1.13 +++ src/frontends/qt2/QWorkArea.C 4 Aug 2003 21:01:14 -0000 @@ -12,11 +12,12 @@ #include "debug.h" -#include "LyXView.h" -#include "version.h" // lyx_version +//#include "LyXView.h" +//#include "version.h" // lyx_version +#include "lfuns.h" -#include "support/filetools.h" // LibFileSearch -#include "support/lstrings.h" +//#include "support/filetools.h" // LibFileSearch +//#include "support/lstrings.h" #include "support/LAssert.h" #include "QWorkArea.h" @@ -25,6 +26,7 @@ #include <qapplication.h> #include <qevent.h> +#include <qdragobject.h> #include <qpainter.h> #include <qmainwindow.h> #include <qlayout.h> @@ -51,6 +53,7 @@ (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this); setFocusProxy(content_); + setAcceptDrops(true); content_->show(); @@ -141,4 +144,23 @@ QApplication::clipboard()->setSelectionMode(true); #endif QApplication::clipboard()->setText(toqstr(str)); +} + + +void QWorkArea::dragEnterEvent(QDragEnterEvent * event) +{ + event->accept(QUriDrag::canDecode(event)); +} + + +void QWorkArea::dropEvent(QDropEvent* event) +{ + QStringList files; + + if (QUriDrag::decodeLocalFiles(event, files)) { + lyxerr << "QWorkArea::dropEvent: got uris!" << endl; + for (QStringList::Iterator i = files.begin(); + i!=files.end(); ++i) + dispatch(FuncRequest(LFUN_FILE_OPEN, fromqstr(*i))); + } } Index: src/frontends/qt2/QWorkArea.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QWorkArea.h,v retrieving revision 1.9 diff -u -r1.9 QWorkArea.h --- src/frontends/qt2/QWorkArea.h 13 Feb 2003 16:52:53 -0000 1.9 +++ src/frontends/qt2/QWorkArea.h 4 Aug 2003 21:01:14 -0000 @@ -52,6 +52,10 @@ virtual string const getClipboard() const; /// virtual void putClipboard(string const &) const; + /// + virtual void dragEnterEvent(QDragEnterEvent * event); + /// + virtual void dropEvent(QDropEvent* event); /// get the pixmap we paint on to QPixmap * getPixmap() const { return content_->pixmap(); }