• 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
fov.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  fov.cpp - description
3  -------------------
4  begin : Fri 05 Sept 2003
5  copyright : (C) 2003 by Jason Harris
6  email : kstars@30doradus.org
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 "fov.h"
19 #include "Options.h"
20 
21 #include <algorithm>
22 
23 #include <QPainter>
24 #include <QTextStream>
25 #include <QFile>
26 #include <kdebug.h>
27 #include <kstandarddirs.h>
28 
29 FOV::Shape FOV::intToShape(int s)
30 {
31  return (s >= FOV::UNKNOWN || s < 0) ? FOV::UNKNOWN : static_cast<FOV::Shape>(s);
32 }
33 
34 FOV::FOV( const QString &n, float a, float b, float xoffset, float yoffset, float rot, Shape sh, const QString &col )
35 {
36  m_name = n;
37  m_sizeX = a;
38  m_sizeY = (b < 0.0) ? a : b;
39 
40  m_offsetX = xoffset;
41  m_offsetY = yoffset;
42  m_rotation = rot;
43  m_shape = sh;
44  m_color = col;
45 }
46 
47 FOV::FOV()
48 {
49  m_name = i18n( "No FOV" );
50  m_color = "#FFFFFF";
51 
52  m_sizeX = m_sizeY = 0;
53  m_shape = SQUARE;
54  m_offsetX=m_offsetY=m_rotation=0;
55 }
56 
57 void FOV::draw( QPainter &p, float zoomFactor ) {
58  p.setPen( QColor( color() ) );
59  p.setBrush( Qt::NoBrush );
60 
61  p.setRenderHint( QPainter::Antialiasing, Options::useAntialias() );
62 
63 
64  float pixelSizeX = sizeX() * zoomFactor / 57.3 / 60.0;
65  float pixelSizeY = sizeY() * zoomFactor / 57.3 / 60.0;
66 
67  float offsetXPixelSize = offsetX() * zoomFactor / 57.3 / 60.0;
68  float offsetYPixelSize = offsetY() * zoomFactor / 57.3 / 60.0;
69 
70  p.save();
71  p.translate(p.viewport().center());
72 
73  p.translate(offsetXPixelSize, offsetYPixelSize);
74  p.rotate(rotation());
75 
76  QPointF center(0,0);
77 
78  switch ( shape() )
79  {
80  case SQUARE:
81  p.drawRect( center.x() - pixelSizeX/2, center.y() - pixelSizeY/2, pixelSizeX, pixelSizeY);
82  break;
83  case CIRCLE:
84  p.drawEllipse( center, pixelSizeX/2, pixelSizeY/2 );
85  break;
86  case CROSSHAIRS:
87  //Draw radial lines
88  p.drawLine(center.x() + 0.5*pixelSizeX, center.y(),
89  center.x() + 1.5*pixelSizeX, center.y());
90  p.drawLine(center.x() - 0.5*pixelSizeX, center.y(),
91  center.x() - 1.5*pixelSizeX, center.y());
92  p.drawLine(center.x(), center.y() + 0.5*pixelSizeY,
93  center.x(), center.y() + 1.5*pixelSizeY);
94  p.drawLine(center.x(), center.y() - 0.5*pixelSizeY,
95  center.x(), center.y() - 1.5*pixelSizeY);
96  //Draw circles at 0.5 & 1 degrees
97  p.drawEllipse( center, 0.5 * pixelSizeX, 0.5 * pixelSizeY);
98  p.drawEllipse( center, pixelSizeX, pixelSizeY);
99  break;
100  case BULLSEYE:
101  p.drawEllipse(center, 0.5 * pixelSizeX, 0.5 * pixelSizeY);
102  p.drawEllipse(center, 2.0 * pixelSizeX, 2.0 * pixelSizeY);
103  p.drawEllipse(center, 4.0 * pixelSizeX, 4.0 * pixelSizeY);
104  break;
105  case SOLIDCIRCLE: {
106  QColor colorAlpha = color();
107  colorAlpha.setAlpha(127);
108  p.setBrush( QBrush( colorAlpha ) );
109  p.drawEllipse(center, pixelSizeX/2, pixelSizeY/2 );
110  p.setBrush(Qt::NoBrush);
111  break;
112  }
113  default: ;
114  }
115 
116  p.restore();
117 }
118 
119 void FOV::draw(QPainter &p, float x, float y)
120 {
121  float xfactor = x / sizeX() * 57.3 * 60.0;
122  float yfactor = y / sizeY() * 57.3 * 60.0;
123  float zoomFactor = std::min(xfactor, yfactor);
124  switch( shape() ) {
125  case CROSSHAIRS: zoomFactor /= 3; break;
126  case BULLSEYE: zoomFactor /= 8; break;
127  default: ;
128  }
129  draw(p, zoomFactor);
130 }
131 
132 void FOV::setShape( int s)
133 {
134  m_shape = intToShape(s);
135 }
136 
137 
138 QList<FOV*> FOV::defaults()
139 {
140  QList<FOV*> fovs;
141  fovs << new FOV(i18nc("use field-of-view for binoculars", "7x35 Binoculars" ),
142  558, 558, 0,0,0, CIRCLE,"#AAAAAA")
143  << new FOV(i18nc("use a Telrad field-of-view indicator", "Telrad" ),
144  30, 30, 0,0,0, BULLSEYE,"#AA0000")
145  << new FOV(i18nc("use 1-degree field-of-view indicator", "One Degree"),
146  60, 60, 0,0,0, CIRCLE,"#AAAAAA")
147  << new FOV(i18nc("use HST field-of-view indicator", "HST WFPC2"),
148  2.4, 2.4, 0,0,0, SQUARE,"#AAAAAA")
149  << new FOV(i18nc("use Radiotelescope HPBW", "30m at 1.3cm" ),
150  1.79, 1.79, 0,0,0, SQUARE,"#AAAAAA");
151  return fovs;
152 }
153 
154 void FOV::writeFOVs(const QList<FOV*> fovs)
155 {
156  QFile f;
157  f.setFileName( KStandardDirs::locateLocal( "appdata", "fov.dat" ) );
158 
159  if ( ! f.open( QIODevice::WriteOnly ) ) {
160  kDebug() << i18n( "Could not open fov.dat." );
161  return;
162  }
163  QTextStream ostream(&f);
164  foreach(FOV* fov, fovs) {
165  ostream << fov->name() << ':'
166  << fov->sizeX() << ':'
167  << fov->sizeY() << ':'
168  << fov->offsetX() << ':'
169  << fov->offsetY() << ':'
170  << fov->rotation() << ':'
171  << QString::number( fov->shape() ) << ':' //FIXME: is this needed???
172  << fov->color() << endl;
173  }
174  f.close();
175 }
176 
177 QList<FOV*> FOV::readFOVs()
178 {
179  QFile f;
180  QList<FOV*> fovs;
181  f.setFileName( KStandardDirs::locateLocal( "appdata", "fov.dat" ) );
182 
183  if( !f.exists() ) {
184  fovs = defaults();
185  writeFOVs(fovs);
186  return fovs;
187  }
188 
189  if( f.open(QIODevice::ReadOnly) ) {
190  fovs.clear();
191  QTextStream istream(&f);
192  while( !istream.atEnd() ) {
193  QStringList fields = istream.readLine().split(':');
194  bool ok;
195  QString name, color;
196  float sizeX, sizeY, xoffset, yoffset, rot, orient;
197  Shape shape;
198  if( fields.count() == 8 )
199  {
200  name = fields[0];
201  sizeX = fields[1].toFloat(&ok);
202  if( !ok ) {
203  return QList<FOV*>();
204  }
205  sizeY = fields[2].toFloat(&ok);
206  if( !ok ) {
207  return QList<FOV*>();
208  }
209  xoffset = fields[3].toFloat(&ok);
210  if( !ok ) {
211  return QList<FOV*>();
212  }
213 
214  yoffset = fields[4].toFloat(&ok);
215  if( !ok ) {
216  return QList<FOV*>();
217  }
218 
219  rot = fields[5].toFloat(&ok);
220  if( !ok ) {
221  return QList<FOV*>();
222  }
223 
224  shape = intToShape( fields[6].toInt(&ok) );
225  if( !ok ) {
226  return QList<FOV*>();
227  }
228  color = fields[7];
229  } else {
230  continue;
231  }
232  fovs.append( new FOV(name, sizeX, sizeY, xoffset, yoffset, rot, shape, color) );
233  }
234  }
235  return fovs;
236 }
FOV::setShape
void setShape(Shape s)
Definition: fov.h:50
FOV::FOV
FOV()
Default constructor.
Definition: fov.cpp:47
FOV
class encapulating a Field-of-View symbol
Definition: fov.h:32
FOV::offsetX
float offsetX() const
Definition: fov.h:59
FOV::sizeX
float sizeX() const
Definition: fov.h:53
FOV::readFOVs
static QList< FOV * > readFOVs()
Read list of FOVs from "fov.dat".
Definition: fov.cpp:177
FOV::rotation
float rotation() const
Definition: fov.h:63
fov.h
NaN::f
const float f
Definition: nan.h:36
FOV::writeFOVs
static void writeFOVs(const QList< FOV * > fovs)
Write list of FOVs to "fov.dat".
Definition: fov.cpp:154
FOV::CIRCLE
Definition: fov.h:35
FOV::SQUARE
Definition: fov.h:34
i18nc
i18nc("string from libindi, used in the config dialog","100x")
FOV::SOLIDCIRCLE
Definition: fov.h:38
FOV::draw
void draw(QPainter &p, float zoomFactor)
draw the FOV symbol on a QPainter
Definition: fov.cpp:57
FOV::defaults
static QList< FOV * > defaults()
Fill list with default FOVs.
Definition: fov.cpp:138
FOV::Shape
Shape
Definition: fov.h:34
FOV::offsetY
float offsetY() const
Definition: fov.h:60
Options.h
FOV::intToShape
static FOV::Shape intToShape(int)
Definition: fov.cpp:29
FOV::CROSSHAIRS
Definition: fov.h:36
FOV::BULLSEYE
Definition: fov.h:37
QTextStream
FOV::shape
Shape shape() const
Definition: fov.h:49
FOV::name
QString name() const
Definition: fov.h:46
FOV::UNKNOWN
Definition: fov.h:39
FOV::sizeY
float sizeY() const
Definition: fov.h:54
Options::useAntialias
static bool useAntialias()
Get Use antialiasing when drawing the screen?
Definition: Options.h:2500
FOV::color
QString color() const
Definition: fov.h:65
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 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