summaryrefslogtreecommitdiffstats
path: root/src/knutdock.h
blob: aec3612c425a578284b1aa8d2f17ec557521d368 (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
525
526
527
528
/***************************************************************************
                          knutdock.h  -  description
                             -------------------
    begin                : �t zari 23 2003
    copyright            : (C) 2003 by Daniel Prynych
    email                : Daniel.Prynych@alo.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KNUTDOCK_H
#define KNUTDOCK_H

#include "knutupsdata.h"
#include "knutvardata.h"
#include "knutconst.h"


#include <ksystemtray.h>
#include <kpopupmenu.h>

#include <tqobject.h>


class TQString;
class TQPixmap;
class TQColor;

/**
 * This class makes icons in dock.
 * Tato trida zajistuje vytvoreni icony v docku.
 *
 * @author Daniel Prynych
 * @short Dock's icons
 * @version 0.3
  */
class KNutDock : public KSystemTray  {
  Q_OBJECT
  TQ_OBJECT
  public:

  enum KNTDconst { DefaultToolTipFlags = 0x398};


  enum upsConnection {
   idle, // ups isn't connected
   connecting, // ups is connecting
   ok, // ups is connected
   error // error of connecting
   };

  enum eTypeOfIcons { pictureKI = 0, generalKI};


  enum toolTipItems {
   TTMFR = 0x8, // 8,    // FRM
   TTModel = 0x10, // 16,    // Model
   TTSerial = 0x20, // 32,    // Serial
   TTFirm = 0x40, //64,    // Firmware Revision
   TTRun = 0x80,// 128,    // Runtime
   TTCharge = 0x100, // 256,    // Charge
   TTLoad = 0x200 // 512    // Load
   };




/**
 * Constructor - makes icon in dockbar.
 * Konstruktor - vytvori iconu v docku.
 *
 * @param  activeUpsInfo odkaz na structuru upsInfo
 * @param  activeUpsInfo pointer to structure upsInfo
 * @param  settingData  odkaz na strukturu typu SettingDataDef
 * @param  settingData  pointer to structure type of SettingDataDef
 * @param  upsRecord odkaz na instanci tridy tActiveUpsInfo
 * @param  upsRecord pointer to class tActiveUpsInfo
 * @since  0.3
 */
    KNutDock(KNutVarData::upsInfoDef* activeUpsInfo, KNutVarData::SettingDataDef* settingData, KNutUpsData* upsRecords);

/**
 * Destruktor.
 *
 * @since  0.1.2
 **/
    ~KNutDock();


/**
 * Nastavi zakladni nastaveni pro dock.
 * Sets basic setting for dock.
 *
 * @since  0.1
 **/
 void clearDockValues(void);


/**
 * Vytvori menu (seznam) UPS.
 * Makes menu (list) of UPS.
 *
 * @since  0.1
 **/
  void changeUps(void);


/**
 * Zmeni styl/typ icon
 * Changes style/type of icon
 *
 * @since  0.1
 **/
  void changeKIcon (void);

/**
 * Zmeni pozadi icony v kickeru
 * Changes background of icon in kicker
 *
 * @since  0.2
 **/
  void changeKIBColor(void);


/**
 * Zmeni prvky v tooltip-u
 * Changes items in toolTip
 *
 * @since  0.1
 **/
 void changeToolTip(void);

/**
 * Provede nove zpracovani dat a jejich nakresli iconu docku, interni tqrepaint je volan vzdy.
 * Tato funkce take vola funkci ToolTip.
 * Makes new processing of data and paints icons of dock, internal tqrepaint is colled always.
 * This function calls function ToolTips too.
 * @param always Kdyz je true prorovede vykresleni vzdy, kde je false provede vykresleni jen kdyz je zmenena nejaka hodnota UPS.
 * @param always When param is true, icon is made always, is one is false icon is makeing when same UPS's value is changed.
 *
 * @since  0.4
 **/
  void tqrepaintDock ( const bool always = false);



/**
 * Nastavi v Menu oznaceni pro aktivni UPS.
 * Sets mark for active UPS in menu.
 *
 * @since  0.1
 **/
  void setNewUPS(void);




 signals:
/**This signal is emited when end of application was selected in menu.
 * Tento signal je vyslan pokud bylo vybrano v menu ukonceni aplikace.
 *
 *
 * @since  0.1
 **/
  void endApplication(void);

/**
 * Tento signal je vyslan pokud bylo vybrano v menu minimalizace aplikace.
 * Tento signal is emited when minimize application was selected in menu.
 *
 *
 * @since  0.1
 **/
  void minimize(void);

/**
 * Tento signal je vyslan pokud bylo vybrano v menu polozka preferences.
 * This signal is emited when item preferences was selected in menu.
 *
 * @since  0.1
 **/
  void preferences(void);



/**
 * Tento signal je vyslan pokud byla vybrana activace hlavniho okna (Main Window).
 *
 * @since  0.1
 **/
  void activeMainWindow(void);


/**
 * Tento signal je vyslan pokud bylo vybrano zobrazeni promennych;
 * This signal is emited when showing values was selected.
 *
 * @since  0.1
 **/
  void printUPSVars(void);

/**
 * Tento signal je vyslan pokud bylo vybrano provedeni okamziteho prikazu;
 * This signal is emited when running instant command was selected.
 *
 * @since  0.1
 **/
  void instComms(void);

/**
 * Tento signal je vyslan pokud bylo vybrana zmena RW promennych.
 * This signal is emited when change of RW values was selected.
 *
 * @since  0.1
 **/
  void RWVars(void);

/**
 * Tento signal je vyslan pokud bylo vybrana zmena RW promennych.
 * This signal is emited when refresh connection was selected
 *
 * @since  0.1
 **/
  void makeRefreshConnection(void);


/**
 * Tento signal je vyslan pokud je vybrana nova UPS;
 * This signal is emited when new UPS is selected
 *
 * @since  0.1
 **/
  void UPSChanged(TQString name);


  protected slots:

  virtual void mousePressEvent(TQMouseEvent *e);

/**
 * @internal
 * Vola proceduru KAboutApplication, zobrazi informace o teto aplikaci a KDE.
 * Calls procedure KAboutApplication, shows informations about this application and KDE.
 *
 * @since  0.1
 **/
  void slotShowMyAbout();
  void slotExitApplication (void);

/**
 * @internal
 * Vysle signal minimize.
 * Sends signal minimize.
 *
 * @since  0.1
 **/
  void slotMinimize (void);


/**
 * @internal
 * Vysle signal peferences.
 * Sends signal preferences.
 *
 * @since  0.1
 **/
  void slotPreferences (void);

/**
 * @internal
 * Vysle signal printUPSVars.
 * Sends signal printUPSVars.
 *
 * @since  0.1
 **/
  void slotPrintUPSVars(void);

/**
 * @internal
 * Vysle signal instComms.
 * Sends signal instComms.
 *
 * @since  0.1
 **/
  void slotInstComms(void);


/**
 * @internal
 * Vysle signal RWVars.
 * Sends signal RWVars.
 *
 * @since  0.1
 **/
  void slotRWVars(void);

/**
 * @internal
 * Vysle signal upsName
 * Sends signal upsName.
 *
 * @since  0.1
 **/
  void slotUpsName(int i);

/**
 * @internal
 * Vysle signal makeRefreshConnection
 * Sends signal makeRefreshConnection.
 *
 * @since  0.1
 **/
  void slotRefreshConnection(void);


  protected:
/**
 * @internal
 * Nastavi vse pro vykresleni zakladni ikony.
 * Tato ikona je kreslena dokud neni navazano spojeni
 * Sets all for painting of basic icon.
 * This icon is painted
 *
 * @since  0.2
 **/
  void initImage(void);



/**
 * @internal
 * Sets tooltip.
 * Nastavi ToolTip.
 *
 * @since  0.1
 **/
    void toolTip (int runtime, int status, int batteryCharge, int upsLoad );


/**
 * @internal
 * Vytvori a hlavni menu panelu.
 * Makes a main menu of panel
 *
 * @since  0.1
 **/
    void createMainMenu(void);

/**
 * @internal
 * Vytvori a podmenu pro seznam UPS-ek.
 * Makes a  submenu for list ig UPSes.
 *
 * @since  0.1
 **/
    void createUpsMenu(void);

/**
 * @internal
 * Paints a numbers.
 * Vykresli cisla.
 * @param number je hodnota cisla.
 * @param x je leva souradnice cisla
 * @param y je horni souradnice cisla
 * @param p je ukazatel na painter
 *
 * @since  0.2
 **/
    void paintNumbers (int numbers, int x, int y, TQPainter* p, float sizeMult ); //x,y levy horni roh cisla 1

/**
 * @internal
 * Paints a number
 * Vykresli cislici.
 * @param number je hodnota cislice.
 * @param x je leva souradnice cislice
 * @param y je horni souradnice cislice
 * @param p je ukazatel na painter
 *
 * @since  0.1
 **/
    void paintNumber (int x, int y, int number, TQPainter *p, float sizeMult);

/**
 * @internal
 * Paints a char.
 * Vykresli znak.
 * @param x je leva souradnice cislice
 * @param y je horni souradnice cislice
 * @param p je ukazatel na painter
 * @param char je vykreslovany znak.
 *
 * @since  0.1
 **/
    void paintChar (int x, int y, char LCDChar, TQPainter *p);


/**
 * @internal
 * Vykresli pomlcku.
 * @param x je leva souradnice pomlcky
 * @param y je horni souradnice pomlcky
 * @param p je ukazatel na painter
 *
 * @since  0.1
 **/
    void paintDash (int x, int y, TQPainter *p, float sizeMult);


/**
 * @internal
 * Paints runtime layer.
 * Vykresli vrstvu runtime.
 *
 * @since  0.1
 **/
    void paintRuntime (int runtime, int status);

/**
 * @internal
 * Paints layer for UPS Load
 * Vykresli vrstvu pro UPS Load.
 *
 * @since  0.2
 **/
    void paintLoad (int load );

/**
 * @internal
 * Paints layer for Battery Charge, only for type general.
 * Vykresli vrstvu pro Battery Charge.
 *
 * @since  0.2
 **/
    void paintCharge (int charge );

/**
 * @internal
 * Paints layer for UPS tqStatus, only for type general
 * Vykresli vrstvu pro UPS tqStatus.
 *
 * @since  0.2
 **/
    void painttqStatus (int status );


    void paintEvent (TQPaintEvent *);

/**
 * @internal
 * Paints green point into main layer, only for type picture.
 * Vykresli do hlavni vrstvy zeleny bod.
 * Ma vyznam jen pro typ picture.
 *
 * @since  0.3
 **/
    void paintErrorPoint ( TQPainter& paint );

/**
 * @internal
 * Paints red point into main layer, only for type picture.
 * Vykresli do hlavni vrstvy cerveny bod.
 * Ma vyznam jen pro typ picture.
 *
 * @since  0.3
 **/
    void paintOKPoint ( TQPainter& paint );

/**
 * @internal
 * Clean internal variables this class.
 * Vycisti interni promene teto tridy.
 *
 * @since  0.1
 **/
  void clearValues(void);

  void resizeEvent ( TQResizeEvent * );


    KNutUpsData* m_upsRecords;
    KNutVarData::SettingDataDef* m_settingData;  // v teto strukture jsou ulozeny promene ktere nastavuji konfiguraci
    KNutVarData::upsInfoDef* m_activeUpsInfo; // values for selected ups

    TQPixmap m_mainPix;
    TQPixmap m_errorPix;
    TQPixmap m_connectPix;
    TQPixmap m_upsPix;
    TQPixmap m_battPix;

    TQPixmap m_mainLayer1;

    TQColor backgroundColor;

    KPopupMenu* m_menu;
    KPopupMenu* m_upsServerMenu;

    TQPixmap *m_statusLayer;
    TQPixmap *m_runtimeLayer;
    TQPixmap *m_loadLayer;
    TQPixmap *m_chargeLayer;
    TQPixmap *m_mainLayer;

    int m_runtimeValue;
    int m_upsLoadValue;
    int m_batteryChargeValue;
    int m_statusValue;
    int m_statusBatValue;
    int m_statusWarningValue;


    upsConnection m_dataOk; // selects one from four type of icons's view //idle, connecting, connected, error
    upsConnection m_dataOkOld;

    int m_typeOfIcon;
    TQColor m_myBGColor;
    unsigned int m_toolTipFlags;

};

#endif