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

kstars

skymapevents.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           skymapevents.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Sat Feb 10 2001
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 //This file contains Event handlers for the SkyMap class.
00019 
00020 #include <stdlib.h>
00021 #include <math.h> //using fabs()
00022 
00023 #include <qcursor.h>
00024 #include <qpainter.h>
00025 #include <qfile.h>
00026 
00027 #include <kiconloader.h>
00028 #include <kstatusbar.h>
00029 #include <kshortcut.h> //KKey class
00030 
00031 #include "skymap.h"
00032 #include "Options.h"
00033 #include "kstars.h"
00034 #include "kstarsdata.h"
00035 #include "ksutils.h"
00036 #include "simclock.h"
00037 #include "infoboxes.h"
00038 #include "ksfilereader.h"
00039 #include "kspopupmenu.h"
00040 #include "ksmoon.h"
00041 
00042 void SkyMap::resizeEvent( QResizeEvent * )
00043 {
00044     computeSkymap = true; // skymap must be new computed
00045     if ( testWState(WState_AutoMask) ) updateMask();
00046 
00047     // avoid phantom positions of infoboxes
00048     if ( ksw && ( isVisible() || width() == ksw->width() || height() == ksw->height() ) ) {
00049         infoBoxes()->resize( width(), height() );
00050     }
00051     sky->resize( width(), height() );
00052     sky2->resize( width(), height() );
00053 }
00054 
00055 void SkyMap::keyPressEvent( QKeyEvent *e ) {
00056     QString s;
00057     bool arrowKeyPressed( false );
00058     bool shiftPressed( false );
00059     float step = 1.0;
00060     if ( e->state() & ShiftButton ) { step = 10.0; shiftPressed = true; }
00061     
00062     //If the DCOP resume key was pressed, we process it here
00063     if ( ! data->resumeKey.isNull() && e->key() == data->resumeKey.keyCodeQt() ) {
00064         //kdDebug() << "resumeKey pressed; resuming DCOP." << endl;
00065         ksw->resumeDCOP();
00066         return;
00067     }
00068 
00069     switch ( e->key() ) {
00070         case Key_Left :
00071             if ( Options::useAltAz() ) {
00072                 focus()->setAz( dms( focus()->az()->Degrees() - step * MINZOOM/Options::zoomFactor() ).reduce() );
00073                 focus()->HorizontalToEquatorial( data->LST, data->geo()->lat() );
00074             } else {
00075                 focus()->setRA( focus()->ra()->Hours() + 0.05*step * MINZOOM/Options::zoomFactor() );
00076                 focus()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
00077             }
00078 
00079             arrowKeyPressed = true;
00080             slewing = true;
00081             ++scrollCount;
00082             break;
00083 
00084         case Key_Right :
00085             if ( Options::useAltAz() ) {
00086                 focus()->setAz( dms( focus()->az()->Degrees() + step * MINZOOM/Options::zoomFactor() ).reduce() );
00087                 focus()->HorizontalToEquatorial( data->LST, data->geo()->lat() );
00088             } else {
00089                 focus()->setRA( focus()->ra()->Hours() - 0.05*step * MINZOOM/Options::zoomFactor() );
00090                 focus()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
00091             }
00092 
00093             arrowKeyPressed = true;
00094             slewing = true;
00095             ++scrollCount;
00096             break;
00097 
00098         case Key_Up :
00099             if ( Options::useAltAz() ) {
00100                 focus()->setAlt( focus()->alt()->Degrees() + step * MINZOOM/Options::zoomFactor() );
00101                 if ( focus()->alt()->Degrees() > 90.0 ) focus()->setAlt( 90.0 );
00102                 focus()->HorizontalToEquatorial( data->LST, data->geo()->lat() );
00103             } else {
00104                 focus()->setDec( focus()->dec()->Degrees() + step * MINZOOM/Options::zoomFactor() );
00105                 if (focus()->dec()->Degrees() > 90.0) focus()->setDec( 90.0 );
00106                 focus()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
00107             }
00108 
00109             arrowKeyPressed = true;
00110             slewing = true;
00111             ++scrollCount;
00112             break;
00113 
00114         case Key_Down:
00115             if ( Options::useAltAz() ) {
00116                 focus()->setAlt( focus()->alt()->Degrees() - step * MINZOOM/Options::zoomFactor() );
00117                 if ( focus()->alt()->Degrees() < -90.0 ) focus()->setAlt( -90.0 );
00118                 focus()->HorizontalToEquatorial( data->LST, data->geo()->lat() );
00119             } else {
00120                 focus()->setDec( focus()->dec()->Degrees() - step * MINZOOM/Options::zoomFactor() );
00121                 if (focus()->dec()->Degrees() < -90.0) focus()->setDec( -90.0 );
00122                 focus()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
00123             }
00124 
00125             arrowKeyPressed = true;
00126             slewing = true;
00127             ++scrollCount;
00128             break;
00129 
00130         case Key_Plus:   //Zoom in
00131         case Key_Equal:
00132             if ( ksw ) ksw->slotZoomIn();
00133             break;
00134 
00135         case Key_Minus:  //Zoom out
00136         case Key_Underscore:
00137             if ( ksw ) ksw->slotZoomOut();
00138             break;
00139 
00140 //In the following cases, we set slewing=true in order to disengage tracking
00141         case Key_N: //center on north horizon
00142             stopTracking();
00143             setDestinationAltAz( 15.0, 0.0001 );
00144             break;
00145 
00146         case Key_E: //center on east horizon
00147             stopTracking();
00148             setDestinationAltAz( 15.0, 90.0 );
00149             break;
00150 
00151         case Key_S: //center on south horizon
00152             stopTracking();
00153             setDestinationAltAz( 15.0, 180.0 );
00154             break;
00155 
00156         case Key_W: //center on west horizon
00157             stopTracking();
00158             setDestinationAltAz( 15.0, 270.0 );
00159             break;
00160 
00161         case Key_Z: //center on Zenith
00162             stopTracking();
00163             setDestinationAltAz( 90.0, focus()->az()->Degrees() );
00164             break;
00165 
00166         case Key_0: //center on Sun
00167             setClickedObject( data->PCat->findByName("Sun") );
00168             setClickedPoint( clickedObject() );
00169             slotCenter();
00170             break;
00171 
00172         case Key_1: //center on Mercury
00173             setClickedObject( data->PCat->findByName("Mercury") );
00174             setClickedPoint( clickedObject() );
00175             slotCenter();
00176             break;
00177 
00178         case Key_2: //center on Venus
00179             setClickedObject( data->PCat->findByName("Venus") );
00180             setClickedPoint( clickedObject() );
00181             slotCenter();
00182             break;
00183 
00184         case Key_3: //center on Moon
00185             setClickedObject( data->Moon );
00186             setClickedPoint( clickedObject() );
00187             slotCenter();
00188             break;
00189 
00190         case Key_4: //center on Mars
00191             setClickedObject( data->PCat->findByName("Mars") );
00192             setClickedPoint( clickedObject() );
00193             slotCenter();
00194             break;
00195 
00196         case Key_5: //center on Jupiter
00197             setClickedObject( data->PCat->findByName("Jupiter") );
00198             setClickedPoint( clickedObject() );
00199             slotCenter();
00200             break;
00201 
00202         case Key_6: //center on Saturn
00203             setClickedObject( data->PCat->findByName("Saturn") );
00204             setClickedPoint( clickedObject() );
00205             slotCenter();
00206             break;
00207 
00208         case Key_7: //center on Uranus
00209             setClickedObject( data->PCat->findByName("Uranus") );
00210             setClickedPoint( clickedObject() );
00211             slotCenter();
00212             break;
00213 
00214         case Key_8: //center on Neptune
00215             setClickedObject( data->PCat->findByName("Neptune") );
00216             setClickedPoint( clickedObject() );
00217             slotCenter();
00218             break;
00219 
00220         case Key_9: //center on Pluto
00221             setClickedObject( data->PCat->findByName("Pluto") );
00222             setClickedPoint( clickedObject() );
00223             slotCenter();
00224             break;
00225 
00226         case Key_BracketLeft:   // Begin measuring angular distance
00227             if ( !isAngleMode() ) {
00228                 slotBeginAngularDistance();
00229             }
00230 
00231             break;
00232 
00233         case Key_BracketRight:  // End measuring angular distance
00234             if ( isAngleMode() ) {
00235                 slotEndAngularDistance();
00236             }
00237 
00238             break;
00239 
00240         case Key_Escape:        // Cancel angular distance measurement
00241             if  (isAngleMode() ) {
00242                 slotCancelAngularDistance();
00243             }
00244             break;
00245 
00246         case Key_Comma:  //advance one step backward in time
00247         case Key_Less:
00248             if ( data->clock()->isActive() ) data->clock()->stop();
00249             data->clock()->setScale( -1.0 * data->clock()->scale() ); //temporarily need negative time step
00250             data->clock()->manualTick( true );
00251             data->clock()->setScale( -1.0 * data->clock()->scale() ); //reset original sign of time step
00252             update();
00253             kapp->processEvents();
00254             break;
00255 
00256         case Key_Period: //advance one step forward in time
00257         case Key_Greater:
00258             if ( data->clock()->isActive() ) data->clock()->stop();
00259             data->clock()->manualTick( true );
00260             update();
00261             kapp->processEvents();
00262             break;
00263 
00264             //FIXME: Uncomment after feature thaw!
00265 //      case Key_C: //Center clicked object object
00266 //          if ( clickedObject() ) slotCenter();
00267 //          break;
00268 
00269         case Key_D: //Details window for Clicked/Centered object
00270             if ( shiftPressed ) setClickedObject( focusObject() );
00271             if ( clickedObject() ) slotDetail();
00272             break;
00273 
00274         case Key_P: //Show Popup menu for Clicked/Centered object
00275             if ( shiftPressed ) setClickedObject( focusObject() );
00276             if ( clickedObject() ) 
00277                 clickedObject()->showPopupMenu( pmenu, QCursor::pos() );
00278             break;
00279 
00280         case Key_O: //Add object to Observing List
00281             if ( shiftPressed ) setClickedObject( focusObject() );
00282             if ( clickedObject() ) 
00283                 ksw->observingList()->slotAddObject();
00284             break;
00285 
00286         case Key_L: //Toggle User label on Clicked/Centered object
00287             if ( shiftPressed ) setClickedObject( focusObject() );
00288             if ( clickedObject() ) {
00289                 if ( isObjectLabeled( clickedObject() ) )
00290                     slotRemoveObjectLabel();
00291                 else 
00292                     slotAddObjectLabel();
00293             }
00294             break;
00295 
00296         case Key_T: //Toggle planet trail on Clicked/Centered object (if solsys) 
00297             if ( shiftPressed ) setClickedObject( focusObject() );
00298             if ( clickedObject() && clickedObject()->isSolarSystem() ) {
00299                 if ( ((KSPlanetBase*)clickedObject())->hasTrail() )
00300                     slotRemovePlanetTrail();
00301                 else 
00302                     slotAddPlanetTrail();
00303             }
00304             break;
00305 
00306 
00307 
00308 //TIMING
00309 /*
00310         case Key_G: //loop through all cities
00311         {
00312 
00313       QFile file;
00314         if ( KSUtils::openDataFile( file, "Cities.dat" ) ) {
00315         KSFileReader fileReader( file );
00316         int nCount = 0;
00317         while (fileReader.hasMoreLines()) {
00318           QString line = fileReader.readLine();
00319           nCount++;
00320                 kdDebug() << "Line " << nCount << " : " << line;
00321         }
00322       }
00323 
00324             QTime t1;
00325             t1.start();
00326       for (int i=0;i<10;i++) {
00327         if ( KSUtils::openDataFile( file, "Cities.dat" ) ) {
00328           QString sAll( file.readAll() );
00329           QStringList lines = QStringList::split( "\n", sAll );
00330           int nSize = lines.size();
00331           for ( int i=0; i<nSize; i++ ) {
00332             QString& line = lines[i];
00333           }
00334             file.close();
00335         }
00336       }
00337             kdDebug() << "time taken for reading city data via read all (10 times): (msec): " << t1.elapsed() << endl;
00338 
00339             QTime t2;
00340             t2.start();
00341       for (int i=0;i<10;i++) {
00342         if ( KSUtils::openDataFile( file, "Cities.dat" ) ) {
00343             QTextStream stream( &file );
00344             while ( !stream.eof() ) {
00345                 QString line = stream.readLine();
00346             }
00347             file.close();
00348         }
00349       }
00350             kdDebug() << "time taken for reading city data old code (10 times): (msec): " << t2.elapsed() << endl;
00351 
00352             QTime t3;
00353             t3.start();
00354       for (int i=0;i<1;i++) {
00355         if ( KSUtils::openDataFile( file, "ngcic.dat" ) ) {
00356           QString sAll( file.readAll() );
00357           QStringList lines = QStringList::split( "\n", sAll );
00358           int nSize = lines.size();
00359           for ( int i=0; i<nSize; i++ ) {
00360             QString& line = lines[i];
00361           }
00362             file.close();
00363         }
00364       }
00365             kdDebug() << "time taken for reading deep sky data via read all (1 times): (msec): " << t3.elapsed() << endl;
00366 
00367             QTime t4;
00368             t4.start();
00369       for (int i=0;i<1;i++) {
00370         if ( KSUtils::openDataFile( file, "ngcic.dat" ) ) {
00371             QTextStream stream( &file );
00372             while ( !stream.eof() ) {
00373                 QString line = stream.readLine();
00374             }
00375             file.close();
00376         }
00377       }
00378             kdDebug() << "time taken for reading deep sky data old code  (1 times): (msec): " << t4.elapsed() << endl;
00379 
00380             break;
00381         }
00382 */
00383 
00384 //END_TIMING
00385     }
00386 
00387     setOldFocus( focus() );
00388     oldfocus()->setAz( focus()->az()->Degrees() );
00389     oldfocus()->setAlt( focus()->alt()->Degrees() );
00390 
00391     double dHA = data->LST->Hours() - focus()->ra()->Hours();
00392     while ( dHA < 0.0 ) dHA += 24.0;
00393     data->HourAngle->setH( dHA );
00394 
00395     if ( arrowKeyPressed ) {
00396         infoBoxes()->focusObjChanged( i18n( "nothing" ) );
00397         stopTracking();
00398         
00399         if ( scrollCount > 10 ) {
00400             setDestination( focus() );
00401             scrollCount = 0;
00402         }
00403     }
00404 
00405     forceUpdate(); //need a total update, or slewing with the arrow keys doesn't work.
00406 }
00407 
00408 void SkyMap::stopTracking() {
00409     if ( ksw && Options::isTracking() ) ksw->slotTrack();
00410 }
00411 
00412 void SkyMap::keyReleaseEvent( QKeyEvent *e ) {
00413     switch ( e->key() ) {
00414         case Key_Left :  //no break; continue to Key_Down
00415         case Key_Right :  //no break; continue to Key_Down
00416         case Key_Up :  //no break; continue to Key_Down
00417         case Key_Down :
00418             slewing = false;
00419             scrollCount = 0;
00420 
00421             if ( Options::useAltAz() ) 
00422                 setDestinationAltAz( focus()->alt()->Degrees(), focus()->az()->Degrees() );
00423             else
00424                 setDestination( focus() );
00425 
00426             showFocusCoords( true );
00427             forceUpdate();  // Need a full update to draw faint objects that are not drawn while slewing.
00428             break;
00429     }
00430 }
00431 
00432 void SkyMap::mouseMoveEvent( QMouseEvent *e ) {
00433     if ( Options::useHoverLabel() ) {
00434         //First of all, if the transientObject() pointer is not NULL, then 
00435         //we just moved off of a hovered object.  Begin fading the label.
00436         if ( transientObject() && ! TransientTimer.isActive() ) {
00437             fadeTransientLabel();
00438         }
00439         
00440         //Start a single-shot timer to monitor whether we are currently hovering.  
00441         //The idea is that whenever a moveEvent occurs, the timer is reset.  It
00442         //will only timeout if there are no move events for HOVER_INTERVAL ms
00443         HoverTimer.start( HOVER_INTERVAL, true );
00444     }
00445     
00446     //Are we dragging an infoBox?
00447     if ( infoBoxes()->dragBox( e ) ) {
00448         update();
00449         return;
00450     }
00451 
00452     //Are we defining a ZoomRect?
00453     if ( ZoomRect.center().x() > 0 && ZoomRect.center().y() > 0 ) {
00454         //cancel operation if the user let go of CTRL
00455         if ( !( e->state() & ControlButton ) ) {
00456             ZoomRect = QRect(); //invalidate ZoomRect
00457             update();
00458         } else {
00459             //Resize the rectangle so that it passes through the cursor position
00460             QPoint pcenter = ZoomRect.center();
00461             int dx = abs(e->x() - pcenter.x());
00462             int dy = abs(e->y() - pcenter.y());
00463             if ( dx == 0 || float(dy)/float(dx) > float(height())/float(width()) ) {
00464                 //Size rect by height
00465                 ZoomRect.setHeight( 2*dy );
00466                 ZoomRect.setWidth( 2*dy*width()/height() );
00467             } else {
00468                 //Size rect by height
00469                 ZoomRect.setWidth( 2*dx );
00470                 ZoomRect.setHeight( 2*dx*height()/width() );
00471             }
00472             ZoomRect.moveCenter( pcenter ); //reset center
00473 
00474             update();
00475             return;
00476         }
00477     }
00478 
00479     double dx = ( 0.5*width()  - e->x() )/Options::zoomFactor();
00480     double dy = ( 0.5*height() - e->y() )/Options::zoomFactor();
00481     double dyPix = 0.5*height() - e->y();
00482 
00483     if (unusablePoint (dx, dy)) return; // break if point is unusable
00484 
00485     //determine RA, Dec of mouse pointer
00486     setMousePoint( dXdYToRaDec( dx, dy, Options::useAltAz(), data->LST, data->geo()->lat(), Options::useRefraction() ) );
00487     mousePoint()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
00488 
00489 
00490     if ( midMouseButtonDown ) { //zoom according to y-offset
00491         float yoff = dyPix - y0;
00492 
00493         if (yoff > 10 ) {
00494             y0 = dyPix;
00495             if ( ksw ) ksw->slotZoomIn();
00496         }
00497         if (yoff < -10 ) {
00498             y0 = dyPix;
00499             if ( ksw ) ksw->slotZoomOut();
00500         }
00501     }
00502 
00503     if ( mouseButtonDown ) {
00504         // set the mouseMoveCursor and set slewing=true, if they are not set yet
00505         if (!mouseMoveCursor) setMouseMoveCursor();
00506         if (!slewing) {
00507             slewing = true;
00508             infoBoxes()->focusObjChanged( i18n( "nothing" ) );
00509             stopTracking(); //toggle tracking off
00510         }
00511 
00512         //Update focus such that the sky coords at mouse cursor remain approximately constant
00513         if ( Options::useAltAz() ) {
00514             mousePoint()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
00515             clickedPoint()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
00516             dms dAz = mousePoint()->az()->Degrees() - clickedPoint()->az()->Degrees();
00517             dms dAlt = mousePoint()->alt()->Degrees() - clickedPoint()->alt()->Degrees();
00518             focus()->setAz( focus()->az()->Degrees() - dAz.Degrees() ); //move focus in opposite direction
00519             focus()->setAlt( focus()->alt()->Degrees() - dAlt.Degrees() );
00520 
00521             if ( focus()->alt()->Degrees() >90.0 ) focus()->setAlt( 90.0 );
00522             if ( focus()->alt()->Degrees() <-90.0 ) focus()->setAlt( -90.0 );
00523             focus()->setAz( focus()->az()->reduce() );
00524             focus()->HorizontalToEquatorial( data->LST, data->geo()->lat() );
00525         } else {
00526             dms dRA = mousePoint()->ra()->Degrees() - clickedPoint()->ra()->Degrees();
00527             dms dDec = mousePoint()->dec()->Degrees() - clickedPoint()->dec()->Degrees();
00528             focus()->setRA( focus()->ra()->Hours() - dRA.Hours() ); //move focus in opposite direction
00529             focus()->setDec( focus()->dec()->Degrees() - dDec.Degrees() );
00530 
00531             if ( focus()->dec()->Degrees() >90.0 ) focus()->setDec( 90.0 );
00532             if ( focus()->dec()->Degrees() <-90.0 ) focus()->setDec( -90.0 );
00533             focus()->setRA( focus()->ra()->reduce() );
00534             focus()->EquatorialToHorizontal( data->LST, data->geo()->lat() );
00535         }
00536 
00537         ++scrollCount;
00538         if ( scrollCount > 4 ) {
00539             showFocusCoords( true );
00540             scrollCount = 0;
00541         }
00542 
00543         setOldFocus( focus() );
00544 
00545         double dHA = data->LST->Hours() - focus()->ra()->Hours();
00546         while ( dHA < 0.0 ) dHA += 24.0;
00547         data->HourAngle->setH( dHA );
00548 
00549         //redetermine RA, Dec of mouse pointer, using new focus
00550         setMousePoint( dXdYToRaDec( dx, dy, Options::useAltAz(), data->LST, data->geo()->lat(), Options::useRefraction() ) );
00551         setClickedPoint( mousePoint() );
00552 
00553         forceUpdate();  // must be new computed
00554     } else {
00555 
00556         if ( ksw ) {
00557             QString sX, sY, s;
00558             sX = mousePoint()->az()->toDMSString(true);  //true = force +/- symbol
00559             sY = mousePoint()->alt()->toDMSString(true); //true=force +/- symbol
00560             if ( Options::useAltAz() && Options::useRefraction() ) 
00561                 sY = refract( mousePoint()->alt(), true ).toDMSString(true);
00562 
00563             s = sX + ",  " + sY;
00564             ksw->statusBar()->changeItem( s, 1 );
00565             
00566             sX = mousePoint()->ra()->toHMSString();
00567             sY = mousePoint()->dec()->toDMSString(true); //true = force +/- symbol
00568             s = sX + ",  " + sY;
00569             ksw->statusBar()->changeItem( s, 2 );
00570         }
00571     }
00572 }
00573 
00574 void SkyMap::wheelEvent( QWheelEvent *e ) {
00575     if ( ksw && e->delta() > 0 ) ksw->slotZoomIn();
00576     else if ( ksw ) ksw->slotZoomOut();
00577 }
00578 
00579 void SkyMap::mouseReleaseEvent( QMouseEvent * ) {
00580     if ( infoBoxes()->unGrabBox() ) {
00581         update();
00582         return;
00583     }
00584 
00585     if ( ZoomRect.isValid() ) {
00586         //Zoom in on center of Zoom Circle, by a factor equal to the ratio
00587         //of the sky pixmap's width to the Zoom Circle's diameter
00588         float factor = float(width()) / float(ZoomRect.width());
00589 
00590         double dx = ( 0.5*width()  - ZoomRect.center().x() )/Options::zoomFactor();
00591         double dy = ( 0.5*height() - ZoomRect.center().y() )/Options::zoomFactor();
00592 
00593         infoBoxes()->focusObjChanged( i18n( "nothing" ) );
00594         stopTracking();
00595 
00596         SkyPoint newcenter = dXdYToRaDec( dx, dy, Options::useAltAz(), data->LST, data->geo()->lat(), Options::useRefraction() );
00597 
00598         setFocus( &newcenter );
00599         setDestination( &newcenter );
00600         ksw->zoom( Options::zoomFactor() * factor );
00601         
00602         setDefaultMouseCursor();
00603         ZoomRect = QRect(); //invalidate ZoomRect
00604         forceUpdate();
00605     } else {
00606         setDefaultMouseCursor();
00607         ZoomRect = QRect(); //just in case user Ctrl+clicked + released w/o dragging...
00608     }
00609 
00610     if (mouseMoveCursor) setDefaultMouseCursor();   // set default cursor
00611     if (mouseButtonDown) { //false if double-clicked, because it's unset there.
00612         mouseButtonDown = false;
00613         if ( slewing ) {
00614             slewing = false;
00615             
00616             if ( Options::useAltAz() ) 
00617                 setDestinationAltAz( focus()->alt()->Degrees(), focus()->az()->Degrees() );
00618             else
00619                 setDestination( focus() );
00620         }
00621 
00622         setOldFocus( focus() );
00623         forceUpdate();  // is needed because after moving the sky not all stars are shown
00624     }
00625     if ( midMouseButtonDown ) midMouseButtonDown = false;  // if middle button was pressed unset here
00626 
00627     scrollCount = 0;
00628 }
00629 
00630 void SkyMap::mousePressEvent( QMouseEvent *e ) {
00631     //did we Grab an infoBox?
00632     if ( e->button() == LeftButton && infoBoxes()->grabBox( e ) ) {
00633         update(); //refresh without redrawing skymap
00634         return;
00635     }
00636 
00637     if ( (e->state() & ControlButton) && (e->button() == LeftButton) ) {
00638         ZoomRect.moveCenter( e->pos() );
00639         setZoomMouseCursor();
00640         update(); //refresh without redrawing skymap
00641         return;
00642     }
00643 
00644     // if button is down and cursor is not moved set the move cursor after 500 ms
00645     QTimer t;
00646     t.singleShot (500, this, SLOT (setMouseMoveCursor()));
00647 
00648     double dx = ( 0.5*width()  - e->x() )/Options::zoomFactor();
00649     double dy = ( 0.5*height() - e->y() )/Options::zoomFactor();
00650     if (unusablePoint (dx, dy)) return; // break if point is unusable
00651 
00652     if ( !midMouseButtonDown && e->button() == MidButton ) {
00653         y0 = 0.5*height() - e->y();  //record y pixel coordinate for middle-button zooming
00654         midMouseButtonDown = true;
00655     }
00656 
00657     if ( !mouseButtonDown ) {
00658         if ( e->button()==LeftButton ) {
00659             mouseButtonDown = true;
00660             scrollCount = 0;
00661         }
00662 
00663         //determine RA, Dec of mouse pointer
00664         setMousePoint( dXdYToRaDec( dx, dy, Options::useAltAz(),
00665                 data->LST, data->geo()->lat(), Options::useRefraction() ) );
00666         setClickedPoint( mousePoint() );
00667 
00668         //Find object nearest to clickedPoint()
00669         setClickedObject( objectNearest( clickedPoint() ) );
00670 
00671         if ( clickedObject() ) {
00672             setClickedPoint( clickedObject() );
00673             
00674             if ( e->button() == RightButton ) {
00675                 clickedObject()->showPopupMenu( pmenu, QCursor::pos() );
00676             }
00677             
00678             if ( ksw && e->button() == LeftButton ) {
00679                 ksw->statusBar()->changeItem( clickedObject()->translatedLongName(), 0 );
00680             }
00681         } else {
00682             //Empty sky selected.  If left-click, display "nothing" in the status bar.
00683         //If right-click, open "empty" popup menu.
00684             setClickedObject( NULL );
00685 
00686             switch (e->button()) {
00687                 case LeftButton:
00688                     if ( ksw ) ksw->statusBar()->changeItem( i18n( "Empty sky" ), 0 );
00689                     break;
00690                 case RightButton:
00691                 {
00692                     SkyObject *nullObj = new SkyObject( SkyObject::TYPE_UNKNOWN, clickedPoint()->ra()->Hours(), clickedPoint()->dec()->Degrees() );
00693                     pmenu->createEmptyMenu( nullObj );
00694                     delete nullObj;
00695                     
00696                     pmenu->popup(  QCursor::pos() );
00697                     break;
00698                 }
00699                 
00700                 default:
00701                     break;
00702             }
00703         }
00704     }
00705 }
00706 
00707 void SkyMap::mouseDoubleClickEvent( QMouseEvent *e ) {
00708     //Was the event inside an infoBox?  If so, shade the box.
00709     if ( e->button() == LeftButton ) {
00710         if ( infoBoxes()->shadeBox( e ) ) {
00711             update();
00712             return;
00713         }
00714 
00715         double dx = ( 0.5*width()  - e->x() )/Options::zoomFactor();
00716         double dy = ( 0.5*height() - e->y() )/Options::zoomFactor();
00717         if (unusablePoint (dx, dy)) return; // break if point is unusable
00718 
00719         if (mouseButtonDown ) mouseButtonDown = false;
00720         if ( dx != 0.0 || dy != 0.0 )  slotCenter();
00721     }
00722 }
00723 
00724 void SkyMap::paintEvent( QPaintEvent * )
00725 {
00726     //If computeSkymap is false, then we just refresh the window using the stored sky pixmap 
00727     //and draw the "overlays" on top.  This lets us update the overlay information rapidly
00728     //without needing to recompute the entire skymap.
00729     //use update() to trigger this "short" paint event; to force a full "recompute" 
00730     //of the skymap, use forceUpdate().
00731     if (!computeSkymap)
00732     {
00733         *sky2 = *sky;
00734         drawOverlays( sky2 );
00735         bitBlt( this, 0, 0, sky2 );
00736         return ; // exit because the pixmap is repainted and that's all what we want
00737     }
00738 
00739     QPainter psky;
00740     setMapGeometry();
00741 
00742     //checkSlewing combines the slewing flag (which is true when the display is actually in motion),
00743     //the hideOnSlew option (which is true if slewing should hide objects),
00744     //and clockSlewing (which is true if the timescale exceeds Options::slewTimeScale)
00745     bool checkSlewing = ( ( slewing || ( clockSlewing && data->clock()->isActive() ) )
00746                 && Options::hideOnSlew() );
00747 
00748     //shortcuts to inform wheter to draw different objects
00749     bool drawPlanets( Options::showPlanets() && !(checkSlewing && Options::hidePlanets() ) );
00750     bool drawMW( Options::showMilkyWay() && !(checkSlewing && Options::hideMilkyWay() ) );
00751     bool drawCNames( Options::showCNames() && !(checkSlewing && Options::hideCNames() ) );
00752     bool drawCLines( Options::showCLines() &&!(checkSlewing && Options::hideCLines() ) );
00753     bool drawCBounds( Options::showCBounds() &&!(checkSlewing && Options::hideCBounds() ) );
00754     bool drawGrid( Options::showGrid() && !(checkSlewing && Options::hideGrid() ) );
00755 
00756     psky.begin( sky );
00757     psky.fillRect( 0, 0, width(), height(), QBrush( data->colorScheme()->colorNamed( "SkyColor" ) ) );
00758 
00759     if ( drawMW ) drawMilkyWay( psky );
00760     if ( drawGrid ) drawCoordinateGrid( psky );
00761     
00762     if ( drawCBounds ) drawConstellationBoundaries( psky );
00763     if ( drawCLines ) drawConstellationLines( psky );
00764     if ( drawCNames ) drawConstellationNames( psky );
00765 
00766     if ( Options::showEquator() ) drawEquator( psky );
00767     if ( Options::showEcliptic() ) drawEcliptic( psky );
00768 
00769     //drawing to screen, so leave scale parameter at its default value of 1.0
00770     drawStars( psky );
00771     drawDeepSkyObjects( psky );
00772     drawSolarSystem( psky, drawPlanets );
00773     drawAttachedLabels( psky );
00774     drawHorizon( psky );
00775 
00776     //Finish up
00777     psky.end();
00778 
00779     *sky2 = *sky;
00780     drawOverlays( sky2 );
00781     bitBlt( this, 0, 0, sky2 );
00782 
00783     computeSkymap = false;  // use forceUpdate() to compute new skymap else old pixmap will be shown
00784 }
00785 

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