summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/fov.cpp
blob: 2820221a7f879b883eaacf80f8f06961f0f68435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***************************************************************************
                          fov.cpp  -  description
                             -------------------
    begin                : Fri 05 Sept 2003
    copyright            : (C) 2003 by Jason Harris
    email                : kstars@30doradus.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tqpainter.h>
#include <tqfile.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstandarddirs.h>

#include "fov.h"

//------------FOV-----------------//
FOV::FOV( TQString n, float sz, int sh, TQString col ) : Name( n ), Color( col ), Size( sz ), Shape( sh )
{}

FOV::FOV() : Name( i18n( "No FOV" ) ), Color( "#FFFFFF" ), Size( 0.0 ), Shape( 0 )
{}

FOV::FOV( TQString sname ) {
	TQFile f;
	f.setName( locate( "appdata", "fov.dat" ) );
	
	int sh;
	float sz;

	if ( f.exists() && f.open( IO_ReadOnly ) ) {
		TQTextStream stream( &f );
		while ( !stream.eof() ) {
			TQStringList fields = TQStringList::split( ":", stream.readLine() );
			bool ok( false );

			if ( fields.count() == 4 ) {
				if ( fields[0] == sname ) {
					sz = (float)(fields[1].toDouble( &ok ));
					if ( ok ) {
						sh = fields[2].toInt( &ok );
						if ( ok ) {
							Name = fields[0];
							Size = sz;
							Shape = sh;
							Color = fields[3]; 
							
							return;
						}
					}
					
					break;
				}
			}
		}
	}
	
	//If we get here, then the symbol could not be assigned
	Name = i18n( "No FOV" );
	Size = 0.0;
	Shape = 0;
	Color = "#FFFFFF";
}

void FOV::draw( TQPainter &p, float pixelsize ) {
	p.setPen( TQColor( color() ) );
	p.setBrush( Qt::NoBrush );
	int w = p.viewport().width();
	int h = p.viewport().height();

	switch ( shape() ) {
		case 0: { //Square
			int s = int( pixelsize );
			p.drawRect( (w - s)/2, (h - s)/2, s, s );
			break;
		}
		case 1: { //Circle
			int s = int( pixelsize );
			p.drawEllipse( (w - s)/2, (h - s)/2, s, s );
			break;
		}
		case 2: { //Crosshairs
			int s1 = int( pixelsize );
			int s2 = 2*int( pixelsize );
			int s3 = 3*int( pixelsize );

			int x0 = w/2;  int y0 = h/2;
			int x1 = x0 - s1/2;  int y1 = y0 - s1/2;
			int x2 = x0 - s2/2;  int y2 = y0 - s2/2;
			int x3 = x0 - s3/2;  int y3 = y0 - s3/2;

			//Draw radial lines
			p.drawLine( x1, y0, x3, y0 );
			p.drawLine( x0+s3/2, y0, x0+s1/2, y0 );
			p.drawLine( x0, y1, x0, y3 );
			p.drawLine( x0, y0+s1/2, x0, y0+s3/2 );

			//Draw circles at 0.5 & 1 degrees
			p.drawEllipse( x1, y1, s1, s1 );
			p.drawEllipse( x2, y2, s2, s2 );

			break;
		}
		case 3: { //Bullseye
			int s1 = int( pixelsize );
			int s2 = 2*int( pixelsize );
			int s3 = 3*int( pixelsize );

			int x0 = w/2;  int y0 = h/2;
			int x1 = x0 - s1/2;  int y1 = y0 - s1/2;
			int x2 = x0 - s2/2;  int y2 = y0 - s2/2;
			int x3 = x0 - s3/2;  int y3 = y0 - s3/2;

			p.drawEllipse( x1, y1, s1, s1 );
			p.drawEllipse( x2, y2, s2, s2 );
			p.drawEllipse( x3, y3, s3, s3 );

			break;
		}
		case 4: { // Solid Circle
			int s = int( pixelsize );
			p.setBrush( TQBrush ( TQColor( color() ), Qt::Dense4Pattern) );
			p.drawEllipse( (w - s)/2, (h - s)/2, s, s );
			p.setBrush(Qt::NoBrush);
			break;
		}
	}
}