APservice/keypad.cpp

346 lines
8.8 KiB
C++
Executable File

#include "keypad.h"
#define numPadKeyWidth 40
static bool keypad_NumberIsVisible;
static bool keypad_visiKeyAllowed;
T_keypad::T_keypad(QWidget *parent) : QWidget(parent)
{
QFont myTabFont;
myTabFont.setPixelSize(20);
myMainLay = new QVBoxLayout;
mySubLayout = new QGridLayout;
valueDisplay = new QLabel();
valueDisplay->setStyleSheet("background-color: white");
valueDisplay->setLineWidth(5);
valueDisplay->setFont(myTabFont);
myMainLay->addWidget(valueDisplay);
myMainLay->addLayout(mySubLayout);
// number Pad Popup for Value entry:
numPad = new QGroupBox(" ");
numPad->setStyleSheet("background-color: grey");
numPad->setLayout(myMainLay);
QPushButton *key1 = new QPushButton("1");
mySubLayout->addWidget(key1,0,0);
key1->setMaximumWidth(numPadKeyWidth);
key1->setFont(myTabFont);
connect(key1, SIGNAL(clicked()), this, SLOT(key1Clicked()));
QPushButton *key2 = new QPushButton("2");
mySubLayout->addWidget(key2,0,1);
key2->setMaximumWidth(numPadKeyWidth);
key2->setFont(myTabFont);
connect(key2, SIGNAL(clicked()), this, SLOT(key2Clicked()));
QPushButton *key3 = new QPushButton("3");
mySubLayout->addWidget(key3,0,2);
key3->setMaximumWidth(numPadKeyWidth);
key3->setFont(myTabFont);
connect(key3, SIGNAL(clicked()), this, SLOT(key3Clicked()));
QPushButton *key4 = new QPushButton("4");
mySubLayout->addWidget(key4,1,0);
key4->setMaximumWidth(numPadKeyWidth);
key4->setFont(myTabFont);
connect(key4, SIGNAL(clicked()), this, SLOT(key4Clicked()));
QPushButton *key5 = new QPushButton("5");
mySubLayout->addWidget(key5,1,1);
key5->setMaximumWidth(numPadKeyWidth);
key5->setFont(myTabFont);
connect(key5, SIGNAL(clicked()), this, SLOT(key5Clicked()));
QPushButton *key6 = new QPushButton("6");
mySubLayout->addWidget(key6,1,2);
key6->setMaximumWidth(numPadKeyWidth);
key6->setFont(myTabFont);
connect(key6, SIGNAL(clicked()), this, SLOT(key6Clicked()));
QPushButton *key7 = new QPushButton("7");
mySubLayout->addWidget(key7,2,0);
key7->setMaximumWidth(numPadKeyWidth);
key7->setFont(myTabFont);
connect(key7, SIGNAL(clicked()), this, SLOT(key7Clicked()));
QPushButton *key8 = new QPushButton("8");
mySubLayout->addWidget(key8,2,1);
key8->setMaximumWidth(numPadKeyWidth);
key8->setFont(myTabFont);
connect(key8, SIGNAL(clicked()), this, SLOT(key8Clicked()));
QPushButton *key9 = new QPushButton("9");
mySubLayout->addWidget(key9,2,2);
key9->setMaximumWidth(numPadKeyWidth);
key9->setFont(myTabFont);
connect(key9, SIGNAL(clicked()), this, SLOT(key9Clicked()));
QPushButton *keyAc = new QPushButton("AC");
mySubLayout->addWidget(keyAc,3,0);
keyAc->setMaximumWidth(numPadKeyWidth);
keyAc->setFont(myTabFont);
connect(keyAc, SIGNAL(clicked()), this, SLOT(keyAcClicked()));
QPushButton *key0 = new QPushButton("0");
mySubLayout->addWidget(key0,3,1);
key0->setMaximumWidth(numPadKeyWidth);
key0->setFont(myTabFont);
connect(key0, SIGNAL(clicked()), this, SLOT(key0Clicked()));
QPushButton *keyBs = new QPushButton("<<");
mySubLayout->addWidget(keyBs,3,2);
keyBs->setMaximumWidth(numPadKeyWidth);
keyBs->setFont(myTabFont);
connect(keyBs, SIGNAL(clicked()), this, SLOT(keyBsClicked()));
QPushButton *keyC = new QPushButton("Esc");
mySubLayout->addWidget(keyC,4,0);
keyC->setMaximumWidth(numPadKeyWidth);
keyC->setFont(myTabFont);
connect(keyC, SIGNAL(clicked()), this, SLOT(keyCancelClicked()));
QPushButton *keySee = new QPushButton("see");
mySubLayout->addWidget(keySee,4,1);
keySee->setMaximumWidth(numPadKeyWidth);
keySee->setFont(myTabFont);
connect(keySee, SIGNAL(clicked()), this, SLOT(keySeeEntryClicked()));
QPushButton *keyOK = new QPushButton("OK");
mySubLayout->addWidget(keyOK,4,2);
keyOK->setMaximumWidth(numPadKeyWidth);
keyOK->setFont(myTabFont);
connect(keyOK, SIGNAL(clicked()), this, SLOT(keyOkClicked()));
numPad->hide();
myValueString.clear();
valueDisplay->clear();
myReturnString.clear();
keypad_visiKeyAllowed=true;
keypad_NumberIsVisible=true;
}
T_keypad::~T_keypad()
{
}
void T_keypad::show(void)
{
numPad->show();
numPad->setFocus();
numPad->setEnabled(true);
numPad->raise();
myValueString.clear();
valueDisplay->clear();
myReturnString.clear();
}
void T_keypad::hide(void)
{
numPad->hide();
}
void T_keypad::keysVisible(uint8_t visib)
{
// visib=0: show * 1:show numbers 2: show * but allow visi-key
if (visib==0)
{
keypad_NumberIsVisible=false;
keypad_visiKeyAllowed=false;
} else
if (visib==1)
{
keypad_NumberIsVisible=true;
keypad_visiKeyAllowed=false;
} else
if (visib==2)
{
keypad_NumberIsVisible=false;
keypad_visiKeyAllowed=true;
}
}
QString T_keypad::getValueString(void)
{
return myReturnString;
}
int32_t T_keypad::getValueDecimal(void)
{
return myReturnString.toULong();
}
void T_keypad::key0Clicked(void)
{
myReturnString.append("0");
if (keypad_NumberIsVisible)
{
myValueString.append("0");
} else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key1Clicked(void)
{
myReturnString.append("1");
if (keypad_NumberIsVisible)
{
myValueString.append("1");
} else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key2Clicked(void)
{
myReturnString.append("2");
if (keypad_NumberIsVisible)
{
myValueString.append("2");
} else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key3Clicked(void)
{
myReturnString.append("3");
if (keypad_NumberIsVisible)
{
myValueString.append("3");
} else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key4Clicked(void)
{
myReturnString.append("4");
if (keypad_NumberIsVisible)
{
myValueString.append("4");
} else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key5Clicked(void)
{
myReturnString.append("5");
if (keypad_NumberIsVisible)
{
myValueString.append("5");
} else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key6Clicked(void)
{
myReturnString.append("6");
if (keypad_NumberIsVisible)
{
myValueString.append("6");
} else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key7Clicked(void)
{
myReturnString.append("7");
if (keypad_NumberIsVisible)
{
myValueString.append("7");
} else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key8Clicked(void)
{
myReturnString.append("8");
if (keypad_NumberIsVisible)
myValueString.append("8");
else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::key9Clicked(void)
{
myReturnString.append("9");
if (keypad_NumberIsVisible)
myValueString.append("9");
else
myValueString.append("*");
valueDisplay->setText(myValueString);
}
void T_keypad::keyOkClicked(void)
{
numPad->hide();
emit keyEntryFinished();
}
void T_keypad::keyCancelClicked(void)
{
myValueString.clear();
myReturnString.clear();
valueDisplay->clear();
numPad->hide();
emit keyEntryFinished();
}
void T_keypad::keySeeEntryClicked(void)
{
if (keypad_visiKeyAllowed)
{
if (keypad_NumberIsVisible)
{
// dont want to see the entry, so overwrite number(s) with asteriks
int len=myValueString.length();
myValueString.clear();
for (int nn=0; nn<len; nn++)
myValueString.append('*');
keypad_NumberIsVisible=false;
} else
{
// wanna see entry from now
// by now we have only *'s in myValueString
// numbers are saved in "myReturnString"
myValueString=myReturnString;
keypad_NumberIsVisible=true;
}
}
valueDisplay->setText(myValueString);
}
void T_keypad::keyAcClicked(void)
{
myValueString.clear();
myReturnString.clear();
valueDisplay->clear();
}
void T_keypad::keyBsClicked(void)
{
myValueString.chop(1);
myReturnString.chop(1);
valueDisplay->setText(myValueString);
}