1 /* GNUPLOT - QtGnuplotEvent.h */ 2 3 /*[ 4 * Copyright 2009 Jérôme Lodewyck 5 * 6 * Permission to use, copy, and distribute this software and its 7 * documentation for any purpose with or without fee is hereby granted, 8 * provided that the above copyright notice appear in all copies and 9 * that both that copyright notice and this permission notice appear 10 * in supporting documentation. 11 * 12 * Permission to modify the software is granted, but not the right to 13 * distribute the complete modified source code. Modifications are to 14 * be distributed as patches to the released version. Permission to 15 * distribute binaries produced by compiling modified sources is granted, 16 * provided you 17 * 1. distribute the corresponding source modifications from the 18 * released version in the form of a patch file along with the binaries, 19 * 2. add special version identification to distinguish your version 20 * in addition to the base release version number, 21 * 3. provide your name and address as the primary contact for the 22 * support of your modified version, and 23 * 4. retain our contact information in regard to use of the base 24 * software. 25 * Permission to distribute the released version of the source code along 26 * with corresponding source modifications in the form of a patch file is 27 * granted with same provisions 2 through 4 for binary distributions. 28 * 29 * This software is provided "as is" without express or implied warranty 30 * to the extent permitted by applicable law. 31 * 32 * 33 * Alternatively, the contents of this file may be used under the terms of the 34 * GNU General Public License Version 2 or later (the "GPL"), in which case the 35 * provisions of GPL are applicable instead of those above. If you wish to allow 36 * use of your version of this file only under the terms of the GPL and not 37 * to allow others to use your version of this file under the above gnuplot 38 * license, indicate your decision by deleting the provisions above and replace 39 * them with the notice and other provisions required by the GPL. If you do not 40 * delete the provisions above, a recipient may use your version of this file 41 * under either the GPL or the gnuplot license. 42 ]*/ 43 44 #ifndef QTGNUPLOTEVENT_H 45 #define QTGNUPLOTEVENT_H 46 47 #include <QObject> 48 49 // Defines events used to communicate from qt_term.cpp to the GUI elements 50 51 enum QtGnuplotEventType { 52 // Events for QtGnuplotApplication 53 GESetCurrentWindow = 1000, GEInitWindow, GECloseWindow, GEExit, GEPersist, 54 // Events for QtGnuplotWindow 55 GEStatusText, GETitle, GESetCtrl, GESetPosition, GEPID, 56 // Events for QtGnuplotWidget 57 GESetWidgetSize, GECursor, 58 // Events for QtGnuplotScene 59 GEPenColor, GEBackgroundColor, GEBrushStyle, GEPenStyle, GEPointSize, GELineWidth, 60 GEFillBox, GEPutText, GEFilledPolygon, GETextAngle, GETextAlignment, GEPoint, GEClear, 61 GEZoomStart, GEZoomStop, GERuler, GECopyClipboard, GEMove, GEVector, GELineTo, 62 GESetFont, GEEnhancedFlush, GEEnhancedFinish, GEImage, GESetSceneSize, GERaise, 63 GEWrapCursor, GEScale, GEActivate, GEDesactivate, GELayer, GEPlotNumber, GEHypertext, 64 GETextBox, GEModPlots, GEAfterPlot, GEFontMetricRequest, GEDashPattern, 65 // GEDone must be the last. Any event claiming a type > GEDone is treated as an error. 66 GEDone 67 }; 68 69 enum QtGnuplotModPlots { 70 QTMODPLOTS_SET_VISIBLE, 71 QTMODPLOTS_SET_INVISIBLE, 72 QTMODPLOTS_INVERT_VISIBILITIES 73 }; 74 75 enum QtGnuplotLayer { 76 QTLAYER_BEGIN_KEYSAMPLE, QTLAYER_END_KEYSAMPLE, QTLAYER_BEFORE_ZOOM 77 }; 78 79 class QLocalServer; 80 class QLocalSocket; 81 class QtGnuplotEventHandler; 82 class QtGnuplotWidget; 83 84 /** 85 * A GUI object that wishes to receive gnuplot events has to inherit from 86 * this class and implement the processEvent function. The object is 87 * registered as the main receiver upon creation of a QtGnuplotEventHandler object 88 * For a given communication channel, only one QtGnuplotEventHandler should 89 * be created, hence only one main receiver should be registered. 90 */ 91 class QtGnuplotEventReceiver 92 { 93 public: 94 virtual void processEvent(QtGnuplotEventType type, QDataStream& in) = 0; 95 void swallowEvent(QtGnuplotEventType type, QDataStream& in); 96 QString serverName(); ~QtGnuplotEventReceiver()97 virtual ~QtGnuplotEventReceiver() {} 98 99 protected: 100 QtGnuplotEventHandler* m_eventHandler; 101 }; 102 103 /** 104 * The QtGnuplotEventHandler is responsible for passing message between 105 * Gnuplot and the GUI. It is shared between GUI objects. Its parent is 106 * the main GUI object that processes events and distribute them to other objects. 107 * Events are passed through a QLocalSocket (a crossplatform pipe-like IPC mechanism) 108 * between Gnuplot core and the event handler. 109 */ 110 class QtGnuplotEventHandler : public QObject 111 { 112 Q_OBJECT 113 114 public: 115 QtGnuplotEventHandler(QObject* parent, const QString& socket); 116 117 public: 118 /// Send an event from the GUI elements to gnuplot core 119 bool postTermEvent(int type, int mx, int my, int par1, int par2, QtGnuplotWidget* widget); 120 QString serverName(); 121 122 signals: 123 void connected(); 124 void disconnected(); 125 126 private slots: 127 void newConnection(); 128 void readEvent(); 129 void connectionClosed(); 130 131 private: 132 void init(const QString& inSocket); 133 134 private: 135 QLocalServer* m_server; 136 QLocalSocket* m_socket; 137 quint32 m_blockSize; 138 }; 139 140 #endif // QTGNUPLOTEVENT_H 141