• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

fovdialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           fovdialog.cpp  -  description
00003                              -------------------
00004     begin                : Fri 05 Sept 2003
00005     copyright            : (C) 2003 by Jason Harris
00006     email                : kstars@30doradus.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <qlayout.h>
00019 #include <qfile.h>
00020 #include <qframe.h>
00021 #include <qpainter.h>
00022 #include <qstringlist.h>
00023 
00024 #include <klocale.h>
00025 #include <kdebug.h>
00026 #include <kpushbutton.h>
00027 #include <kcolorbutton.h>
00028 #include <kcombobox.h>
00029 #include <knuminput.h>
00030 #include <klineedit.h>
00031 #include <kmessagebox.h>
00032 #include <kstandarddirs.h>
00033 
00034 #include "fovdialog.h"
00035 #include "kstars.h"
00036 #include "kstarsdata.h"
00037 #include "fovdialogui.h"
00038 #include "newfovui.h"
00039 
00040 
00041 //---------FOVDialog---------------//
00042 FOVDialog::FOVDialog( QWidget *parent )
00043     : KDialogBase( KDialogBase::Plain, i18n( "Set FOV Indicator" ), Ok|Cancel, Ok, parent ) {
00044 
00045     ks = (KStars*)parent;
00046 
00047     QFrame *page = plainPage();
00048     QVBoxLayout *vlay = new QVBoxLayout( page, 0, 0 );
00049     fov = new FOVDialogUI( page );
00050     vlay->addWidget( fov );
00051 
00052     connect( fov->FOVListBox, SIGNAL( currentChanged( QListBoxItem* ) ), SLOT( slotSelect( QListBoxItem* ) ) );
00053     connect( fov->NewButton, SIGNAL( clicked() ), SLOT( slotNewFOV() ) );
00054     connect( fov->EditButton, SIGNAL( clicked() ), SLOT( slotEditFOV() ) );
00055     connect( fov->RemoveButton, SIGNAL( clicked() ), SLOT( slotRemoveFOV() ) );
00056 
00057     FOVList.setAutoDelete( true );
00058     initList();
00059 }
00060 
00061 FOVDialog::~FOVDialog()
00062 {}
00063 
00064 void FOVDialog::initList() {
00065     QStringList fields;
00066     QFile f;
00067 
00068     QString nm, cl;
00069     int sh(0);
00070     float sz(0.0);
00071 
00072     f.setName( locate( "appdata", "fov.dat" ) );
00073 
00074     if ( f.exists() && f.open( IO_ReadOnly ) ) {
00075         QListBoxItem *item = 0;
00076 
00077         QTextStream stream( &f );
00078         while ( !stream.eof() ) {
00079             fields = QStringList::split( ":", stream.readLine() );
00080             bool ok( false );
00081 
00082             if ( fields.count() == 4 ) {
00083                 nm = fields[0];
00084                 sz = (float)(fields[1].toDouble( &ok ));
00085                 if ( ok ) {
00086                     sh = fields[2].toInt( &ok );
00087                     if ( ok ) {
00088                         cl = fields[3];
00089                     }
00090                 }
00091             }
00092 
00093             if ( ok ) {
00094                 FOV *newfov = new FOV( nm, sz, sh, cl );
00095                 fov->FOVListBox->insertItem( nm );
00096                 FOVList.append( newfov );
00097 
00098                 //Tag item if its name matches the current fov symbol in the main window
00099                 if ( nm == ks->data()->fovSymbol.name() ) item = fov->FOVListBox->item( fov->FOVListBox->count()-1 );
00100             }
00101         }
00102 
00103         f.close();
00104 
00105         //preset the listbox selection to the current setting in the main window
00106         fov->FOVListBox->setSelected( item, true );
00107         slotSelect( item );
00108     }
00109 }
00110 
00111 void FOVDialog::slotSelect(QListBoxItem *item) {
00112     if ( item == 0 ) { //no item selected
00113         fov->RemoveButton->setEnabled( false );
00114         fov->EditButton->setEnabled( false );
00115     } else {
00116         fov->RemoveButton->setEnabled( true );
00117         fov->EditButton->setEnabled( true );
00118     }
00119 
00120     //paint dialog with selected FOV symbol
00121     update();
00122 }
00123 
00124 void FOVDialog::paintEvent( QPaintEvent * ) {
00125     //Draw the selected target symbol in the pixmap.
00126     QPainter p;
00127     p.begin( fov->ViewBox );
00128     p.fillRect( fov->ViewBox->contentsRect(), QColor( "black" ) );
00129 
00130     if ( fov->FOVListBox->currentItem() >= 0 ) {
00131         FOV *f = FOVList.at( fov->FOVListBox->currentItem() );
00132         if ( f->size() > 0 ) {
00133             f->draw( p, (float)( 0.3*fov->ViewBox->contentsRect().width() ) );
00134             QFont smallFont = p.font();
00135             smallFont.setPointSize( p.font().pointSize() - 2 );
00136             p.setFont( smallFont );
00137             p.drawText( 0, fov->ViewBox->contentsRect().height(), i18n("angular size in arcminutes", "%1 arcmin").arg( KGlobal::locale()->formatNumber( f->size() ), 3 ) );
00138         }
00139     }
00140 
00141     p.end();
00142 }
00143 
00144 void FOVDialog::slotNewFOV() {
00145     NewFOV newfdlg( this );
00146 
00147     if ( newfdlg.exec() == QDialog::Accepted ) {
00148         FOV *newfov = new FOV( newfdlg.ui->FOVName->text(), newfdlg.ui->FOVEdit->text().toDouble(),
00149                 newfdlg.ui->ShapeBox->currentItem(), newfdlg.ui->ColorButton->color().name() );
00150         fov->FOVListBox->insertItem( newfdlg.ui->FOVName->text() );
00151         fov->FOVListBox->setSelected( fov->FOVListBox->count() -1, true );
00152         FOVList.append( newfov );
00153     }
00154 }
00155 
00156 void FOVDialog::slotEditFOV() {
00157     NewFOV newfdlg( this );
00158     //Preload current values
00159     FOV *f = FOVList.at( fov->FOVListBox->currentItem() );
00160 
00161     if (!f)
00162      return;
00163 
00164     newfdlg.ui->FOVName->setText( f->name() );
00165     newfdlg.ui->FOVEdit->setText( KGlobal::locale()->formatNumber( f->size(), 3 ) );
00166     newfdlg.ui->ColorButton->setColor( QColor( f->color() ) );
00167     newfdlg.ui->ShapeBox->setCurrentItem( f->shape() );
00168     newfdlg.slotUpdateFOV();
00169 
00170     if ( newfdlg.exec() == QDialog::Accepted ) {
00171         FOV *newfov = new FOV( newfdlg.ui->FOVName->text(), newfdlg.ui->FOVEdit->text().toDouble(),
00172                 newfdlg.ui->ShapeBox->currentItem(), newfdlg.ui->ColorButton->color().name() );
00173         fov->FOVListBox->changeItem( newfdlg.ui->FOVName->text(), fov->FOVListBox->currentItem() );
00174         FOVList.replace( fov->FOVListBox->currentItem(), newfov );
00175     }
00176 }
00177 
00178 void FOVDialog::slotRemoveFOV() {
00179     uint i = fov->FOVListBox->currentItem();
00180     FOVList.remove( i );
00181     fov->FOVListBox->removeItem( i );
00182     if ( i == fov->FOVListBox->count() ) i--; //last item was removed
00183     fov->FOVListBox->setSelected( i, true );
00184     fov->FOVListBox->update();
00185     
00186     if ( FOVList.isEmpty() ) {
00187         QString message( i18n( "You have removed all FOV symbols.  If the list remains empty when you exit this tool, the default symbols will be regenerated." ) );
00188         KMessageBox::information( 0, message, i18n( "FOV list is empty" ), "dontShowFOVMessage" );
00189     }
00190 
00191     update();
00192 }
00193 
00194 //-------------NewFOV------------------//
00195 NewFOV::NewFOV( QWidget *parent )
00196     : KDialogBase( KDialogBase::Plain, i18n( "New FOV Indicator" ), Ok|Cancel, Ok, parent ), f() {
00197     QFrame *page = plainPage();
00198     QVBoxLayout *vlay = new QVBoxLayout( page, 0, 0 );
00199     ui = new NewFOVUI( page );
00200     vlay->addWidget( ui );
00201 
00202     connect( ui->FOVName, SIGNAL( textChanged( const QString & ) ), SLOT( slotUpdateFOV() ) );
00203     connect( ui->FOVEdit, SIGNAL( textChanged( const QString & ) ), SLOT( slotUpdateFOV() ) );
00204     connect( ui->ColorButton, SIGNAL( changed( const QColor & ) ), SLOT( slotUpdateFOV() ) );
00205     connect( ui->ShapeBox, SIGNAL( activated( int ) ), SLOT( slotUpdateFOV() ) );
00206     connect( ui->ComputeEyeFOV, SIGNAL( clicked() ), SLOT( slotComputeFOV() ) );
00207     connect( ui->ComputeCameraFOV, SIGNAL( clicked() ), SLOT( slotComputeFOV() ) );
00208     connect( ui->ComputeHPBW, SIGNAL( clicked() ), SLOT( slotComputeFOV() ) );
00209 
00210     slotUpdateFOV();
00211 }
00212 
00213 void NewFOV::slotUpdateFOV() {
00214     bool sizeOk( false );
00215     f.setName( ui->FOVName->text() );
00216     float size = (float)(ui->FOVEdit->text().toDouble( &sizeOk ));
00217     if ( sizeOk ) f.setSize( size );
00218     f.setShape( ui->ShapeBox->currentItem() );
00219     f.setColor( ui->ColorButton->color().name() );
00220 
00221     if ( ! f.name().isEmpty() && sizeOk )
00222         enableButtonOK( true );
00223     else
00224         enableButtonOK( false );
00225 
00226     update();
00227 }
00228 
00229 void NewFOV::paintEvent( QPaintEvent * ) {
00230     QPainter p;
00231     p.begin( ui->ViewBox );
00232     p.fillRect( ui->ViewBox->contentsRect(), QColor( "black" ) );
00233     f.draw( p, (float)( 0.3*ui->ViewBox->contentsRect().width() ) );
00234     p.drawText( 0, 0, i18n("angular size in arcminutes", "%1 arcmin").arg( KGlobal::locale()->formatNumber( f.size() ), 3 ) );
00235     p.end();
00236 }
00237 
00238 void NewFOV::slotComputeFOV() {
00239     //DEBUG
00240     kdDebug() << ":" << sender()->name() << ":" << endl;
00241     if ( sender()->name() == QString( "ComputeEyeFOV" ) ) kdDebug() << "A" << endl;
00242     if ( sender()->name() == QString( "ComputeEyeFOV" ) && ui->TLength1->value() > 0.0 ) kdDebug() << "B" << endl;
00243 
00244     if ( sender()->name() == QString( "ComputeEyeFOV" ) && ui->TLength1->value() > 0.0 )
00245         ui->FOVEdit->setText( KGlobal::locale()->formatNumber( ui->EyeFOV->value() * ui->EyeLength->value() / ui->TLength1->value() ) );
00246     else if ( sender()->name() == QString( "ComputeCameraFOV" ) && ui->TLength2->value() > 0.0 )
00247         ui->FOVEdit->setText( KGlobal::locale()->formatNumber( ui->ChipSize->value() * 3438.0 / ui->TLength2->value() ) );
00248     else if ( sender()->name() == QString( "ComputeHPBW" ) && ui->RTDiameter->value() > 0.0 && ui->WaveLength->value() > 0.0 ) {
00249         ui->FOVEdit->setText( KGlobal::locale()->formatNumber( 34.34 * 1.2 * ui->WaveLength->value() / ui->RTDiameter->value() ) );
00250         // Beam width for an antenna is usually a circle on the sky.
00251         ui->ShapeBox->setCurrentItem(4);
00252         slotUpdateFOV();
00253 
00254     }
00255 }
00256 
00257 unsigned int FOVDialog::currentItem() const { return fov->FOVListBox->currentItem(); }
00258 
00259 #include "fovdialog.moc"

kstars

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

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal