• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • printing
simplefovexporter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  simplefovexporter.cpp - K Desktop Planetarium
3  -------------------
4  begin : Thu Jul 7 2011
5  copyright : (C) 2011 by Rafał Kułaga
6  email : rl.kulaga@gmail.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "simplefovexporter.h"
19 #include "kstarsdata.h"
20 #include "skymap.h"
21 #include "skyqpainter.h"
22 #include "fov.h"
23 #include "skymapcomposite.h"
24 #include "kstars/Options.h"
25 
26 SimpleFovExporter::SimpleFovExporter() :
27  m_KSData(KStarsData::Instance()), m_Map(KStars::Instance()->map()),
28  m_StopClock(false), m_OverrideFovShape(false), m_DrawFovSymbol(false),
29  m_PrevClockState(false), m_PrevSlewing(false), m_PrevPoint(0),
30  m_PrevZoom(0)
31 {}
32 
33 void SimpleFovExporter::exportFov(SkyPoint *point, FOV *fov, QPaintDevice *pd)
34 {
35  saveState(true);
36  pExportFov(point, fov, pd);
37  restoreState(true);
38 }
39 
40 void SimpleFovExporter::exportFov(FOV *fov, QPaintDevice *pd)
41 {
42  pExportFov(0, fov, pd);
43 }
44 
45 void SimpleFovExporter::exportFov(QPaintDevice *pd)
46 {
47  SkyQPainter painter(m_Map, pd);
48  painter.begin();
49 
50  painter.drawSkyBackground();
51 
52  // translate painter coordinates - it's necessary to extract only the area of interest (FOV)
53  int dx = (m_Map->width() - pd->width()) / 2;
54  int dy = (m_Map->height() - pd->height()) / 2;
55  painter.translate(-dx, -dy);
56 
57  m_KSData->skyComposite()->draw(&painter);
58  m_Map->getSkyMapDrawAbstract()->drawOverlays(painter, false);
59 }
60 
61 void SimpleFovExporter::exportFov(const QList<SkyPoint*> &points, const QList<FOV*> &fovs, const QList<QPaintDevice*> &pds)
62 {
63  Q_ASSERT(points.size() == fovs.size() && fovs.size() == pds.size());
64 
65  saveState(true);
66 
67  for(int i = 0; i < points.size(); i++)
68  {
69  exportFov(points.value(i), fovs.at(i), pds.value(i));
70  }
71 
72  restoreState(true);
73 }
74 
75 void SimpleFovExporter::exportFov(const QList<SkyPoint*> &points, FOV *fov, const QList<QPaintDevice*> &pds)
76 {
77  Q_ASSERT(points.size() == pds.size());
78 
79  saveState(true);
80 
81  for(int i = 0; i < points.size(); i++)
82  {
83  exportFov(points.at(i), fov, pds.at(i));
84  }
85 
86  restoreState(true);
87 }
88 
89 void SimpleFovExporter::pExportFov(SkyPoint *point, FOV *fov, QPaintDevice *pd)
90 {
91  if(point)
92  {
93  // center sky map on selected point
94  m_Map->setClickedPoint(point);
95  m_Map->slotCenter();
96  }
97 
98  // this is temporary 'solution' that will be changed during the implementation of printing
99  // on large paper sizes (>A4), in which case it'll be desirable to export high-res FOV
100  // representations
101  if(pd->height() > m_Map->height() || pd->width() > m_Map->width())
102  {
103  return;
104  }
105 
106  // calculate zoom factor
107  double zoom = 0;
108  QRegion region;
109  int regionX(0), regionY(0);
110  double fovSizeX(0), fovSizeY(0);
111  if(fov->sizeX() > fov->sizeY())
112  {
113  zoom = calculateZoomLevel(pd->width(), fov->sizeX());
114 
115  // calculate clipping region size
116  fovSizeX = calculatePixelSize(fov->sizeX(), zoom);
117  fovSizeY = calculatePixelSize(fov->sizeY(), zoom);
118  regionX = 0;
119  regionY = 0.5 * (pd->height() - fovSizeY);
120  }
121 
122  else
123  {
124  zoom = calculateZoomLevel(pd->height(), fov->sizeY());
125 
126  // calculate clipping region size
127  fovSizeX = calculatePixelSize(fov->sizeX(), zoom);
128  fovSizeY = calculatePixelSize(fov->sizeY(), zoom);
129  regionX = 0.5 * (pd->width() - fovSizeX);
130  regionY = 0;
131  }
132 
133  if(fov->shape() == FOV::SQUARE)
134  {
135  region = QRegion(regionX, regionY, fovSizeX, fovSizeY, QRegion::Rectangle);
136  }
137 
138  else
139  {
140  region = QRegion(regionX, regionY, fovSizeX, fovSizeY, QRegion::Ellipse);
141  }
142 
143  m_Map->setZoomFactor(zoom);
144 
145  SkyQPainter painter(m_Map, pd);
146  painter.begin();
147 
148  painter.drawSkyBackground();
149 
150  if(!m_OverrideFovShape)
151  {
152  painter.setClipRegion(region);
153  }
154  // translate painter coordinates - it's necessary to extract only the area of interest (FOV)
155  int dx = (m_Map->width() - pd->width()) / 2;
156  int dy = (m_Map->height() - pd->height()) / 2;
157  painter.translate(-dx, -dy);
158 
159  m_KSData->skyComposite()->draw(&painter);
160  m_Map->getSkyMapDrawAbstract()->drawOverlays(painter, false);
161 
162  // reset painter coordinate transform to paint FOV symbol in the center
163  painter.resetTransform();
164 
165  if(m_DrawFovSymbol)
166  {
167  fov->draw(painter, zoom);
168  }
169 }
170 
171 void SimpleFovExporter::saveState(bool savePos)
172 {
173  // stop simulation if it's not already stopped
174  m_PrevClockState = m_KSData->clock()->isActive();
175  if(m_StopClock && m_PrevClockState)
176  {
177  m_KSData->clock()->stop();
178  }
179 
180  // disable useAnimatedSlewing option
181  m_PrevSlewing = Options::useAnimatedSlewing();
182  if(m_PrevSlewing)
183  {
184  Options::setUseAnimatedSlewing(false);
185  }
186 
187  // save current central point and zoom level
188  m_PrevPoint = savePos ? m_Map->focusPoint() : 0;
189  m_PrevZoom = Options::zoomFactor();
190 }
191 
192 void SimpleFovExporter::restoreState(bool restorePos)
193 {
194  // restore previous useAnimatedSlewing option
195  if(m_PrevSlewing)
196  {
197  Options::setUseAnimatedSlewing(true);
198  }
199 
200  if(restorePos)
201  {
202  // restore previous central point
203  m_Map->setClickedPoint(m_PrevPoint);
204  m_Map->slotCenter();
205  }
206  // restore previous zoom level
207  m_Map->setZoomFactor(m_PrevZoom);
208 
209  // restore clock state (if it was stopped)
210  if(m_StopClock && m_PrevClockState)
211  {
212  m_KSData->clock()->start();
213  }
214 }
SkyQPainter::drawSkyBackground
virtual void drawSkyBackground()
Draw the sky background.
Definition: skyqpainter.cpp:124
KStarsData::clock
SimClock * clock()
Definition: kstarsdata.h:158
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
FOV
class encapulating a Field-of-View symbol
Definition: fov.h:32
SkyMap::slotCenter
void slotCenter()
Center the display at the point ClickedPoint.
Definition: skymap.cpp:373
SimpleFovExporter::calculatePixelSize
static double calculatePixelSize(float degrees, double zoomLevel)
Calculate pixel size of given angular length at given zoom level.
Definition: simplefovexporter.h:139
FOV::sizeX
float sizeX() const
Definition: fov.h:53
SkyMapDrawAbstract::drawOverlays
void drawOverlays(QPainter &p, bool drawFov=true)
Draw the overlays on top of the sky map.
Definition: skymapdrawabstract.cpp:67
SkyMapComposite::draw
virtual void draw(SkyPainter *skyp)
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint...
Definition: skymapcomposite.cpp:170
SkyMap::focusPoint
SkyPoint * focusPoint()
retrieve the FocusPoint position.
Definition: skymap.h:140
SkyQPainter::begin
virtual void begin()
Begin painting.
Definition: skyqpainter.cpp:110
KStars
This is the main window for KStars.
Definition: kstars.h:94
Options::useAnimatedSlewing
static bool useAnimatedSlewing()
Get Use animated slewing effects when changing focus position?
Definition: Options.h:961
SimpleFovExporter::SimpleFovExporter
SimpleFovExporter()
Constructor.
Definition: simplefovexporter.cpp:26
SimClock::isActive
bool isActive()
Whether the clock is active or not is a bit complicated by the introduction of "manual mode"...
Definition: simclock.cpp:97
fov.h
SkyQPainter
The QPainter-based painting backend.
Definition: skyqpainter.h:32
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
SimpleFovExporter::calculateZoomLevel
static double calculateZoomLevel(int pixelSize, float degrees)
Calculate zoom level at which given angular length will occupy given length in pixels.
Definition: simplefovexporter.h:131
SkyMap::setZoomFactor
void setZoomFactor(double factor)
@ Set zoom factor.
Definition: skymap.cpp:976
skymapcomposite.h
FOV::SQUARE
Definition: fov.h:34
skymap.h
SimClock::stop
Q_SCRIPTABLE Q_NOREPLY void stop()
DBUS function to stop the SimClock.
Definition: simclock.cpp:104
FOV::draw
void draw(QPainter &p, float zoomFactor)
draw the FOV symbol on a QPainter
Definition: fov.cpp:57
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
Options::setUseAnimatedSlewing
static void setUseAnimatedSlewing(bool v)
Set Use animated slewing effects when changing focus position?
Definition: Options.h:951
Options.h
SkyMap::setClickedPoint
void setClickedPoint(SkyPoint *f)
Set the ClickedPoint to the skypoint given as an argument.
Definition: skymap.cpp:829
SimpleFovExporter::exportFov
void exportFov(SkyPoint *point, FOV *fov, QPaintDevice *pd)
Paint FOV representation on passed QPaintDevice subclass.
Definition: simplefovexporter.cpp:33
simplefovexporter.h
Options::zoomFactor
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
Definition: Options.h:2531
skyqpainter.h
FOV::shape
Shape shape() const
Definition: fov.h:49
SimClock::start
Q_SCRIPTABLE Q_NOREPLY void start()
DBUS function to start the SimClock.
Definition: simclock.cpp:117
kstarsdata.h
FOV::sizeY
float sizeY() const
Definition: fov.h:54
SkyMap::getSkyMapDrawAbstract
SkyMapDrawAbstract * getSkyMapDrawAbstract()
Definition: skymap.h:274
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal