feat(macOS): support file open event for association

This commit is contained in:
Gary Wang 2024-12-03 23:25:00 +08:00
parent e64b871a2f
commit 64c4d2e064
2 changed files with 20 additions and 0 deletions

View File

@ -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()
@ -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);

View File

@ -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();