Skip to content

Commit

Permalink
feat(macOS): support file open event for association
Browse files Browse the repository at this point in the history
  • Loading branch information
BLumia committed Dec 3, 2024
1 parent e64b871 commit 64c4d2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ MainWindow::MainWindow(QWidget *parent)
installResizeCapture(m_graphicsView->viewport());
installResizeCapture(m_gv);
installResizeCapture(m_gv->viewport());

#ifdef Q_OS_MACOS
qApp->installEventFilter(this);
#endif // Q_OS_MACOS
}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -653,6 +657,19 @@ QSize MainWindow::sizeHint() const
return QSize(710, 530);
}

#ifdef Q_OS_MACOS
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
Q_UNUSED(obj);
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *fileOpenEvent = static_cast<QFileOpenEvent *>(event);
showUrls({fileOpenEvent->url()});
return true;
}
return false;
}
#endif // Q_OS_MACOS

void MainWindow::on_actionOpen_triggered()
{
QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
Expand Down
3 changes: 3 additions & 0 deletions app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ protected slots:

protected:
QSize sizeHint() const override;
#ifdef Q_OS_MACOS
bool eventFilter(QObject *obj, QEvent *event) override;
#endif // Q_OS_MACOS

private slots:
void on_actionOpen_triggered();
Expand Down

0 comments on commit 64c4d2e

Please sign in to comment.