From c9501badec363d4c9ef9840ab476738c1c3f591d Mon Sep 17 00:00:00 2001 From: Binhao Qian Date: Thu, 22 Jan 2026 14:05:50 +0800 Subject: [PATCH 1/2] Add dnd support. --- src/mainwindow.cpp | 31 +++++++++++++++++++++++++++++++ src/mainwindow.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f610645a..84e6755d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -41,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +107,8 @@ MainWindow::MainWindow( const QStringList& arguments ) // UIC stuff setupUi( this ); + setAcceptDrops( true ); + // Set up layout direction if ( pConfig->m_advLayoutDirectionRL ) qApp->setLayoutDirection( Qt::RightToLeft ); @@ -608,6 +613,32 @@ void MainWindow::closeEvent( QCloseEvent* e ) QMainWindow::closeEvent( e ); } +void MainWindow::dragEnterEvent( QDragEnterEvent* e ) +{ + if ( e->mimeData()->hasUrls() ) + e->acceptProposedAction(); + else + e->ignore(); +} + +void MainWindow::dropEvent( QDropEvent* e ) +{ + if ( e->mimeData()->hasUrls() ) + { + QUrl url = e->mimeData()->urls().first(); + + if ( url.isLocalFile() ) + { + QString fileName = url.toLocalFile(); + + if ( fileName.endsWith( ".chm", Qt::CaseInsensitive ) || fileName.endsWith( ".epub", Qt::CaseInsensitive ) ) + loadFile( fileName ); + } + + e->acceptProposedAction(); + } +} + void MainWindow::printHelpAndExit() { fprintf( stderr, "Usage: %s [options] [helpfile]\n" diff --git a/src/mainwindow.h b/src/mainwindow.h index ed847dce..c10f8c03 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -172,6 +172,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindow protected: // Reimplemented functions void closeEvent( QCloseEvent* e ); + void dragEnterEvent( QDragEnterEvent* e ); + void dropEvent( QDropEvent* e ); bool event( QEvent* e ); private: From c99eefb2b74080ac0d5a579edf1a92a16de593d3 Mon Sep 17 00:00:00 2001 From: Binhao Qian Date: Fri, 23 Jan 2026 06:43:15 +0800 Subject: [PATCH 2/2] Add checks when drag begin. --- src/mainwindow.cpp | 19 ++++++++++++++++--- src/viewwindowmgr.cpp | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 84e6755d..72f6221f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -616,9 +616,22 @@ void MainWindow::closeEvent( QCloseEvent* e ) void MainWindow::dragEnterEvent( QDragEnterEvent* e ) { if ( e->mimeData()->hasUrls() ) - e->acceptProposedAction(); - else - e->ignore(); + { + QUrl url = e->mimeData()->urls().first(); + + if ( url.isLocalFile() ) + { + QString fileName = url.toLocalFile(); + + if ( fileName.endsWith( ".chm", Qt::CaseInsensitive ) || fileName.endsWith( ".epub", Qt::CaseInsensitive ) ) + { + e->acceptProposedAction(); + return; + } + } + } + + e->ignore(); } void MainWindow::dropEvent( QDropEvent* e ) diff --git a/src/viewwindowmgr.cpp b/src/viewwindowmgr.cpp index 19630d84..288f4609 100644 --- a/src/viewwindowmgr.cpp +++ b/src/viewwindowmgr.cpp @@ -160,6 +160,7 @@ ViewWindow* ViewWindowMgr::current() ViewWindow* ViewWindowMgr::addNewTab( bool set_active ) { ViewWindow* browser = new ViewWindow( m_tabWidget ); + browser->setAcceptDrops( false ); editFind->installEventFilter( this );