| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#ifndef GUI_APPLICATION_H |
| 25 |
#define GUI_APPLICATION_H |
| 26 |
|
| 27 |
#include "GuiApplicationNativeEventAware.h" |
| 28 |
#include <Base/Interpreter.h> // For Base::SystemExitException |
| 29 |
#include <QList> |
| 30 |
#include <memory> |
| 31 |
|
| 32 |
class QSessionManager; |
| 33 |
|
| 34 |
namespace Gui |
| 35 |
{ |
| 36 |
/** Override QCoreApplication::notify() to fetch exceptions in Qt widgets |
| 37 |
* properly that are not handled in the event handler or slot. |
| 38 |
*/ |
| 39 |
class GUIApplication: public GUIApplicationNativeEventAware |
| 40 |
{ |
| 41 |
Q_OBJECT |
| 42 |
|
| 43 |
public: |
| 44 |
explicit GUIApplication(int& argc, char** argv); |
| 45 |
~GUIApplication() override; |
| 46 |
|
| 47 |
/** |
| 48 |
* Make forwarding events exception-safe and get more detailed information |
| 49 |
* where an unhandled exception comes from. |
| 50 |
*/ |
| 51 |
bool notify(QObject* receiver, QEvent* event) override; |
| 52 |
|
| 53 |
/// Pointer to exceptions caught in Qt event handler |
| 54 |
std::shared_ptr<Base::SystemExitException> caughtException; |
| 55 |
|
| 56 |
public Q_SLOTS: |
| 57 |
void commitData(QSessionManager& manager); |
| 58 |
|
| 59 |
protected: |
| 60 |
bool event(QEvent* event) override; |
| 61 |
}; |
| 62 |
|
| 63 |
class GUISingleApplication: public GUIApplication |
| 64 |
{ |
| 65 |
Q_OBJECT |
| 66 |
|
| 67 |
public: |
| 68 |
explicit GUISingleApplication(int& argc, char** argv); |
| 69 |
~GUISingleApplication() override; |
| 70 |
|
| 71 |
bool isRunning() const; |
| 72 |
bool sendMessage(const QString& message, int timeout = 5000); |
| 73 |
|
| 74 |
private Q_SLOTS: |
| 75 |
void receiveConnection(); |
| 76 |
void processMessages(); |
| 77 |
void readFromSocket(); |
| 78 |
|
| 79 |
Q_SIGNALS: |
| 80 |
void messageReceived(const QList<QString>&); |
| 81 |
|
| 82 |
private: |
| 83 |
class Private; |
| 84 |
QScopedPointer<Private> d_ptr; |
| 85 |
}; |
| 86 |
|
| 87 |
class WheelEventFilter: public QObject |
| 88 |
{ |
| 89 |
Q_OBJECT |
| 90 |
|
| 91 |
public: |
| 92 |
explicit WheelEventFilter(QObject* parent); |
| 93 |
bool eventFilter(QObject* obj, QEvent* ev) override; |
| 94 |
}; |
| 95 |
|
| 96 |
} // namespace Gui |
| 97 |
|
| 98 |
#endif // GUI_APPLICATION_H |