File indexing completed on 2024-04-14 14:11:57

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