moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / fov.cpp
blobd7fd5d323552e559c6a08ae9252f2817b547c121
1 /***************************************************************************
2 fov.cpp - description
3 -------------------
4 begin : Fri 05 Sept 2003
5 copyright : (C) 2003 by Jason Harris
6 email : kstars@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include <qpainter.h>
19 #include <qfile.h>
20 #include <kdebug.h>
21 #include <klocale.h>
22 #include <kstandarddirs.h>
24 #include "fov.h"
26 //------------FOV-----------------//
27 FOV::FOV( QString n, float sz, int sh, QString col ) : Name( n ), Color( col ), Size( sz ), Shape( sh )
30 FOV::FOV() : Name( i18n( "No FOV" ) ), Color( "#FFFFFF" ), Size( 0.0 ), Shape( 0 )
33 FOV::FOV( QString sname ) {
34 QFile f;
35 f.setName( locate( "appdata", "fov.dat" ) );
37 int sh;
38 float sz;
40 if ( f.exists() && f.open( IO_ReadOnly ) ) {
41 QTextStream stream( &f );
42 while ( !stream.eof() ) {
43 QStringList fields = QStringList::split( ":", stream.readLine() );
44 bool ok( false );
46 if ( fields.count() == 4 ) {
47 if ( fields[0] == sname ) {
48 sz = (float)(fields[1].toDouble( &ok ));
49 if ( ok ) {
50 sh = fields[2].toInt( &ok );
51 if ( ok ) {
52 Name = fields[0];
53 Size = sz;
54 Shape = sh;
55 Color = fields[3];
57 return;
61 break;
67 //If we get here, then the symbol could not be assigned
68 Name = i18n( "No FOV" );
69 Size = 0.0;
70 Shape = 0;
71 Color = "#FFFFFF";
74 void FOV::draw( QPainter &p, float pixelsize ) {
75 p.setPen( QColor( color() ) );
76 p.setBrush( Qt::NoBrush );
77 int w = p.viewport().width();
78 int h = p.viewport().height();
80 switch ( shape() ) {
81 case 0: { //Square
82 int s = int( pixelsize );
83 p.drawRect( (w - s)/2, (h - s)/2, s, s );
84 break;
86 case 1: { //Circle
87 int s = int( pixelsize );
88 p.drawEllipse( (w - s)/2, (h - s)/2, s, s );
89 break;
91 case 2: { //Crosshairs
92 int s1 = int( pixelsize );
93 int s2 = 2*int( pixelsize );
94 int s3 = 3*int( pixelsize );
96 int x0 = w/2; int y0 = h/2;
97 int x1 = x0 - s1/2; int y1 = y0 - s1/2;
98 int x2 = x0 - s2/2; int y2 = y0 - s2/2;
99 int x3 = x0 - s3/2; int y3 = y0 - s3/2;
101 //Draw radial lines
102 p.drawLine( x1, y0, x3, y0 );
103 p.drawLine( x0+s3/2, y0, x0+s1/2, y0 );
104 p.drawLine( x0, y1, x0, y3 );
105 p.drawLine( x0, y0+s1/2, x0, y0+s3/2 );
107 //Draw circles at 0.5 & 1 degrees
108 p.drawEllipse( x1, y1, s1, s1 );
109 p.drawEllipse( x2, y2, s2, s2 );
111 break;
113 case 3: { //Bullseye
114 int s1 = int( pixelsize );
115 int s2 = 2*int( pixelsize );
116 int s3 = 3*int( pixelsize );
118 int x0 = w/2; int y0 = h/2;
119 int x1 = x0 - s1/2; int y1 = y0 - s1/2;
120 int x2 = x0 - s2/2; int y2 = y0 - s2/2;
121 int x3 = x0 - s3/2; int y3 = y0 - s3/2;
123 p.drawEllipse( x1, y1, s1, s1 );
124 p.drawEllipse( x2, y2, s2, s2 );
125 p.drawEllipse( x3, y3, s3, s3 );
127 break;
129 case 4: { // Solid Circle
130 int s = int( pixelsize );
131 p.setBrush( QBrush ( QColor( color() ), Qt::Dense4Pattern) );
132 p.drawEllipse( (w - s)/2, (h - s)/2, s, s );
133 p.setBrush(Qt::NoBrush);
134 break;