From: Abdelrazak Younes Date: Tue, 14 Aug 2007 13:14:47 +0000 (+0000) Subject: Transfer Drag&Drop handling from GuiWorkArea to GuiView. X-Git-Tag: 1.6.10~8876 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3d1cfa550bb3b63b563fe74cee52e2a126e1b95b;p=lyx.git Transfer Drag&Drop handling from GuiWorkArea to GuiView. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19556 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index acbab7d2c2..3c6fb19fd3 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -30,31 +30,36 @@ #include "support/filetools.h" #include "support/convert.h" #include "support/lstrings.h" +#include "support/os.h" +#include "Buffer.h" #include "BufferView.h" #include "BufferList.h" +#include "callback.h" #include "debug.h" #include "FuncRequest.h" -#include "callback.h" -#include "LyXRC.h" #include "LyX.h" -#include "Session.h" #include "LyXFunc.h" +#include "LyXRC.h" #include "MenuBackend.h" -#include "Buffer.h" -#include "BufferList.h" +#include "Session.h" #include #include #include +#include +#include +#include +#include +#include +#include #include +#include #include #include #include -#include +#include #include -#include -#include #include @@ -222,6 +227,9 @@ GuiView::GuiView(int id) if (!iconname.empty()) setWindowIcon(QPixmap(toqstr(iconname.absFilename()))); #endif + + // For Drag&Drop. + setAcceptDrops(true); } @@ -320,6 +328,33 @@ void GuiView::closeEvent(QCloseEvent * close_event) } +void GuiView::dragEnterEvent(QDragEnterEvent * event) +{ + if (event->mimeData()->hasUrls()) + event->accept(); + /// \todo Ask lyx-devel is this is enough: + /// if (event->mimeData()->hasFormat("text/plain")) + /// event->acceptProposedAction(); +} + + +void GuiView::dropEvent(QDropEvent* event) +{ + QList files = event->mimeData()->urls(); + if (files.isEmpty()) + return; + + LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION + << " got URLs!" << endl; + for (int i = 0; i!=files.size(); ++i) { + string const file = support::os::internal_path(fromqstr( + files.at(i).toLocalFile())); + if (!file.empty()) + dispatch(FuncRequest(LFUN_FILE_OPEN, file)); + } +} + + void GuiView::saveGeometry() { static bool done = false; diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 2d8d172eee..ad22ddf463 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -117,6 +117,11 @@ protected: virtual void moveEvent(QMoveEvent * e); private: + /// + void dragEnterEvent(QDragEnterEvent * ev); + /// + void dropEvent(QDropEvent * ev); + /// focus the command buffer widget void focus_command_widget(); diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index a6c08b1eff..b9c0a9dab8 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -18,32 +18,28 @@ #include "QKeySymbol.h" #include "qt_helpers.h" -#include "LyXView.h" +#include "frontends/LyXView.h" #include "BufferView.h" -#include "rowpainter.h" +#include "Color.h" #include "debug.h" #include "FuncRequest.h" -#include "Color.h" -#include "version.h" #include "LyXRC.h" +#include "rowpainter.h" +#include "version.h" #include "support/filetools.h" // LibFileSearch -#include "support/os.h" #include "support/convert.h" #include "graphics/GraphicsImage.h" #include "graphics/GraphicsLoader.h" +#include #include #include -#include -#include -#include #include #include #include -#include #include #include @@ -63,9 +59,6 @@ int const CursorWidth = 1; using std::endl; using std::string; -namespace os = lyx::support::os; - - namespace lyx { using support::FileName; @@ -271,31 +264,6 @@ void GuiWorkArea::adjustViewWithScrollBar(int) } -void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event) -{ - if (event->mimeData()->hasUrls()) - event->accept(); - /// \todo Ask lyx-devel is this is enough: - /// if (event->mimeData()->hasFormat("text/plain")) - /// event->acceptProposedAction(); -} - - -void GuiWorkArea::dropEvent(QDropEvent* event) -{ - QList files = event->mimeData()->urls(); - if (files.isEmpty()) - return; - - LYXERR(Debug::GUI) << "GuiWorkArea::dropEvent: got URIs!" << endl; - for (int i = 0; i!=files.size(); ++i) { - string const file = os::internal_path(fromqstr(files.at(i).toLocalFile())); - if (!file.empty()) - dispatch(FuncRequest(LFUN_FILE_OPEN, file)); - } -} - - void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/) { // No need to do anything if we didn't change views... diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index f64ed84cae..09ba83c6d1 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -117,10 +117,6 @@ public: private: void doGreyOut(QLPainter & pain); /// - void dragEnterEvent(QDragEnterEvent * ev); - /// - void dropEvent(QDropEvent * ev); - /// void focusInEvent(QFocusEvent *); /// void focusOutEvent(QFocusEvent *);