summaryrefslogtreecommitdiffstats
path: root/kalzium/src/periodictableview.h
blob: 3ceb58888ef27d3bb119ff1abd38c34794d4c203 (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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
/***************************************************************************
 *   Copyright (C) 2003-2005 by Carsten Niehaus                            *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#ifndef PerodicTableView_H
#define PerodicTableView_H

class TQLabel;
class TQPixmap;
class TQPoint;
class TQVBoxLayout;
class Element;
class KalziumDataObject;
class KalziumTip;

#include <tqvaluelist.h>
#include <tqwidget.h>
#include <tqtimer.h>

// A PerodicTableView is ...
/**
 * @short basic class for the specific PerodicTableViews
 * @author Carsten Niehaus
 */
class PerodicTableView : public TQWidget
{
	Q_OBJECT
  

	public:
		/**
		 * Constructor
		 * @param parent parent widget
		 * @param name name of this widget
		 */
		PerodicTableView( TQWidget *parent = 0, const char *name = 0);
		~PerodicTableView();

		enum SCHEMETYPE
		{
			NOCOLOUR = 0,
			GROUPS,
			BLOCK,
			ACIDIC,
			FAMILY,
			GRADIENT,
			CRYSTAL
		};
		
		enum NUMERATIONTYPE
		{
			NO=0,              /// no numeration
			CAS = 1,           /// Chemical Abstract Service
			IUPAC = 2,         /// International Union of Pure and Applied Chemistry
			IUPACOLD = 3       /// old IUPAC numeration
		};

		/**
		 * if this mode is activated a click on a button will not open
		 * a information dialog
		 */
		virtual void activateMolcalcmode( bool mode ){
			m_molcalcIsActive = mode;
		}

		/**
		 * @return if the molcalc mode is active or not
		 */
		virtual bool molcalcMode() const{
			return m_molcalcIsActive;
		}

		/**
		 * sets the NUMERATIONTYPE @p num of the periodic table
		 * @see NUMERATIONTYPE
		 */
		void setNumerationType( NUMERATIONTYPE num ){
			m_num = num;
			update();
		}
		/**
		 * @return whether the tooltips are enabled
		 */
		bool tooltipsEnabled() const{
			return m_tooltipsEnabled;
		}

		/**
		 * if @p enabled is true the tooltips
		 * will be enabled
		 */
		void setTooltipsEnabled( bool enabled ){
			m_tooltipsEnabled = enabled;
		}

		/**
		 * This method sets the colors of the PerodicTableView.
		 * @param nr takes 5 different values:
		 * @li normal view
		 * @li groups
		 * @li blocks
		 * @li state of matter
		 * @li acidic behavior
		 * @li family view
		 */
		void activateColorScheme( const int nr);

		/**
		 * @return the short and descriptive name of this PerodicTableView
		 */
		TQString shortName() const{
			return m_ShortName;
		}

		/**
		 * if @p show is true the tooltip will be displayed
		 */
		void setShowTooltip( bool show ){
			m_showTooltip = show;
		}

		/**
		 * @return whether tooltips will be displayed
		 */
		bool showTooltip() const {
			return m_showTooltip;
		}

		/**
		 * @return whether if the SOM is active or not
		 */
		bool som() const{
			return m_showSOM;
		}
		
		void activateSOMMode( bool som ){
			m_showSOM = som;
			setFullDraw();
			update();
		}
		
		/**
		 * @return if the gradient mode is active
		 */
		bool gradient() const{
			return m_showGradient;
		}
		
		/**
		 * Defines if the gradient mode will be activated or
		 * deactivated
		 * @param gradient defines if the gradient mode should be activated or not
		 */
		void setGradient( bool gradient ){
			m_showGradient = gradient;
			setFullDraw();
			update();
		}

		//XXX can't use Element::TYPE here... why?
		void setGradientType( int type ){ 
			m_gradientType = type;
		}

		/**
		 * if false, the user disabled tooltips
		 */
		bool m_tooltipsEnabled;

		bool m_showLegendTooltip;

		/**
		 * activates or deactivates the legend
		 */
		void showLegend( bool show ){
			m_showLegend = show;
		}

		bool showLegend() const{
			return m_showLegend;
		}

		bool timeline() const{
			return m_timeline;
		}

		void setTimeline( bool timeline ){
			if ( m_timeline != timeline )
				m_timeline = timeline;
		}
		
		int date() const{
			return m_date;
		}

		/**
		 * load the colours from the config file. This is done
		 * on startup and everytime the user changed the configuration
		 */
		void reloadColours();

		/**
		 * JH: Draw the full table next time
		 */
		void setFullDraw(){
			doFullDraw = true;
		}

		/**
		 * @param type set the scheme
		 * @param which set the type of gradient
		 * @see Element::TYPE
		 */
		void setLook( PerodicTableView::SCHEMETYPE type, int which = 0 );

		/**
		 * This method paints the marker around the currently selected
		 * element
		 */
		virtual void paintCurrentSelection();

	private:
		/**
		 * if true the tooltips will be displayed
		 */
		bool m_showTooltip;

		/**
		 * the type of the gradient.
		 * @see Element::TYPE
		 */
		int m_gradientType;

		/**
		 * calculates the min and max values to prepare the painting
		 */
		void calculateGradient( TQPainter* );

		/**
		 * @return true if the mouse is over the legend area
		 */
		bool pointerOnLegend(int,int);

		/**
		 * @param p The painter for drawing
		 * @param e the element which is to be drawn
		 * @param coeff ?
		 * @param value the value
		 * @param minValue the smallest of all the values
		 */
		void drawGradientButton( TQPainter* p, Element* e, double coeff, double value, double minValue );

		/**
		 * calculates the color of an element which has a value which
		 * is @p percentage of the maximum value. This will be the
		 * color used in the gradient view for an element.
		 */
		TQColor calculateColor( const double percentage );
	
		/**
		 * the date used in the timeline
		 */
		int m_date;

		/**
		 * the current colour scheme
		 */
		int m_currentScheme;
	
		KalziumTip* m_kalziumTip;	
		bool m_timeline;
		
		/**
		 * the temperature of the table (for the SOM-feature)
		 */
		double m_temperature;

		/**
		 * if true the State Of Matter will be shown
		 */
		bool m_showSOM;
		
		/**
		 * if true the gradients will be shown
		 */
		bool m_showGradient;

		/**
		 * timer used for the tooltop
		 */
		TQTimer HoverTimer,
			   MouseoverTimer;

		KalziumDataObject *d;

		/**
		 * the number of the element the mouse-cursor is over
		 */
		int m_tooltipElementNumber;

		/**
		 * @return the number of the element at position x/y. If there
		 * is no element it will return 0
		 */
		int ElementNumber( int x, int y );
		
		/**
		 * @return the coordinates of the element under the mouseCursor.
		 * For example, H will be 1/1 and Li will be 1/2
		 */
		TQPoint ElementUnderMouse();

		/**
		 * the currently selected element (the x/y-coordinates)
		 */
		TQPoint m_currentPoint;

		void mouseReleaseEvent( TQMouseEvent* );
		void mousePressEvent( TQMouseEvent* );
		void mouseMoveEvent( TQMouseEvent* );

		TQStringList m_IUPAClist;
		TQStringList m_IUPACOLDlist;

		/**
		 * if the the legend will be displayed
		 */
		bool m_showLegend;

		/**
		 * this is a short, descriptive name of the PerodicTableView
		 */
		TQString m_ShortName;

		/**
		 * true if the molcalc-mode is active
		 */
		bool m_molcalcIsActive;

		/**
		 * the type of the nummeration ( NO, CAS, IUPACOLD, IUPAC )
		 */
		NUMERATIONTYPE m_num;

		/**
		 * implements double buffering of the widget.
		 */
		TQPixmap *table;			// The basic PerodicTableView
		TQPixmap *table2;		// Basic PerodicTableView + extra data such as tooltip, etc

		/**
		 * used for bitBlit. If true the complete table will be drawn
		 */
		bool doFullDraw;
		

		//I am holding all colours as member so that they don't need to 
		//be reloaded on every reload
		TQColor color_s;//Blocks
		TQColor color_p;
		TQColor color_d;
		TQColor color_f;
		TQColor color_1;//Groups
		TQColor color_2;
		TQColor color_3;
		TQColor color_4;
		TQColor color_5;
		TQColor color_6;
		TQColor color_7;
		TQColor color_8;
		TQColor color_ba;//Acidic
		TQColor color_ac;
		TQColor color_neu;
		TQColor color_amp;
		TQColor c_alkalie;//Family
		TQColor c_rare;
		TQColor c_nonmetal;
		TQColor c_alkaline;
		TQColor c_other_metal;
		TQColor c_halogene; 
		TQColor c_transition;
		TQColor c_noble_gas;
		TQColor c_metalloid;
		TQColor c_liquid;
		TQColor c_solid;
		TQColor c_vapor;
		
	protected:
		virtual void paintEvent( TQPaintEvent *e );

		/**
		 * draw the tooltip for the legend
		 */
		virtual void drawLegendToolTip( TQPainter *p );

		virtual void drawTimeLine( TQPainter *p );

		/**
		 * called if the user resized the table
		 */
		virtual void resizeEvent( TQResizeEvent *e );

		/**
		 * the central place for the drawing of the table
		 */
		virtual void drawPerodicTableView( TQPainter* p, bool isCrystal );

		/**
		 * draw a gradient of the type @p type
		 */
		virtual void drawGradientPerodicTableView( TQPainter* p, const double min, const double max );

		/**
		 * draw the state of matter
		 */
		virtual void drawSOMPerodicTableView( TQPainter* p );

		/**
		 * draw the legend
		 */
		virtual void drawLegend( TQPainter* p );
		
		/**
		 * draw the numeration
		 */
		virtual void drawNumeration( TQPainter* p );

	public slots:
		/**
		 * This method sets the color for the buttons corresponding to
		 * the given temperature @p temp
		 * @param temp is the temperature to which all buttons will be set
		 */
		void setTemperature( int temp ){
			m_temperature = (double)temp;
			update();
		}

		void setDate( int date ){
			//These elements have always been known:
			//6 16 26 29 33 47 50 51 79 80 82 83
			m_date = date;
			update();
		}

		/**
		 * this slot removes the selection of any point
		 */
		void unSelect();

	private slots:
		/**
		 * If called this slot will emit the signal MouseOver( num )
		 * where num is the number of the element the mouse if over.
		 * If the mouse is not over an element nothing will be emited
		 * @see MouseOver()
		 */
		void slotMouseover();
		
		/**
		 * start the calculation of the element over which the mouse-cursor
		 * is over. Finally the signal ToolTip( int ) is emitted
		 */
		void slotTransientLabel();
		
		/**
		 * this slot updates the currently selected point
		 */
		void selectPoint( const TQPoint& point );

		/**
		 * this slot updates the element given in the @p num
		 * @param num The number of the selected element
		 */
		void selectElement( int num );

		/**
		 * sets the current element to @p number
		 * and updates the table
		 */
		void slotToolTip( int number );
		
	signals:
		/**
		 * this signal is emitted when the table is clicked
		 */
		void tableClicked(TQPoint);

		/**
		 * this signal is emitted when an element is clicked
		 */
		void ElementClicked(int);

		/**
		 * this signal is emitted when the tooltip of an element
		 * has to be displayed
		 */
		void ToolTip(int);

		/**
		 * This signal is emited when the mouse pointer is
		 * over an element
		 */
		void MouseOver( int );
};


#endif