From 8c092f1b16a904d67aa016f141c5ed4e4ca8c846 Mon Sep 17 00:00:00 2001 From: John Fultz Date: Wed, 10 Dec 2014 03:10:22 -0600 Subject: Implement FileOpen event This allows Quackle to respond to system file open events. So, if .gcg is associated with Quackle, then double-clicking a .gcg file will now make it open in Quackle (whether it's running or not). And drag and drop, etc. This definitely fixes issues trying to open files with double-click on Mac. Windows doesn't have the .gcg association set up yet, so code is untested there, but it should be platform independent. --- quacker/main.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'quacker/main.cpp') diff --git a/quacker/main.cpp b/quacker/main.cpp index 964f9b2..213297f 100644 --- a/quacker/main.cpp +++ b/quacker/main.cpp @@ -17,13 +17,53 @@ */ #include +#include #include "quacker.h" +class QuackerApplication : public QApplication +{ +public: + QuackerApplication(int& argc, char** argv) + : QApplication(argc, argv) + , m_TopLevel(NULL) + { + // empty + }; + + virtual bool event(QEvent* event) + { + switch(event->type()) + { + case QEvent::FileOpen: + { + QFileOpenEvent* fileOpenEvent = static_cast(event); + if (m_TopLevel && !fileOpenEvent->file().isEmpty()) + { + m_TopLevel->openFile(fileOpenEvent->file()); + return true; + } + } + // no break + default: + return QApplication::event(event); + } + } + + void setTopLevel(TopLevel* topLevel) + { + m_TopLevel = topLevel; + } + +private: + TopLevel* m_TopLevel; +}; + int main(int argc, char **argv) { - QApplication a(argc, argv); + QuackerApplication a(argc, argv); TopLevel topLevel; + a.setTopLevel(&topLevel); topLevel.show(); return a.exec(); } -- cgit v1.2.3