Drop file opens it, command line arguments

This commit is contained in:
Jakub Melka 2020-11-07 12:03:43 +01:00
parent 08d069ce32
commit 8d9b9cb493
4 changed files with 56 additions and 3 deletions

View File

@ -43,5 +43,11 @@ int main(int argc, char *argv[])
pdfviewer::PDFViewerMainWindow mainWindow;
mainWindow.show();
QStringList arguments = application.arguments();
if (arguments.size() > 1)
{
mainWindow.openDocument(arguments[1]);
}
return application.exec();
}

View File

@ -102,6 +102,8 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
{
ui->setupUi(this);
setAcceptDrops(true);
// Initialize toolbar icon size
QSize iconSize = pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24));
ui->mainToolBar->setIconSize(iconSize);
@ -1503,4 +1505,42 @@ void PDFViewerMainWindow::saveDocument(const QString& fileName)
}
}
void PDFViewerMainWindow::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls())
{
event->setDropAction(Qt::LinkAction);
event->accept();
}
}
void PDFViewerMainWindow::dragMoveEvent(QDragMoveEvent* event)
{
if (event->mimeData()->hasUrls())
{
event->setDropAction(Qt::LinkAction);
event->accept();
}
}
void PDFViewerMainWindow::dragLeaveEvent(QDragLeaveEvent* event)
{
}
void PDFViewerMainWindow::dropEvent(QDropEvent* event)
{
if (event->mimeData()->hasUrls())
{
QList<QUrl> urls = event->mimeData()->urls();
if (urls.size() == 1)
{
openDocument(urls.front().toLocalFile());
event->acceptProposedAction();
}
}
}
} // namespace pdfviewer

View File

@ -74,9 +74,17 @@ public:
virtual void closeEvent(QCloseEvent* event) override;
virtual void showEvent(QShowEvent* event) override;
void openDocument(const QString& fileName);
signals:
void queryPasswordRequest(QString* password, bool* ok);
protected:
virtual void dragEnterEvent(QDragEnterEvent* event) override;
virtual void dragMoveEvent(QDragMoveEvent* event) override;
virtual void dragLeaveEvent(QDragLeaveEvent* event) override;
virtual void dropEvent(QDropEvent* event) override;
private slots:
void onQueryPasswordRequest(QString* password, bool* ok);
@ -137,7 +145,6 @@ private:
void onViewerSettingsChanged();
void onRenderingOptionTriggered(bool checked);
void openDocument(const QString& fileName);
void setDocument(pdf::PDFModifiedDocument document);
void closeDocument();
void saveDocument(const QString& fileName);

View File

@ -1,7 +1,7 @@
==========================================================================
PDFforQt library / PDF viewer
(c) Jakub Melka 2018-2019
(c) Jakub Melka 2018-2020
==========================================================================
This software is consisting of PDF rendering library, and viewer,