File indexing completed on 2024-05-12 16:06:35
0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*- 0002 /** 0003 * \file dviexport.h 0004 * Distributed under the GNU GPL version 2 or (at your option) 0005 * any later version. See accompanying file COPYING or copy at 0006 * http://www.gnu.org/copyleft/gpl.html 0007 * 0008 * \author Angus Leeming 0009 * \author Stefan Kebekus 0010 * 0011 * Classes DVIExportToPDF and DVIExportToPS control the export 0012 * of a DVI file to PDF or PostScript format, respectively. 0013 * Common functionality is factored out into a common base class, 0014 * DVIExport which itself derives from QSharedData allowing easy, 0015 * polymorphic storage of multiple QExplicitlySharedDataPointer<DVIExport> variables 0016 * in a container of all exported processes. 0017 */ 0018 0019 #ifndef DVIEXPORT_H 0020 #define DVIEXPORT_H 0021 0022 #include <QExplicitlySharedDataPointer> 0023 0024 #include <QObject> 0025 #include <QPrinter> 0026 0027 class dviRenderer; 0028 class KProcess; 0029 0030 class DVIExport : public QObject, public QSharedData 0031 { 0032 Q_OBJECT 0033 public: 0034 ~DVIExport() override; 0035 0036 /** @c started() Flags whether or not the external process was 0037 * spawned successfully. 0038 * Can be used to decide whether to discard the DVIExport variable, 0039 * or to store it and await notification that the external process 0040 * has finished. 0041 */ 0042 bool started() const 0043 { 0044 return started_; 0045 } 0046 0047 Q_SIGNALS: 0048 void error(const QString &message, int duration); 0049 0050 protected: 0051 /** @param parent is stored internally in order to inform the parent 0052 * that the external process has finished and that this variable 0053 * can be removed from any stores. 0054 */ 0055 explicit DVIExport(dviRenderer &parent); 0056 0057 /** Spawns the external process having connected slots to the child 0058 * process's stdin and stdout streams. 0059 */ 0060 void start(const QString &command, const QStringList &args, const QString &working_directory, const QString &error_message); 0061 0062 /** The real implementation of the abort_process() slot that is 0063 * called when the fontProcessDialog is closed by the user, 0064 * indicating that the export should be halted. 0065 */ 0066 virtual void abort_process_impl(); 0067 0068 /** The real implementation of the finished() slot that is called 0069 * when the external process finishes. 0070 * @param exit_code the exit code returned by the external process. 0071 */ 0072 virtual void finished_impl(int exit_code); 0073 0074 private Q_SLOTS: 0075 /// Calls an impl() inline so that derived classes don't need slots. 0076 void abort_process() 0077 { 0078 abort_process_impl(); 0079 } 0080 void finished(int exit_code) 0081 { 0082 finished_impl(exit_code); 0083 } 0084 0085 /** This slot receives all output from the child process's stdin 0086 * and stdout streams. 0087 */ 0088 void output_receiver(); 0089 0090 private: 0091 QString error_message_; 0092 bool started_; 0093 KProcess *process_; 0094 dviRenderer *parent_; 0095 }; 0096 0097 class DVIExportToPDF : public DVIExport 0098 { 0099 Q_OBJECT 0100 0101 public: 0102 /** @param parent is stored internally in order to inform the parent 0103 * that the external process has finished. 0104 * @param output_name is the name of the PDF file that is 0105 * to contain the exported data. */ 0106 DVIExportToPDF(dviRenderer &parent, const QString &output_name); 0107 }; 0108 0109 class DVIExportToPS : public DVIExport 0110 { 0111 Q_OBJECT 0112 0113 public: 0114 /** @param parent is stored internally in order to inform the parent 0115 * that the external process has finished. 0116 * @param output_name is the name of the PostScript file that is 0117 * to contain the exported data. 0118 * @param options extra command line arguments that are to be 0119 * passed to the external process's argv command line. 0120 * @param printer having generated the PostScript file, it is passed 0121 * to @c printer (if not null). 0122 * @param useFontHinting boolean that defines whether to use font hinting. 0123 * @param orientation the original orientation of the document 0124 */ 0125 DVIExportToPS(dviRenderer &parent, const QString &output_name, const QStringList &options, QPrinter *printer, bool useFontHinting, QPageLayout::Orientation orientation = QPageLayout::Portrait); 0126 0127 private: 0128 void abort_process_impl() override; 0129 void finished_impl(int exit_code) override; 0130 0131 QPrinter *printer_; 0132 QString output_name_; 0133 QString tmpfile_name_; 0134 QPageLayout::Orientation orientation_; 0135 }; 0136 0137 #endif