1 /************************************************************************ 2 * 3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com) 4 * 5 * This file is part of SuperCollider Qt GUI. 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * 20 ************************************************************************/ 21 22 #pragma once 23 24 #include "Common.h" 25 26 #include <QApplication> 27 #include <QEventLoop> 28 #include <QMutex> 29 #include <QMenuBar> 30 31 namespace QtCollider { 32 33 class EventProcessor : public QObject { 34 public: work()35 void work() { 36 QApplication::postEvent(this, new QEvent(QEvent::User)); 37 _loop.exec(); 38 } customEvent(QEvent * e)39 void customEvent(QEvent* e) { _loop.exit(); } 40 41 private: 42 QEventLoop _loop; 43 }; 44 45 } // namespace QtCollider 46 47 class QcApplication : public QApplication { 48 Q_OBJECT 49 50 public: 51 QcApplication(int& argc, char** argv); 52 virtual ~QcApplication(); 53 static bool compareThread(); // NOTE: language must be locked processEvents()54 static void processEvents() { 55 if (_instance) 56 _instance->_eventProc.work(); 57 } SystemHasMouseWheel()58 static inline bool SystemHasMouseWheel() { return _systemHasMouseWheel; } getMainMenu()59 static QMenuBar* getMainMenu() { return _instance->_mainMenu.data(); } 60 61 public Q_SLOTS: 62 void interpret(const QString& code, bool printResult = true); 63 void onQuit(); 64 65 protected: 66 virtual bool event(QEvent*); 67 virtual bool notify(QObject*, QEvent*); 68 69 private: 70 QSharedPointer<QMenuBar> _mainMenu; 71 void createMenu(); 72 73 QtCollider::EventProcessor _eventProc; 74 75 static QMutex _mutex; 76 static QcApplication* _instance; 77 static bool _systemHasMouseWheel; 78 79 bool _handleCmdPeriod; 80 }; 81