summaryrefslogtreecommitdiffstats
path: root/kalzium/src/detailedgraphicaloverview.cpp
blob: 0042474630f764fe35c62cc6d6027a036a7505c5 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/***************************************************************************

copyright            : (C) 2004, 2005 by Carsten Niehaus
email                : cniehaus@kde.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 "detailedgraphicaloverview.h"
#include "element.h"
#include "kalziumutils.h"

//KDE-Includes
#include <kdebug.h>
#include <klocale.h>
#include <kglobalsettings.h>
#include <kglobal.h>

//QT-Includes
#include <tqpainter.h>
#include <tqstring.h>
#include <tqpixmap.h>
#include <tqrect.h>

DetailedGraphicalOverview::DetailedGraphicalOverview( Element *el, TQWidget *parent, const char *name ) 
: TQWidget( parent, name )
{
	init( el );
}

DetailedGraphicalOverview::DetailedGraphicalOverview( TQWidget *parent, const char *name ) 
: TQWidget( parent, name )
{
	init( 0L );
}

void DetailedGraphicalOverview::init( Element *el )
{
	setBackgroundMode( NoBackground );

	m_element = el;
	setMinimumSize( 300, 200 );
	update();
}

void DetailedGraphicalOverview::paintEvent( TQPaintEvent* )
{
	int h = height();
	int w = width();

	TQPixmap pm( w, h );

	TQPainter p;
	p.begin( &pm );

	p.setBrush(TQt::SolidPattern);

	if ( !m_element )
	{
		pm.fill( paletteBackgroundColor() );
		p.drawText( 0, 0, w, h, TQt::AlignCenter | TQt::WordBreak, i18n( "No element selected" ) );
	}
	else
	{

		h_t = 20; //height of the texts

		x1 =  0;
		y1 =  0;

		x2 = w;
		y2 = h;

		p.setBrush( m_element->elementColor() );
		p.drawRect( x1 , y1 , x2 , y2 );

		p.setBrush( TQt::black );
		p.setBrush(TQt::NoBrush);

		TQFont fA = TDEGlobalSettings::generalFont();
		TQFont fB = TDEGlobalSettings::generalFont();
		TQFont fC = TDEGlobalSettings::generalFont();

		TQString strLocalizedMass = KalziumUtils::localizedValue( m_element->mass(), 6 );

		fA.setPointSize( fA.pointSize() + 20 ); //Huge font
		fA.setBold( true );
		fB.setPointSize( fB.pointSize() + 6 ); //Big font
		fC.setPointSize( fC.pointSize() + 4 ); //Big font
		fC.setBold( true );
		TQFontMetrics fmA = TQFontMetrics( fA );
		TQFontMetrics fmB = TQFontMetrics( fB );

		//coordinates for element symbol: near the center
		int xA = 4 * w / 10;
		int yA = h / 2;

		//coordinates for the atomic number: offset from element symbol to the upper left
		int xB = xA - fmB.width( TQString::number( m_element->number() ) );
		int yB = yA - fmA.height() + fmB.height();

		//Element Symbol
		p.setFont( fA );
		p.drawText( xA, yA , m_element->symbol() ); 

		//Atomic number
		p.setFont( fB );
		p.drawText( xB, yB, TQString::number( m_element->number() ));

		TQRect rect( 0, 20, w/2, h );
		
		p.setFont( fC );
				
		int size = KalziumUtils::maxSize(m_element->elname(), rect , fC, &p);
		int size2 = KalziumUtils::maxSize(m_element->oxstage(), rect, fC, &p);
		int size3 = KalziumUtils::maxSize( strLocalizedMass , rect , fC, &p);

		//Name and other data
		fC.setPointSize( size );
		p.setFont( fC );
		
		//Name
		p.drawText( 1, 0, w/2, h, TQt::AlignLeft, m_element->elname() );
		
		//Oxidationstates
		fC.setPointSize( size2 );
		p.setFont( fC );
		int offsetOx = KalziumUtils::StringHeight( strLocalizedMass , fC, &p );
		p.drawText( 1, h-offsetOx, w/2, offsetOx, TQt::AlignLeft, m_element->oxstage() );

		//Mass
		fC.setPointSize( size3 );
		p.setFont( fC );
		
		int offset = KalziumUtils::StringHeight( strLocalizedMass, fC, &p );
		p.drawText( w/2, h-offset, w/2, offset, TQt::AlignRight, strLocalizedMass );

		drawBiologicalSymbol( &p );
	}

	p.end();


	bitBlt( this, 0, 0, &pm );
}

void DetailedGraphicalOverview::drawBiologicalSymbol( TQPainter *p )
{
	if ( !m_element ) return;
	const int db = h_t;        //diameter of the big circle
	const int ds = db/2;      //diameter of the inner circle

	int d_ds = ( db/2 )-( ds/2 ); //the delta-x/y of the inner circle

	int pos_x = width() - 4 - db;
	int pos_y = 4;

	if ( m_element->biological() > 0 )
	{
		const int radius = db + 8;
		p->setBrush( TQt::SolidPattern );
		p->setBrush( TQt::white );
		p->setPen( TQt::black );
		p->drawRoundRect( TQRect( width() - radius, 
					-radius, 
					2 * radius, 
					2 * radius ), 70, 70 );
	}
	
	switch ( m_element->biological() )
	{
		case 0:        //nothing
			break;
		case 1:        //red, red
			p->setBrush( TQt::red );
			p->setBrush(TQt::NoBrush);
			p->setPen( TQt::red );
			p->drawEllipse( pos_x,pos_y,db,db );
			p->setBrush(TQt::SolidPattern);
			p->setBrush( TQt::red );
			p->drawEllipse( pos_x+d_ds, pos_y+d_ds, ds, ds );
			break;
		case 2:        //green, red
			p->setBrush( TQt::red );
			p->setBrush(TQt::NoBrush);
			p->setPen( TQt::red );
			p->drawEllipse( pos_x,pos_y,db,db );
			p->setBrush(TQt::SolidPattern);
			p->setBrush( TQt::green );
			p->setPen( TQt::green );
			p->drawEllipse( pos_x+d_ds, pos_y+d_ds, ds, ds );
			break;
		case 3:        //green
			p->setBrush(TQt::SolidPattern);
			p->setBrush( TQt::green );
			p->setPen( TQt::green );
			p->drawEllipse( pos_x+d_ds, pos_y+d_ds, ds, ds );
			break;
		case 4:        //green, blue
			p->setBrush( TQt::blue );
			p->setBrush(TQt::NoBrush);
			p->setPen( TQt::blue );
			p->drawEllipse( pos_x,pos_y,db,db );
			p->setBrush(TQt::SolidPattern);
			p->setBrush( TQt::green );
			p->setPen( TQt::green );
			p->drawEllipse( pos_x+d_ds, pos_y+d_ds, ds, ds );
			break;
		case 5:        //blue
			p->setBrush(TQt::SolidPattern);
			p->setBrush( TQt::blue );
			p->setPen( TQt::blue );
			p->drawEllipse( pos_x+d_ds, pos_y+d_ds, ds, ds );
			break;
		case 6:        //blue, blue
			p->setBrush( TQt::blue );
			p->setBrush(TQt::NoBrush);
			p->setPen( TQt::blue );
			p->drawEllipse( pos_x,pos_y,db,db );
			p->setBrush(TQt::SolidPattern);
			p->drawEllipse( pos_x+d_ds, pos_y+d_ds, ds, ds );
			break;
	}
}

#include "detailedgraphicaloverview.moc"