File indexing completed on 2024-04-21 15:55:46

0001 /***************************************************************************
0002     date                 : Feb 15 2007
0003     version              : 0.34
0004     copyright            : (C) 2005-2007 by Holger Danielsson
0005     email                : holger.danielsson@versanet.de
0006  ***************************************************************************/
0007 
0008 /***************************************************************************
0009  *                                                                         *
0010  *   This program is free software; you can redistribute it and/or modify  *
0011  *   it under the terms of the GNU General Public License as published by  *
0012  *   the Free Software Foundation; either version 2 of the License, or     *
0013  *   (at your option) any later version.                                   *
0014  *                                                                         *
0015  ***************************************************************************/
0016 
0017 #ifndef QUICKPREVIEW_H
0018 #define QUICKPREVIEW_H
0019 
0020 #include "kileinfo.h"
0021 #include "kiletool.h"
0022 #include "editorextension.h"
0023 #include "widgets/previewwidget.h"
0024 
0025 #include <QObject>
0026 #include <QString>
0027 #include <QStringList>
0028 
0029 #include <QTemporaryDir>
0030 
0031 namespace KileTool
0032 {
0033 enum { qpSelection=0, qpEnvironment, qpSubdocument, qpMathgroup };
0034 
0035 class QuickPreview : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     explicit QuickPreview(KileInfo *ki);
0041     ~QuickPreview();
0042 
0043     bool run(const QString &text,const QString &textfilename,int startrow);
0044     bool isRunning();
0045 
0046     void previewEnvironment(KTextEditor::Document *doc);
0047     void previewSelection(KTextEditor::View *view, bool previewInWidgetConfig=true);
0048     void previewSubdocument(KTextEditor::Document *doc);
0049     void previewMathgroup(KTextEditor::Document *doc);
0050 
0051     /**
0052      * run (text, textfilename, startrow) works with the
0053      * default configuration for QuickPreview. This method
0054      * supports a forth parameter to choose the configuration as
0055      * comma - separated string as you can see them in run (text, textfilename, startrow)
0056      *
0057      * It is also possible not to specify a viewer, so the viewer is not
0058      * executed.
0059      *
0060      * @param text         Text to preview
0061      * @param textfilename Filename of the document
0062      * @param startrow     Position of preview text in the document
0063      * @param spreviewlist user-defined configuration, e.g. "PreviewLaTeX,DVItoPS,,,ps" (with no preview)
0064      * @return             true if method succeeds, else false
0065      */
0066     bool run (const QString &text, const QString &textfilename, int startrow, const QString &spreviewlist);
0067     void getTaskList(QStringList &tasklist);
0068 
0069     /**
0070      * QuickPreview uses temporary files for processing the output.
0071      * If you want to work with files from QuickPreview, you
0072      * can use this method. The method run returns true, and then
0073      * you can get the generated ps e.g. with getPreviewFile ("eps");
0074      * It works with all extensions which are generated while running
0075      * the corresponding tools (e.g. tex, dvi, ps, pdf, ...)
0076      *
0077      * @param  extension defines which file to use
0078      * @return           The temporary file with extension
0079      */
0080     QString getPreviewFile(const QString &extension);
0081 
0082 private Q_SLOTS:
0083     void toolDestroyed();
0084 
0085 private:
0086     enum { pvLatex=0, pvDvips=1, pvDvipsCfg=2, pvViewer=3, pvViewerCfg=4, pvExtension=5 };
0087 
0088     KileInfo *m_ki;
0089     QString m_tempFile;
0090     QStringList m_taskList;
0091     int m_running;
0092     QTemporaryDir *m_tempDir;
0093 
0094     int createTempfile(const QString &text);
0095     void showError(const QString &text);
0096 };
0097 
0098 }
0099 
0100 #endif