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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
|
/***************************************************************************
knutdock.cpp - 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. *
* *
***************************************************************************/
#include "knutdock.h"
#include "knutnet.h"
//#include <kglobal.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kapp.h>
#include <kaboutapplication.h>
#include <kmessagebox.h>
#include <tqpainter.h>
#include <tqtooltip.h>
#include <tqpixmap.h>
#include <tqbitmap.h>
#include <tqstring.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
//#include <iostream>
//#define ICON_SIZE 24
#define ICON_SIZE 22
KNutDock::KNutDock(KNutVarData::upsInfoDef* activeUpsInfo, KNutVarData::SettingDataDef* settingData, KNutUpsData* upsRecords){
TQString valueName;
m_settingData = settingData;
m_upsRecords = upsRecords;
m_activeUpsInfo = activeUpsInfo;
//saves backgroundcolor of kicker
backgroundColor = paletteBackgroundColor();
m_typeOfIcon = m_settingData->typeOfKIcon;
if (!m_settingData->customKIconColor) m_myBGColor = backgroundColor;
else m_myBGColor = m_settingData->kIconBackgroundColor;
m_toolTipFlags=m_settingData->toolTipFlags;
clearValues();
KIconLoader *loader = KGlobal::iconLoader();
m_mainPix = loader->loadIcon ("knutclient",KIcon::Small,16);
// aplications's own icons
m_errorPix = UserIcon ("knc_error");
m_connectPix = UserIcon ("knc_conn");
m_upsPix = UserIcon ("knc_ups");
m_battPix = UserIcon ("knc_batt");
createMainMenu();
#define ICON_SIZE 22
m_statusLayer = 0;
m_runtimeLayer = 0;
m_loadLayer = new TQPixmap(ICON_SIZE,ICON_SIZE);
m_chargeLayer = new TQPixmap(ICON_SIZE,ICON_SIZE);
m_mainLayer = new TQPixmap(ICON_SIZE,ICON_SIZE);
initImage();
changeKIcon(); // this function calls function tqrepaintIcon
}
KNutDock::~KNutDock(){
if (m_statusLayer) delete m_statusLayer;
if (m_runtimeLayer) delete m_runtimeLayer;
delete m_loadLayer;
delete m_chargeLayer;
delete m_mainLayer;
delete m_upsServerMenu;
delete m_menu;
}
void KNutDock::resizeEvent ( TQResizeEvent * ){
initImage();
changeKIcon(); // this function calls function tqrepaintIcon
}
void KNutDock::changeUps (void) {
m_upsServerMenu->clear();
createUpsMenu();
}
void KNutDock::clearDockValues(void){
initImage(); // paints standart icon
clearValues();
tqrepaintDock(true);
}
void KNutDock::changeToolTip(void){
m_toolTipFlags=m_settingData->toolTipFlags;
toolTip(m_runtimeValue, m_statusValue, m_batteryChargeValue, m_upsLoadValue);
}
void KNutDock::changeKIBColor(void) {
if (!m_settingData->customKIconColor) m_myBGColor = backgroundColor;
else m_myBGColor = m_settingData->kIconBackgroundColor; // uses defined color
tqrepaintDock(true);
}
void KNutDock::changeKIcon (void) {
m_typeOfIcon = m_settingData->typeOfKIcon;
if ( m_typeOfIcon == generalKI) {
if (m_mainLayer) {
delete m_mainLayer;
m_mainLayer=new TQPixmap(ICON_SIZE,ICON_SIZE);
}
if (!m_statusLayer) {
m_statusLayer = new TQPixmap(ICON_SIZE,ICON_SIZE);
}
if (!m_runtimeLayer) {
m_runtimeLayer = new TQPixmap(ICON_SIZE,ICON_SIZE);
}
painttqStatus(m_statusValue);
paintRuntime(m_runtimeValue, m_statusValue);
}
else { // picture Icon
delete m_statusLayer;
m_statusLayer = 0;
delete m_runtimeLayer;
m_runtimeLayer=0;
}
paintLoad(m_upsLoadValue);
paintCharge(m_batteryChargeValue);
m_statusWarningValue = m_statusValue & (KNutNet::CAL | KNutNet::TRIM | KNutNet::BOOST
| KNutNet::OVER | KNutNet::RB);
tqrepaintDock(true);
}
void KNutDock::initImage(void) {
setPixmap(m_mainPix);
m_dataOk = idle;
m_dataOkOld = m_dataOk;
}
void KNutDock::setNewUPS(void) {
m_upsServerMenu->clear();
createUpsMenu();
}
void KNutDock::tqrepaintDock (const bool always) {
TQString nutStringVar;
int myRuntimeValue;
int myUpsLoadValue;
int myStatusValue;
int myStatusBatValue;
int myBatteryChargeValue;
bool tqrepaintNow = false;
// value tqrepaintNow is seted when some ups values are changed
bool okFloat;
TQString valueName;
TQPainter paint;
if (m_activeUpsInfo->upsNet == 0) { tqrepaint(); return;}
m_dataOkOld=m_dataOk;
if ((m_activeUpsInfo->upsNet->getState() == KNutNet::Connected) // paints icons with information values
&& (!m_activeUpsInfo->netError)) {
// ups is connected dataOK is ok (program shows icon of connecting UPS)
m_dataOk = ok; // pro paint event udava ze mam pouzit nase ikony
if (!m_activeUpsInfo->upsNet->existName(m_activeUpsInfo->runtimeVar)) {
nutStringVar = m_activeUpsInfo->upsNet->readStringVar(m_activeUpsInfo->runtimeVar);
//std::cout << "KNutDock::tqrepaintDock RUNTIME " << nutStringVar << std::endl;
if (nutStringVar.isEmpty()) myRuntimeValue=knc::numberVarError;
else {
myRuntimeValue = (int)nutStringVar.toFloat(&okFloat);
if (!okFloat) myRuntimeValue = knc::numberVarError;
}
}
else myRuntimeValue = knc::numberVarError;
myStatusValue = m_activeUpsInfo->upsNet->readtqStatus();
switch (m_typeOfIcon) {
case generalKI:
// *********STATUS****************
if (myStatusValue !=m_statusValue ) {
m_statusValue = myStatusValue;
painttqStatus(m_statusValue);
tqrepaintNow = true;
}
// **********RUNTIME***********
myStatusBatValue = myStatusValue & KNutNet::OB; // OB = UPS runs on battery
if ((myRuntimeValue != m_runtimeValue) || (myStatusBatValue != m_statusBatValue)) {
// when runtime is changed or flags OB is changed we must tqrepaint icons
// when OB is changed same items in icon will change color
m_runtimeValue = myRuntimeValue; // runtime is old value of runtime, one is defined like global value of class
m_statusBatValue = myStatusBatValue;
paintRuntime(m_runtimeValue, m_statusValue);
tqrepaintNow = true;
}
break;
case pictureKI:
// *********STATUS****************
if (myStatusValue !=m_statusValue ) {
m_statusValue = myStatusValue;
m_statusWarningValue = myStatusValue & (KNutNet::CAL | KNutNet::TRIM | KNutNet::BOOST
| KNutNet::OVER | KNutNet::RB);
tqrepaintNow = true;
}
// **********RUNTIME***********
if (myRuntimeValue != m_runtimeValue) {
m_runtimeValue = myRuntimeValue;
tqrepaintNow = true;
}
break;
} ///////////////////// end of models
// Other values are for all modes
// **********UPS LOAD***************
if (m_activeUpsInfo->nutVariables == 1) valueName = "LOADPCT";
else valueName = "ups.load";
if (!m_activeUpsInfo->upsNet->existName(valueName)) {
nutStringVar = m_activeUpsInfo->upsNet->readStringVar(valueName);
if (nutStringVar.isEmpty()) myUpsLoadValue=knc::numberVarError;
else {
myUpsLoadValue = (int)nutStringVar.toFloat(&okFloat);
if (!okFloat) myUpsLoadValue=knc::numberVarError;
}
}
else myUpsLoadValue=knc::numberVarError;
if (myUpsLoadValue != m_upsLoadValue) {
m_upsLoadValue = myUpsLoadValue;
if (m_typeOfIcon == generalKI) paintLoad(m_upsLoadValue);
tqrepaintNow = true;
}
// *********BATTERY CHARGE****************
if (m_activeUpsInfo->nutVariables == 1) valueName="BATTPCT";
else valueName="battery.charge";
if (!m_activeUpsInfo->upsNet->existName(valueName)) {
nutStringVar = m_activeUpsInfo->upsNet->readStringVar(valueName);
if (nutStringVar.isEmpty()) myBatteryChargeValue=knc::numberVarError;
else {
myBatteryChargeValue = (int)nutStringVar.toFloat(&okFloat);
if (!okFloat) myBatteryChargeValue = knc::numberVarError;
}
}
else myBatteryChargeValue=knc::numberVarError;
if (myBatteryChargeValue != m_batteryChargeValue) {
m_batteryChargeValue = myBatteryChargeValue;
if (m_typeOfIcon == generalKI)paintCharge(m_batteryChargeValue);
tqrepaintNow = true;
}
// ************* End of values********************
if (tqrepaintNow || always || (m_dataOk != m_dataOkOld)) {
switch (m_typeOfIcon) {
case generalKI:
m_mainLayer->fill(m_myBGColor);
// copyBlt (m_mainLayer,0,0,m_runtimeLayer,0,0,ICON_SIZE,ICON_SIZE);
bitBlt (m_mainLayer,0,0,m_runtimeLayer,0,0,ICON_SIZE,ICON_SIZE,AndROP);
bitBlt (m_mainLayer,0,0,m_loadLayer,0,0,ICON_SIZE,ICON_SIZE,AndROP);
bitBlt (m_mainLayer,0,0,m_chargeLayer,0,0,ICON_SIZE,ICON_SIZE,AndROP);
bitBlt (m_mainLayer,0,0,m_statusLayer,0,0,ICON_SIZE,ICON_SIZE,AndROP);
break;
case pictureKI:
// if (m_statusValue & KNutNet::OL) bitBlt (m_mainLayer,0,0,m_loadLayer,0,0,ICON_SIZE,ICON_SIZE,AndROP); // icon of UPS
if (m_statusValue & KNutNet::OL) { // ONLINE - icon of UPS
int myLoad;
TQPainter paint;
copyBlt (m_mainLayer,0,0,&m_upsPix,0,0,ICON_SIZE,ICON_SIZE); // icon of UPS
paint.begin(m_mainLayer);
if (m_upsLoadValue == knc::numberVarError) myLoad=0;
else myLoad = abs(m_upsLoadValue/10);
if (m_upsLoadValue != knc::numberVarError) {
if (myLoad > 12) myLoad=12;
if (myLoad > 10) myLoad++; // preskocime rysku pro 100 %
if (myLoad < 9) paint.setPen(TQColor(0,192,0)); //green
else {
if (myLoad < 11) paint.setPen(TQColor(255,255,0)); //yellow
else paint.setPen(TQColor(255,0,0));//red
}
for (int i = 19; i < 22; i++) paint.drawLine(i,13,i,13-myLoad +1);
if (myLoad < 13) {
paint.setPen(TQColor(168,220,255));
for (int i = 20; i < 23; i++ ) paint.drawLine(i,1,i,13-myLoad);
}
}
paint.setPen(TQColor(TQt::black)); // line for 100 % load
paint.drawLine(19,3,22,3);
if (!m_statusWarningValue) paintOKPoint(paint);
else paintErrorPoint(paint);
paint.end();
}
else {
TQPainter paint;
copyBlt (m_mainLayer,0,0,&m_battPix,0,0,ICON_SIZE,ICON_SIZE); // icon of Battery
paint.begin(m_mainLayer);
if (m_batteryChargeValue != knc::numberVarError) {
if (m_batteryChargeValue < 40) paint.setPen(TQt::red);
else paint.setPen(TQt::black);
if (m_batteryChargeValue < 40) paint.setPen(TQt::red);
else {
if (m_batteryChargeValue < 50) paint.setPen(TQt::yellow);
else paint.setPen(TQt::green);
}
int delka = abs((16*m_batteryChargeValue)/100);
delka += abs((delka-1)/4) -1;
paint.drawLine (2,7,2+delka,7);
paint.drawLine (2,8,2+delka,8);
paint.drawLine (2,9,2+delka,9);
}
paint.end();
}
break;
}
toolTip(m_runtimeValue, m_statusValue, m_batteryChargeValue, m_upsLoadValue);
setPixmap(*m_mainLayer);
}
}
else { // KNutNet->state isn't connected
// we must test activeUpsInfo->netError because error can rise higher level
if (m_activeUpsInfo->netError)
m_dataOk = error; // error is value not variable
else {
if ((m_activeUpsInfo->upsNet->getState() == KNutNet::Connecting) ||
(m_activeUpsInfo->upsNet->getState() == KNutNet::HostLookup))
m_dataOk = connecting;
else m_dataOk = idle;
}
if ((m_dataOk != m_dataOkOld) or always) {
toolTip(0, -1, 0, 0);
m_dataOkOld=m_dataOk;
if (m_dataOk == connecting) setPixmap(m_connectPix);
else {
if (m_dataOk == error) setPixmap(m_errorPix);
else {
setPixmap(m_mainPix);
}
}
}
}
tqrepaint();
}
void KNutDock::toolTip (int runtime, int status, int batteryCharge, int upsLoad ) {
TQString text;
TQString manufacturer = "";
TQString upsModel = "";
TQString serial = "";
TQString firmware = "";
int myNetErr = 0;
int min = abs(runtime/60);
int sec = runtime - (min*60);
if (m_activeUpsInfo->upsNet != 0) {
myNetErr= m_activeUpsInfo->upsNet->getError();
switch (m_activeUpsInfo->nutVariables) {
case 1:
manufacturer = m_activeUpsInfo->upsNet->readStringVar("MFR");
upsModel = m_activeUpsInfo->upsNet->readStringVar("MODEL");
serial = m_activeUpsInfo->upsNet->readStringVar("SERIAL");
firmware = m_activeUpsInfo->upsNet->readStringVar("FIRMREV");
break;
case 2:
manufacturer = m_activeUpsInfo->upsNet->readStringVar("ups.mfr");
upsModel = m_activeUpsInfo->upsNet->readStringVar("ups.model");
serial = m_activeUpsInfo->upsNet->readStringVar("ups.serial");
firmware = m_activeUpsInfo->upsNet->readStringVar("ups.firmware");
break;
}
}
text = i18n("Name")+" : "+m_activeUpsInfo->record.name + "\n"
+i18n("UPS name")+" : "+m_activeUpsInfo->record.upsName + "\n"
+i18n("UPS address")+" : "+m_activeUpsInfo->record.upsAddress +"\n"
+i18n("tqStatus : ");
if (status == -1) {
text += i18n("Connection doesn't exist.");
}
else {
if (status & KNutNet::OL) {
text += i18n("UPS On line");
}
else {
if (status & KNutNet::OB) {
text += i18n("UPS On battery");
}
else {
if (status & KNutNet::OFF) {
text += i18n("UPS Of line");
}
}
}
if (status & KNutNet::LB) {
text += "\n" + i18n("tqStatus : ") + i18n("UPS Battery is low");
}
if (status & KNutNet::RB) {
text += "\n" + i18n("tqStatus : ") + i18n("Replace battery");
}
if (status & KNutNet::CAL) {
text += "\n" + i18n("tqStatus : ") + i18n("UPS is performing calibration");
}
if (status & KNutNet::OVER) {
text += "\n" + i18n("tqStatus : ") + i18n("UPS is Overload");
}
if (status & KNutNet::TRIM) {
text += "\n" + i18n("tqStatus : ") + i18n("UPS is trimming voltage");
}
if (status & KNutNet::BOOST) {
text += "\n" + i18n("tqStatus : ")+ i18n("UPS is boosting voltage");
}
}
if ((status == -1) && (myNetErr != KNutNet::NoError)) {
text += "\n" + i18n("Error : ")+ KNutVarData::errorToText(myNetErr);
}
if (m_toolTipFlags & TTMFR) text += "\n" + i18n("Manufac. : ")+ manufacturer;
if (m_toolTipFlags & TTModel) text += "\n" + i18n("Name")+" : "+ upsModel;
if (m_toolTipFlags & TTSerial) text += "\n" + i18n("Serial")+" : "+ serial;
if (m_toolTipFlags & TTFirm) text += "\n" + i18n("Firmware")+" : "+ firmware;
if (m_toolTipFlags & TTRun) {
if (runtime != knc::numberVarError)
text += "\n" + i18n("Runtime") + i18n(" : %1:%2 min").tqarg(min).tqarg(sec);
}
if (m_toolTipFlags & TTCharge) {
if (batteryCharge != knc::numberVarError)
text += "\n" + i18n("Battery Charge") + TQString(" : %1 %").tqarg(batteryCharge);
}
if (m_toolTipFlags & TTLoad) {
if (upsLoad != knc::numberVarError)
text += "\n" + i18n("UPS Load") + TQString(" : %1 %").tqarg(upsLoad);
}
TQToolTip::remove(this);
TQToolTip::add(this,text);
}
/*********************************************************************************************/
/* */
/* PRIVATE SLOTS */
/* */
/*********************************************************************************************/
void KNutDock::slotShowMyAbout() {
KAboutApplication *dialog;
dialog= new KAboutApplication;
dialog->exec();
delete dialog;
}
void KNutDock::slotExitApplication (void) {
if (m_settingData->areYouSure) {
if (KMessageBox::warningYesNo (0,i18n("Are you sure ?")) == 3)
emit endApplication();
}
else emit endApplication();
}
void KNutDock::slotUpsName(int i) {
emit UPSChanged(m_upsRecords->getName(i-101));
}
void KNutDock::slotMinimize(void) {
emit minimize ();
}
void KNutDock::slotPreferences(void) {
emit preferences();
}
void KNutDock::slotPrintUPSVars(void) {
emit printUPSVars();
}
void KNutDock::slotInstComms(void) {
emit instComms();
}
void KNutDock::slotRWVars(void) {
emit RWVars();
}
void KNutDock::slotRefreshConnection(void) {
emit makeRefreshConnection();
}
//------------------------------------------
void KNutDock::mousePressEvent(TQMouseEvent *e) {
//qDebug("KNutDock::mousePressEvent");
if( e->button()==Qt::LeftButton ) emit activeMainWindow();
if( e->button()==Qt::RightButton ) m_menu->popup(e->globalPos());
}
void KNutDock::paintEvent (TQPaintEvent *e) {
KSystemTray::paintEvent(e);
if ((m_activeUpsInfo->upsNet->getState() == KNutNet::Connected) and
(m_statusValue != KNutNet::NS)) { // When driver isn't connected, getState is connected and m_statusValue is NS // NONE STATUS
if (m_typeOfIcon == pictureKI) {
TQPainter painter(this);
// painter.begin();
if (m_statusValue & KNutNet::OL) { // ONLINE - icon of UPS
painter.setPen(TQt::black);
paintNumbers (m_upsLoadValue, (width()/-11), ((float) width()/(float) 1.46666666667), &painter, ((float) width()/(float) 22) );
}
else { // OFFLINE icon of battery
if (m_batteryChargeValue != knc::numberVarError) {
if (m_batteryChargeValue < 40) painter.setPen(TQt::red);
else painter.setPen(TQt::black);
paintNumbers(m_batteryChargeValue,(width()/-11),((float) width()/(float) 1.375),&painter, ((float) width()/(float) 22));
}
else {
painter.setPen(TQt::black);
paintDash (((float) width()/(float) 7.33333333333),((float) width()/(float) 1.375),&painter, ((float) width()/(float) 22));
paintDash (((float) width()/(float) 2.75),((float) width()/(float) 1.375),&painter, ((float) width()/(float) 22));
}
}
// painter.end();
}
}
}
/*********************************************************************************************/
/* */
/* PRIVATE FUNCTIONS */
/* */
/*********************************************************************************************/
void KNutDock::clearValues(void) {
m_batteryChargeValue = 0;
m_runtimeValue = 0;
m_upsLoadValue = 0;
m_statusValue = 0;
}
void KNutDock::createUpsMenu(void) {
int n = m_upsRecords->getCount();
for (int i =0; i < n; i++) {
if (m_activeUpsInfo->record.name == m_upsRecords->getName(i))
m_upsServerMenu->insertItem(kapp->miniIcon(),m_upsRecords->getName(i), this, TQT_SLOT(slotUpsName(int)),0,101+i);
else
m_upsServerMenu->insertItem(m_upsRecords->getName(i), this, TQT_SLOT(slotUpsName(int)),0,101+i);
}
}
void KNutDock::createMainMenu(void) {
m_menu = new KPopupMenu;
m_upsServerMenu = new KPopupMenu;
createUpsMenu();
m_menu->insertTitle (kapp->miniIcon(),"knutclient");
m_menu->insertSeparator();
m_menu->insertItem("UPS",m_upsServerMenu);
m_menu->insertSeparator();
m_menu->insertItem(i18n("&Showing UPS variables and commands"), this, TQT_SLOT(slotPrintUPSVars()));
m_menu->insertItem(i18n("&Running instant commands"), this, TQT_SLOT(slotInstComms()));
m_menu->insertItem(i18n("Setting R&W variables"), this, TQT_SLOT(slotRWVars()));
m_menu->insertSeparator();
m_menu->insertItem(SmallIcon("reload"),i18n("Reconnect"), this, TQT_SLOT(slotRefreshConnection()));
m_menu->insertSeparator();
m_menu->insertItem(SmallIcon("configure"),i18n("&Preferences"), this, TQT_SLOT(slotPreferences()));
m_menu->insertSeparator();
m_menu->insertItem(kapp->miniIcon(),i18n("&About KNutClient"), this, TQT_SLOT(slotShowMyAbout()));
m_menu->insertSeparator();
m_menu->insertItem(i18n("&Minimize"), this, TQT_SLOT(slotMinimize()));
m_menu->insertSeparator();
m_menu->insertItem (SmallIcon("exit"),i18n("&Exit"),this ,TQT_SLOT(slotExitApplication()));
}
void KNutDock::paintCharge (int charge ) {
TQPainter paint;
m_chargeLayer->fill(TQt::white);
paint.begin(m_chargeLayer);
if (charge > 199) charge = 199;
if (m_typeOfIcon == generalKI) {
if (charge != knc::numberVarError) {
if (charge < 40) paint.setPen(TQt::red);
else paint.setPen(TQt::black);
paintNumbers(charge,8,2,&paint, 1);
}
else {
paint.setPen(TQt::black);
paintDash (13,2,&paint, 1);
paintDash (18,2,&paint, 1);
}
}
else {
// picture version
if (charge != knc::numberVarError) {
if (charge < 40) paint.setPen(TQt::red);
else paint.setPen(TQt::black);
paintNumbers(charge,-2,16,&paint, 1);
if (charge < 40) paint.setPen(TQt::red);
else {
if (charge < 50) paint.setPen(TQt::yellow);
else paint.setPen(TQt::green);
}
int delka = abs((16*charge)/100);
delka += abs((delka-1)/4) -1;
paint.drawLine (2,7,2+delka,7);
paint.drawLine (2,8,2+delka,8);
paint.drawLine (2,9,2+delka,9);
}
else {
paint.setPen(TQt::black);
paintDash (3,16,&paint, 1);
paintDash (8,16,&paint, 1);
}
}
paint.end();
}
void KNutDock::paintErrorPoint ( TQPainter& paint ) {
paint.setPen(TQColor(0,0,255));
paint.setPen(TQColor(255,0,0));
paint.drawLine(19,18,21,18);
paint.drawLine(19,19,21,19);
paint.drawLine(19,20,21,20);
}
void KNutDock::paintOKPoint (TQPainter& paint ) {
paint.setPen(TQColor(0,255,0));
paint.drawLine(19,18,21,18);
paint.drawLine(19,19,21,19);
paint.drawLine(19,20,21,20);
}
void KNutDock::painttqStatus (int status ) {
TQPainter paint;
int lastPos = 0;
m_statusLayer->fill(TQt::white);
paint.begin(m_statusLayer);
if (status & KNutNet::OL) {
paint.setPen(TQt::black);
paintChar (1,2,'P',&paint);
}
else {
if (status & KNutNet::OB) {
paint.setPen(TQt::red);
paintChar (1,2,'B',&paint);
}
}
if (status & KNutNet::LB) {
paint.setPen(TQt::red);
paintChar (6,2,'L',&paint);
}
if ((lastPos <2) && (status & KNutNet::RB)) {
paint.setPen(TQt::red);
paintChar (6,2,'R',&paint);
lastPos++;
}
if ((lastPos <2) && (status & KNutNet::BOOST)) {
paint.setPen(TQt::red);
paintChar (6,2,'B',&paint);
lastPos++;
}
if ((lastPos <2) && (status & KNutNet::TRIM)) {
paint.setPen(TQt::red);
paintChar (6,2,'T',&paint);
lastPos++;
}
if ((lastPos <2) && (status & KNutNet::CAL)) {
paint.setPen(TQt::red);
paintChar (6,2,'C',&paint);
lastPos++;
}
paint.end();
}
void KNutDock::paintRuntime (int runtime, int status ) {
TQPainter paint;
m_runtimeLayer->fill(TQt::white);
paint.begin(m_runtimeLayer);
if (status & KNutNet::OB)
paint.setPen(TQt::red);
else
paint.setPen(TQt::black);
if (runtime != knc::numberVarError) {
int min = abs(runtime/60);
int sec = runtime - (min*60);
paintNumber(1,11, abs(min/10) ,&paint, 1);
paintNumber(6,11,min-((abs(min/10))*10) ,&paint, 1);
paintNumber(13,11, abs(sec/10) ,&paint, 1);
paintNumber(18,11,sec-((abs(sec/10))*10) ,&paint, 1);
}
else {
paintDash (1,11,&paint, 1);
paintDash (6,11,&paint, 1);
paintDash (13,11,&paint, 1);
paintDash (18,11,&paint, 1);
}
paint.drawLine (11,12,11,13);
paint.drawLine (11,15,11,16);
paint.end();
}
void KNutDock::paintLoad (int load ) {
TQPainter paint;
int myLoad;
// if (m_typeOfIcon != generalKI) bitBlt (m_loadLayer,0,0,m_upsLayer,0,0,ICON_SIZE,ICON_SIZE,AndROP);
m_loadLayer->fill(TQt::white);
paint.begin(m_loadLayer);
if (load == knc::numberVarError) myLoad=0;
else myLoad = abs(load/10);
if (m_typeOfIcon == generalKI) {
if (load != knc::numberVarError) {
if (myLoad > 11) myLoad=11;
if (myLoad < 9) paint.setPen(TQt::green);
else {
if (myLoad < 11) paint.setPen(TQt::yellow);
else paint.setPen(TQt::red);
}
paint.setPen(TQt::green.light(60));
for (int i = 0; i < myLoad; i++) {
paint.drawLine((i*2)+1,19,(i*2)+1,21);
}
paint.setPen(TQt::cyan.light(150));
for (int i = myLoad; i < 11; i++) {
paint.drawLine((i*2)+1,19,(i*2)+1,21);
}
}
}
paint.end();
}
void KNutDock::paintNumbers (int numbers, int x, int y, TQPainter* p, float sizeMult ) {
bool first = false;
if (numbers > 199) numbers = 199;
if (numbers != knc::numberVarError) {
if (numbers > 99) {
paintNumber (x,y,1,p,sizeMult);
numbers -= 100;
first=true;
}
int second = abs (numbers/10);
int third = numbers - (second * 10);
if ((second != 0) || (first)) paintNumber (((float) x+(5*sizeMult)),y,second,p,sizeMult);
paintNumber (((float) x+(10*sizeMult)),y,third,p,sizeMult);
}
else {
p->setPen(TQt::black);
paintDash (((float) x+(5*sizeMult)),y,p,sizeMult);
paintDash (((float) x+(10*sizeMult)),y,p,sizeMult);
}
}
void KNutDock::paintDash (int x, int y, TQPainter *p, float sizeMult) {
TQPen oldPen = p->pen();
TQPen newPen;
newPen.setWidth(((float) (oldPen.width()+1)*sizeMult)-1);
p->setPen(newPen);
p->drawLine(x,((float) y+(3*sizeMult)),((float) x+(3*sizeMult)),((float) y+(3*sizeMult)));
p->setPen(oldPen);
}
void KNutDock::paintNumber (int x, int y, int number, TQPainter *p, float sizeMult) {
// x and y are left top corner
TQPen oldPen = p->pen();
TQPen newPen;
newPen.setWidth(((float) (oldPen.width()+1)*sizeMult)-1);
p->setPen(newPen);
if ((number > -1) && (number < 10)) {
// painting - kreslim
switch (number) {
case 0:
p->drawRect(x,y,((float) 4*sizeMult),((float) 7*sizeMult));
break;
case 1:
p->drawLine (((float) x+(3*sizeMult)),y,((float) x+(3*sizeMult)),((float) y+(6*sizeMult)));
break;
case 2:
p->drawLine(x,y,((float) x+(3*sizeMult)),y);
p->lineTo(((float) x+(3*sizeMult)),((float) y+(3*sizeMult)));
p->lineTo(x,((float) y+(3*sizeMult)));
p->lineTo(x,((float) y+(6*sizeMult)));
p->lineTo(((float) x+(3*sizeMult)),((float) y+(6*sizeMult)));
break;
case 3:
p->drawLine(x,y,((float) x+(3*sizeMult)),y);
p->lineTo(((float) x+(3*sizeMult)),((float) y+(6*sizeMult)));
p->lineTo(x,((float) y+(6*sizeMult)));
p->drawLine(x,((float) y+(3*sizeMult)),((float) x+(3*sizeMult)),((float) y+(3*sizeMult)));
break;
case 4:
p->drawLine(x,y,x,((float) y+(3*sizeMult)));
p->lineTo(((float) x+(3*sizeMult)),((float) y+(3*sizeMult)));
p->drawLine (((float) x+(3*sizeMult)),y,((float) x+(3*sizeMult)),((float) y+(6*sizeMult)));
break;
case 5:
p->drawLine(((float) x+(3*sizeMult)),y,x,y);
p->lineTo(x,((float) y+(3*sizeMult)));
p->lineTo(((float) x+(3*sizeMult)),((float) y+(3*sizeMult)));
p->lineTo(((float) x+(3*sizeMult)),((float) y+(6*sizeMult)));
p->lineTo(x,((float) y+(6*sizeMult)));
break;
case 6:
p->drawRect(x,((float) y+(3*sizeMult)),((float) 4*sizeMult),((float) 4*sizeMult));
p->drawLine(x,((float) y+(3*sizeMult)),x,y);
p->lineTo(((float) x+(3*sizeMult)),y);
break;
case 7:
p->drawLine(x,y,((float) x+(3*sizeMult)),y);
p->lineTo(((float) x+(3*sizeMult)),((float) y+(6*sizeMult)));
break;
case 8:
p->drawRect(x,y,((float) 4*sizeMult),((float) 7*sizeMult));
p->drawLine(x,((float) y+(3*sizeMult)),((float) x+(3*sizeMult)),((float) y+(3*sizeMult)));
break;
case 9:
p->drawRect(x,y,((float) 4*sizeMult),((float) 4*sizeMult));
p->drawLine(((float) x+(3*sizeMult)),((float) y+(3*sizeMult)),((float) x+(3*sizeMult)),((float) y+(6*sizeMult)));
p->lineTo(x,((float) y+(6*sizeMult)));
break;
}
}
p->setPen(oldPen);
}
void KNutDock::paintChar (int x, int y, char LCDChar, TQPainter *p) {
// x and y are left up corner
switch (LCDChar) {
case 'L':
p->drawLine(x,y,x,y+6);
p->lineTo(x+3,y+6);
break;
case 'O':
p->drawRect(x,y,4,7);
break;
case 'B':
p->drawLine(x,y,x,y+6);
p->lineTo(x+2,y+6);
p->drawLine(x,y,x+2,y);
p->drawLine(x,y+3,x+2,y+3);
p->drawLine(x+3,y+1,x+3,y+2);
p->drawLine(x+3,y+4,x+3,y+5);
break;
case 'U':
p->drawLine(x,y,x,y+6);
p->lineTo(x+3,y+6);
p->lineTo(x+3,y);
break;
case 'C':
p->drawLine(x+3,y+1,x+3,y);
p->lineTo(x,y);
p->lineTo(x,y+6);
p->lineTo(x+3,y+6);
p->lineTo(x+3,y+5);
break;
case 'R':
p->drawLine(x,y,x,y+6);
p->drawLine(x,y,x+2,y);
p->drawLine(x,y+3,x+2,y+3);
p->drawLine(x+3,y+1,x+3,y+2);
p->drawLine(x+3,y+4,x+3,y+6);
break;
case 'P':
p->drawLine(x,y,x,y+6);
p->drawLine(x,y,x+2,y);
p->drawLine(x,y+3,x+2,y+3);
p->drawLine(x+3,y+1,x+3,y+2);
break;
case 'T':
p->drawLine(x+2,y,x+2,y+6);
p->drawLine(x,y,x+4,y);
break;
}
}
#include "knutdock.moc"
|