summaryrefslogtreecommitdiffstats
path: root/src/knutanalog.h
blob: 8c5e95f64c722b8b75e8b78fdb3386faa226e517 (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
/***************************************************************************
 *   Copyright (C) 2007 by Daniel Prynych   *
 *   [email protected]   *
 *                                                                         *
 *   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 KNUTANALOG_H
#define KNUTANALOG_H

#include <tqframe.h>

#include <tqpixmap.h>  // po odladeni smazat
#include <tqimage.h>
#include <tqmutex.h>


class TQPainter;
class TQFont;

enum speedOfAAlias { none,fast,slow};


/**
 * This class shows analog measuring panels
 *
 * @author Daniel Prynych
 * @short analog measuring panels
 * @version 0.1
*/

class KNutAnalog : public TQFrame  {
  Q_OBJECT
  
public:


  struct extentOfDyeDef {
    double start,end;
    int color;
    };



/**
 * Construct - makes object for analog measuring panel about size 130 x 130 points
 * Konstruktor - vytvori objekt pro analogovy merici panel o rozmerech 130 x 130 bodu
 *
 * When you need paint or repainr panel you have to call functiin reapaint
 * other functions calls this function theirself, when run = true
 * Pokud je potreba vykreslit nebo prekreslit panel je nutno zavolat funkci repaint,
 * ostatni funkce ji zavolaji sami pokud je run = TRUE.
 *
 * @param bottomLimit Is bottom value of scale..
 * @param topLimit is end value of scale.
 * @param typeOfView determine type view of scale 1- circle 2- right part of circle, 3 - top part of circle
 * @param countOfParts determine count of big parts (parents parts) of scale.
 * @param countOfSubParts determine count small parts (children parts) id scale, evere big part include e few small part.
 * @param pointerColor  determine color of pointer.
 * @param scaleColor determine color of scale.
 * @param textColor determine color of  text.
 * @param analogFonts determine fonts for text and scale.
 * @param qualityOfPainter determine  quality painting of pointer- 0 nothing. 1 fast antialiasing, 2 slow antialiasing, 3 blur motion + fast antialiasing, 4 blur motion + slow antialiasing 
 * @since  0.3
 **/
  KNutAnalog(TQWidget *parent = 0, const char *name = 0, int Astart = 0, int topLimit = 100, int typeOfView = 1, int countOfParts = 5, int countOfSubParts = 0, TQColor pointerColor = TQt::black, TQColor m_scaleColor = TQt::black, TQColor textColor = TQt::black, TQFont *analogFonts = 0, int qualityOfPointer = 4, bool makeBG = false );

/**
 * Destruktor
 * @since  0.1
 **/
    ~KNutAnalog();


/**
 * Sets text for top and bottom text of panel.
 * Nastavi text dolni a horni text na panelu.
 *
 * @param  m_inscription  determinuje inscription , bottom text , usually.
 * @param  m_inscription Udava nadpis, "dolni" text, obvykle co je mereno.
 * @param text_up Udava mernou jednotku "horni" text, obvykle merna jednotka.
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.1
 **/
  void setText (TQString m_inscription, TQString text_up, bool run=false);


/**
 * Makes background of analog panel.
 * Vytvori pozadi analogoveho panelu.
 *
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite  prekresleni panelu.
 *
 * @since  0.2
 **/
  void makeBackground (bool run=false);


/**
 * Repaint pointer of analog panel.
 * Prekresli rucicku analogoveho panelu.
 *
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite  prekresleni panelu.
 *
 * @since  0.2
 **/
  void repaintPointer ( bool run );



/**
 * Nastavuje devet zakladnich barev pro mezikruzi.
 * Sets nine basic color for circle in scale
 *
 * @param run = TRUE provede okamzite prekresleni panelu.
 * @param run = TRUE makes immediately repaint of panel 
 *
 * @since  0.1
 **/
  void setDefaultArcColor(bool run=false);


/**
 * Nastavi zakladni barvu pro mezikruzi.
 * Sets basic color for circle in scale
 *
 * @param reg Poradove cislo barvy (barevneho registru).
 * @param color Barva na kterou bude nastaven registr barvy.
 *
 * @since  0.1
 **/
  void setArcColor(int reg, TQColor color );



/**
 * Vybarvi cast stupnice zadanou barvou.
 * Nastavi rozsah mezikruzi, podle stupnice od pocatecni hodnoty do koncove hodnoty stupnice
 * Barevne casti se barvy postupne, podel poradoveho cisla, mohou se prekryvat.
 * Je mozno nastavit jen 5 casti !!
 *
 * @param startOfCircle Urcuje zazatek mezikruzi.
 * @param endOfCircle Urcuje konec mezikruzi.
 * @param color Urcuje barvu.
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.2
 **/
  void addArc (double startOfCircle, double endOfCircle, int regColor, bool run=false);



/**
 * Clear colors of scale
 * Zrusi vybarveni stupnice.
 *
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.1
 **/
  void delArc (bool run=false);



/**
 *
 * Nastavi rozsah stupnice.
 *
 * @param Astart Urcuje pocatecni hodnotu stupnice.
 * @param AEND Urcuje koncovou hodnotu stupnice.
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.2
 */
  void setRange (int Astart = 0, int Aend = 100, bool run=false);

/**
 * Sets number of parts od scale
 * Nastavi pocet dilku stupnice.
 *
 * @param Count Determine number of parts of pointer..
 * @param Count Urcuje pocet casti stupnice.
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.1
 */
  void setMember (int Count, bool run=false);

/**
 * Sets color of analog pointer.
 * Nastavi barvu analogove rucicky.
 *
 * @param pointerColor determine color of pointer.
 * @param pointerColor Urcuje barvu rucicky.
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 * @since  0.2
 */
  void setPointerColor (TQColor pointerColor, bool run=false);

/**
 * sets color of text;
 * Nastavi barvu textu.
 *
 * @param fontColor determine color of font.
 * @param fontColor urcuje barvu fontu.
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.1
 */
  void setFontColor (TQColor fontColor,  bool run=false );



/**
 * Sets color of scale
 * Nastavi barvu stupnice.
 *
 * @param scaleColor determine color if scale.
 * @param scaleColor urcuje barvu stupnice.
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.1
 */
  void setScaleColor (TQColor scaleColor, bool run=false);


/**
 * Sets type of digital processing of pointer. 0 nothing. 1 fast antialiasing, 2 slow antialiasing, 3 blur motion + fast antialiasing, 4 blur motion + slow antialiasing.
 *
 * @param qualityOfPointer determine quality of pointer's digital procesing
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.1
 */
  void setDigitalProcesing (int qualityOfPointer, bool run =false );



/**
 * Sets pointer on value pointerValue.
 * Posune rucicku na hodnotu pointerValue.
 *
 * @param pointerValue Urcuje hodnotu na jakou bude nastavena rucicka.
 * @param run = TRUE makes immediately repaint of panel 
 * @param run = TRUE provede okamzite prekresleni panelu.
 *
 * @since  0.1
 */
  void setPointer (double pointerValue,  bool run=true );


/**
 * Const. determines width of analog panel in points
 * Konstanta, udava velikost analogoveho panelu v bodech.
 *
 * @since  0.1
 */
  static const int AnalogWidth = 130;


  public slots:

/**
 * Sets font of scale, change is doing immediately
 * Nastavi font stupnice, zmena je provedena okamzite.
 *
 * @param newScaleFont Urcuje novy font hodnot stupnice.
 * @param newScaleFont Urcuje novy font hodnot stupnice.
 *
 * @since  0.1
 */
  void slotSetScaleFont(TQFont newScaleFont);


/**
 * Sets font of text. change is doing immediately.
 * Nastavi font textu, zmena je provedena okamzite.
 *
 * @param newTextFont Urcuje novy font pro texty.
 *
 * @since  0.1
 */
  void slotSetTextFont(TQFont newTextFont);


/**
 * Nastavi font stupnice a textu, zmena je provedena okamzite.
 *
 * @param newTextFont Urcuje novy font pro texty a hodnoty stupnice.
 *
 * @since  0.1
 */
  void slotSetAllFont(TQFont newAllFont);


/**
 * Repaint layer of backgroud and layer of pointer,
 * all panel will be repainted
 * Da povel k prekreseni urovne pozadi a  urovne rucicky.
 * To znamena, ze bude prekreslen kompletne cely panel.
 *
 * @since  0.1
 */
  void repaintAll (void);


  protected:
  virtual void resizeEvent( TQResizeEvent * );
  virtual void paintEvent( TQPaintEvent * );

  private:


/**
 * @internal
 */
  void paintBackGround ( void );


/**
 * @internal
 */
  void paintPointer ( void );


/**
 * @internal
 */
  void paintPointerSlowly ( double position, int centerX , int centerY, int widthOfCircle);

/**
 * @internal
 */
  void paintPointerFastly (  double position);


/**
 * @internal
 */
  void paintPartOfCircle ( TQPainter *paint, int centerX , int centerY, int widthOfCircle );


/**
 * @internal
 */
  void paintScale ( TQPainter *paint , int centerX , int centerY, int widthOfCircle);


/**
 * @internal
 */
  void makeAntialiasing (TQImage* myImage, TQPixmap* smallPixmap, const TQRgb colorOfBG, speedOfAAlias speed = slow , int typeOfView = 0);


/**
 * @internal
 */
  void makeMotionBlur (TQImage* myImage, const TQRgb colorOfBG, int typeOfView = 0);


/**
 * @internal
 */
  void paintScaleNumbers ( TQPainter *paint );

/**
 * @internal
 */
  void paintText ( TQPainter *paint );


/**
 * @internal
 */
  void paintValueOfPointer ( TQPainter *p, double value);



  static const int m_widthOfBackGround = 122;
  static const int m_startOfBackGround = 4;

  bool m_showBackGround;
  bool m_showPointer;

  int m_bottomLimit;
  int m_topLimit;
  int m_typeOfView;   // udava typ meraku
  int m_countOfParts; // pocet policek na stupnici
  int m_countOfSubParts; // pocet dilku v policku na stupnici
  TQColor m_pointerColor, m_scaleColor, m_textColor; // colors of pointer, text and scale

  TQColor m_arcColors[9];
  TQString m_inscription;
  TQString AnMJ;
  int m_countOfColorParts; // count of color parts on scale
  double m_valueOfPointer; //  position of pointer;
  double m_angleOfViewer, m_startAngle; //pocatecni_uhel;
  int m_centerX;
  int m_centerY;
  int m_direction;
  int m_widthOfScale;
  int m_radiusOfScaleNumbers;


  speedOfAAlias m_speedOfAAlias;
  bool m_makeBlurMotion;

  TQFont m_scaleFont;
  TQFont m_textFont;

  TQPixmap *m_wholeLayer;

  TQPixmap *m_backgroudLayerBig;


  TQPixmap *m_scaleLayerBig;
  TQPixmap *m_scaleLayerSmall;

  TQPixmap *m_pointerLayerBig;
  TQPixmap *m_pointerLayerSmall;


  extentOfDyeDef m_extentOfDye[5];

  TQMutex m_pointerMutex;
};


#endif