Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <QDesktopServices>
#include <QDialog>
#include <QDir>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QEvent>
#include <QFile>
#include <QFileDialog>
Expand All @@ -41,6 +43,7 @@
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include <QMimeData>
#include <QObject>
#include <QPixmap>
#include <QPrinter>
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -608,6 +613,45 @@ void MainWindow::closeEvent( QCloseEvent* e )
QMainWindow::closeEvent( e );
}

void MainWindow::dragEnterEvent( QDragEnterEvent* 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 ) )
{
e->acceptProposedAction();
return;
}
}
}

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"
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/viewwindowmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down