File indexing completed on 2024-03-24 03:45:01
0001 /* 0002 SPDX-FileCopyrightText: 2013 Akarsh Simha <akarsh.simha@kdemail.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef IMAGEEXPORTER_H 0008 #define IMAGEEXPORTER_H 0009 0010 #include "../printing/legend.h" 0011 0012 #include <QObject> 0013 0014 class KStars; 0015 class QSize; 0016 0017 /** 0018 * @class ImageExporter 0019 * @short Backends for exporting a sky image, either raster or vector, with a legend 0020 * @author Rafał Kułaga <rl.kulaga@gmail.com> 0021 * @author Akarsh Simha <akarsh.simha@kdemail.net> 0022 */ 0023 class ImageExporter : public QObject 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 /** 0029 * @short Constructor 0030 */ 0031 explicit ImageExporter(QObject *parent = nullptr); 0032 0033 /** 0034 * @short Destructor 0035 */ 0036 ~ImageExporter() override; 0037 0038 /** 0039 * @return last error message 0040 */ 0041 inline QString getLastErrorMessage() const { return m_lastErrorMessage; } 0042 0043 public Q_SLOTS: 0044 /** 0045 * @short Exports an image with the defined settings. 0046 * @param url URL of the exported image 0047 * @return false if the URL was a network location and uploading to the network location failed 0048 * @note This method calls an SVG backend instead if the file extension is svg. Otherwise, it draws raster. 0049 */ 0050 bool exportImage(QString url); 0051 0052 /** 0053 * @short Set the legend properties 0054 * @param type Legend type. (See enum LEGEND_TYPE in legend.h) 0055 * @param orientation Legend orientation. (See LEGEND_ORIENTATION in legend.h) 0056 * @param position Legend position. (See LEGEND_POSITION in legend.h) 0057 * @param alpha Legend alpha (transparency). Default value is 160. 0058 * @param include Include the legend? 0059 */ 0060 void setLegendProperties(Legend::LEGEND_TYPE type, Legend::LEGEND_ORIENTATION orientation, 0061 Legend::LEGEND_POSITION position, int alpha = 160, bool include = true); 0062 0063 /** 0064 * @short Include legend? 0065 * @param include The legend will be included if the flag is set to true 0066 */ 0067 inline void includeLegend(bool include) { m_includeLegend = include; } 0068 0069 /** 0070 * @short Set legend transparency 0071 * @param alpha Transparency level 0072 */ 0073 void setLegendAlpha(int alpha); 0074 0075 /** 0076 * @short Set the size of output raster images 0077 * @param size a pointer to a QSize containing the size of images. If a null pointer is supplied, the SkyMap size is used. 0078 * @note If size is larger than the skymap size, then the sky image is padded; if it is smaller, then it is cropped. No rescaling is done. 0079 */ 0080 void setRasterOutputSize(const QSize *size); 0081 0082 /** 0083 * @return a pointer to the legend used 0084 */ 0085 inline Legend *getLegend() { return m_Legend; } 0086 0087 private: 0088 void exportSvg(const QString &fileName); 0089 bool exportRasterGraphics(const QString &fileName); 0090 void addLegend(SkyQPainter *painter); 0091 void addLegend(QPaintDevice *pd); 0092 0093 bool m_includeLegend; 0094 Legend *m_Legend; 0095 QSize *m_Size; 0096 QString m_lastErrorMessage; 0097 }; 0098 0099 #endif