File: pageitem_latexframe.h

package info (click to toggle)
scribus 1.4.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 246,704 kB
  • ctags: 25,243
  • sloc: cpp: 272,543; xml: 15,558; ansic: 3,438; python: 3,427; makefile: 1,160; perl: 94; sh: 41
file content (130 lines) | stat: -rw-r--r-- 4,249 bytes parent folder | download | duplicates (4)
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
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
						pageitem_latexframe.h  -  description
						-------------------
copyright            : Scribus Team
***************************************************************************/

/***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/

#ifndef PAGEITEM_LATEXFRAME_H
#define PAGEITEM_LATEXFRAME_H

#include <QObject>
#include <QWidget>
#include <QString>
#include <QProcess>
#include <QMap>

#include "scribusapi.h"
#include "pageitem.h"
#include "pageitem_imageframe.h"

class QTemporaryFile;
class LatexEditor;
class LatexConfigParser;
class QTimer;

/** @brief Displays all kinds of content generated by external programs.
	Named LatexFrame because it initally only showed the output of Latex.
*/
class SCRIBUS_API PageItem_LatexFrame : public PageItem_ImageFrame
{
	Q_OBJECT

	public:
		PageItem_LatexFrame(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline);
		~PageItem_LatexFrame();
		
		virtual PageItem_LatexFrame * asLatexFrame() { return this; }
		virtual bool isLatexFrame() const { return true; }

		virtual void clearContents();
		virtual ItemType realItemType() const { return PageItem::LatexFrame; }
		virtual void applicableActions(QStringList& actionList);
		virtual QString infoDescription();
		void layout();
		
		/** @brief Perform undo/redo action */
		void restore(UndoState *state, bool isUndo);
		
		
		/** @brief UI-Callback that runs the editor. */
		void runEditor();
		/*TODO void convertToVector(); */
		
		/** @brief Sets the formula text and forces rerunning latex.
			Emits formulaAutoUpdate() when undoable is false.
			@return Returns true if the frame has to be updated, false if nothing changed.
		*/
		bool setFormula(QString formula, bool undoable=true);
		/** @brief Get current source. */
		QString formula() const { return formulaText; }
		
		/** @brief Runs the external application and sets internal vars and loads
		the image.*/
		void runApplication();
		
		void rerunApplication(bool updateDisplay=false);
		
		QString configFile() const;
		void setConfigFile(QString newConfig, bool relative=false);
		QString application() const;
		bool usePreamble() const { return m_usePreamble; }
		int dpi() const { return m_dpi; }
		int realDpi() const;
		
		const QString output() const { return appStdout; }
		QProcess::ProcessState state() const { return latex->state(); }
		int error() const { return err; }

		QMap<QString,QString> editorProperties;
	protected:
		virtual void DrawObj_Item(ScPainter *p, QRectF e, double sc);
		double lastWidth, lastHeight;
		
		QString formulaText;

		void writeFileContents(QFile *tempfile);
		void deleteImageFile();
		/* Last error code */
		int err;
		int m_dpi;
		
		QString imageFile, tempFileBase;
		QString appStdout;
		QString configFilename;
		
		QProcess *latex;
		LatexEditor *internalEditor;
		LatexConfigParser *config;
		bool imgValid;
		bool m_usePreamble;
		bool killed;
	signals:
		void formulaAutoUpdate(QString oldText, QString newText);
		void latexFinished();
		void stateChanged(QProcess::ProcessState state);
		void applicationChanged();
	protected slots:
		void updateImage(int exitCode, QProcess::ExitStatus exitStatus);
		void latexError(QProcess::ProcessError error);
	public slots:
		void killProcess();
		void setDpi(int dpi);
		void setUsePreamble(bool);
};

#endif