File indexing completed on 2022-12-06 18:58:56

0001 /*
0002     SPDX-FileCopyrightText: 2010 Henry de Valence <hdevalence@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "skypainter.h"
0010 #include "config-kstars.h"
0011 
0012 #include <QColor>
0013 #include <QMap>
0014 
0015 class Projector;
0016 class QWidget;
0017 class QSize;
0018 class QMessageBox;
0019 class HIPSRenderer;
0020 class TerrainRenderer;
0021 class KSEarthShadow;
0022 
0023 /**
0024  * @short The QPainter-based painting backend.
0025  * This class implements the SkyPainter interface using a QPainter.
0026  * For documentation, @see SkyPainter.
0027  */
0028 class SkyQPainter : public SkyPainter, public QPainter
0029 {
0030     public:
0031         /** Release the image cache */
0032         static void releaseImageCache();
0033 
0034         /**
0035              * @short Creates a SkyQPainter with the given QPaintDevice and uses the dimensions of the paint device as canvas dimensions
0036              * @param pd the painting device. Cannot be 0
0037              * @param canvasSize the size of the canvas
0038              */
0039         SkyQPainter(QPaintDevice *pd, const QSize &canvasSize);
0040 
0041         /**
0042              * @short Creates a SkyQPainter with the given QPaintDevice and given canvas size
0043              * @param pd the painting device. Cannot be 0
0044              */
0045         explicit SkyQPainter(QPaintDevice *pd);
0046 
0047         /**
0048              * @short Creates a SkyQPainter given a QWidget and an optional QPaintDevice.
0049              * @param widget the QWidget that provides the canvas size, and also the paint device unless @p pd is specified
0050              * @param pd the painting device. If 0, then @p widget will be used.
0051              */
0052         explicit SkyQPainter(QWidget *widget, QPaintDevice *pd = nullptr);
0053 
0054         ~SkyQPainter() override;
0055 
0056         void setPaintDevice(QPaintDevice *pd)
0057         {
0058             m_pd = pd;
0059         }
0060         void setPen(const QPen &pen) override;
0061         void setBrush(const QBrush &brush) override;
0062 
0063         /**
0064              * @param vectorStars Draw stars as vector graphics whenever possible.
0065              * @note Drawing stars as vectors is slower, but is better when saving .svg files. Set to true only when you are drawing on a canvas where speed doesn't matter. Definitely not when drawing on the SkyMap.
0066              */
0067         inline void setVectorStars(bool vectorStars)
0068         {
0069             m_vectorStars = vectorStars;
0070         }
0071         inline bool getVectorStars() const
0072         {
0073             return m_vectorStars;
0074         }
0075 
0076         void begin() override;
0077         void end() override;
0078 
0079         /** Recalculates the star pixmaps. */
0080         static void initStarImages();
0081 
0082         // Sky drawing functions
0083         void drawSkyBackground() override;
0084         void drawSkyLine(SkyPoint *a, SkyPoint *b) override;
0085         void drawSkyPolyline(LineList *list, SkipHashList *skipList = nullptr,
0086                              LineListLabel *label = nullptr) override;
0087         void drawSkyPolygon(LineList *list, bool forceClip = true) override;
0088         bool drawPointSource(const SkyPoint *loc, float mag, char sp = 'A') override;
0089         bool drawCatalogObject(const CatalogObject &obj) override;
0090         void drawCatalogObjectImage(const QPointF &pos, const CatalogObject &obj,
0091                                     float positionAngle);
0092         bool drawPlanet(KSPlanetBase *planet) override;
0093         bool drawEarthShadow(KSEarthShadow *shadow) override;
0094         void drawObservingList(const QList<SkyObject *> &obs) override;
0095         void drawFlags() override;
0096         void drawHorizon(bool filled, SkyPoint *labelPoint = nullptr,
0097                          bool *drawLabel = nullptr) override;
0098         bool drawSatellite(Satellite *sat) override;
0099         virtual void drawDeepSkySymbol(const QPointF &pos, int type, float size, float e,
0100                                        float positionAngle);
0101         bool drawSupernova(Supernova *sup) override;
0102         bool drawComet(KSComet *com) override;
0103         /// This function exists so that we can draw other objects (e.g., planets) as point sources.
0104         virtual void drawPointSource(const QPointF &pos, float size, char sp = 'A');
0105         bool drawConstellationArtImage(ConstellationsArt *obj) override;
0106 #ifdef HAVE_INDI
0107         bool drawMosaicPanel(MosaicTiles *obj) override;
0108 #endif
0109         bool drawHips(bool useCache = false) override;
0110         bool drawTerrain(bool useCache = false) override;
0111 
0112     private:
0113         QPaintDevice *m_pd{ nullptr };
0114         const Projector *m_proj{ nullptr };
0115         bool m_vectorStars{ false };
0116         HIPSRenderer *m_hipsRender{ nullptr };
0117         TerrainRenderer *m_terrainRender{ nullptr };
0118         QSize m_size;
0119         QScopedPointer<QImage> m_HiPSImage;
0120         static int starColorMode;
0121         static QColor m_starColor;
0122         static QMap<char, QColor> ColorMap;
0123 };