Kstars

skymapqdraw.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Akarsh Simha <[email protected]>
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 
27 void SkyMapQDraw::paintEvent(QPaintEvent *event)
28 {
29  Q_UNUSED(event)
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
73  QPainterPath path;
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 
82  QPainter psky2;
83  psky2.begin(this);
84  psky2.drawLine(0, 0, 1, 1); // Dummy op.
85  psky2.drawPixmap(0, 0, *m_SkyPixmap);
86  drawOverlays(psky2);
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 
99 void SkyMapQDraw::resizeEvent(QResizeEvent *e)
100 {
101  Q_UNUSED(e)
102  delete m_SkyPixmap;
103  m_SkyPixmap = new QPixmap(width(), height());
104 }
The QPainter-based painting backend.
Definition: skyqpainter.h:28
void addPolygon(const QPolygonF &polygon)
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
virtual bool event(QEvent *event) override
void fill(const QColor &color)
This class defines the methods that both rendering engines (GLPainter and QPainter) must implement.
~SkyMapQDraw() override
Destructor.
Definition: skymapqdraw.cpp:22
void drawOverlays(QPainter &p, bool drawFov=true)
Draw the overlays on top of the sky map.
SkyMapQDraw(SkyMap *parent)
Constructor.
Definition: skymapqdraw.cpp:16
bool begin(QPaintDevice *device)
T * data() const const
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
bool end()
void setupProjector()
Call to set up the projector before a draw cycle.
Definition: skymap.cpp:1212
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:165
void updateInfoBoxes()
Update info boxes coordinates.
Definition: skymap.cpp:300
Canvas widget for displaying the sky bitmap; also handles user interaction events.
Definition: skymap.h:52
virtual QPolygonF clipPoly() const
Definition: projector.cpp:385
void drawLine(const QLineF &line)
const Projector * projector() const
Get the current projector.
Definition: skymap.h:299
void reset(T *other)
static void setDrawLock(bool state)
Acquire / release a draw lock.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.