1
/***************************************************************************
2
knutfrontpanel.cpp - description
4
begin : Tue Aug 21 2001
5
copyright : (C) 2001 by Daniel Prynych
6
email : Daniel.Prynych@alo.cz
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
19
#include "knutfrontpanel.h"
20
#include "knutvardata.h"
28
#include <qpaintdevice.h>
30
#include <qlcdnumber.h>
36
#include <qgroupbox.h>
40
KNutFrontPanel::KNutFrontPanel( QPalette* const paletteIn, QWidget *parent, const unsigned int flags, QFont* const panelFonts, const char *name) : QFrame( parent, name ), m_panelFlags(flags) {
42
m_myPalette = paletteIn->copy(); // makes deep copy of palette
43
m_upsOkColor = Qt::green;
44
m_upsErrorColor = Qt::red;
45
m_upsBackColor = Qt::white; //backgroundColor();
46
m_helpColor = Qt::black;
47
m_typeOfLCDColor=true;
51
setFrameStyle( QFrame::Box | QFrame::Raised );
54
if (panelFonts == 0) {
55
m_panelFont =kapp->font(); // sets font - system font
56
m_panelBoldFont = kapp->font();
59
m_panelFont = *panelFonts; // sets font / our selected font
60
m_panelBoldFont = *panelFonts; // change later
62
m_panelBoldFont.setBold (TRUE);
63
m_panelFont.setBold (FALSE); // sets no bold
65
m_mainLayout = new QVBoxLayout(this);
66
m_mainLayout->setMargin ( 10 );
67
m_mainLayout->setSpacing ( 10 );
71
m_bulbsGroupBox = new QGroupBox(this);
72
m_mainLayout->addWidget(m_bulbsGroupBox);
73
m_bulbsGroupBox->setFrameStyle( QFrame::Panel + QFrame::Raised);
74
// m_bulbsGroupBox->setFrameStyle( QFrame::Panel + QFrame::Sunken);
75
m_bulbsGroupBox->setLineWidth(2);
76
QVBoxLayout* bulbsLayout = new QVBoxLayout(m_bulbsGroupBox);
77
bulbsLayout->setMargin( 5 );
80
m_textLabel1 = new QLabel( i18n("UPS On line"),m_bulbsGroupBox);
81
m_frameOL = new KLed (m_upsBackColor,KLed::Off,KLed::Sunken,KLed::Circular,m_bulbsGroupBox);
82
m_frameOL->setMaximumSize(30,30);
83
m_frameOL->setMinimumSize(25,25);
84
QToolTip::add(m_textLabel1,m_textLabel1->text());
86
QHBoxLayout* OLLayout = new QHBoxLayout(bulbsLayout);
87
OLLayout->addWidget(m_textLabel1);
88
OLLayout->addSpacing(10);
89
OLLayout->addWidget(m_frameOL);
90
OLLayout->setMargin (3);
91
OLLayout->setStretchFactor(m_textLabel1,20);
92
OLLayout->setStretchFactor(m_frameOL,5);
95
m_textLabel2 = new QLabel( i18n("UPS On battery"), m_bulbsGroupBox);
96
m_frameOB = new KLed (m_upsBackColor,KLed::Off,KLed::Sunken,KLed::Circular,m_bulbsGroupBox);
97
m_frameOB->setMaximumSize(30,30);
98
m_frameOB->setMinimumSize(25,25);
99
QToolTip::add(m_textLabel2,m_textLabel2->text());
101
QHBoxLayout* OBLayout = new QHBoxLayout(bulbsLayout);
102
OBLayout->addWidget(m_textLabel2);
103
OBLayout->addSpacing(10);
104
OBLayout->addWidget(m_frameOB);
105
OBLayout->setMargin (3);
106
OBLayout->setStretchFactor(m_textLabel2,20);
107
OBLayout->setStretchFactor(m_frameOB,5);
110
m_textLabel3 = new QLabel( i18n("UPS Overload"), m_bulbsGroupBox);
111
m_frameOVER = new KLed (m_upsBackColor,KLed::Off,KLed::Sunken,KLed::Circular,m_bulbsGroupBox);
112
m_frameOVER->setMaximumSize(30,30);
113
m_frameOVER->setMinimumSize(25,25);
114
QToolTip::add(m_textLabel3,m_textLabel3->text());
116
m_OLayout = new QHBoxLayout(bulbsLayout);
117
m_OLayout->addWidget(m_textLabel3);
118
m_OLayout->addSpacing(10);
119
m_OLayout->addWidget(m_frameOVER);
120
m_OLayout->setMargin (3);
121
m_OLayout->setStretchFactor(m_textLabel3,20);
122
m_OLayout->setStretchFactor(m_frameOVER,5);
124
m_textLabel4 = new QLabel( i18n("UPS Battery low"), m_bulbsGroupBox);
125
m_frameLB = new KLed (m_upsBackColor,KLed::Off,KLed::Sunken,KLed::Circular,m_bulbsGroupBox);
126
m_frameLB->setMaximumSize(30,30);
127
m_frameLB->setMinimumSize(25,25);
128
QToolTip::add(m_textLabel4,m_textLabel4->text());
130
m_LBLayout = new QHBoxLayout(bulbsLayout);
131
m_LBLayout->addWidget(m_textLabel4);
132
m_LBLayout->addSpacing(10);
133
m_LBLayout->addWidget(m_frameLB);
134
m_LBLayout->setMargin (3);
135
m_LBLayout->setStretchFactor(m_textLabel4,20);
136
m_LBLayout->setStretchFactor(m_frameLB,5);
138
m_textLabel5 = new QLabel( i18n("Replace battery"), m_bulbsGroupBox);
139
m_frameRB = new KLed (m_upsBackColor,KLed::Off,KLed::Sunken,KLed::Circular,m_bulbsGroupBox);
140
m_frameRB->setMaximumSize(30,30);
141
m_frameRB->setMinimumSize(25,25);
142
QToolTip::add(m_textLabel5,m_textLabel5->text());
144
m_RBLayout = new QHBoxLayout(bulbsLayout);
145
m_RBLayout->addWidget(m_textLabel5);
146
m_RBLayout->addSpacing(10);
147
m_RBLayout->addWidget(m_frameRB);
148
m_RBLayout->setMargin (3);
149
m_RBLayout->setStretchFactor(m_textLabel5,20);
150
m_RBLayout->setStretchFactor(m_frameRB,5);
152
m_textLabel6 = new QLabel( i18n("UPS calibration"), m_bulbsGroupBox);
153
m_frameCAL = new KLed (m_upsBackColor,KLed::Off,KLed::Sunken,KLed::Circular,m_bulbsGroupBox);
154
m_frameCAL->setMaximumSize(30,30);
155
m_frameCAL->setMinimumSize(25,25);
156
QToolTip::add(m_textLabel6,m_textLabel6->text());
158
m_CALLayout = new QHBoxLayout(bulbsLayout);
159
m_CALLayout->addWidget(m_textLabel6);
160
m_CALLayout->addSpacing(10);
161
m_CALLayout->addWidget(m_frameCAL);
162
m_CALLayout->setMargin (3);
163
m_CALLayout->setStretchFactor(m_textLabel6,20);
164
m_CALLayout->setStretchFactor(m_frameCAL,5);
167
m_messGroupBox = new QGroupBox(this);
168
m_mainLayout->addWidget(m_messGroupBox);
169
m_messGroupBox->setFrameStyle( QFrame::Panel + QFrame::Raised);
170
// m_messGroupBox->setFrameStyle( QFrame::Panel + QFrame::Sunken);
171
m_messGroupBox->setLineWidth(2);
172
QVBoxLayout* messLayout = new QVBoxLayout(m_messGroupBox);
173
messLayout->setMargin( 3 );
176
m_textLabel7 = new QLabel( "", m_messGroupBox);
177
QToolTip::add(m_textLabel7,m_textLabel7->text());
178
m_manufacModelLayout = new QHBoxLayout(messLayout);
179
m_manufacModelLayout->addWidget(m_textLabel7);
180
m_manufacModelLayout->setMargin ( 3 );
182
m_textLabelManufac = new QLabel( i18n("Manufac. : "), m_messGroupBox);
183
m_textLabel8 = new QLabel( "", m_messGroupBox);
184
QToolTip::add(m_textLabelManufac,m_textLabelManufac->text());
186
m_manufacLayout = new QHBoxLayout(messLayout);
187
m_manufacLayout->addWidget(m_textLabelManufac);
188
m_manufacLayout->addWidget(m_textLabel8);
189
m_manufacLayout->addStretch(20);
190
m_manufacLayout->setMargin ( 3 );
192
m_textLabelName = new QLabel( i18n("Name")+" : ", m_messGroupBox);
193
m_textLabel9 = new QLabel( "", m_messGroupBox);
194
QToolTip::add(m_textLabelName,m_textLabelName->text());
196
m_nameLayout = new QHBoxLayout(messLayout);
197
m_nameLayout->addWidget(m_textLabelName);
198
m_nameLayout->addWidget(m_textLabel9);
199
m_nameLayout->addStretch(20);
200
m_nameLayout->setMargin ( 3 );
202
m_textLabelSerial = new QLabel( i18n("Serial : "), m_messGroupBox);
203
m_textLabel10 = new QLabel( "", m_messGroupBox);
204
QToolTip::add(m_textLabelSerial,m_textLabelSerial->text());
206
m_serialLayout = new QHBoxLayout(messLayout);
207
m_serialLayout->addWidget(m_textLabelSerial);
208
m_serialLayout->addWidget(m_textLabel10);
209
m_serialLayout->addStretch(20);
210
m_serialLayout->setMargin ( 3 );
212
m_textLabelFirm = new QLabel( i18n("Firm. rev. : "), m_messGroupBox);
213
m_textLabel11 = new QLabel( "", m_messGroupBox);
214
QToolTip::add(m_textLabelFirm,m_textLabelFirm->text());
216
m_firmLayout = new QHBoxLayout(messLayout);
217
m_firmLayout->addWidget(m_textLabelFirm);
218
m_firmLayout->addWidget(m_textLabel11);
219
m_firmLayout->addStretch(20);
220
m_firmLayout->setMargin ( 3 );
223
m_valGroupBox = new QGroupBox(this);
224
m_mainLayout->addWidget(m_valGroupBox);
225
m_valGroupBox->setFrameStyle( QFrame::Panel + QFrame::Raised);
226
// m_bulbsGroupBox->setFrameStyle( QFrame::Panel + QFrame::Sunken);
227
m_valGroupBox->setLineWidth(2);
228
QVBoxLayout* valLayout = new QVBoxLayout(m_valGroupBox);
229
valLayout->setMargin( 3 );
233
m_textLabelRun = new QLabel( i18n("Runtime")+" : ", m_valGroupBox);
234
QToolTip::add(m_textLabelRun,m_textLabelRun->text());
236
m_LCDNumber1 = new QLCDNumber (5,m_valGroupBox);
237
m_LCDNumber1->setSegmentStyle (QLCDNumber::Flat);
238
m_LCDNumber1->setFrameStyle( QFrame::NoFrame );
239
m_LCDNumber1->setMinimumSize(50,20);
241
m_runLayout = new QHBoxLayout(valLayout);
242
m_runLayout->addWidget(m_textLabelRun);
243
m_runLayout->addStretch(20);
244
m_runLayout->addWidget(m_LCDNumber1);
245
m_runLayout->setMargin ( 5 );
247
m_mainLayout->addStretch(20);
248
m_mainLayout->addSpacing(5);
257
KNutFrontPanel::~KNutFrontPanel(){
261
//************************************************************
263
void KNutFrontPanel::paintPanel( void ) {
265
if (m_panelFlags & PBOnLine) {
266
m_textLabel1->show();
270
m_textLabel1->hide();
274
if (m_panelFlags & PBOnBatt) {
275
m_textLabel2->show();
279
m_textLabel2->hide();
283
if (m_panelFlags & PBOver) {
284
m_OLayout->setMargin ( 3 );
285
m_textLabel3->show();
289
m_textLabel3->hide();
291
m_OLayout->setMargin ( 0 );
294
if (m_panelFlags & PBBattLow) {
295
m_textLabel4->show();
297
m_LBLayout->setMargin ( 3 );
300
m_textLabel4->hide();
302
m_LBLayout->setMargin ( 0 );
305
if (m_panelFlags & PBRepBatt) {
306
m_textLabel5->show();
308
m_RBLayout->setMargin ( 3 );
311
m_textLabel5->hide();
313
m_RBLayout->setMargin ( 0 );
316
if (m_panelFlags & PBCal) {
317
m_textLabel6->show();
319
m_CALLayout->setMargin ( 3 );
322
m_textLabel6->hide();
324
m_CALLayout->setMargin ( 0 );
327
if (m_panelFlags & PBMFRMod) {
328
m_textLabel7->show();
329
m_manufacModelLayout->setMargin ( 5 );
332
m_textLabel7->hide();
333
m_manufacModelLayout->setMargin ( 0 );
337
if (m_panelFlags & PBMFR) {
338
m_textLabel8->show();
339
m_textLabelManufac->show();
340
m_manufacLayout->setMargin ( 5 );
343
m_textLabel8->hide();
344
m_textLabelManufac->hide();
345
m_manufacLayout->setMargin ( 0 );
348
if (m_panelFlags & PBModel) {
349
m_textLabel9->show();
350
m_textLabelName->show();
351
m_nameLayout->setMargin ( 5 );
354
m_textLabel9->hide();
355
m_textLabelName->hide();
356
m_nameLayout->setMargin ( 0 );
359
if (m_panelFlags & PBSerial) {
360
m_textLabel10->show();
361
m_textLabelSerial->show();
362
m_serialLayout->setMargin ( 5 );
365
m_textLabel10->hide();
366
m_textLabelSerial->hide();
367
m_serialLayout->setMargin ( 0 );
370
if (m_panelFlags & PBFirm) {
371
m_textLabel11->show();
372
m_textLabelFirm->show();
373
m_firmLayout->setMargin ( 5 );
376
m_textLabel11->hide();
377
m_textLabelFirm->hide();
378
m_firmLayout->setMargin ( 0 );
381
if ( (m_panelFlags & PBMFRMod) || (m_panelFlags & PBMFR) || (m_panelFlags & PBModel) || (m_panelFlags & PBSerial) ||(m_panelFlags & PBFirm))
382
m_messGroupBox->show();
384
m_messGroupBox->hide();
386
if (m_panelFlags & PBRun) {
387
// LCDNumber1->show();
388
// textLabelRun->show();
389
// runLayout->setMargin ( 5 );
390
m_valGroupBox->show();
393
// LCDNumber1->hide();
394
// textLabelRun->hide();
395
// runLayout->setMargin ( 0 );
396
m_valGroupBox->hide();
401
int KNutFrontPanel::getPanelHeight( void) { return 0; } ///// correct !!!!!!!!
403
unsigned int KNutFrontPanel::getPanelFlags( void) { return m_panelFlags; }
405
void KNutFrontPanel::setPanelFlags(const int upsPanelFlags) { m_panelFlags = upsPanelFlags; }
407
void KNutFrontPanel::setAllNameUps(const QString panelUpsAllName ){
408
m_textLabel7->setText(panelUpsAllName);
409
QToolTip::remove(m_textLabel7);
410
QToolTip::add(m_textLabel7,panelUpsAllName);
413
void KNutFrontPanel::setMFRUps(const QString panelUpsFRM ){
414
m_textLabel8->setText(panelUpsFRM);
415
QToolTip::remove(m_textLabelManufac);
416
QToolTip::add(m_textLabelManufac,m_textLabelManufac->text()+panelUpsFRM);
419
void KNutFrontPanel::setNameUps(const QString panelUpsName ){
420
m_textLabel9->setText(panelUpsName);
421
QToolTip::remove(m_textLabelName);
422
QToolTip::add(m_textLabelName,m_textLabelName->text()+panelUpsName);
425
void KNutFrontPanel::setSerialUps(const QString panelUpsSerial ){
426
m_textLabel10->setText(panelUpsSerial);
427
QToolTip::remove(m_textLabelSerial);
428
QToolTip::add(m_textLabelSerial,m_textLabelSerial->text()+panelUpsSerial);
431
void KNutFrontPanel::setFirmRevUps(const QString upsPanelFormRev ){
432
m_textLabel11->setText(upsPanelFormRev);
433
QToolTip::remove(m_textLabelFirm);
434
QToolTip::add(m_textLabelFirm,m_textLabelFirm->text()+upsPanelFormRev);
438
void KNutFrontPanel::cleanPanel(void) {
439
m_textLabel7->setText("");
440
m_textLabel8->setText("");
441
m_textLabel9->setText("");
442
m_textLabel10->setText("");
443
m_textLabel11->setText("");
445
m_frameOL->setColor(m_upsBackColor);
447
m_frameOB->setColor(m_upsBackColor);
449
m_frameOVER->setColor(m_upsBackColor);
451
m_frameLB->setColor(m_upsBackColor);
453
m_frameRB->setColor(m_upsBackColor);
455
m_frameCAL->setColor(m_upsBackColor);
458
m_LCDNumber1->display("-:--");
459
m_LCDNumber1->setPalette (palette());
462
void KNutFrontPanel::setRuntime(const int runtime) {
463
QString runtimeString;
465
if (runtime != knc::numberVarError) {
466
int min = (int)floor(runtime/60);
467
int sec = runtime - (min*60);
468
runtimeString=QString("%1:%2").arg(min,2).arg(sec,2);
469
if (runtimeString[3] == ' ') runtimeString[3]='0';
471
else runtimeString="-:--";
473
m_LCDNumber1->display(runtimeString);
478
void KNutFrontPanel::setPanel(const int panelBulbs) {
479
// OFF - 1 ups je vypnuta
480
// OL - 2 ups je bezi na sit
481
// OB - 4 ups bezi na baterie
482
// LB - 8 baterie je vybyta (pokud je zaroven OB dojde k shutdownu)
483
// CAL - 16 je spustena calibrace
484
// OVER - 128 ups je pretizena
485
// RB - 256 ups pozaduje vymenu baterie
488
if (!(panelBulbs < 0)) {
489
// ups online /na sit
490
if (panelBulbs & KNutNet::OL) {
491
m_frameOL->setColor(m_upsOkColor);
493
m_LCDNumber1->setPalette (m_LCDPaletteOk);
494
m_typeOfLCDColor=true;
497
m_frameOL->setColor(m_upsBackColor);
501
// ups ofline /na baterie
502
if (panelBulbs & KNutNet::OB) {
503
m_frameOB->setColor(m_upsErrorColor);
505
m_LCDNumber1->setPalette (m_LCDPaletteErr);
506
m_typeOfLCDColor=false;
509
m_frameOB->setColor(m_upsBackColor);
513
if (panelBulbs & KNutNet::LB) {
514
m_frameLB->setColor(m_upsErrorColor);
518
m_frameLB->setColor(m_upsBackColor);
522
if (panelBulbs & KNutNet::OVER) {
523
m_frameOVER->setColor(m_upsErrorColor);
527
m_frameOVER->setColor(m_upsBackColor);
531
if (panelBulbs & KNutNet::RB) {
532
m_frameRB->setColor(m_upsErrorColor);
536
m_frameRB->setColor(m_upsBackColor);
540
if (panelBulbs & KNutNet::CAL) {
541
m_frameCAL->setColor(m_upsErrorColor);
545
m_frameCAL->setColor(m_upsBackColor);
552
/*********************************************************************************************/
556
/*********************************************************************************************/
559
void KNutFrontPanel::slotSetPanelFont(QFont newPanelFont) {
561
m_panelFont = newPanelFont; // nastavime font
562
m_panelBoldFont = newPanelFont; // pozdeji zmenime
564
m_panelBoldFont.setBold (TRUE);
565
m_panelFont.setBold (FALSE); // Zrusime bold u panelu
567
changePanelFont(); // zmeni pismo
572
/*********************************************************************************************/
574
/* PRIVATE FUNCTIONS */
576
/*********************************************************************************************/
579
void KNutFrontPanel::setLCDPalette (void) {
580
m_LCDPaletteOk = m_myPalette;
581
m_LCDPaletteErr = m_myPalette;
582
//Nastavime barvu pro OK system je online
583
QColorGroup activeColorGroup = m_LCDPaletteOk.active();
584
activeColorGroup.setColor( QColorGroup::Foreground, green);
586
m_LCDPaletteOk.setActive(activeColorGroup);
587
m_LCDPaletteOk.setInactive(activeColorGroup);
589
//Nastavime Barvu pro Error - System neni online
590
activeColorGroup = m_LCDPaletteErr.active();
591
activeColorGroup.setColor( QColorGroup::Foreground, red);
592
m_LCDPaletteErr.setActive(activeColorGroup);
593
m_LCDPaletteErr.setInactive(activeColorGroup);
596
void KNutFrontPanel::setPalette (const QPalette & p){
603
void KNutFrontPanel::setAllPalettes (void){
606
QFrame::setPalette (m_myPalette);
607
//QColorGroup myColorGroup = myPalette.active();
609
// LCDPaletteOk = myPalette;
610
// LCDPaletteErr = myPalette;
614
m_bulbsPalette = m_myPalette;
616
m_frameOL->setPalette(m_bulbsPalette);
618
// we must correct feature of KLed, KLed repaint background when color of item (function KLed::setColor()) is changed only
619
// when we change palette backround only, KLed ignore this change
621
myColor = m_frameOL->color();
622
m_frameOL->setColor(m_helpColor); // black is neutral (unprofitable) color for us
623
m_frameOL->setColor(myColor);
625
myColor = m_frameOB->color();
626
m_frameOB->setColor(m_helpColor);
627
m_frameOB->setColor(myColor);
629
myColor = m_frameLB->color();
630
m_frameLB->setColor(m_helpColor);
631
m_frameLB->setColor(myColor);
633
myColor = m_frameOVER->color();
634
m_frameOVER->setColor(m_helpColor);
635
m_frameOVER->setColor(myColor);
637
myColor = m_frameRB->color();
638
m_frameRB->setColor(m_helpColor);
639
m_frameRB->setColor(myColor);
641
myColor = m_frameCAL->color();
642
m_frameCAL->setColor(m_helpColor);
643
m_frameCAL->setColor(myColor);
647
if (m_typeOfLCDColor)
648
m_LCDNumber1->setPalette (m_LCDPaletteOk);
650
m_LCDNumber1->setPalette (m_LCDPaletteErr);
654
void KNutFrontPanel::changePanelFont (void) {
655
m_textLabel1->setFont(m_panelFont);
656
m_textLabel2->setFont(m_panelFont);
657
m_textLabel3->setFont(m_panelFont);
658
m_textLabel4->setFont(m_panelFont);
659
m_textLabel5->setFont(m_panelFont);
660
m_textLabel6->setFont(m_panelFont);
662
m_textLabelManufac->setFont(m_panelFont);
663
m_textLabelName->setFont (m_panelFont);
664
m_textLabelSerial->setFont (m_panelFont);
665
m_textLabelFirm->setFont (m_panelFont);
666
m_textLabelRun->setFont (m_panelFont);
667
m_textLabel7->setFont (m_panelBoldFont);
668
m_textLabel8->setFont (m_panelBoldFont);
669
m_textLabel9->setFont (m_panelBoldFont);
670
m_textLabel10->setFont (m_panelBoldFont);
671
m_textLabel11->setFont (m_panelBoldFont);
672
m_textLabelRun->setFont (m_panelFont);
676
#include "knutfrontpanel.moc"