23 #include <QTextStream>
24 #include <QPaintEvent>
26 #include <kactioncollection.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>
42 Q_DECLARE_METATYPE(
FOV*)
44 int FOVDialog::fovID = -1;
48 inline double textToDouble(
const KLineEdit* edit,
bool* ok = 0)
50 return edit->text().replace( KGlobal::locale()->decimalSymbol(),
"." ).toDouble(ok);
54 FOV* getFOV(QListWidgetItem* item)
56 return item->data(Qt::UserRole).value<
FOV*>();
60 QString toString(
double x,
int precision = 2)
62 return QString::number(x,
'f', precision).replace(
'.', KGlobal::locale()->decimalSymbol() );
81 fovID = qRegisterMetaType<FOV*>(
"FOV*");
84 setCaption( i18n(
"Set FOV Indicator" ) );
85 setButtons( KDialog::Ok | KDialog::Cancel );
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() ) );
101 for(
int i = 0; i < fov->FOVListBox->count(); i++) {
102 delete getFOV( fov->FOVListBox->item(i) );
106 QListWidgetItem* FOVDialog::addListWidget(
FOV*
f)
108 QListWidgetItem* item =
new QListWidgetItem( f->
name(), fov->FOVListBox );
109 item->setData( Qt::UserRole, QVariant::fromValue<FOV*>(f) );
115 for(
int i = 0; i < fov->FOVListBox->count(); i++) {
116 fovs << getFOV( fov->FOVListBox->item(i) );
121 void FOVDialog::slotSelect(
int irow ) {
122 bool enable = irow >= 0;
123 fov->RemoveButton->setEnabled( enable );
124 fov->EditButton->setEnabled( enable);
127 fov->ViewBox->setFOV( getFOV( fov->FOVListBox->currentItem() ) );
128 fov->ViewBox->update();
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 );
142 void FOVDialog::slotEditFOV() {
144 QListWidgetItem* item = fov->FOVListBox->currentItem();
147 FOV *f = item->data(Qt::UserRole).value<
FOV*>();
150 QPointer<NewFOV> newfdlg =
new NewFOV(
this, f );
151 if ( newfdlg->exec() == QDialog::Accepted ) {
153 *f = newfdlg->getFOV();
154 fov->ViewBox->update();
159 void FOVDialog::slotRemoveFOV() {
160 int i = fov->FOVListBox->currentRow();
162 QListWidgetItem* item = fov->FOVListBox->takeItem(i);
175 setCaption( i18n(
"New FOV Indicator" ) );
176 setButtons( KDialog::Ok|KDialog::Cancel );
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() );
190 ui->ViewBox->setFOV( &f );
191 ui->ViewBox->update();
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() ) );
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 );
225 ui->LinearFOVDistance->insertItem( 0, i18n(
"1000 yards" ) );
226 ui->LinearFOVDistance->insertItem( 1, i18n(
"1000 meters" ) );
233 QString text = (index == 0 ? i18n(
"feet") : i18n(
"meters"));
234 ui->LabelUnits->setText( text );
239 f.
setName( ui->FOVName->text() );
240 float sizeX = textToDouble(ui->FOVEditX, &okX);
241 float sizeY = textToDouble(ui->FOVEditY, &okY);
245 float xoffset = textToDouble(ui->FOVEditOffsetX, &okX);
246 float yoffset = textToDouble(ui->FOVEditOffsetY, &okY);
250 float rot = textToDouble(ui->FOVEditRotation, &okX);
254 f.
setShape( ui->ShapeBox->currentIndex() );
255 f.
setColor( ui->ColorButton->color().name() );
257 enableButtonOk( !f.
name().isEmpty() && okX && okY );
259 ui->ViewBox->setFOV( &f );
260 ui->ViewBox->update();
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() );
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;
271 ui->FOVEditX->setText( toString(sx) );
272 ui->FOVEditY->setText( toString(sx / aspectratio) );
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()) );
277 ui->ShapeBox->setCurrentIndex(4);
278 ui->FOVEditY->setText( ui->FOVEditX->text() );
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() );
290 ui->EyeFOV->setEnabled(
true );
294 ui->EyeFOV->setEnabled(
false );
295 ui->EyeFOV->setValue( ui->EyepieceAFOV->itemData( index ).toFloat( &ok ) );
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() );
307 delete telescopeFLDialog;
314 KDialog( parent ), aperture( 0 ), fNumber( 0 ), apertureUnit( 0 ) {
316 setCaption( i18n(
"Telescope Focal Length Calculator" ) );
317 setButtons( KDialog::Ok|KDialog::Cancel );
320 QGridLayout *mainLayout =
new QGridLayout( mainWidget );
321 mainWidget->setLayout( mainLayout );
322 setMainWidget( mainWidget );
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 );
338 const double inch_to_mm = 25.4;
339 return ( aperture->value() * fNumber->value() * ( ( apertureUnit->currentIndex() == 1 ) ? inch_to_mm : 1.0 ) );
342 unsigned int FOVDialog::currentItem()
const {
return fov->FOVListBox->currentRow(); }
344 #include "fovdialog.moc"
void setRotation(float rt)
class encapulating a Field-of-View symbol
double computeFL() const
Compute and return the focal length in mm.
static QList< FOV * > readFOVs()
Read list of FOVs from "fov.dat".
void slotBinocularFOVDistanceChanged(int index)
void slotEyepieceAFOVChanged(int index)
NewFOVUI(QWidget *parent=0)
static void writeFOVs(const QList< FOV * > fovs)
Write list of FOVs to "fov.dat".
void writeFOVList()
Write list of FOVs to disk.
i18nc("string from libindi, used in the config dialog","100x")
void slotComputeTelescopeFL()
NewFOV(QWidget *parent=0, const FOV *fov=0)
Create new dialog.
void setOffset(float fx, float fy)
FOVDialogUI(QWidget *parent=0)
FOVDialog(QWidget *parent=0)
void setName(const QString &n)
calculating telescope focal length from f-number and diameter
TelescopeFL(QWidget *parent=0)
Create a telescope focal length dialog.
void setColor(const QString &c)