File: QFaustItem.h

package info (click to toggle)
faustworks 0.5~repack0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,028 kB
  • ctags: 1,141
  • sloc: cpp: 7,460; sh: 166; xml: 71; makefile: 66; ansic: 9
file content (266 lines) | stat: -rwxr-xr-x 6,270 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
 * QFaustItem.h
 *
 * Created by Christophe Daudin on 12/05/09.
 * Copyright 2009 Grame. All rights reserved.
 *
 * GNU Lesser General Public License Usage
 * Alternatively, this file may be used under the terms of the GNU Lesser
 * General Public License version 2.1 as published by the Free Software
 * Foundation and appearing in the file LICENSE.LGPL included in the
 * packaging of this file.  Please review the following information to
 * ensure the GNU Lesser General Public License version 2.1 requirements
 * will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 *
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
 
#ifndef FAUST_ITEM_H
#define FAUST_ITEM_H

#include "QLanguageItem.h"

#include <QProcess>
#include <QTime>
#include <QSvgRenderer>
#include <QPen>
#include <QBrush>
#include <QTextEdit>

#include "QSwitcher.h"

#define FAUST_ITEM_PALETTE	1

#define FAUST_ITEM_BASE_RGB 238,219,0

extern QTextEdit* gErrorWindow;

class QGraphicsSvgItem;

class QBuildItem;

class QFaustItem : public QLanguageItem
{
	Q_OBJECT

	public:

		enum {
			SCRIPT_NO_FILE = 0 ,
			SCRIPT_ERROR,
			SCRIPT_CRASHED,
			SCRIPT_FILE_NOT_FOUND
		};
		
		/**
		*	\brief Constructor.
		*/
		QFaustItem(QGraphicsItem * parent = 0);
		QFaustItem(const QMimeData * mimeData		, QGraphicsItem * parent = 0);
		QFaustItem(const QDomElement * domElement	, QGraphicsItem * parent = 0);
		QFaustItem(const QFaustItem * other			, QGraphicsItem * parent = 0);
		
		~QFaustItem();
		
		void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
		
        void save(const QString& fileName);

		bool	setCode( const QString& code );
		QString	code() const;
		QString cppCode() const;
		
		void checkBinary();
		void setModified( bool isModified );

		QString lastErrorMessage() const;
		bool isValid() const;

		float currentScale() const;
	
	Q_SIGNALS:
	
		void launchScriptError( const QString& command );
		void buildError( int errorType , const QString& msg );

    public Q_SLOTS:
        void runBinary();           // run the binary code of the item
        void exploreSVG ();         // run an external brwoser to explore the SVG block-diagram
        void generateMath ();       // generate mathematical documentation
        void generateLoopGraph ();  // generate internal loop DAG
        void generateSigGraph ();   // generate internal signal graph

		void resized( const QRectF& newRect );

	protected Q_SLOTS:
	
		void buildFinished ( int exitCode, QProcess::ExitStatus exitStatus );
		void updateNameLabel();
	
 	protected:
	
        virtual QMenu * buildContextMenu();
        void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *  );
	
		void connectNotify (const QMetaMethod &signal);
	
		bool generateSVG();
		bool generateCPP();
		bool generateBinary();
		QString interpretCommand(const QString& command) const;
		
		void setupAnimation();
		
		void faustUpdateGeometry( const QRectF& newGeometry );

		QString svgFolder() const;
		QString svgRootFile() const;
		QString svgRootFileQuoted() const;
		QString cppFile() const;
		QString cppFileQuoted() const;
		QString dspFile() const;
		QString dspFileQuoted() const;
        QString dspFileQuotedSpecial() const;
		QString tempName() const;
		QString itemName() const;
		//QString namedDSPFile() const;
		
		void setFile(const QString& file);
		
		void cleanFiles();
		void cleanWorkingDirectoryFiles();
		void cleanSVGFiles();
		void cleanNamedFiles();
		void cleanBinaries();

		void init();
		void init( const QMimeData * mimeData );
		void init( const QDomElement * e );
		void init( const QFaustItem * other );
		
		/*!
		*	\brief Specialization of QLanguageItem::saveToDomElement
		*/
		QDomElement saveToDomElement( QDomDocument * doc);
		
		/*!
		*	\brief Specialization of QLanguageItem::buildMimeData
		*/
		QMimeData *	buildMimeData();
		
		void updateName();
		void updatePenAndBrush();
		
		/*!
		*	\brief QGraphicsItem standard event handler implementation.
		*/
		QVariant itemChange( GraphicsItemChange change, const QVariant& value );

		/*!
		*	\brief QGraphicsItem standard event handler implementation.
		*/		
		void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
		
		/*!
		*	\brief QGraphicsItem standard event handler implementation.
		*/
		void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
				
		QImage*	buildDragImage();

		/*
		*	\brief Scales and centers the SVG Item, as it's opaque : we have
		*	to diminish its size to see the selection border's pen.
		*/
//		void centerSVGItem();
		
		QGraphicsSvgItem * mSVGItem;
		QSvgRenderer		mSVGRenderer;
		
		QGraphicsSimpleTextItem * mFileNameItem;

		QBuildItem * mBuildAnimationItem;
		
		struct PenBrush {
			QPen mPen;
			QBrush mBrush;
			PenBrush(const QPen& p = QPen() , const QBrush& b = QBrush()) { mPen = p; mBrush = b; }
		};
		QSwitcher<PenBrush> mPenBrushSwitcher;

		//QString mDSPFile;
		QString mFile;
		QString mCode;
		QString mCppCode;
		QString mTempName;
		QString mWorkingDirectory;
		
		QString mItemBuildCommand;
		QString mItemBuildOptions;

		QProcess * mBuildProcess;
		
		int		mItemId;
		QString mIdString;
		
		QString mExName;
		
		QStringList mFiles;
		
		bool mIsValid;
		bool mIsBinaryReady;
		bool mBuildError;
		QStringList mBinaryFiles;
        QTime   mSaveTime;           // updated when saved

// -------------------- Static members --------------------

	public:
		
		static void setFaustPath( const QString& faustPath );

		static void setBuildCommand( const QString& buildCommand );
		static void setBuildOptions( const QString& buildOptions );
		
		enum DroppedFileType 
		{
			DROP_SVG = 0 ,
			DROP_CPP ,
			DROP_DSP ,
			DROP_BINARY
		};
		static void setDroppedFileType( int droppedFileType );

	protected:
	
		static QString mFaustPath;
		static QString mBuildCommand;
		static QString mBuildOptions;
		static int mDroppedFileType;
		static int mCount;
};

#include <QUrl>
/*
#include <QWebView>
#include <QtDebug>
#include <QUrl>
#include <QWebFrame>

class MyWebView : public QWebView
{
	Q_OBJECT

	public : 
	
		MyWebView();

	protected Q_SLOTS :

		void loadIsFinished(bool );

};
*/
#endif //LANGUAGE_ITEM_H