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

kstars

fov.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           fov.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 <qpainter.h>
00019 #include <qfile.h>
00020 #include <kdebug.h>
00021 #include <klocale.h>
00022 #include <kstandarddirs.h>
00023 
00024 #include "fov.h"
00025 
00026 //------------FOV-----------------//
00027 FOV::FOV( QString n, float sz, int sh, QString col ) : Name( n ), Color( col ), Size( sz ), Shape( sh )
00028 {}
00029 
00030 FOV::FOV() : Name( i18n( "No FOV" ) ), Color( "#FFFFFF" ), Size( 0.0 ), Shape( 0 )
00031 {}
00032 
00033 FOV::FOV( QString sname ) {
00034     QFile f;
00035     f.setName( locate( "appdata", "fov.dat" ) );
00036     
00037     int sh;
00038     float sz;
00039 
00040     if ( f.exists() && f.open( IO_ReadOnly ) ) {
00041         QTextStream stream( &f );
00042         while ( !stream.eof() ) {
00043             QStringList fields = QStringList::split( ":", stream.readLine() );
00044             bool ok( false );
00045 
00046             if ( fields.count() == 4 ) {
00047                 if ( fields[0] == sname ) {
00048                     sz = (float)(fields[1].toDouble( &ok ));
00049                     if ( ok ) {
00050                         sh = fields[2].toInt( &ok );
00051                         if ( ok ) {
00052                             Name = fields[0];
00053                             Size = sz;
00054                             Shape = sh;
00055                             Color = fields[3]; 
00056                             
00057                             return;
00058                         }
00059                     }
00060                     
00061                     break;
00062                 }
00063             }
00064         }
00065     }
00066     
00067     //If we get here, then the symbol could not be assigned
00068     Name = i18n( "No FOV" );
00069     Size = 0.0;
00070     Shape = 0;
00071     Color = "#FFFFFF";
00072 }
00073 
00074 void FOV::draw( QPainter &p, float pixelsize ) {
00075     p.setPen( QColor( color() ) );
00076     p.setBrush( Qt::NoBrush );
00077     int w = p.viewport().width();
00078     int h = p.viewport().height();
00079 
00080     switch ( shape() ) {
00081         case 0: { //Square
00082             int s = int( pixelsize );
00083             p.drawRect( (w - s)/2, (h - s)/2, s, s );
00084             break;
00085         }
00086         case 1: { //Circle
00087             int s = int( pixelsize );
00088             p.drawEllipse( (w - s)/2, (h - s)/2, s, s );
00089             break;
00090         }
00091         case 2: { //Crosshairs
00092             int s1 = int( pixelsize );
00093             int s2 = 2*int( pixelsize );
00094             int s3 = 3*int( pixelsize );
00095 
00096             int x0 = w/2;  int y0 = h/2;
00097             int x1 = x0 - s1/2;  int y1 = y0 - s1/2;
00098             int x2 = x0 - s2/2;  int y2 = y0 - s2/2;
00099             int x3 = x0 - s3/2;  int y3 = y0 - s3/2;
00100 
00101             //Draw radial lines
00102             p.drawLine( x1, y0, x3, y0 );
00103             p.drawLine( x0+s3/2, y0, x0+s1/2, y0 );
00104             p.drawLine( x0, y1, x0, y3 );
00105             p.drawLine( x0, y0+s1/2, x0, y0+s3/2 );
00106 
00107             //Draw circles at 0.5 & 1 degrees
00108             p.drawEllipse( x1, y1, s1, s1 );
00109             p.drawEllipse( x2, y2, s2, s2 );
00110 
00111             break;
00112         }
00113         case 3: { //Bullseye
00114             int s1 = int( pixelsize );
00115             int s2 = 2*int( pixelsize );
00116             int s3 = 3*int( pixelsize );
00117 
00118             int x0 = w/2;  int y0 = h/2;
00119             int x1 = x0 - s1/2;  int y1 = y0 - s1/2;
00120             int x2 = x0 - s2/2;  int y2 = y0 - s2/2;
00121             int x3 = x0 - s3/2;  int y3 = y0 - s3/2;
00122 
00123             p.drawEllipse( x1, y1, s1, s1 );
00124             p.drawEllipse( x2, y2, s2, s2 );
00125             p.drawEllipse( x3, y3, s3, s3 );
00126 
00127             break;
00128         }
00129         case 4: { // Solid Circle
00130             int s = int( pixelsize );
00131             p.setBrush( QBrush ( QColor( color() ), Qt::Dense4Pattern) );
00132             p.drawEllipse( (w - s)/2, (h - s)/2, s, s );
00133             p.setBrush(Qt::NoBrush);
00134             break;
00135         }
00136     }
00137 }
00138 

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