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

kstars

kspopupmenu.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           kspopupmenu.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Sat Feb 27 2003
00005     copyright            : (C) 2001 by Jason Harris
00006     email                : jharris@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 <qlabel.h>
00019 
00020 #include "kspopupmenu.h"
00021 #include "kstars.h"
00022 #include "kstarsdata.h"
00023 #include "starobject.h"
00024 #include "ksmoon.h"
00025 #include "skyobject.h"
00026 #include "ksplanetbase.h"
00027 #include "skymap.h"
00028 
00029 #include "indimenu.h"
00030 #include "devicemanager.h"
00031 #include "indidevice.h"
00032 #include "indigroup.h"
00033 #include "indiproperty.h"
00034 
00035 KSPopupMenu::KSPopupMenu( QWidget *parent, const char *name )
00036  : KPopupMenu( parent, name )
00037 {
00038     ksw = ( KStars* )parent;
00039 }
00040 
00041 KSPopupMenu::~KSPopupMenu()
00042 {
00043 }
00044 
00045 void KSPopupMenu::createEmptyMenu( SkyObject *nullObj ) {
00046     initPopupMenu( nullObj, i18n( "Empty sky" ), QString::null, QString::null, true, true, false, false, false, true, false );
00047 
00048     insertItem( i18n( "First Generation Digitized Sky Survey", "Show 1st-Gen DSS Image" ), ksw->map(), SLOT( slotDSS() ) );
00049     insertItem( i18n( "Second Generation Digitized Sky Survey", "Show 2nd-Gen DSS Image" ), ksw->map(), SLOT( slotDSS2() ) );
00050 }
00051 
00052 void KSPopupMenu::createStarMenu( StarObject *star ) {
00053     //Add name, rise/set time, center/track, and detail-window items
00054     initPopupMenu( star, star->translatedLongName(), i18n( "Spectral type: %1" ).arg(star->sptype()),
00055         i18n( "star" ) );
00056 
00057 //If the star is named, add custom items to popup menu based on object's ImageList and InfoList
00058     if ( star->name() != "star" ) {
00059         addLinksToMenu( star );
00060     } else {
00061         insertItem( i18n( "First Generation Digitized Sky Survey", "Show 1st-Gen DSS Image" ), ksw->map(), SLOT( slotDSS() ) );
00062         insertItem( i18n( "Second Generation Digitized Sky Survey", "Show 2nd-Gen DSS Image" ), ksw->map(), SLOT( slotDSS2() ) );
00063     }
00064 }
00065 
00066 void KSPopupMenu::createDeepSkyObjectMenu( SkyObject *obj ) {
00067     QString TypeName = ksw->data()->TypeName[ obj->type() ];
00068     QString secondName = obj->translatedName2();
00069     if ( obj->longname() != obj->name() ) secondName = obj->translatedLongName();
00070 
00071     initPopupMenu( obj, obj->translatedName(), secondName, TypeName );
00072     addLinksToMenu( obj );
00073 }
00074 
00075 void KSPopupMenu::createCustomObjectMenu( SkyObject *obj ) {
00076     QString TypeName = ksw->data()->TypeName[ obj->type() ];
00077     QString secondName = obj->translatedName2();
00078     if ( obj->longname() != obj->name() ) secondName = obj->translatedLongName();
00079 
00080     initPopupMenu( obj, obj->translatedName(), secondName, TypeName );
00081 
00082     addLinksToMenu( obj, true, false ); //don't allow user to add more links (temporary)
00083 }
00084 
00085 void KSPopupMenu::createPlanetMenu( SkyObject *p ) {
00086     bool addTrail( ! ((KSPlanetBase*)p)->hasTrail() );
00087     QString oname = "";
00088     if ( p->name() == "Moon" ) {
00089         oname = ((KSMoon *)p)->phaseName();
00090     }
00091     initPopupMenu( p, p->translatedName(), oname, i18n("Solar System"), true, true, true, true, addTrail );
00092     addLinksToMenu( p, false ); //don't offer DSS images for planets
00093 }
00094 
00095 void KSPopupMenu::addLinksToMenu( SkyObject *obj, bool showDSS, bool allowCustom ) {
00096     QString sURL;
00097     QStringList::Iterator itList, itTitle, itListEnd;
00098 
00099     itList  = obj->ImageList.begin();
00100     itTitle = obj->ImageTitle.begin();
00101     itListEnd = obj->ImageList.end();
00102 
00103     int id = 100;
00104     for ( ; itList != itListEnd; ++itList ) {
00105         QString t = QString(*itTitle);
00106         sURL = QString(*itList);
00107         insertItem( i18n( "Image/info menu item (should be translated)", t.local8Bit() ), ksw->map(), SLOT( slotImage( int ) ), 0, id++ );
00108         ++itTitle;
00109     }
00110 
00111     if ( showDSS ) {
00112       insertItem( i18n( "First Generation Digitized Sky Survey", "Show 1st-Gen DSS Image" ), ksw->map(), SLOT( slotDSS() ) );
00113       insertItem( i18n( "Second Generation Digitized Sky Survey", "Show 2nd-Gen DSS Image" ), ksw->map(), SLOT( slotDSS2() ) );
00114       insertSeparator();
00115     }
00116     else if ( obj->ImageList.count() ) insertSeparator();
00117 
00118     itList  = obj->InfoList.begin();
00119     itTitle = obj->InfoTitle.begin();
00120     itListEnd = obj->InfoList.end();
00121 
00122     id = 200;
00123     for ( ; itList != itListEnd; ++itList ) {
00124         QString t = QString(*itTitle);
00125         sURL = QString(*itList);
00126         insertItem( i18n( "Image/info menu item (should be translated)", t.local8Bit() ), ksw->map(), SLOT( slotInfo( int ) ), 0, id++ );
00127         ++itTitle;
00128     }
00129 
00130     if ( allowCustom ) {
00131         insertSeparator();
00132         insertItem( i18n( "Add Link..." ), ksw->map(), SLOT( addLink() ), 0, id++ );
00133     }
00134 }
00135 
00136 bool KSPopupMenu::addINDI(void)
00137 {
00138   
00139   INDIMenu *indiMenu = ksw->getINDIMenu();
00140   DeviceManager *mgr;
00141   INDI_D *dev;
00142   INDI_G *grp;
00143   INDI_P *prop(NULL);
00144   INDI_E *element;
00145   int id=0;
00146 
00147   if (indiMenu->mgr.count() == 0)
00148    return false;
00149 
00150   for (mgr = indiMenu->mgr.first(); mgr != NULL; mgr = indiMenu->mgr.next())
00151   {
00152     for (dev = mgr->indi_dev.first(), id = 0; dev != NULL; dev = mgr->indi_dev.next())
00153     {
00154         if (!dev->INDIStdSupport)
00155      continue;
00156 
00157     KPopupMenu *menuDevice = new KPopupMenu();
00158     
00159     insertItem(dev->label, menuDevice);
00160 
00161         for (grp = dev->gl.first(); grp != NULL; grp = dev->gl.next())
00162     {
00163        for (prop = grp->pl.first(); prop != NULL; prop = grp->pl.next())
00164        {
00165          /* Only std are allowed to show. Movement is somewhat problematic due to an issue with the LX200 telescopes (the telescope does not update RA/DEC while moving N/W/E/S) so it's better off the skymap. It's avaiable in the INDI control panel nonetheless.
00166          CCD_EXPOSE_DURATION is an INumber property, but it's so common that it's better to include in the context menu */
00167          
00168          if (prop->stdID == -1 || prop->stdID == MOVEMENT) continue;
00169          // Only switches are shown
00170          if (prop->guitype != PG_BUTTONS && prop->guitype != PG_RADIO && prop->stdID !=CCD_EXPOSE_DURATION) continue;
00171        
00172          menuDevice->insertSeparator();
00173 
00174          prop->assosiatedPopup = menuDevice;
00175          
00176          if (prop->stdID == CCD_EXPOSE_DURATION)
00177          {
00178            menuDevice->insertItem (prop->label, id);
00179            menuDevice->setItemChecked(id, false);
00180            //kdDebug() << "Expose ID: " << id << endl;
00181            id++;
00182          }
00183          else
00184          {
00185          for (element = prop->el.first(); element != NULL; element = prop->el.next(), id++)
00186              {
00187         menuDevice->insertItem (element->label, id);
00188         if (element->state == PS_ON)
00189         {
00190                 // Slew, Track, Sync, Exppse are never checked in the skymap
00191             if ((element->name != "SLEW") && (element->name != "TRACK") &&
00192                 (element->name != "SYNC"))
00193                 menuDevice->setItemChecked(id, true);
00194             else
00195                 menuDevice->setItemChecked(id, false);
00196         }
00197         else
00198                 menuDevice->setItemChecked(id, false);
00199             
00200         //kdDebug() << element->name << " ID is " << id << endl;
00201          }
00202          }
00203 
00204          QObject::connect(menuDevice, SIGNAL(activated(int)), prop, SLOT (convertSwitch(int)));
00205         
00206         } // end property
00207       } // end group
00208 
00209     // For telescopes, add option to center the telescope position
00210     if ( dev->findElem("RA") || dev->findElem("ALT"))
00211     {
00212         menuDevice->insertSeparator();
00213         menuDevice->insertItem(i18n("Center && Track Crosshair"), id++);
00214                 if (dev->findElem("RA"))
00215             prop = dev->findElem("RA")->pp;
00216         else    
00217             prop = dev->findElem("ALT")->pp;
00218 
00219         prop->assosiatedPopup = menuDevice;
00220         QObject::connect(menuDevice, SIGNAL(activated(int)), prop, SLOT(convertSwitch(int)));   
00221     }
00222        } // end device
00223     
00224     } // end device manager
00225 
00226  return true;
00227 }
00228 
00229 void KSPopupMenu::initPopupMenu( SkyObject *obj, QString s1, QString s2, QString s3,
00230         bool showRiseSet, bool showCenterTrack, bool showDetails, bool showTrail, bool addTrail, 
00231         bool showAngularDistance, bool showObsList ) {
00232     
00233     clear();
00234     if ( s1.isEmpty() ) s1 = i18n( "Empty sky" );
00235 
00236     bool showLabel( true );
00237     if ( s1 == i18n( "star" ) || s1 == i18n( "Empty sky" ) ) showLabel = false;
00238 
00239     pmTitle = new QLabel( s1, this );
00240     pmTitle->setAlignment( AlignCenter );
00241     QPalette pal( pmTitle->palette() );
00242     pal.setColor( QPalette::Normal, QColorGroup::Background, pal.color( QPalette::Normal, QColorGroup::Base ) );
00243     pal.setColor( QPalette::Normal, QColorGroup::Foreground, pal.color( QPalette::Normal, QColorGroup::Text ) );
00244     pmTitle->setPalette( pal );
00245     insertItem( pmTitle );
00246 
00247     if ( ! s2.isEmpty() ) {
00248         pmTitle2 = new QLabel( s2, this );
00249         pmTitle2->setAlignment( AlignCenter );
00250         pmTitle2->setPalette( pal );
00251         insertItem( pmTitle2 );
00252     }
00253 
00254     if ( ! s3.isEmpty() ) {
00255         pmType = new QLabel( s3, this );
00256         pmType->setAlignment( AlignCenter );
00257         pmType->setPalette( pal );
00258         insertItem( pmType );
00259     }
00260 
00261     QString c = obj->constellation( ksw->data()->csegmentList, ksw->data()->cnameList );
00262     pmConstellation = new QLabel( c, this );
00263     pmConstellation->setAlignment( AlignCenter );
00264     pmConstellation->setPalette( pal );
00265     insertItem( pmConstellation );
00266     
00267     //Insert Rise/Set/Transit labels
00268     if ( showRiseSet && obj ) {
00269         pmRiseTime = new QLabel( i18n( "Rise time: 00:00" ), this );
00270         pmRiseTime->setAlignment( AlignCenter );
00271         pmRiseTime->setPalette( pal );
00272         QFont rsFont = pmRiseTime->font();
00273         rsFont.setPointSize( rsFont.pointSize() - 2 );
00274         pmRiseTime->setFont( rsFont );
00275         pmSetTime = new QLabel( i18n( "the time at which an object falls below the horizon", "Set time:" ) + " 00:00", this );
00276         pmSetTime->setAlignment( AlignCenter );
00277         pmSetTime->setPalette( pal );
00278         pmSetTime->setFont( rsFont );
00279         pmTransitTime = new QLabel( i18n( "Transit time: 00:00" ), this );
00280         pmTransitTime->setAlignment( AlignCenter );
00281         pmTransitTime->setPalette( pal );
00282         pmTransitTime->setFont( rsFont );
00283         insertSeparator();
00284         insertItem( pmRiseTime );
00285         insertItem( pmTransitTime );
00286         insertItem( pmSetTime );
00287 
00288         setRiseSetLabels( obj );
00289     }
00290 
00291     //Insert item for centering on object
00292     if ( showCenterTrack && obj ) {
00293         insertSeparator();
00294         insertItem( i18n( "Center && Track" ), ksw->map(), SLOT( slotCenter() ) );
00295     }
00296     
00297     //Insert item for measuring distances
00298     if ( showAngularDistance && obj ) {
00299         if (! (ksw->map()->isAngleMode()) ) {
00300             insertItem( i18n( "Angular Distance To...            [" ), ksw->map(), SLOT( slotBeginAngularDistance() ) );
00301         } else {
00302             insertItem( i18n( "Compute Angular Distance          ]" ), ksw->map(), SLOT( slotEndAngularDistance() ) );
00303         }
00304 
00305     }
00306 
00307 
00308     //Insert item for Showing details dialog
00309     if ( showDetails && obj ) {
00310         insertItem( i18n( "Show Detailed Information Dialog", "Details" ), ksw->map(), SLOT( slotDetail() ) );
00311     }
00312 
00313     //Insert "Add/Remove Label" item
00314     if ( showLabel && obj ) {
00315         if ( ksw->map()->isObjectLabeled( obj ) ) {
00316             insertItem( i18n( "Remove Label" ), ksw->map(), SLOT( slotRemoveObjectLabel() ) );
00317         } else {
00318             insertItem( i18n( "Attach Label" ), ksw->map(), SLOT( slotAddObjectLabel() ) );
00319         }
00320     }
00321 
00322     if ( showObsList && obj ) {
00323         if ( ksw->observingList()->contains( obj ) )
00324             insertItem( i18n("Remove From List"), ksw->observingList(), SLOT( slotRemoveObject() ) );
00325         else 
00326             insertItem( i18n("Add to List"), ksw->observingList(), SLOT( slotAddObject() ) );
00327     }
00328     
00329     if ( showTrail && obj && obj->isSolarSystem() ) {
00330         if ( addTrail ) {
00331             insertItem( i18n( "Add Trail" ), ksw->map(), SLOT( slotAddPlanetTrail() ) );
00332         } else {
00333             insertItem( i18n( "Remove Trail" ), ksw->map(), SLOT( slotRemovePlanetTrail() ) );
00334         }
00335     }
00336 
00337     insertSeparator();
00338 
00339     if (addINDI())
00340         insertSeparator();
00341 }
00342 
00343 void KSPopupMenu::setRiseSetLabels( SkyObject *obj ) {
00344     if ( ! obj ) return;
00345     
00346     QString rt, rt2, rt3;
00347     QTime rtime = obj->riseSetTime( ksw->data()->ut(), ksw->geo(), true );
00348     dms rAz = obj->riseSetTimeAz( ksw->data()->ut(), ksw->geo(), true );
00349 
00350     if ( rtime.isValid() ) {
00351         //We can round to the nearest minute by simply adding 30 seconds to the time.
00352         rt = i18n( "Rise time: %1" ).arg( rtime.addSecs(30).toString( "hh:mm" ) );
00353 
00354     } else if ( obj->alt()->Degrees() > 0 ) {
00355         rt = i18n( "No rise time: Circumpolar" );
00356     } else {
00357         rt = i18n( "No rise time: Never rises" );
00358     }
00359 
00360     KStarsDateTime dt = ksw->data()->ut();
00361     QTime stime = obj->riseSetTime( dt, ksw->geo(), false );
00362 
00363     QString st, st2, st3;
00364     dms sAz = obj->riseSetTimeAz( dt,  ksw->geo(), false );
00365     
00366     if ( stime.isValid() ) {
00367         //We can round to the nearest minute by simply adding 30 seconds to the time.
00368         st = i18n( "the time at which an object falls below the horizon", "Set time: %1" ).arg( stime.addSecs(30).toString( "hh:mm" ) );
00369 
00370     } else if ( obj->alt()->Degrees() > 0 ) {
00371         st = i18n( "No set time: Circumpolar" );
00372     } else {
00373         st = i18n( "No set time: Never rises" );
00374     }
00375 
00376     QTime ttime = obj->transitTime( dt, ksw->geo() );
00377     dms trAlt = obj->transitAltitude( dt, ksw->geo() );
00378     QString tt, tt2, tt3;
00379 
00380     if ( ttime.isValid() ) {
00381         //We can round to the nearest minute by simply adding 30 seconds to the time.
00382         tt = i18n( "Transit time: %1" ).arg( ttime.addSecs(30).toString( "hh:mm" ) );
00383     } else {
00384         tt = "--:--";
00385     }
00386 
00387     pmRiseTime->setText( rt );
00388     pmSetTime->setText( st );
00389     pmTransitTime->setText( tt ) ;
00390 }
00391 
00392 #include "kspopupmenu.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