1 /*
2 SPDX-FileCopyrightText: 2010 Akarsh Simha <akarsh.simha@kdemail.net>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "skymapqdraw.h"
8 #include "skymapcomposite.h"
9 #include "skyqpainter.h"
10 #include "skymap.h"
11 #include "projections/projector.h"
12 #include "printing/legend.h"
13 #include "kstars_debug.h"
14 #include <QPainterPath>
15
SkyMapQDraw(SkyMap * sm)16 SkyMapQDraw::SkyMapQDraw(SkyMap *sm) : QWidget(sm), SkyMapDrawAbstract(sm)
17 {
18 m_SkyPixmap = new QPixmap(width(), height());
19 }
20
~SkyMapQDraw()21 SkyMapQDraw::~SkyMapQDraw()
22 {
23 delete m_SkyPixmap;
24 }
25
paintEvent(QPaintEvent * event)26 void SkyMapQDraw::paintEvent(QPaintEvent *event)
27 {
28 Q_UNUSED(event)
29 // This is machinery to prevent multiple concurrent paint events / recursive paint events
30 if (m_DrawLock)
31 {
32 qCDebug(KSTARS) << "Prevented a recursive / concurrent draw!";
33 return;
34 }
35 setDrawLock(true);
36
37 // JM 2016-05-03: Not needed since we're not using OpenGL for now
38 //calculateFPS();
39
40 //If computeSkymap is false, then we just refresh the window using the stored sky pixmap
41 //and draw the "overlays" on top. This lets us update the overlay information rapidly
42 //without needing to recompute the entire skymap.
43 //use update() to trigger this "short" paint event; to force a full "recompute"
44 //of the skymap, use forceUpdate().
45
46 if (!m_SkyMap->computeSkymap)
47 {
48 QPainter p;
49 p.begin(this);
50 p.drawLine(0, 0, 1, 1); // Dummy operation to circumvent bug. TODO: Add details
51 p.drawPixmap(0, 0, *m_SkyPixmap);
52 drawOverlays(p);
53 p.end();
54
55 setDrawLock(false);
56 return; // exit because the pixmap is repainted and that's all what we want
57 }
58
59 // FIXME: used to notify infobox about possible change of object coordinates
60 // Not elegant at all. Should find better option
61 m_SkyMap->showFocusCoords();
62 m_SkyMap->setupProjector();
63
64 SkyQPainter psky(this, m_SkyPixmap);
65 //FIXME: we may want to move this into the components.
66 psky.begin();
67
68 //Draw all sky elements
69 psky.drawSkyBackground();
70
71 // Set Clipping
72 QPainterPath path;
73 path.addPolygon(m_SkyMap->projector()->clipPoly());
74 psky.setClipPath(path);
75 psky.setClipping(true);
76
77 m_KStarsData->skyComposite()->draw(&psky);
78 //Finish up
79 psky.end();
80
81 QPainter psky2;
82 psky2.begin(this);
83 psky2.drawLine(0, 0, 1, 1); // Dummy op.
84 psky2.drawPixmap(0, 0, *m_SkyPixmap);
85 drawOverlays(psky2);
86 psky2.end();
87
88 if (m_SkyMap->m_previewLegend)
89 {
90 m_SkyMap->m_legend.paintLegend(m_SkyPixmap);
91 }
92
93 m_SkyMap->computeSkymap = false; // use forceUpdate() to compute new skymap else old pixmap will be shown
94
95 setDrawLock(false);
96 }
97
resizeEvent(QResizeEvent * e)98 void SkyMapQDraw::resizeEvent(QResizeEvent *e)
99 {
100 Q_UNUSED(e)
101 delete m_SkyPixmap;
102 m_SkyPixmap = new QPixmap(width(), height());
103 }
104