• 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
  • dialogs
fovdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  fovdialog.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 "fovdialog.h"
19 
20 #include <QFile>
21 #include <QFrame>
22 #include <QPainter>
23 #include <QTextStream>
24 #include <QPaintEvent>
25 
26 #include <kactioncollection.h>
27 #include <klocale.h>
28 #include <kdebug.h>
29 #include <kpushbutton.h>
30 #include <kcolorbutton.h>
31 #include <kcombobox.h>
32 #include <knuminput.h>
33 #include <klineedit.h>
34 #include <kmessagebox.h>
35 #include <kstandarddirs.h>
36 
37 #include "kstars.h"
38 #include "kstarsdata.h"
39 #include "widgets/fovwidget.h"
40 
41 // This is needed to make FOV work with QVariant
42 Q_DECLARE_METATYPE(FOV*)
43 
44 int FOVDialog::fovID = -1;
45 
46 namespace {
47  // Try to convert text in KLine edit to double
48  inline double textToDouble(const KLineEdit* edit, bool* ok = 0)
49  {
50  return edit->text().replace( KGlobal::locale()->decimalSymbol(), "." ).toDouble(ok);
51  }
52 
53  // Extract FOV from QListWidget. No checking is done
54  FOV* getFOV(QListWidgetItem* item)
55  {
56  return item->data(Qt::UserRole).value<FOV*>();
57  }
58 
59  // Convert double to QString
60  QString toString(double x, int precision = 2)
61  {
62  return QString::number(x, 'f', precision).replace( '.', KGlobal::locale()->decimalSymbol() );
63  }
64 }
65 
66 
67 FOVDialogUI::FOVDialogUI( QWidget *parent ) : QFrame( parent ) {
68  setupUi( this );
69 }
70 
71 NewFOVUI::NewFOVUI( QWidget *parent ) : QFrame( parent ) {
72  setupUi( this );
73 }
74 
75 //---------FOVDialog---------------//
76 FOVDialog::FOVDialog( QWidget* p ) :
77  KDialog( p )
78 {
79  // Register FOV* data type
80  if( fovID == -1 )
81  fovID = qRegisterMetaType<FOV*>("FOV*");
82  fov = new FOVDialogUI( this );
83  setMainWidget( fov );
84  setCaption( i18n( "Set FOV Indicator" ) );
85  setButtons( KDialog::Ok | KDialog::Cancel );
86 
87  connect( fov->FOVListBox, SIGNAL( currentRowChanged( int ) ), SLOT( slotSelect( int ) ) );
88  connect( fov->NewButton, SIGNAL( clicked() ), SLOT( slotNewFOV() ) );
89  connect( fov->EditButton, SIGNAL( clicked() ), SLOT( slotEditFOV() ) );
90  connect( fov->RemoveButton, SIGNAL( clicked() ), SLOT( slotRemoveFOV() ) );
91 
92  // Read list of FOVs and for each FOV create listbox entry, which stores it.
93  foreach(FOV* f, FOV::readFOVs() ) {
94  addListWidget(f);
95  }
96 }
97 
98 FOVDialog::~FOVDialog()
99 {
100  // Delete FOVs
101  for(int i = 0; i < fov->FOVListBox->count(); i++) {
102  delete getFOV( fov->FOVListBox->item(i) );
103  }
104 }
105 
106 QListWidgetItem* FOVDialog::addListWidget(FOV* f)
107 {
108  QListWidgetItem* item = new QListWidgetItem( f->name(), fov->FOVListBox );
109  item->setData( Qt::UserRole, QVariant::fromValue<FOV*>(f) );
110  return item;
111 }
112 
113 void FOVDialog::writeFOVList() {
114  QList<FOV*> fovs;
115  for(int i = 0; i < fov->FOVListBox->count(); i++) {
116  fovs << getFOV( fov->FOVListBox->item(i) );
117  }
118  FOV::writeFOVs(fovs);
119 }
120 
121 void FOVDialog::slotSelect( int irow ) {
122  bool enable = irow >= 0;
123  fov->RemoveButton->setEnabled( enable );
124  fov->EditButton->setEnabled( enable);
125  if( enable ) {
126  //paint dialog with selected FOV symbol
127  fov->ViewBox->setFOV( getFOV( fov->FOVListBox->currentItem() ) );
128  fov->ViewBox->update();
129  }
130 }
131 
132 void FOVDialog::slotNewFOV() {
133  QPointer<NewFOV> newfdlg = new NewFOV( this );
134  if ( newfdlg->exec() == QDialog::Accepted ) {
135  FOV *newfov = new FOV( newfdlg->getFOV() );
136  addListWidget( newfov );
137  fov->FOVListBox->setCurrentRow( fov->FOVListBox->count() -1 );
138  }
139  delete newfdlg;
140 }
141 
142 void FOVDialog::slotEditFOV() {
143  //Preload current values
144  QListWidgetItem* item = fov->FOVListBox->currentItem();
145  if( item == 0 )
146  return;
147  FOV *f = item->data(Qt::UserRole).value<FOV*>();
148 
149  // Create dialog
150  QPointer<NewFOV> newfdlg = new NewFOV( this, f );
151  if ( newfdlg->exec() == QDialog::Accepted ) {
152  // Overwrite FOV
153  *f = newfdlg->getFOV();
154  fov->ViewBox->update();
155  }
156  delete newfdlg;
157 }
158 
159 void FOVDialog::slotRemoveFOV() {
160  int i = fov->FOVListBox->currentRow();
161  if( i >= 0 ) {
162  QListWidgetItem* item = fov->FOVListBox->takeItem(i);
163  delete getFOV(item);
164  delete item;
165  }
166 }
167 
168 //-------------NewFOV------------------//
169 
170 NewFOV::NewFOV( QWidget *parent, const FOV* fov ) :
171  KDialog( parent ), f()
172 {
173  ui = new NewFOVUI( this );
174  setMainWidget( ui );
175  setCaption( i18n( "New FOV Indicator" ) );
176  setButtons( KDialog::Ok|KDialog::Cancel );
177 
178  // Initialize FOV if required
179  if( fov != 0 ) {
180  f = *fov;
181  ui->FOVName->setText( f.name() );
182  ui->FOVEditX->setText( toString(f.sizeX()) );
183  ui->FOVEditY->setText( toString(f.sizeY()) );
184  ui->FOVEditOffsetX->setText( toString(f.offsetX()));
185  ui->FOVEditOffsetY->setText( toString(f.offsetY()));
186  ui->FOVEditRotation->setText(toString(f.rotation()));
187  ui->ColorButton->setColor( QColor( f.color() ) );
188  ui->ShapeBox->setCurrentIndex( f.shape() );
189 
190  ui->ViewBox->setFOV( &f );
191  ui->ViewBox->update();
192  }
193 
194  connect( ui->FOVName, SIGNAL( textChanged( const QString & ) ), SLOT( slotUpdateFOV() ) );
195  connect( ui->FOVEditX, SIGNAL( textChanged( const QString & ) ), SLOT( slotUpdateFOV() ) );
196  connect( ui->FOVEditY, SIGNAL( textChanged( const QString & ) ), SLOT( slotUpdateFOV() ) );
197  connect( ui->FOVEditOffsetX, SIGNAL( textChanged( const QString & ) ), SLOT( slotUpdateFOV() ) );
198  connect( ui->FOVEditOffsetY, SIGNAL( textChanged( const QString & ) ), SLOT( slotUpdateFOV() ) );
199  connect( ui->FOVEditRotation, SIGNAL( textChanged( const QString & ) ), SLOT( slotUpdateFOV() ) );
200  connect( ui->ColorButton, SIGNAL( changed( const QColor & ) ), SLOT( slotUpdateFOV() ) );
201  connect( ui->ShapeBox, SIGNAL( activated( int ) ), SLOT( slotUpdateFOV() ) );
202  connect( ui->ComputeEyeFOV, SIGNAL( clicked() ), SLOT( slotComputeFOV() ) );
203  connect( ui->ComputeCameraFOV, SIGNAL( clicked() ), SLOT( slotComputeFOV() ) );
204  connect( ui->ComputeHPBW, SIGNAL( clicked() ), SLOT( slotComputeFOV() ) );
205  connect( ui->ComputeBinocularFOV, SIGNAL( clicked() ), SLOT( slotComputeFOV() ) );
206  connect( ui->ComputeTLengthFromFNum1, SIGNAL( clicked() ), SLOT( slotComputeTelescopeFL() ) );
207  connect( ui->ComputeTLengthFromFNum2, SIGNAL( clicked() ), SLOT( slotComputeTelescopeFL() ) );
208 
209  // Populate eyepiece AFOV options. The userData field contains the apparent FOV associated with that option
210  ui->EyepieceAFOV->insertItem( 0, i18nc("Specify the apparent field of view (AFOV) manually", "Specify AFOV"), -1 );
211  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Ramsden (Typical)"), 30 );
212  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Orthoscopic (Typical)"), 45 );
213  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Ploessl (Typical)"), 50 );
214  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Erfle (Typical)"), 60 );
215  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Tele Vue Radian"), 60 );
216  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Baader Hyperion"), 68 );
217  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Tele Vue Panoptic"), 68 );
218  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Tele Vue Delos"), 72 );
219  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Meade UWA"), 82 );
220  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Tele Vue Nagler"), 82 );
221  ui->EyepieceAFOV->addItem( i18nc("Eyepiece Design / Brand / Name; Optional", "Tele Vue Ethos (Typical)"), 100 );
222 
223  connect( ui->EyepieceAFOV, SIGNAL( currentIndexChanged( int ) ), SLOT( slotEyepieceAFOVChanged( int ) ) );
224 
225  ui->LinearFOVDistance->insertItem( 0, i18n( "1000 yards" ) );
226  ui->LinearFOVDistance->insertItem( 1, i18n( "1000 meters" ) );
227  connect( ui->LinearFOVDistance, SIGNAL( currentIndexChanged( int ) ), SLOT( slotBinocularFOVDistanceChanged( int ) ) );
228 
229  slotUpdateFOV();
230 }
231 
232 void NewFOV::slotBinocularFOVDistanceChanged( int index ) {
233  QString text = (index == 0 ? i18n("feet") : i18n("meters"));
234  ui->LabelUnits->setText( text );
235 }
236 
237 void NewFOV::slotUpdateFOV() {
238  bool okX, okY;
239  f.setName( ui->FOVName->text() );
240  float sizeX = textToDouble(ui->FOVEditX, &okX);
241  float sizeY = textToDouble(ui->FOVEditY, &okY);
242  if ( okX && okY )
243  f.setSize( sizeX, sizeY );
244 
245  float xoffset = textToDouble(ui->FOVEditOffsetX, &okX);
246  float yoffset = textToDouble(ui->FOVEditOffsetY, &okY);
247  if (okX && okY)
248  f.setOffset(xoffset, yoffset);
249 
250  float rot = textToDouble(ui->FOVEditRotation, &okX);
251  if (okX)
252  f.setRotation(rot);
253 
254  f.setShape( ui->ShapeBox->currentIndex() );
255  f.setColor( ui->ColorButton->color().name() );
256 
257  enableButtonOk( !f.name().isEmpty() && okX && okY );
258 
259  ui->ViewBox->setFOV( &f );
260  ui->ViewBox->update();
261 }
262 
263 void NewFOV::slotComputeFOV() {
264  if ( sender() == ui->ComputeEyeFOV && ui->TLength1->value() > 0.0 ) {
265  ui->FOVEditX->setText( toString(60.0 * ui->EyeFOV->value() * ui->EyeLength->value() / ui->TLength1->value()) );
266  ui->FOVEditY->setText( ui->FOVEditX->text() );
267  }
268  else if ( sender() == ui->ComputeCameraFOV && ui->TLength2->value() > 0.0 ) {
269  double sx = (double) ui->ChipSize->value() * 3438.0 / ui->TLength2->value();
270  const double aspectratio = 3.0/2.0; // Use the default aspect ratio for DSLRs / Film (i.e. 3:2)
271  ui->FOVEditX->setText( toString(sx) );
272  ui->FOVEditY->setText( toString(sx / aspectratio) );
273  }
274  else if ( sender() == ui->ComputeHPBW && ui->RTDiameter->value() > 0.0 && ui->WaveLength->value() > 0.0 ) {
275  ui->FOVEditX->setText( toString(34.34 * 1.2 * ui->WaveLength->value() / ui->RTDiameter->value()) );
276  // Beam width for an antenna is usually a circle on the sky.
277  ui->ShapeBox->setCurrentIndex(4);
278  ui->FOVEditY->setText( ui->FOVEditX->text() );
279  slotUpdateFOV();
280  }
281  else if ( sender() == ui->ComputeBinocularFOV && ui->LinearFOV->value() > 0.0 && ui->LinearFOVDistance->currentIndex() >= 0 ) {
282  double sx = atan( (double) ui->LinearFOV->value() / ( (ui->LinearFOVDistance->currentIndex() == 0 ) ? 3000.0 : 1000.0 ) ) * 180.0 * 60.0 / dms::PI;
283  ui->FOVEditX->setText( toString(sx) );
284  ui->FOVEditY->setText( ui->FOVEditX->text() );
285  }
286 }
287 
288 void NewFOV::slotEyepieceAFOVChanged( int index ) {
289  if( index == 0 ) {
290  ui->EyeFOV->setEnabled( true );
291  }
292  else {
293  bool ok;
294  ui->EyeFOV->setEnabled( false );
295  ui->EyeFOV->setValue( ui->EyepieceAFOV->itemData( index ).toFloat( &ok ) );
296  Q_ASSERT( ok );
297  }
298 }
299 
300 void NewFOV::slotComputeTelescopeFL() {
301  QObject *whichTab = sender();
302  TelescopeFL *telescopeFLDialog = new TelescopeFL( this );
303  if ( telescopeFLDialog->exec() == QDialog::Accepted ) {
304  Q_ASSERT( whichTab == ui->ComputeTLengthFromFNum1 || whichTab == ui->ComputeTLengthFromFNum2 );
305  (( whichTab == ui->ComputeTLengthFromFNum1 ) ? ui->TLength1 : ui->TLength2 )->setValue( telescopeFLDialog->computeFL() );
306  }
307  delete telescopeFLDialog;
308 }
309 
310 
311 //-------------TelescopeFL------------------//
312 
313 TelescopeFL::TelescopeFL( QWidget *parent ) :
314  KDialog( parent ), aperture( 0 ), fNumber( 0 ), apertureUnit( 0 ) {
315 
316  setCaption( i18n( "Telescope Focal Length Calculator" ) );
317  setButtons( KDialog::Ok|KDialog::Cancel );
318 
319  QWidget *mainWidget = new QWidget( this );
320  QGridLayout *mainLayout = new QGridLayout( mainWidget );
321  mainWidget->setLayout( mainLayout );
322  setMainWidget( mainWidget );
323 
324  aperture = new KDoubleNumInput( 0.0, 100000.0, 0.0, this, 0.1, 2 );
325  fNumber = new KDoubleNumInput( 0.0, 99.9, 0.0, this, 0.1, 2 );
326  apertureUnit = new KComboBox( this );
327  apertureUnit->insertItem( 0, i18nc("millimeters", "mm") );
328  apertureUnit->insertItem( 1, i18n("inch") );
329  mainLayout->addWidget( new QLabel( i18n("Aperture diameter: "), this ), 0, 0 );
330  mainLayout->addWidget( aperture, 0, 1 );
331  mainLayout->addWidget( apertureUnit, 0, 2 );
332  mainLayout->addWidget( new QLabel( i18nc("F-Number or F-Ratio of optical system", "F-Number: "), this ), 1, 0 );
333  mainLayout->addWidget( fNumber, 1, 1 );
334  show();
335 }
336 
337 double TelescopeFL::computeFL() const {
338  const double inch_to_mm = 25.4; // 1 inch, by definition, is 25.4 mm
339  return ( aperture->value() * fNumber->value() * ( ( apertureUnit->currentIndex() == 1 ) ? inch_to_mm : 1.0 ) ); // Focal Length = Aperture * F-Number, by definition of F-Number
340 }
341 
342 unsigned int FOVDialog::currentItem() const { return fov->FOVListBox->currentRow(); }
343 
344 #include "fovdialog.moc"
FOV::setRotation
void setRotation(float rt)
Definition: fov.h:62
FOV::setShape
void setShape(Shape s)
Definition: fov.h:50
NewFOV::slotUpdateFOV
void slotUpdateFOV()
Definition: fovdialog.cpp:237
FOV
class encapulating a Field-of-View symbol
Definition: fov.h:32
NewFOV::slotComputeFOV
void slotComputeFOV()
Definition: fovdialog.cpp:263
TelescopeFL::computeFL
double computeFL() const
Compute and return the focal length in mm.
Definition: fovdialog.cpp:337
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
QWidget
FOV::rotation
float rotation() const
Definition: fov.h:63
KDialog
QObject
fovdialog.h
NewFOV::slotBinocularFOVDistanceChanged
void slotBinocularFOVDistanceChanged(int index)
Definition: fovdialog.cpp:232
NewFOV::slotEyepieceAFOVChanged
void slotEyepieceAFOVChanged(int index)
Definition: fovdialog.cpp:288
fovwidget.h
NewFOVUI::NewFOVUI
NewFOVUI(QWidget *parent=0)
Definition: fovdialog.cpp:71
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
FOVDialog::writeFOVList
void writeFOVList()
Write list of FOVs to disk.
Definition: fovdialog.cpp:113
FOVDialogUI
Definition: fovdialog.h:36
i18nc
i18nc("string from libindi, used in the config dialog","100x")
NewFOV::slotComputeTelescopeFL
void slotComputeTelescopeFL()
Definition: fovdialog.cpp:300
NewFOV::NewFOV
NewFOV(QWidget *parent=0, const FOV *fov=0)
Create new dialog.
Definition: fovdialog.cpp:170
FOV::setSize
void setSize(float s)
Definition: fov.h:55
FOV::setOffset
void setOffset(float fx, float fy)
Definition: fov.h:58
FOV::offsetY
float offsetY() const
Definition: fov.h:60
FOVDialogUI::FOVDialogUI
FOVDialogUI(QWidget *parent=0)
Definition: fovdialog.cpp:67
KLineEdit
NewFOVUI
Definition: fovdialog.h:42
KDoubleNumInput
FOVDialog::~FOVDialog
virtual ~FOVDialog()
Definition: fovdialog.cpp:98
PI
#define PI
Definition: satellite.cpp:43
QLabel
FOVDialog::FOVDialog
FOVDialog(QWidget *parent=0)
Definition: fovdialog.cpp:76
FOV::shape
Shape shape() const
Definition: fov.h:49
FOV::name
QString name() const
Definition: fov.h:46
kstarsdata.h
FOV::setName
void setName(const QString &n)
Definition: fov.h:47
TelescopeFL
calculating telescope focal length from f-number and diameter
Definition: fovdialog.h:105
TelescopeFL::TelescopeFL
TelescopeFL(QWidget *parent=0)
Create a telescope focal length dialog.
Definition: fovdialog.cpp:313
QFrame
FOV::sizeY
float sizeY() const
Definition: fov.h:54
kstars.h
FOV::color
QString color() const
Definition: fov.h:65
FOV::setColor
void setColor(const QString &c)
Definition: fov.h:66
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