From 9a747c4130c1b1daad9e5171006ffdc58251ac21 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 5 Aug 2003 19:51:45 +0000 Subject: [PATCH] implement basic drag-and-drop support in qt git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7508 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 58 +++++++++++++++++++++-------------- src/ChangeLog | 5 +++ src/frontends/qt2/ChangeLog | 6 ++++ src/frontends/qt2/QWorkArea.C | 36 ++++++++++++++-------- src/frontends/qt2/QWorkArea.h | 4 +++ 5 files changed, 74 insertions(+), 35 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 0664fd6772..0ecc1893ca 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -955,37 +955,49 @@ void BufferView::Pimpl::trackChanges() } -// Doesn't go through lyxfunc, so we need to update the -// layout choice etc. ourselves -bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in) +bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev) { - // e.g. Qt mouse press when no buffer - if (!available()) - return false; + switch (ev.action) { + case LFUN_MOUSE_PRESS: + case LFUN_MOUSE_MOTION: + case LFUN_MOUSE_RELEASE: + case LFUN_MOUSE_DOUBLE: + case LFUN_MOUSE_TRIPLE: + { + // We pass those directly to the Bufferview, since + // otherwise selection handling breaks down - screen().hideCursor(); + // Doesn't go through lyxfunc, so we need to update + // the layout choice etc. ourselves - // Make sure that the cached BufferView is correct. - FuncRequest ev = ev_in; - ev.setView(bv_); + // e.g. Qt mouse press when no buffer + if (!available()) + return false; - bool const res = dispatch(ev); + screen().hideCursor(); - // see workAreaKeyPress - cursor_timeout.restart(); - screen().showCursor(*bv_); + bool const res = dispatch(ev); + + // see workAreaKeyPress + cursor_timeout.restart(); + screen().showCursor(*bv_); - // FIXME: we should skip these when selecting - bv_->owner()->updateLayoutChoice(); - bv_->owner()->updateToolbar(); - bv_->fitCursor(); + // FIXME: we should skip these when selecting + owner_->updateLayoutChoice(); + owner_->updateToolbar(); + fitCursor(); - // 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(); + // slight hack: this is only called currently when we + // clicked somewhere, so we force through the display + // of the new status here. + owner_->clearMessage(); - return res; + return res; + } + default: + owner_->dispatch(ev); + return true; + } } diff --git a/src/ChangeLog b/src/ChangeLog index fe2889bf9c..6a67719661 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-08-05 Jean-Marc Lasgouttes + + * BufferView_pimpl.C (workAreaDispatch): change to use + LyXView::dispatch instead of BufferView::Pimpl::dispatch for lfuns + that are no mouse related. 2003-08-05 André Pönitz diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index d4ffcaf1a7..0cf15a15a6 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,9 @@ +2003-08-05 Jean-Marc Lasgouttes + + * QWorkArea.C (QWorkArea): + (dragEnterEvent): + (dropEvent): add support for drag and drop of URIs + 2003-08-03 Jean-Marc Lasgouttes * ui/moc/Makefile.am (INCLUDES): forgot to use QT_INCLUDES diff --git a/src/frontends/qt2/QWorkArea.C b/src/frontends/qt2/QWorkArea.C index b5971a214a..322d7947a3 100644 --- a/src/frontends/qt2/QWorkArea.C +++ b/src/frontends/qt2/QWorkArea.C @@ -11,20 +11,15 @@ #include -#include "debug.h" -#include "LyXView.h" -#include "version.h" // lyx_version - -#include "support/filetools.h" // LibFileSearch -#include "support/lstrings.h" -#include "support/LAssert.h" - #include "QWorkArea.h" +#include "debug.h" +#include "lfuns.h" #include "qt_helpers.h" #include "lcolorcache.h" #include #include +#include #include #include #include @@ -34,13 +29,9 @@ #include #endif -#include #include using std::endl; -using std::abs; -using std::hex; - QWorkArea::QWorkArea(int, int, int, int) : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this) @@ -51,6 +42,7 @@ QWorkArea::QWorkArea(int, int, int, int) (static_cast(qApp->mainWidget()))->setCentralWidget(this); setFocusProxy(content_); + setAcceptDrops(true); content_->show(); @@ -142,3 +134,23 @@ void QWorkArea::putClipboard(string const & str) const #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[Debug::GUI] << "QWorkArea::dropEvent: got URIs!" + << endl; + for (QStringList::Iterator i = files.begin(); + i!=files.end(); ++i) + dispatch(FuncRequest(LFUN_FILE_OPEN, fromqstr(*i))); + } +} diff --git a/src/frontends/qt2/QWorkArea.h b/src/frontends/qt2/QWorkArea.h index 7edaf4c176..c13e1589fb 100644 --- a/src/frontends/qt2/QWorkArea.h +++ b/src/frontends/qt2/QWorkArea.h @@ -52,6 +52,10 @@ public: 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(); } -- 2.39.2