912 lines
20 KiB
C++
912 lines
20 KiB
C++
|
|
#include "numerinputdialog.h"
|
|||
|
|
#include "ui_numerinputdialog.h"
|
|||
|
|
|
|||
|
|
NumerInputDialog::NumerInputDialog(QWidget *parent) :
|
|||
|
|
QDialog(parent),
|
|||
|
|
ui(new Ui::NumerInputDialog)
|
|||
|
|
{
|
|||
|
|
ui->setupUi(this);
|
|||
|
|
setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
|
|||
|
|
setWindowModality(Qt::ApplicationModal);
|
|||
|
|
setAttribute(Qt::WA_TranslucentBackground, true);//设置窗体背景透明
|
|||
|
|
|
|||
|
|
initDialog();
|
|||
|
|
initControl();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
NumerInputDialog::~NumerInputDialog()
|
|||
|
|
{
|
|||
|
|
delete ui;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString NumerInputDialog::getShowString(int64_t val, int pointflag)
|
|||
|
|
{
|
|||
|
|
double value = val;
|
|||
|
|
|
|||
|
|
if (pointflag < 0)
|
|||
|
|
{
|
|||
|
|
pointflag = 0;
|
|||
|
|
}
|
|||
|
|
else if (pointflag > 5)
|
|||
|
|
{
|
|||
|
|
pointflag = 5;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (int i = 1; i < pointflag; i++)
|
|||
|
|
{
|
|||
|
|
value /= 10;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString str;
|
|||
|
|
if (pointflag == 0)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.0f", value);
|
|||
|
|
}
|
|||
|
|
else if (pointflag == 1)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.0f", value);
|
|||
|
|
str += ".";
|
|||
|
|
}
|
|||
|
|
else if (pointflag == 2)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.1f", value);
|
|||
|
|
}
|
|||
|
|
else if (pointflag == 3)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.2f", value);
|
|||
|
|
}
|
|||
|
|
else if (pointflag == 4)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.3f", value);
|
|||
|
|
}
|
|||
|
|
else // if (pointflag >= 5)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.4f", value);
|
|||
|
|
}
|
|||
|
|
return str;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString NumerInputDialog::getShowStringPublic(int64_t val, int pointflag)
|
|||
|
|
{
|
|||
|
|
double value = val;
|
|||
|
|
|
|||
|
|
if (pointflag < 0)
|
|||
|
|
{
|
|||
|
|
pointflag = 0;
|
|||
|
|
}
|
|||
|
|
else if (pointflag > 5)
|
|||
|
|
{
|
|||
|
|
pointflag = 5;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (int i = 1; i < pointflag; i++)
|
|||
|
|
{
|
|||
|
|
value /= 10;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString str;
|
|||
|
|
if (pointflag == 0)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.0f", value);
|
|||
|
|
}
|
|||
|
|
else if (pointflag == 1)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.0f", value);
|
|||
|
|
str += ".";
|
|||
|
|
}
|
|||
|
|
else if (pointflag == 2)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.1f", value);
|
|||
|
|
}
|
|||
|
|
else if (pointflag == 3)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.2f", value);
|
|||
|
|
}
|
|||
|
|
else if (pointflag == 4)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.3f", value);
|
|||
|
|
}
|
|||
|
|
else // if (pointflag >= 5)
|
|||
|
|
{
|
|||
|
|
str.sprintf("%.4f", value);
|
|||
|
|
}
|
|||
|
|
return str;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int NumerInputDialog::checkValueRange(int64_t val, int pointflag)
|
|||
|
|
{
|
|||
|
|
int i, xsws;
|
|||
|
|
int64_t min, max;
|
|||
|
|
min = m_min;
|
|||
|
|
max = m_max;
|
|||
|
|
|
|||
|
|
xsws = pointflag - 1;
|
|||
|
|
if (xsws < 0)
|
|||
|
|
{
|
|||
|
|
xsws = 0;
|
|||
|
|
}
|
|||
|
|
xsws = m_afterPoint - xsws;
|
|||
|
|
if (xsws < 0)
|
|||
|
|
{
|
|||
|
|
xsws = 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (i = 0; i < xsws; i++)
|
|||
|
|
{
|
|||
|
|
min /= 10;
|
|||
|
|
max /= 10;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (val < min || val > max)
|
|||
|
|
{
|
|||
|
|
return 1;
|
|||
|
|
}
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int64_t NumerInputDialog::fixValue(int64_t val, int pointflag)
|
|||
|
|
{
|
|||
|
|
int i, xsws;
|
|||
|
|
int64_t min, max;
|
|||
|
|
min = m_min;
|
|||
|
|
max = m_max;
|
|||
|
|
|
|||
|
|
xsws = pointflag - 1;
|
|||
|
|
if (xsws < 0)
|
|||
|
|
{
|
|||
|
|
xsws = 0;
|
|||
|
|
}
|
|||
|
|
xsws = m_afterPoint - xsws;
|
|||
|
|
if (xsws < 0)
|
|||
|
|
{
|
|||
|
|
xsws = 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (i = 0; i < xsws; i++)
|
|||
|
|
{
|
|||
|
|
min /= 10;
|
|||
|
|
max /= 10;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (val < min)
|
|||
|
|
{
|
|||
|
|
val = min;
|
|||
|
|
}
|
|||
|
|
if (val > max)
|
|||
|
|
{
|
|||
|
|
val = max;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return val;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int NumerInputDialog::getPointMuti(int pointflag)
|
|||
|
|
{
|
|||
|
|
int muti = 1;
|
|||
|
|
for (int i = 1; i < pointflag; i++)
|
|||
|
|
{
|
|||
|
|
muti *= 10;
|
|||
|
|
}
|
|||
|
|
return muti;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::showValue()
|
|||
|
|
{
|
|||
|
|
ui->labelValue->setText(getShowString(m_value, m_pointFlag));
|
|||
|
|
|
|||
|
|
QString str = ui->labelValue->text();
|
|||
|
|
|
|||
|
|
// 修复判断数值范围时,无法正确区分小数点的问题
|
|||
|
|
int val = m_value;
|
|||
|
|
int i;
|
|||
|
|
if (m_pointFlag <= 1)
|
|||
|
|
{
|
|||
|
|
for (i=0; i<m_afterPoint; i++)
|
|||
|
|
{
|
|||
|
|
val *= 10;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
for (i=m_pointFlag-1; i<m_afterPoint; i++)
|
|||
|
|
{
|
|||
|
|
val *= 10;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (str.length() > 0 && val >= m_min && val <= m_max)
|
|||
|
|
{
|
|||
|
|
ui->buttonOk->setEnabled(true);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ui->buttonOk->setEnabled(false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::showRange()
|
|||
|
|
{
|
|||
|
|
QString min, max, def;
|
|||
|
|
|
|||
|
|
if (m_afterPoint == 0)
|
|||
|
|
{
|
|||
|
|
min = getShowString(m_min, 0);
|
|||
|
|
max = getShowString(m_max, 0);
|
|||
|
|
def = getShowString(m_defVal, 0);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
min = getShowString(m_min, m_afterPoint+1);
|
|||
|
|
max = getShowString(m_max, m_afterPoint+1);
|
|||
|
|
def = getShowString(m_defVal, m_afterPoint+1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QString rangeStr = "(" + min + "~" + max + ")" + m_unitStr;
|
|||
|
|
ui->labelRange->setText(rangeStr);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::addNum(int num)
|
|||
|
|
{
|
|||
|
|
if (((m_pointFlag < 5) &&
|
|||
|
|
((m_afterPoint == 0) || (m_pointFlag < m_afterPoint + 1)) &&
|
|||
|
|
((m_value > -100000000) && (m_value < 100000000)) && // 修复数值太大时显示错乱的问题
|
|||
|
|
1 ) ||
|
|||
|
|
(m_defFlag == 0) ||
|
|||
|
|
0 )
|
|||
|
|
{
|
|||
|
|
int64_t val;
|
|||
|
|
int pflag;
|
|||
|
|
|
|||
|
|
if (m_defFlag == 0)
|
|||
|
|
{// 第一次按数字键,从0开始计数,解决每次修改值之前都需要按C键的问题
|
|||
|
|
m_value = 0;
|
|||
|
|
m_pointFlag = 0;
|
|||
|
|
m_defFlag = 1;
|
|||
|
|
}
|
|||
|
|
val = m_value;
|
|||
|
|
pflag = m_pointFlag;
|
|||
|
|
|
|||
|
|
if (num < 0)
|
|||
|
|
{
|
|||
|
|
num = 0;
|
|||
|
|
}
|
|||
|
|
else if (num > 9)
|
|||
|
|
{
|
|||
|
|
num = 9;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
val *= 10;
|
|||
|
|
val += num*((m_value<0)?-1:1);
|
|||
|
|
|
|||
|
|
if (pflag != 0)
|
|||
|
|
{
|
|||
|
|
pflag++;
|
|||
|
|
if (pflag > 5)
|
|||
|
|
{
|
|||
|
|
pflag = 5;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//if (checkValueRange(val, pflag) == 0)
|
|||
|
|
{
|
|||
|
|
m_value = val;
|
|||
|
|
m_pointFlag = pflag;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::changeValue(int weights)
|
|||
|
|
{
|
|||
|
|
int64_t val;
|
|||
|
|
//int pflag;
|
|||
|
|
|
|||
|
|
val = m_value;
|
|||
|
|
|
|||
|
|
m_defFlag = 0; // 初始值
|
|||
|
|
if (weights > -1 && weights < 1) // 小数
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//pflag = m_pointFlag;
|
|||
|
|
val += weights*getPointMuti(m_pointFlag);
|
|||
|
|
|
|||
|
|
//if (checkValueRange(val, pflag) == 0)
|
|||
|
|
{
|
|||
|
|
// val = fixValue(val, m_pointFlag);
|
|||
|
|
// if (val != m_value)
|
|||
|
|
{
|
|||
|
|
m_value = val;
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//初始化窗体
|
|||
|
|
void NumerInputDialog::initDialog()
|
|||
|
|
{
|
|||
|
|
setTitleStr("");
|
|||
|
|
m_value = 0;
|
|||
|
|
m_min = 0;
|
|||
|
|
m_max = 0;
|
|||
|
|
m_afterPoint = 0;
|
|||
|
|
m_defVal = 0;
|
|||
|
|
m_defFlag = 0;
|
|||
|
|
m_pointFlag = 0;
|
|||
|
|
m_unitStr.clear();
|
|||
|
|
|
|||
|
|
m_leftNumberBtnList.clear();
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonPlusMinus);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonClean);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonDelete);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum7);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum8);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum9);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum4);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum5);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum6);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum1);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum2);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum3);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum00);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonNum0);
|
|||
|
|
m_leftNumberBtnList.append(ui->buttonPoint);
|
|||
|
|
|
|||
|
|
m_rightNumberBtnList.clear();
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonDec1000);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonInc1000);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonDec100);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonInc100);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonDec10);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonInc10);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonDec1);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonInc1);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonDec01);
|
|||
|
|
m_rightNumberBtnList.append(ui->buttonInc01);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//初始化窗体控件,包括位置、尺寸、样式
|
|||
|
|
void NumerInputDialog::initControl()
|
|||
|
|
{
|
|||
|
|
if(g_emTheme == theme2)
|
|||
|
|
{
|
|||
|
|
//根据不同分辨率设置控件的位置和尺寸
|
|||
|
|
initResolution_BlueVer();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//根据不同分辨率设置控件的位置和尺寸
|
|||
|
|
initResolution();
|
|||
|
|
}
|
|||
|
|
initControlStyle();//初始化窗体控件样式
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//初始化窗体分辨率
|
|||
|
|
void NumerInputDialog::initResolution_BlueVer()
|
|||
|
|
{
|
|||
|
|
double scaleX,scaleY;
|
|||
|
|
scaleX = getFactoryX();
|
|||
|
|
scaleY = getFactoryY();
|
|||
|
|
this->resize(584*scaleX,448*scaleY);
|
|||
|
|
this->move((1024*scaleX-this->width())/2,(600*scaleY-this->height())/2);
|
|||
|
|
|
|||
|
|
ui->frameBack->setGeometry(0,0,584*scaleX,448*scaleY);
|
|||
|
|
ui->labelTitle->setGeometry(0*scaleX,0,584*scaleX,44*scaleY);
|
|||
|
|
ui->labelValue->setGeometry(22*scaleX,74*scaleY,310*scaleX,44*scaleY);
|
|||
|
|
ui->labelRange->setGeometry(340*scaleX,74*scaleY,224*scaleX,44*scaleY);
|
|||
|
|
|
|||
|
|
for(int i = 0; i < 5; i++)
|
|||
|
|
{
|
|||
|
|
for(int j = 0; j < 3; j ++)
|
|||
|
|
{
|
|||
|
|
m_leftNumberBtnList[i*3+j]->setGeometry(23*scaleX+j*107*scaleX,129*scaleY+i*52*scaleY,96*scaleX,40*scaleY);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for(int i = 0; i < 5; i++)
|
|||
|
|
{
|
|||
|
|
for(int j = 0; j < 2; j ++)
|
|||
|
|
{
|
|||
|
|
if(g_emResolut == resolution0804)
|
|||
|
|
{
|
|||
|
|
m_rightNumberBtnList[i*2+j]->setGeometry((344+j*120)*scaleX,(129+i*52)*scaleY,96*scaleX,40*scaleY);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_rightNumberBtnList[i*2+j]->setGeometry((364+j*107)*scaleX,(129+i*52)*scaleY,96*scaleX,40*scaleY);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ui->buttonOk->setGeometry(365*scaleX,389*scaleY,96*scaleX,40*scaleY);
|
|||
|
|
ui->buttonCancel->setGeometry(471*scaleX,389*scaleY,96*scaleX,40*scaleY);
|
|||
|
|
if(g_emResolut == resolution0804)
|
|||
|
|
{
|
|||
|
|
ui->buttonOk->setGeometry(344*scaleX,389*scaleY,96*scaleX,40*scaleY);
|
|||
|
|
ui->buttonCancel->setGeometry(464*scaleX,389*scaleY,96*scaleX,40*scaleY);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//初始化窗体控件为任意分辨率
|
|||
|
|
void NumerInputDialog::initResolution()
|
|||
|
|
{
|
|||
|
|
#define FRAME_LEFT (203) // 小窗口
|
|||
|
|
#define FRAME_TOP (59)
|
|||
|
|
#define FRAME_WIGHT (620)
|
|||
|
|
#define FRAME_HEIGHT (479)
|
|||
|
|
|
|||
|
|
#define TITLE_HEIGHT (46) // 标题栏高度
|
|||
|
|
#define TITLE_LEFT (367) // 分栏左
|
|||
|
|
|
|||
|
|
#define NUM_LEFT (21) // 数值左
|
|||
|
|
#define NUM_TOP (84) // 数值
|
|||
|
|
#define NUM_WIGHT (324) // 数值宽度
|
|||
|
|
#define NUM_HEIGHT (42) // 数值高度
|
|||
|
|
|
|||
|
|
double factoryX = getFactoryX();
|
|||
|
|
double factoryY = getFactoryY();
|
|||
|
|
|
|||
|
|
int xval = 0;
|
|||
|
|
int xval2 = 0;
|
|||
|
|
if(g_emResolut == resolution0804)
|
|||
|
|
{
|
|||
|
|
xval = 20;
|
|||
|
|
xval2 = 4;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this->resize(GLB_SCR_WIGHT*factoryX,GLB_SCR_HEIGHT*factoryY);
|
|||
|
|
this->move((GLB_SCR_WIGHT*factoryX-this->width())/2+g_mainWidgetPos.x(),(GLB_SCR_HEIGHT*factoryY-this->height())/2+g_mainWidgetPos.y());
|
|||
|
|
ui->frameBack->setGeometry(0*factoryX,0*factoryY,GLB_SCR_WIGHT*factoryX+xval,GLB_SCR_HEIGHT*factoryY);
|
|||
|
|
|
|||
|
|
ui->labelTitle->setGeometry((FRAME_LEFT+GLB_EDGE_WIGHT)*factoryX,(FRAME_TOP+(TITLE_HEIGHT-GLB_TEXT_HEIGHT)/2-6)*factoryY,(FRAME_WIGHT-GLB_TAB_WIGHT*2)*factoryX,(GLB_TEXT_L_HEIGHT+xval2)*factoryY);
|
|||
|
|
ui->labelValue->setGeometry((FRAME_LEFT+NUM_LEFT+GLB_TAB_WIGHT-xval)*factoryX,(FRAME_TOP+NUM_TOP+GLB_ICON_TEXT - xval +xval2*5)*factoryY,(NUM_WIGHT-GLB_TAB_WIGHT*2+2*xval)*factoryX,GLB_TEXT_L_HEIGHT*factoryY);
|
|||
|
|
ui->labelRange->setGeometry((FRAME_LEFT+TITLE_LEFT+xval)*factoryX,(FRAME_TOP+NUM_TOP+NUM_HEIGHT-GLB_TEXT_HEIGHT - 2*xval + xval/2 +xval2*8)*factoryY,(FRAME_WIGHT-TITLE_LEFT-GLB_TAB_WIGHT)*factoryX,GLB_TEXT_HEIGHT*factoryY);
|
|||
|
|
|
|||
|
|
int bgX,bgY;
|
|||
|
|
bgX = FRAME_LEFT + NUM_LEFT;
|
|||
|
|
bgY = FRAME_TOP + NUM_TOP+NUM_HEIGHT + GLB_EDGE_WIGHT;
|
|||
|
|
|
|||
|
|
for(int i = 0; i < 5; i++)
|
|||
|
|
{
|
|||
|
|
for(int j = 0; j < 3; j ++)
|
|||
|
|
{
|
|||
|
|
m_leftNumberBtnList[i*3+j]->setGeometry(((bgX+j*(GLB_LBUT_WIGHT +GLB_BAS_WIGHT+xval2)+xval2))*factoryX,(bgY+i*(GLB_LBUT_HEIGHT + GLB_BAS_WIGHT))*factoryY,GLB_LBUT_WIGHT*factoryX,GLB_LBUT_HEIGHT*factoryY);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
double val = 0;
|
|||
|
|
|
|||
|
|
bgX = FRAME_LEFT + TITLE_LEFT + GLB_EDGE_WIGHT;
|
|||
|
|
for(int i = 0; i < 5; i++)
|
|||
|
|
{
|
|||
|
|
for(int j = 0; j < 2; j ++)
|
|||
|
|
{
|
|||
|
|
if(j == 1)
|
|||
|
|
{
|
|||
|
|
if(g_emResolut == resolution0804)
|
|||
|
|
{
|
|||
|
|
val = 0.01;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
val = 0;
|
|||
|
|
}
|
|||
|
|
m_rightNumberBtnList[i*2+j]->setGeometry((bgX+j*(GLB_LBUT_WIGHT +GLB_BAS_WIGHT))*(factoryX+val),(bgY+i*(GLB_LBUT_HEIGHT + GLB_BAS_WIGHT))*factoryY,GLB_LBUT_WIGHT*(factoryX),GLB_LBUT_HEIGHT*factoryY);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ui->buttonOk->setGeometry((bgX+0*(GLB_LBUT_WIGHT +GLB_BAS_WIGHT))*factoryX,(bgY+5*(GLB_LBUT_HEIGHT + GLB_BAS_WIGHT)+GLB_BAS_WIGHT)*factoryY,
|
|||
|
|
GLB_LBUT_WIGHT*factoryX,GLB_LBUT_HEIGHT*factoryY);
|
|||
|
|
if(g_emResolut == resolution0804)
|
|||
|
|
{
|
|||
|
|
val = 0.01;
|
|||
|
|
}
|
|||
|
|
ui->buttonCancel->setGeometry((bgX+1*(GLB_LBUT_WIGHT +GLB_BAS_WIGHT))*(factoryX+val),(bgY+5*(GLB_LBUT_HEIGHT + GLB_BAS_WIGHT)+GLB_BAS_WIGHT)*factoryY,
|
|||
|
|
GLB_LBUT_WIGHT*factoryX,GLB_LBUT_HEIGHT*factoryY);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//初始化窗体控件样式
|
|||
|
|
void NumerInputDialog::initControlStyle()
|
|||
|
|
{
|
|||
|
|
SetStyle setControlStyle;
|
|||
|
|
setControlStyle.setUiName(this->objectName());
|
|||
|
|
|
|||
|
|
if(g_emTheme == theme2)
|
|||
|
|
{
|
|||
|
|
ui->frameBack->setStyleSheet(frameBackStyle());
|
|||
|
|
ui->labelTitle->setStyleSheet(titleTextColour2());
|
|||
|
|
}else
|
|||
|
|
{
|
|||
|
|
ui->frameBack->setStyleSheet(setControlStyle.getStyleSheet(this->objectName()));
|
|||
|
|
ui->labelTitle->setStyleSheet(transparentStyle());
|
|||
|
|
}
|
|||
|
|
for(int i = 0; i < m_leftNumberBtnList.size(); i++)
|
|||
|
|
{
|
|||
|
|
m_leftNumberBtnList[i]->setStyleSheet(numButtonStyle());
|
|||
|
|
m_leftNumberBtnList[i]->setFont(fontSize_M());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for(int i = 0; i < m_rightNumberBtnList.size(); i++)
|
|||
|
|
{
|
|||
|
|
m_rightNumberBtnList[i]->setStyleSheet(numButtonStyle());
|
|||
|
|
m_rightNumberBtnList[i]->setFont(fontSize_M());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ui->labelTitle->setFont(fontSize_L());
|
|||
|
|
ui->labelTitle->setAlignment(Qt::AlignLeft);
|
|||
|
|
ui->labelTitle->setAlignment(Qt::AlignVCenter);
|
|||
|
|
|
|||
|
|
ui->labelValue->setStyleSheet(numValue());
|
|||
|
|
ui->labelValue->setFont(fontSize_L());
|
|||
|
|
|
|||
|
|
ui->labelRange->setStyleSheet(noteTextColour());
|
|||
|
|
ui->labelRange->setFont(fontSize_M());
|
|||
|
|
ui->labelRange->setAlignment(Qt::AlignLeft);
|
|||
|
|
ui->labelRange->setAlignment(Qt::AlignVCenter);
|
|||
|
|
ui->buttonOk->setStyleSheet(confirmIconStyle());
|
|||
|
|
ui->buttonCancel->setStyleSheet(confirmIconStyle());
|
|||
|
|
if(g_emTheme == theme2)
|
|||
|
|
{
|
|||
|
|
ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet("buttonOk_1"));
|
|||
|
|
ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet("buttonCancel_1"));
|
|||
|
|
}else
|
|||
|
|
{
|
|||
|
|
ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet("buttonOk"));
|
|||
|
|
ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet("buttonCancel"));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//设置标题
|
|||
|
|
void NumerInputDialog::setTitleStr(QString str)
|
|||
|
|
{
|
|||
|
|
ui->labelTitle->setText(str);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::setUnitStr(QString str)
|
|||
|
|
{
|
|||
|
|
m_unitStr = str;
|
|||
|
|
// showRange();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::setValueAndRange(int64_t val, int64_t min, int64_t max, int afterpoint, int defen, int64_t defvalue)
|
|||
|
|
{
|
|||
|
|
m_value = val;
|
|||
|
|
m_min = min;
|
|||
|
|
m_max = max;
|
|||
|
|
m_afterPoint = afterpoint;
|
|||
|
|
|
|||
|
|
if (m_min < -999999999)
|
|||
|
|
{
|
|||
|
|
m_min = -999999999; // 这个值看起来更舒服些
|
|||
|
|
}
|
|||
|
|
if (m_max > 999999999)
|
|||
|
|
{
|
|||
|
|
m_max = 999999999; // 这个值看起来更舒服些
|
|||
|
|
}
|
|||
|
|
if (m_min > m_max)
|
|||
|
|
{
|
|||
|
|
double tmp = m_min;
|
|||
|
|
m_min = m_max;
|
|||
|
|
m_max = tmp;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (m_afterPoint < 0)
|
|||
|
|
{
|
|||
|
|
m_afterPoint = 0;
|
|||
|
|
}
|
|||
|
|
if (m_afterPoint > 4)
|
|||
|
|
{
|
|||
|
|
m_afterPoint = 4;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (m_value < m_min)
|
|||
|
|
{
|
|||
|
|
m_value = m_min;
|
|||
|
|
}
|
|||
|
|
if (m_value > m_max)
|
|||
|
|
{
|
|||
|
|
m_value = m_max;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (m_afterPoint != 0)
|
|||
|
|
{
|
|||
|
|
m_pointFlag = m_afterPoint + 1;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_pointFlag = 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_defFlag = defen;
|
|||
|
|
m_defVal = defvalue;
|
|||
|
|
|
|||
|
|
showRange();
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int64_t NumerInputDialog::getValue()
|
|||
|
|
{
|
|||
|
|
int i, j;
|
|||
|
|
int64_t val = m_value;
|
|||
|
|
i = m_pointFlag;
|
|||
|
|
j = m_afterPoint;
|
|||
|
|
if (j != 0)
|
|||
|
|
{
|
|||
|
|
j += 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
while (i < j)
|
|||
|
|
{
|
|||
|
|
if (i != 0)
|
|||
|
|
{
|
|||
|
|
val *= 10;
|
|||
|
|
}
|
|||
|
|
i++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return val;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonClean_clicked()
|
|||
|
|
{
|
|||
|
|
m_pointFlag = 0;
|
|||
|
|
m_value = 0;
|
|||
|
|
m_defFlag = 0;
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum00_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(0);
|
|||
|
|
addNum(0);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonDelete_clicked()
|
|||
|
|
{
|
|||
|
|
m_defFlag = 1;
|
|||
|
|
|
|||
|
|
if (m_pointFlag != 1)
|
|||
|
|
{
|
|||
|
|
int64_t val;
|
|||
|
|
int pflag;
|
|||
|
|
val = m_value;
|
|||
|
|
pflag = m_pointFlag;
|
|||
|
|
val /= 10;
|
|||
|
|
pflag--;
|
|||
|
|
if (pflag < 0)
|
|||
|
|
{
|
|||
|
|
pflag = 0;
|
|||
|
|
}
|
|||
|
|
//if (checkValueRange(val, pflag) == 0)
|
|||
|
|
{
|
|||
|
|
m_value = val;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (m_pointFlag != 0)
|
|||
|
|
{
|
|||
|
|
m_pointFlag--;
|
|||
|
|
}
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum7_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(7);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum8_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(8);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum9_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(9);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum4_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(4);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum5_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(5);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum6_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(6);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum1_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(1);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum2_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(2);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum3_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(3);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonPlusMinus_clicked()
|
|||
|
|
{
|
|||
|
|
int64_t val;
|
|||
|
|
val = m_value;
|
|||
|
|
val *= -1;
|
|||
|
|
//if (checkValueRange(val, m_pointFlag) == 0)
|
|||
|
|
{
|
|||
|
|
m_value = val;
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonNum0_clicked()
|
|||
|
|
{
|
|||
|
|
addNum(0);
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonPoint_clicked()
|
|||
|
|
{
|
|||
|
|
if (m_pointFlag == 0 && m_afterPoint != 0)
|
|||
|
|
{
|
|||
|
|
m_pointFlag = 1;
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonDec1000_clicked()
|
|||
|
|
{
|
|||
|
|
changeValue(-1000);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonInc1000_clicked()
|
|||
|
|
{
|
|||
|
|
changeValue(1000);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonDec100_clicked()
|
|||
|
|
{
|
|||
|
|
changeValue(-100);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonInc100_clicked()
|
|||
|
|
{
|
|||
|
|
changeValue(100);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonDec10_clicked()
|
|||
|
|
{
|
|||
|
|
changeValue(-10);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonInc10_clicked()
|
|||
|
|
{
|
|||
|
|
changeValue(10);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonDec1_clicked()
|
|||
|
|
{
|
|||
|
|
changeValue(-1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonInc1_clicked()
|
|||
|
|
{
|
|||
|
|
changeValue(1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonDec01_clicked()
|
|||
|
|
{
|
|||
|
|
if (m_afterPoint != 0)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
m_defFlag = 0;
|
|||
|
|
int64_t val;
|
|||
|
|
int pflag, muti;
|
|||
|
|
|
|||
|
|
int dir;
|
|||
|
|
int weights = -1;
|
|||
|
|
muti = 1;
|
|||
|
|
|
|||
|
|
//dir = m_value > 0 ? 1:-1;
|
|||
|
|
dir = m_value > 0 ? 1:1;
|
|||
|
|
val = m_value;
|
|||
|
|
pflag = m_pointFlag;
|
|||
|
|
|
|||
|
|
if (m_pointFlag <= 1) // 是整数
|
|||
|
|
{
|
|||
|
|
val *= 10;
|
|||
|
|
pflag = 2; // 转换为1位小数
|
|||
|
|
}
|
|||
|
|
else // 小数
|
|||
|
|
{
|
|||
|
|
for (int i = 2; i < m_pointFlag; i++)
|
|||
|
|
{
|
|||
|
|
muti *= 10;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
val += weights * dir * muti;
|
|||
|
|
|
|||
|
|
//if (checkValueRange(val, pflag) == 0)
|
|||
|
|
{
|
|||
|
|
// val = fixValue(val, pflag);
|
|||
|
|
m_value = val;
|
|||
|
|
m_pointFlag = pflag;
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonInc01_clicked()
|
|||
|
|
{
|
|||
|
|
if (m_afterPoint != 0)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
m_defFlag = 0;
|
|||
|
|
int64_t val;
|
|||
|
|
int pflag, muti;
|
|||
|
|
int dir;
|
|||
|
|
int weights = 1;
|
|||
|
|
|
|||
|
|
//dir = m_value > 0 ? 1:-1;
|
|||
|
|
dir = m_value > 0 ? 1:1;
|
|||
|
|
muti = 1;
|
|||
|
|
|
|||
|
|
val = m_value;
|
|||
|
|
pflag = m_pointFlag;
|
|||
|
|
|
|||
|
|
if (m_pointFlag <= 1) // 是整数
|
|||
|
|
{
|
|||
|
|
val *= 10;
|
|||
|
|
pflag = 2; // 转换为1位小数
|
|||
|
|
}
|
|||
|
|
else // 小数
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
for (int i = 2; i < m_pointFlag; i++)
|
|||
|
|
{
|
|||
|
|
muti *= 10;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
val += weights * dir * muti;
|
|||
|
|
|
|||
|
|
//if (checkValueRange(val, pflag) == 0)
|
|||
|
|
{
|
|||
|
|
// val = fixValue(val, pflag);
|
|||
|
|
m_value = val;
|
|||
|
|
m_pointFlag = pflag;
|
|||
|
|
showValue();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonOk_clicked()
|
|||
|
|
{
|
|||
|
|
done(1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NumerInputDialog::on_buttonCancel_clicked()
|
|||
|
|
{
|
|||
|
|
done(0);
|
|||
|
|
}
|