1 /***************************************************************************
3 orbitswidget.cpp - description
6 copyright : (C) 2003 by Carsten Niehaus
7 email : cniehaus@kde.org
8 ***************************************************************************/
10 /***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
17 ***************************************************************************/
19 #include "orbitswidget.h"
27 OrbitsWidget::OrbitsWidget( QWidget
*parent
, const char *name
) : QWidget( parent
, name
)
31 void OrbitsWidget::setElementNumber( const int num
)
33 kdDebug() << "Element: " << num
<< endl
;
36 // hulllist.append( "1 2 3" );
37 hulllist
.append( "1" );
38 hulllist
.append( "2" ); //Helium
39 hulllist
.append( "2 1" );
40 hulllist
.append( "2 2" );
41 hulllist
.append( "2 3" );
42 hulllist
.append( "2 4" );
43 hulllist
.append( "2 5" );
44 hulllist
.append( "2 6" );
45 hulllist
.append( "2 7" );
46 hulllist
.append( "2 8" ); //Neon
47 hulllist
.append( "2 8 1" );
48 hulllist
.append( "2 8 2" );
49 hulllist
.append( "2 8 3" );
50 hulllist
.append( "2 8 4" );
51 hulllist
.append( "2 8 5" );
52 hulllist
.append( "2 8 6" );
53 hulllist
.append( "2 8 7" );
54 hulllist
.append( "2 8 8" ); //Argon
55 hulllist
.append( "2 8 8 1" );
56 hulllist
.append( "2 8 8 2" );//Calcium
57 hulllist
.append( "2 8 9 2" );
58 hulllist
.append( "2 8 10 2" );
59 hulllist
.append( "2 8 11 2" );
60 hulllist
.append( "2 8 13 1" );
61 hulllist
.append( "2 8 13 2" );//Manganese
62 hulllist
.append( "2 8 14 2" );
63 hulllist
.append( "2 8 15 2" );
64 hulllist
.append( "2 8 16 2" );
65 hulllist
.append( "2 8 18 1" );//Copper
66 hulllist
.append( "2 8 18 2" );
67 hulllist
.append( "2 8 18 3" );
68 hulllist
.append( "2 8 18 4" );
69 hulllist
.append( "2 8 18 5" );
70 hulllist
.append( "2 8 18 6" );
71 hulllist
.append( "2 8 18 7" );
72 hulllist
.append( "2 8 18 8" );//Krypton
73 // hulllist.append( "1 2 3 4 5" );
74 hulllist
.append( "2 8 18 8 1" );
75 hulllist
.append( "2 8 18 8 2" );//Rubidium
76 hulllist
.append( "2 8 18 9 2" );
77 hulllist
.append( "2 8 18 10 2" );//Zirconium
78 hulllist
.append( "2 8 18 12 1" );
79 hulllist
.append( "2 8 18 13 1" );
80 hulllist
.append( "2 8 18 14 1" );//Techneticum
81 hulllist
.append( "2 8 18 15 1" );
82 hulllist
.append( "2 8 18 16 1" );
83 hulllist
.append( "2 8 18 18" ); //Palladium
84 hulllist
.append( "2 8 18 18 1" );
85 hulllist
.append( "2 8 18 18 2" );
86 hulllist
.append( "2 8 18 18 3" );//Indium
87 hulllist
.append( "2 8 18 18 4" );
88 hulllist
.append( "2 8 18 18 5" );
89 hulllist
.append( "2 8 18 18 6" );
90 hulllist
.append( "2 8 18 18 7" );
91 hulllist
.append( "2 8 18 18 8" );//Xenon
92 hulllist
.append( "2 8 18 18 8 1" );//Caesium
93 hulllist
.append( "2 8 18 18 8 2" );//Barium
94 hulllist
.append( "2 8 18 18 9 2" );
95 hulllist
.append( "2 8 18 20 8 2" );//Cerium
96 hulllist
.append( "2 8 18 21 8 2" );
97 hulllist
.append( "2 8 18 22 8 2" );
98 hulllist
.append( "2 8 18 23 8 2" );
99 hulllist
.append( "2 8 18 24 8 2" );
100 hulllist
.append( "2 8 18 25 8 2" );
101 hulllist
.append( "2 8 18 25 9 2" );//Gadolinium
102 hulllist
.append( "2 8 18 27 8 2" );//Terbium
103 hulllist
.append( "2 8 18 28 8 2" );
104 hulllist
.append( "2 8 18 29 8 2" );
105 hulllist
.append( "2 8 18 30 8 2" );
106 hulllist
.append( "2 8 18 31 8 2" );
107 hulllist
.append( "2 8 18 32 8 2" );//Ytterbium
108 hulllist
.append( "2 8 18 32 9 2" );
109 hulllist
.append( "2 8 18 32 10 2" );//Hafnium
110 hulllist
.append( "2 8 18 32 11 2" );
111 hulllist
.append( "2 8 18 32 12 2" );
112 hulllist
.append( "2 8 18 32 13 2" );
113 hulllist
.append( "2 8 18 32 14 2" );
114 hulllist
.append( "2 8 18 32 15 2" );//Irdium
115 hulllist
.append( "2 8 18 32 17 1" );
116 hulllist
.append( "2 8 18 32 18 1" );
117 hulllist
.append( "2 8 18 32 18 2" );//Mercury
118 hulllist
.append( "2 8 18 32 18 3" );
119 hulllist
.append( "2 8 18 32 18 4" );
120 hulllist
.append( "2 8 18 32 18 5" );
121 hulllist
.append( "2 8 18 32 18 6" );
122 hulllist
.append( "2 8 18 32 18 7" );
123 hulllist
.append( "2 8 18 32 18 8" );//Radon
124 // hulllist.append( "1 2 3 4 5 6" );
130 OrbitsWidget::OrbitsWidget( const int ElemNo
, QWidget
*parent
, const char *name
) : QWidget( parent
, name
)
134 // hulllist.append( "1 2 3" );
135 hulllist
.append( "1" );
136 hulllist
.append( "2" ); //Helium
137 hulllist
.append( "2 1" );
138 hulllist
.append( "2 2" );
139 hulllist
.append( "2 3" );
140 hulllist
.append( "2 4" );
141 hulllist
.append( "2 5" );
142 hulllist
.append( "2 6" );
143 hulllist
.append( "2 7" );
144 hulllist
.append( "2 8" ); //Neon
145 hulllist
.append( "2 8 1" );
146 hulllist
.append( "2 8 2" );
147 hulllist
.append( "2 8 3" );
148 hulllist
.append( "2 8 4" );
149 hulllist
.append( "2 8 5" );
150 hulllist
.append( "2 8 6" );
151 hulllist
.append( "2 8 7" );
152 hulllist
.append( "2 8 8" ); //Argon
153 hulllist
.append( "2 8 8 1" );
154 hulllist
.append( "2 8 8 2" );//Calcium
155 hulllist
.append( "2 8 9 2" );
156 hulllist
.append( "2 8 10 2" );
157 hulllist
.append( "2 8 11 2" );
158 hulllist
.append( "2 8 13 1" );
159 hulllist
.append( "2 8 13 2" );//Manganese
160 hulllist
.append( "2 8 14 2" );
161 hulllist
.append( "2 8 15 2" );
162 hulllist
.append( "2 8 16 2" );
163 hulllist
.append( "2 8 18 1" );//Copper
164 hulllist
.append( "2 8 18 2" );
165 hulllist
.append( "2 8 18 3" );
166 hulllist
.append( "2 8 18 4" );
167 hulllist
.append( "2 8 18 5" );
168 hulllist
.append( "2 8 18 6" );
169 hulllist
.append( "2 8 18 7" );
170 hulllist
.append( "2 8 18 8" );//Krypton
171 // hulllist.append( "1 2 3 4 5" );
172 hulllist
.append( "2 8 18 8 1" );
173 hulllist
.append( "2 8 18 8 2" );//Rubidium
174 hulllist
.append( "2 8 18 9 2" );
175 hulllist
.append( "2 8 18 10 2" );//Zirconium
176 hulllist
.append( "2 8 18 12 1" );
177 hulllist
.append( "2 8 18 13 1" );
178 hulllist
.append( "2 8 18 14 1" );//Techneticum
179 hulllist
.append( "2 8 18 15 1" );
180 hulllist
.append( "2 8 18 16 1" );
181 hulllist
.append( "2 8 18 18" ); //Palladium
182 hulllist
.append( "2 8 18 18 1" );
183 hulllist
.append( "2 8 18 18 2" );
184 hulllist
.append( "2 8 18 18 3" );//Indium
185 hulllist
.append( "2 8 18 18 4" );
186 hulllist
.append( "2 8 18 18 5" );
187 hulllist
.append( "2 8 18 18 6" );
188 hulllist
.append( "2 8 18 18 7" );
189 hulllist
.append( "2 8 18 18 8" );//Xenon
190 hulllist
.append( "2 8 18 18 8 1" );//Caesium
191 hulllist
.append( "2 8 18 18 8 2" );//Barium
192 hulllist
.append( "2 8 18 18 9 2" );
193 hulllist
.append( "2 8 18 20 8 2" );//Cerium
194 hulllist
.append( "2 8 18 21 8 2" );
195 hulllist
.append( "2 8 18 22 8 2" );
196 hulllist
.append( "2 8 18 23 8 2" );
197 hulllist
.append( "2 8 18 24 8 2" );
198 hulllist
.append( "2 8 18 25 8 2" );
199 hulllist
.append( "2 8 18 25 9 2" );//Gadolinium
200 hulllist
.append( "2 8 18 27 8 2" );//Terbium
201 hulllist
.append( "2 8 18 28 8 2" );
202 hulllist
.append( "2 8 18 29 8 2" );
203 hulllist
.append( "2 8 18 30 8 2" );
204 hulllist
.append( "2 8 18 31 8 2" );
205 hulllist
.append( "2 8 18 32 8 2" );//Ytterbium
206 hulllist
.append( "2 8 18 32 9 2" );
207 hulllist
.append( "2 8 18 32 10 2" );//Hafnium
208 hulllist
.append( "2 8 18 32 11 2" );
209 hulllist
.append( "2 8 18 32 12 2" );
210 hulllist
.append( "2 8 18 32 13 2" );
211 hulllist
.append( "2 8 18 32 14 2" );
212 hulllist
.append( "2 8 18 32 15 2" );//Irdium
213 hulllist
.append( "2 8 18 32 17 1" );
214 hulllist
.append( "2 8 18 32 18 1" );
215 hulllist
.append( "2 8 18 32 18 2" );//Mercury
216 hulllist
.append( "2 8 18 32 18 3" );
217 hulllist
.append( "2 8 18 32 18 4" );
218 hulllist
.append( "2 8 18 32 18 5" );
219 hulllist
.append( "2 8 18 32 18 6" );
220 hulllist
.append( "2 8 18 32 18 7" );
221 hulllist
.append( "2 8 18 32 18 8" );//Radon
222 // hulllist.append( "1 2 3 4 5 6" );
228 void OrbitsWidget::getNumberOfOrbits()
230 numOfElectrons
.clear();
231 QRegExp
rxb( "\\s" ); //space
232 QString o
= getNumber();
239 if ( !o
.contains( rxb
) ) //only true for H and He
240 numOfElectrons
.append( o
.toInt() );
241 else //every other element
247 cut
= o
.length()-pos
-1;
248 numOfElectrons
.append(o
.left( pos
).toInt());
252 if ( !o
.contains( rxb
) )
254 numOfElectrons
.append( o
.toInt() );
261 const QString
& OrbitsWidget::getNumber() const
263 return *hulllist
.at( Elemno
-1 );
266 void OrbitsWidget::paintEvent( QPaintEvent
* )
277 //the radius of the current orbit
280 //the radius of an 'electron'
283 //make sure the biggest orbit fits in the widget
286 else r
= ( w
-2*w_c
)/2;
288 r_electron
= r
/20; //diameter of an electron-circle
290 int d
= 2*r
; //Diameter
291 int ddx
= d
/(2*num
);//difference to the previous circle
293 numOfElectrons
.prepend( 999 );
294 intList::Iterator it
= numOfElectrons
.end();
297 for ( int i
= 0 ; i
< num
; ++i
)
299 DC
.setBrush( Dense7Pattern
);
301 int mx
= w_c
+ddx
*i
; //the x-coordinate for the current circle
302 int my
= h_c
+ddx
*i
; //the y-coordinate for the current circle
304 //draw the big ellipses in concentric circles
305 DC
.drawEllipse( mx
, my
, d
, d
);
307 DC
.setBrush( Qt::SolidPattern
);
308 for ( int e
= 0 ; e
< *it
; ++e
)
310 int x
= (int)translateToDX( ( double )d
/2 , ( double )e
, *it
);
311 int y
= (int)translateToDY( ( double )d
/2 , ( double )e
, *it
);
313 DC
.drawEllipse( x
+ mx
+ d
/2 - r_electron
,
314 y
+ mx
+ d
/2 - r_electron
,
326 #include "orbitswidget.moc"