logic: file associations for Mac and opening project files via Mac OS

* hide start screen when opening with project file
* added project icon file to bundle and file type association to plist
* listen for file open events from double click or drag and drop
* fixed crashes in window handling
This commit is contained in:
Eberhard Graether
2016-02-02 13:20:05 +01:00
parent 29a70b8f70
commit 3cbafa6456
18 changed files with 183 additions and 40 deletions
+3
View File
@@ -119,4 +119,7 @@ add_files(
qt/window/QtSplashScreen.h
qt/window/QtStartScreen.cpp
qt/window/QtStartScreen.h
qt/QtApplication.cpp
qt/QtApplication.h
)
+30
View File
@@ -0,0 +1,30 @@
#include "qt/QtApplication.h"
#include <QFileOpenEvent>
#include "utility/file/FilePath.h"
#include "utility/messaging/type/MessageLoadProject.h"
QtApplication::QtApplication(int& argc, char** argv)
: QApplication(argc, argv)
{
}
// responds to FileOpenEvent specific for Mac
bool QtApplication::event(QEvent *event)
{
if (event->type() == QEvent::FileOpen)
{
QFileOpenEvent* fileEvent = dynamic_cast<QFileOpenEvent*>(event);
FilePath path(fileEvent->file().toStdString());
if (path.exists() && path.extension() == ".coatiproject")
{
MessageLoadProject(path.str(), false).dispatch();
return true;
}
}
return QApplication::event(event);
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef QT_APPLICATION_H
#define QT_APPLICATION_H
#include <QApplication>
class QtApplication
: public QApplication
{
public:
QtApplication(int& argc, char** argv);
bool event(QEvent *event);
};
#endif // QT_APPLICATION_H
+8 -2
View File
@@ -5,7 +5,8 @@
#include "qt/window/QtMainWindow.h"
QtMainView::QtMainView()
: m_setTitleFunctor(std::bind(&QtMainView::doSetTitle, this, std::placeholders::_1))
: m_hideStartScreenFunctor(std::bind(&QtMainView::doHideStartScreen, this))
, m_setTitleFunctor(std::bind(&QtMainView::doSetTitle, this, std::placeholders::_1))
, m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this))
, m_updateRecentProjectMenuFunctor(std::bind(&QtMainView::doUpdateRecentProjectMenu, this))
, m_showLicenseScreenFunctor(std::bind(&QtMainView::doShowLicenseScreen, this))
@@ -69,7 +70,7 @@ void QtMainView::setStatusBar(QStatusBar* statusbar)
void QtMainView::hideStartScreen()
{
m_window->clearWindows();
m_hideStartScreenFunctor();
}
void QtMainView::setTitle(const std::string& title)
@@ -97,6 +98,11 @@ void QtMainView::doUpdateRecentProjectMenu()
m_window->updateRecentProjectMenu();
}
void QtMainView::doHideStartScreen()
{
m_window->clearWindows();
}
void QtMainView::doSetTitle(const std::string& title)
{
m_window->setWindowTitle(QString::fromStdString(title));
+2
View File
@@ -40,6 +40,7 @@ public:
virtual void showLicenseScreen();
private:
void doHideStartScreen();
void doSetTitle(const std::string& title);
void doActivateWindow();
void doUpdateRecentProjectMenu();
@@ -48,6 +49,7 @@ private:
std::shared_ptr<QtMainWindow> m_window;
std::vector<View*> m_views;
QtThreadedFunctor<> m_hideStartScreenFunctor;
QtThreadedFunctor<const std::string&> m_setTitleFunctor;
QtThreadedFunctor<> m_activateWindowFunctor;
QtThreadedFunctor<> m_updateRecentProjectMenuFunctor;
+4 -1
View File
@@ -12,8 +12,9 @@
#include "PublicKey.h"
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
#include "utility/file/FilePath.h"
#include "utility/AppPath.h"
#include "utility/file/FilePath.h"
#include "utility/messaging/type/MessageEnteredLicense.h"
#include "utility/ResourcePaths.h"
QtLicense::QtLicense(QWidget *parent)
@@ -152,6 +153,8 @@ void QtLicense::handleUpdateButtonPress()
FilePath p(appLocation);
appSettings->setLicenseCheck(license.hashLocation(p.absolute().str()));
appSettings->save();
MessageEnteredLicense().dispatch();
}
else
{
+3 -5
View File
@@ -62,8 +62,6 @@ bool MouseReleaseFilter::eventFilter(QObject* obj, QEvent* event)
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
if (mouseEvent->button() == m_backButton)
{
MessageUndo().dispatch();
@@ -82,7 +80,6 @@ bool MouseReleaseFilter::eventFilter(QObject* obj, QEvent* event)
MouseWheelFilter::MouseWheelFilter(QObject* parent)
: QObject(parent)
{
}
bool MouseWheelFilter::eventFilter(QObject* obj, QEvent* event)
@@ -106,6 +103,7 @@ bool MouseWheelFilter::eventFilter(QObject* obj, QEvent* event)
return QObject::eventFilter(obj, event);
}
QtMainWindow::QtMainWindow()
: m_showDockWidgetTitleBars(true)
{
@@ -300,9 +298,9 @@ void QtMainWindow::popWindow()
void QtMainWindow::clearWindows()
{
if (m_windowStack.size())
for (QWidget* window : m_windowStack)
{
m_windowStack.back()->hide();
window->hide();
}
m_windowStack.clear();
+1
View File
@@ -63,6 +63,7 @@ protected:
bool eventFilter(QObject* obj, QEvent* event);
};
class QtMainWindow
: public QMainWindow
{