Kstars

skymapqdraw.cpp
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
17{
18 m_SkyPixmap = new QPixmap(width(), height());
19 m_SkyPainter.reset(new SkyQPainter(this, m_SkyPixmap));
20}
21
23{
24 delete m_SkyPixmap;
25}
26
27void SkyMapQDraw::paintEvent(QPaintEvent *event)
28{
30 // This is machinery to prevent multiple concurrent paint events / recursive paint events
31 if (m_DrawLock)
32 {
33 qCDebug(KSTARS) << "Prevented a recursive / concurrent draw!";
34 return;
35 }
36 setDrawLock(true);
37
38 // JM 2016-05-03: Not needed since we're not using OpenGL for now
39 //calculateFPS();
40
41 //If computeSkymap is false, then we just refresh the window using the stored sky pixmap
42 //and draw the "overlays" on top. This lets us update the overlay information rapidly
43 //without needing to recompute the entire skymap.
44 //use update() to trigger this "short" paint event; to force a full "recompute"
45 //of the skymap, use forceUpdate().
46
47 if (!m_SkyMap->computeSkymap)
48 {
49 QPainter p;
50 p.begin(this);
51 p.drawLine(0, 0, 1, 1); // Dummy operation to circumvent bug. TODO: Add details
52 p.drawPixmap(0, 0, *m_SkyPixmap);
53 drawOverlays(p);
54 p.end();
55
56 setDrawLock(false);
57 return; // exit because the pixmap is repainted and that's all what we want
58 }
59
60 m_SkyMap->updateInfoBoxes();
61 m_SkyMap->setupProjector();
62
63 m_SkyPixmap->fill(Qt::black);
64 m_SkyPainter->setPaintDevice(m_SkyPixmap);
65
66 //FIXME: we may want to move this into the components.
67 m_SkyPainter->begin();
68
69 //Draw all sky elements
70 m_SkyPainter->drawSkyBackground();
71
72 // Set Clipping
74 path.addPolygon(m_SkyMap->projector()->clipPoly());
75 m_SkyPainter->setClipPath(path);
76 m_SkyPainter->setClipping(true);
77
78 m_KStarsData->skyComposite()->draw(m_SkyPainter.data());
79 //Finish up
80 m_SkyPainter->end();
81
83 psky2.begin(this);
84 psky2.drawLine(0, 0, 1, 1); // Dummy op.
85 psky2.drawPixmap(0, 0, *m_SkyPixmap);
87 psky2.end();
88
89 if (m_SkyMap->m_previewLegend)
90 {
91 m_SkyMap->m_legend.paintLegend(m_SkyPixmap);
92 }
93
94 m_SkyMap->computeSkymap = false; // use forceUpdate() to compute new skymap else old pixmap will be shown
95
96 setDrawLock(false);
97}
98
99void SkyMapQDraw::resizeEvent(QResizeEvent *e)
100{
101 Q_UNUSED(e)
102 delete m_SkyPixmap;
103 m_SkyPixmap = new QPixmap(width(), height());
104}
SkyMapComposite * skyComposite()
Definition kstarsdata.h:166
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
This class defines the methods that both rendering engines (GLPainter and QPainter) must implement.
static void setDrawLock(bool state)
Acquire / release a draw lock.
void drawOverlays(QPainter &p, bool drawFov=true)
Draw the overlays on top of the sky map.
~SkyMapQDraw() override
Destructor.
SkyMapQDraw(SkyMap *parent)
Constructor.
This is the canvas on which the sky is painted.
Definition skymap.h:54
void setupProjector()
Call to set up the projector before a draw cycle.
Definition skymap.cpp:1246
void updateInfoBoxes()
Update info boxes coordinates.
Definition skymap.cpp:335
const Projector * projector() const
Get the current projector.
Definition skymap.h:300
The QPainter-based painting backend.
Definition skyqpainter.h:31
QString path(const QString &relativePath)
bool begin(QPaintDevice *device)
void drawLine(const QLine &line)
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
bool end()
void fill(const QColor &color)
T * data() const const
void reset(T *other)
virtual bool event(QEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:04 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.