]> git.lyx.org Git - features.git/commitdiff
implement basic drag-and-drop support in qt
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 5 Aug 2003 19:51:45 +0000 (19:51 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 5 Aug 2003 19:51:45 +0000 (19:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7508 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/ChangeLog
src/frontends/qt2/ChangeLog
src/frontends/qt2/QWorkArea.C
src/frontends/qt2/QWorkArea.h

index 0664fd6772f26739d1d48394e994bbe2e72a05d4..0ecc1893ca71bbac76c66f87d19e3e4fed42135f 100644 (file)
@@ -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;
+       }
 }
 
 
index fe2889bf9c3a48d35102e7bfad0adcb187956fda..6a6771966156655191f3066c3c2149d27d28040b 100644 (file)
@@ -1,3 +1,8 @@
+2003-08-05  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * 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  <poenitz@gmx.net>
 
index d4ffcaf1a7bd5126fcfa4a8a673507c227e91895..0cf15a15a6ea6210093b746bc3f930efbdeadffe 100644 (file)
@@ -1,3 +1,9 @@
+2003-08-05  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * QWorkArea.C (QWorkArea): 
+       (dragEnterEvent): 
+       (dropEvent): add support for drag and drop of URIs
+
 2003-08-03  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * ui/moc/Makefile.am (INCLUDES): forgot to use QT_INCLUDES
index b5971a214ad1f9887acffcdb2f77427b0f5e5dd3..322d7947a374f00ef082118413aaff69e1aca814 100644 (file)
 #include <config.h>
 
 
-#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 <qapplication.h>
 #include <qevent.h>
+#include <qdragobject.h>
 #include <qpainter.h>
 #include <qmainwindow.h>
 #include <qlayout.h>
 #include <X11/Xlib.h>
 #endif
 
-#include <cmath>
 #include <cctype>
 
 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<QMainWindow*>(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)));
+       }
+}
index 7edaf4c17624bfcc9fb5032bc20f290dcbae92b7..c13e1589fb47aa79832b4fadcf608ac259404517 100644 (file)
@@ -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(); }