File indexing completed on 2024-09-01 03:36:16
0001 /* 0002 SPDX-FileCopyrightText: 2010 Akarsh Simha <akarsh.simha@kdemail.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef SKYMAPDRAWABSTRACT_H_ 0008 #define SKYMAPDRAWABSTRACT_H_ 0009 0010 #include "kstarsdata.h" 0011 #include <QPainter> 0012 #include <QPaintEvent> 0013 #include <QPaintDevice> 0014 0015 class SkyMap; 0016 class SkyQPainter; 0017 0018 /** 0019 *@short This class defines the methods that both rendering engines 0020 * (GLPainter and QPainter) must implement. This also allows us to add 0021 * more rendering engines if required. 0022 *@version 1.0 0023 *@author Akarsh Simha <akarsh.simha@kdemail.net> 0024 */ 0025 0026 // In summary, this is a class created by stealing all the 0027 // drawing-related methods from the old SkyMap class 0028 0029 class SkyMapDrawAbstract 0030 { 0031 protected: 0032 /** 0033 *@short Virtual Destructor 0034 */ 0035 virtual ~SkyMapDrawAbstract() = default; 0036 0037 public: 0038 /** 0039 *@short Constructor that sets data and m_SkyMap, and initializes 0040 * the FPS counters. 0041 */ 0042 explicit SkyMapDrawAbstract(SkyMap *sm); 0043 0044 // *********************** "IMPURE" VIRTUAL METHODS ******************* // 0045 // NOTE: The following methods are implemented using native 0046 // QPainter in both cases. So it's virtual, but not pure virtual 0047 0048 /**Draw the overlays on top of the sky map. These include the infoboxes, 0049 *field-of-view indicator, telescope symbols, zoom box and any other 0050 *user-interaction graphics. 0051 * 0052 *The overlays can be updated rapidly, without having to recompute the entire SkyMap. 0053 *The stored Sky image is simply blitted onto the SkyMap widget, and then we call 0054 *drawOverlays() to refresh the overlays. 0055 *@param p pointer to the Sky pixmap 0056 *@param drawFov determines if the FOV should be drawn 0057 */ 0058 void drawOverlays(QPainter &p, bool drawFov = true); 0059 0060 /**Draw symbols at the position of each Telescope currently being controlled by KStars. 0061 *@note The shape of the Telescope symbol is currently a hard-coded bullseye. 0062 *@param psky reference to the QPainter on which to draw (this should be the Sky pixmap). 0063 */ 0064 void drawTelescopeSymbols(QPainter &psky); 0065 0066 /**Draw FOV of solved image in Ekos Alignment Module 0067 *@param psky reference to the QPainter on which to draw (this should be the Sky pixmap). 0068 */ 0069 void drawSolverFOV(QPainter &psky); 0070 0071 /** 0072 * @short Draw north and zenith arrows to show the orientation while rotating the sky map 0073 * @param p reference to the QPainter on which to draw (this should be the sky map) 0074 */ 0075 void drawOrientationArrows(QPainter &p); 0076 0077 /** 0078 *@short Draw a dotted-line rectangle which traces the potential new field-of-view in ZoomBox mode. 0079 *@param psky reference to the QPainter on which to draw (this should be the Sky pixmap). 0080 */ 0081 void drawZoomBox(QPainter &psky); 0082 0083 /**Draw a dashed line from the Angular-Ruler start point to the current mouse cursor, 0084 *when in Angular-Ruler mode. 0085 *@param psky reference to the QPainter on which to draw (this should be the Sky pixmap). 0086 */ 0087 void drawAngleRuler(QPainter &psky); 0088 0089 /** @short Draw the current Sky map to a pixmap which is to be printed or exported to a file. 0090 * 0091 *@param pd pointer to the QPaintDevice on which to draw. 0092 *@param scale defines if the Sky map should be scaled. 0093 *@see KStars::slotExportImage() 0094 *@see KStars::slotPrint() 0095 */ 0096 void exportSkyImage(QPaintDevice *pd, bool scale = false); 0097 0098 /** @short Draw the current Sky map using passed SkyQPainter instance. Required when 0099 * used QPaintDevice doesn't support drawing using multiple painters (e.g. QSvgGenerator 0100 * which generates broken SVG output when more than one QPainter subclass is used). 0101 * Passed painter should already be initialized to draw on selected QPaintDevice subclass 0102 * using begin() and it won't be ended [end()] by this method. 0103 *@param painter pointer to the SkyQPainter already set up to paint on selected QPaintDevice subclass. 0104 *@param scale should sky image be scaled to fit used QPaintDevice? 0105 */ 0106 void exportSkyImage(SkyQPainter *painter, bool scale = false); 0107 0108 /** @short Draw "user labels". User labels are name labels attached to objects manually with 0109 * the right-click popup menu. Also adds a label to the FocusObject if the Option UseAutoLabel 0110 * is true. 0111 * @param labelObjects QList of pointers to the objects which need labels (excluding the centered object) 0112 * @note the labelObjects list is managed by the SkyMapComponents class 0113 */ 0114 void drawObjectLabels(QList<SkyObject *> &labelObjects); 0115 0116 /** 0117 *@return true if a draw is in progress or is locked, false otherwise. This is just the value of m_DrawLock 0118 */ 0119 static inline bool drawLock() { return m_DrawLock; } 0120 0121 /** 0122 *@short Acquire / release a draw lock. This prevents other drawing from happening 0123 */ 0124 static void setDrawLock(bool state); 0125 0126 // *********************** PURE VIRTUAL METHODS ******************* // 0127 // NOTE: The following methods differ between GL and QPainter backends 0128 // Thus, they are pure virtual and must be implemented by the subclass 0129 0130 protected: 0131 /** 0132 *@short Overridden paintEvent method. Must be implemented by 0133 * subclasses to draw the SkyMap. (This method is pure 0134 * virtual) 0135 */ 0136 virtual void paintEvent(QPaintEvent *e) = 0; 0137 0138 /* 0139 *NOTE: 0140 * Depending on whether the implementation of this class is a 0141 * GL-backend, it may need to implement these methods: 0142 * virtual void resizeGL(int width, int height); 0143 * virtual void initializeGL(); 0144 * So we will not even bother defining them here. 0145 * They must be taken care of in the subclasses 0146 */ 0147 0148 KStarsData *m_KStarsData; 0149 SkyMap *m_SkyMap; 0150 static bool m_DrawLock; 0151 0152 /** Calculate FPS and dump result to stderr using qDebug */ 0153 //void calculateFPS(); 0154 private: 0155 // int m_framecount; // To count FPS 0156 //QTime m_fpstime; 0157 }; 0158 0159 #endif