diff options
author | John Fultz <jfultz@wolfram.com> | 2014-12-10 03:10:22 -0600 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2014-12-10 03:10:22 -0600 |
commit | 8c092f1b16a904d67aa016f141c5ed4e4ca8c846 (patch) | |
tree | 27d1e24242d43536ee625e38990fd9faa9ce580e /quacker/main.cpp | |
parent | 3c7f297b8d2e0b273ed2d56d138ff0ae026a4032 (diff) |
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.
Diffstat (limited to 'quacker/main.cpp')
-rw-r--r-- | quacker/main.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
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 <QApplication> +#include <QFileOpenEvent> #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<QFileOpenEvent*>(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(); } |