This commit is contained in:
gangphon 2023-05-15 16:06:10 +08:00
parent 2f1adb07e6
commit 86f509d7a2
92 changed files with 12092 additions and 16782 deletions

View File

@ -57,11 +57,6 @@ SOURCES += \
base/loemptydialog.cpp \ base/loemptydialog.cpp \
base/softconfigdialog.cpp \ base/softconfigdialog.cpp \
base/switchcontrol.cpp \ base/switchcontrol.cpp \
base/taesclass.cpp \
base/x_checkboxdelegate.cpp \
base/x_spinboxdelegate.cpp \
base/x_timeeditdelegate.cpp \
base/x_uimsgboxok.cpp \
base/extendedgroupbox.cpp \ base/extendedgroupbox.cpp \
base/ffutil.cpp \ base/ffutil.cpp \
base/locolorselector.cpp \ base/locolorselector.cpp \
@ -72,11 +67,12 @@ SOURCES += \
basedlg.cpp \ basedlg.cpp \
basewin.cpp \ basewin.cpp \
cfg.cpp \ cfg.cpp \
communication/hpptclient.cpp \
communication/taserialthread.cpp \
device/ctrlhdmipanel.cpp \ device/ctrlhdmipanel.cpp \
device/ctrlnetworkpanel.cpp \ device/ctrlnetworkpanel.cpp \
device/ctrlpowerpanel.cpp \
device/ctrlpwdpanel.cpp \ device/ctrlpwdpanel.cpp \
device/ctrltestpanel.cpp \
device/ctrlvolumepanel.cpp \
devicectrlpanel.cpp \ devicectrlpanel.cpp \
deviceitem.cpp \ deviceitem.cpp \
devicepanel.cpp \ devicepanel.cpp \
@ -103,15 +99,9 @@ SOURCES += \
progpanel.cpp \ progpanel.cpp \
synctimer.cpp \ synctimer.cpp \
tools.cpp \ tools.cpp \
device/controlpowerschedule.cpp \
device/controlpowerwidget.cpp \
device/controltestwidget.cpp \
device/controlvolumeschedule.cpp \
device/controlvolumewidget.cpp \
device/ctrladvancedpanel.cpp \ device/ctrladvancedpanel.cpp \
device/ctrlbrightpanel.cpp \ device/ctrlbrightpanel.cpp \
device/ctrlverifyclockpanel.cpp \ device/ctrlverifyclockpanel.cpp \
device/ledcard.cpp \
device/upgradeapkdialog.cpp \ device/upgradeapkdialog.cpp \
device/wupgradeapkitem.cpp \ device/wupgradeapkitem.cpp \
program/copydirthread.cpp \ program/copydirthread.cpp \
@ -145,11 +135,6 @@ HEADERS += \
base/loemptydialog.h \ base/loemptydialog.h \
base/softconfigdialog.h \ base/softconfigdialog.h \
base/switchcontrol.h \ base/switchcontrol.h \
base/taesclass.h \
base/x_checkboxdelegate.h \
base/x_spinboxdelegate.h \
base/x_timeeditdelegate.h \
base/x_uimsgboxok.h \
base/extendedgroupbox.h \ base/extendedgroupbox.h \
base/locolorselector.h \ base/locolorselector.h \
base/lodateselector.h \ base/lodateselector.h \
@ -159,11 +144,12 @@ HEADERS += \
basedlg.h \ basedlg.h \
basewin.h \ basewin.h \
cfg.h \ cfg.h \
communication/hpptclient.h \
communication/taserialthread.h \
device/ctrlhdmipanel.h \ device/ctrlhdmipanel.h \
device/ctrlnetworkpanel.h \ device/ctrlnetworkpanel.h \
device/ctrlpowerpanel.h \
device/ctrlpwdpanel.h \ device/ctrlpwdpanel.h \
device/ctrltestpanel.h \
device/ctrlvolumepanel.h \
devicectrlpanel.h \ devicectrlpanel.h \
deviceitem.h \ deviceitem.h \
devicepanel.h \ devicepanel.h \
@ -189,15 +175,9 @@ HEADERS += \
progpanel.h \ progpanel.h \
synctimer.h \ synctimer.h \
tools.h \ tools.h \
device/controlpowerschedule.h \
device/controlpowerwidget.h \
device/controltestwidget.h \
device/controlvolumeschedule.h \
device/controlvolumewidget.h \
device/ctrladvancedpanel.h \ device/ctrladvancedpanel.h \
device/ctrlbrightpanel.h \ device/ctrlbrightpanel.h \
device/ctrlverifyclockpanel.h \ device/ctrlverifyclockpanel.h \
device/ledcard.h \
device/upgradeapkdialog.h \ device/upgradeapkdialog.h \
device/wupgradeapkitem.h \ device/wupgradeapkitem.h \
program/copydirthread.h \ program/copydirthread.h \
@ -226,11 +206,6 @@ HEADERS += \
program/wprogrampublishitem.h \ program/wprogrampublishitem.h \
FORMS += \ FORMS += \
base/x_uimsgboxok.ui \
mguangyingpinwidget.ui \
device/controlpowerschedule.ui \
device/controltestwidget.ui \
device/controlvolumeschedule.ui \
TRANSLATIONS += \ TRANSLATIONS += \
translations/app_zh_CN.ts \ translations/app_zh_CN.ts \

View File

@ -5,9 +5,13 @@
#include <QPushButton> #include <QPushButton>
#include <QMessageBox> #include <QMessageBox>
#include <QSettings> #include <QSettings>
#include <QDialogButtonBox>
ChangePasswordForm::ChangePasswordForm(QWidget *parent) : BaseDlg(parent) { ChangePasswordForm::ChangePasswordForm(QWidget *parent) : QDialog(parent) {
resize(240, 160); resize(240, 160);
#ifdef Q_OS_WIN
setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
#endif
auto vBox = new QVBoxLayout(this); auto vBox = new QVBoxLayout(this);
auto hBox = new QHBoxLayout(); auto hBox = new QHBoxLayout();
auto label = new QLabel(tr("Old password")); auto label = new QLabel(tr("Old password"));
@ -39,11 +43,9 @@ ChangePasswordForm::ChangePasswordForm(QWidget *parent) : BaseDlg(parent) {
hBox->addWidget(fdAgn); hBox->addWidget(fdAgn);
vBox->addLayout(hBox); vBox->addLayout(hBox);
hBox = new QHBoxLayout(); auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
auto pushButton_2 = new QPushButton(tr("OK")); connect(btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
pushButton_2->setProperty("ssType", "progManageTool"); connect(btnBox, &QDialogButtonBox::accepted, this, [=] {
hBox->addWidget(pushButton_2);
connect(pushButton_2, &QPushButton::clicked, this, [this]() {
QString pwdOld = fdOld->text(); QString pwdOld = fdOld->text();
if(pwdOld.isEmpty()) { if(pwdOld.isEmpty()) {
QMessageBox::warning(this, tr("Tip"), tr("Please input old password")); QMessageBox::warning(this, tr("Tip"), tr("Please input old password"));
@ -74,10 +76,5 @@ ChangePasswordForm::ChangePasswordForm(QWidget *parent) : BaseDlg(parent) {
QMessageBox::information(this, tr("Tip"), tr("Password changed successfully")); QMessageBox::information(this, tr("Tip"), tr("Password changed successfully"));
accept(); accept();
}); });
vBox->addWidget(btnBox);
auto pushButton = new QPushButton(tr("Cancel"));
pushButton->setProperty("ssType", "progManageTool");
hBox->addWidget(pushButton);
connect(pushButton, &QPushButton::clicked, this, &ChangePasswordForm::reject);
vBox->addLayout(hBox);
} }

View File

@ -1,10 +1,10 @@
#ifndef CHANGEPASSWORDFORM_H #ifndef CHANGEPASSWORDFORM_H
#define CHANGEPASSWORDFORM_H #define CHANGEPASSWORDFORM_H
#include "basedlg.h" #include "QDialog.h"
#include <QLineEdit> #include <QLineEdit>
class ChangePasswordForm : public BaseDlg { class ChangePasswordForm : public QDialog {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -25,6 +25,7 @@ LoQTreeWidget::LoQTreeWidget(QWidget *parent) : QTreeWidget(parent), m_checkStat
setProperty("ssType", "topList"); setProperty("ssType", "topList");
connect(fdIsSelAll, SIGNAL(toggled(bool)), this, SLOT(onCheckAll(bool))); connect(fdIsSelAll, SIGNAL(toggled(bool)), this, SLOT(onCheckAll(bool)));
connect(this, &LoQTreeWidget::itemClicked, this, [this](QTreeWidgetItem *item, int column) { connect(this, &LoQTreeWidget::itemClicked, this, [this](QTreeWidgetItem *item, int column) {
if(selectionMode()==QAbstractItemView::NoSelection) return;
if(column > 0) item->setCheckState(0, item->checkState(0) == Qt::Unchecked ? Qt::Checked : Qt::Unchecked); if(column > 0) item->setCheckState(0, item->checkState(0) == Qt::Unchecked ? Qt::Checked : Qt::Unchecked);
adjustCheckState(); adjustCheckState();
}); });

View File

@ -3,10 +3,8 @@
#include <QPainterPath> #include <QPainterPath>
#include "qevent.h" #include "qevent.h"
#include "qtimer.h" #include "qtimer.h"
#include "qdebug.h"
SwitchControl::SwitchControl(QWidget *parent): QWidget(parent) SwitchControl::SwitchControl(QWidget *parent): QWidget(parent) {
{
checked = false; checked = false;
buttonStyle = ButtonStyle_Rect; buttonStyle = ButtonStyle_Rect;

View File

@ -1,472 +0,0 @@
#include "taesclass.h"
Aes::~Aes()
{
}
Aes::Aes()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////
//构造函数
Aes::Aes(int keysize,unsigned char* keyBytes)
{
SetNbNkNr(keysize); //设置密钥块数,轮数
memcpy(key,keyBytes,keysize); //字符串拷贝函数把keyBytes的keysize个字符复制到key中
KeyExpansion(); //密钥扩展,必须提前做的初始化
}
////////////////////////////////////////////////////////////////////////////////////////////////
void Aes::SetNbNkNr(int keySize)
{
Nb=4;
if(keySize==Bits128)
{
Nk=4; //4*4字节128位密钥10轮加密
Nr=10;
}
else if(keySize==Bits192)
{
Nk=6; //6*4字节192位密钥12轮加密
Nr=12;
}
else if(keySize==Bits256)
{
Nk=8; //8*4字节256位密钥14轮加密
Nr=14;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void Aes::KeyExpansion()
{
memset(w,0,16*15);
for(int row=0;row<Nk;row++) //拷贝seed 密钥
{
w[4*row+0] = key[4*row];
w[4*row+1] = key[4*row+1];
w[4*row+2] = key[4*row+2];
w[4*row+3] = key[4*row+3];
}
byte* temp = new byte[4];
for(int row=Nk;row<4*(Nr+1);row++)
{
temp[0]=w[4*row-4]; //当前列的前一列
temp[1]=w[4*row-3];
temp[2]=w[4*row-2];
temp[3]=w[4*row-1];
if(row%Nk==0) //逢nk时对当前列的前一列作特殊处理
{
temp=SubWord(RotWord(temp)); //先移位,再代换,最后和轮常量异或
temp[0] = (byte)( (int)temp[0] ^ (int) AesRcon[4*(row/Nk)+0] );
temp[1] = (byte)( (int)temp[1] ^ (int) AesRcon[4*(row/Nk)+1] );
temp[2] = (byte)( (int)temp[2] ^ (int) AesRcon[4*(row/Nk)+2] );
temp[3] = (byte)( (int)temp[3] ^ (int) AesRcon[4*(row/Nk)+3] );
}
else if ( Nk > 6 && (row % Nk == 4) ) //这个还没有搞清楚
{
temp = SubWord(temp);
}
// w[row] = w[row-Nk] xor temp
w[4*row+0] = (byte) ( (int) w[4*(row-Nk)+0] ^ (int)temp[0] );
w[4*row+1] = (byte) ( (int) w[4*(row-Nk)+1] ^ (int)temp[1] );
w[4*row+2] = (byte) ( (int) w[4*(row-Nk)+2] ^ (int)temp[2] );
w[4*row+3] = (byte) ( (int) w[4*(row-Nk)+3] ^ (int)temp[3] );
} // for loop
}
////////////////////////////////////////////////////////////////////////////////////////////////
//密钥移位函数
unsigned char* Aes::RotWord(unsigned char* word)
{
byte* temp = new byte[4];
temp[0] = word[1];
temp[1] = word[2];
temp[2] = word[3];
temp[3] = word[0];
return temp;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//密钥字代换函数
unsigned char* Aes::SubWord(unsigned char* word)
{
byte* temp = new byte[4];
for(int j=0;j<4;j++)
{
temp[j] = AesSbox[16*(word[j] >> 4)+(word[j] & 0x0f)]; //实际上也可以写成AesSbox[[j]];因为两者相等
}
return temp;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//Aes加密函数
void Aes::Cipher(unsigned char* input, unsigned char* output)
{
memset(&State[0][0],0,16);
for(int i=0;i<4*Nb;i++) //这里是先写列后写行的,即输入是一列一列的进来的
{
State[i%4][i/4]=input[i]; //换成先写行后写列也是可以的,只要在输出时也是这样就可以了
}
AddRoundKey(0); //轮密钥加
for (int round = 1; round <= (Nr - 1); round++) // main round loop
{
SubBytes(); //字节代换
ShiftRows(); //行移位
MixColumns(); //列混淆
AddRoundKey(round); //轮密钥加
} // main round loop
SubBytes(); //字节代换
ShiftRows(); //行移位
AddRoundKey(Nr); //轮密钥加
// output = state
for (int i = 0; i < (4 * Nb); i++)
{
output[i] = State[i % 4][ i / 4];
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//Aes解密函数
void Aes::InvCipher(unsigned char* input,unsigned char* output)
{
memset(&State[0][0],0,16);
for (int i = 0; i < (4 * Nb); i++)
{
State[i % 4][ i / 4] = input[i];
}
AddRoundKey(Nr);
for (int round = Nr-1; round >= 1; round--) // main round loop
{
InvShiftRows();
InvSubBytes();
AddRoundKey(round);
InvMixColumns();
} // end main round loop for InvCipher
InvShiftRows();
InvSubBytes();
AddRoundKey(0);
// output = state
for (int i = 0; i < (4 * Nb); i++)
{
output[i] = State[i % 4][ i / 4];
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//轮密钥加
void Aes::AddRoundKey(int round)
{
int i,j; //i行 j列 //因为密钥w是一列一列排列的即 k0 k4 k8 k12
for(j=0;j<4;j++) // k1 k5 k9 k13
{ // k2 k6 k10k14
for(i=0;i<4;i++) // k3 k7 k11k15
{ // 所以i行j列的下标是4*((round*4)+j)+i即16*round+4*j+i
State[i][j]=(unsigned char)((int)State[i][j]^(int)w[4*((round*4)+j)+i]);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//字节代换函数
void Aes::SubBytes() //Page 103
{
int i,j;
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
State[i][j]=AesSbox[State[i][j]];
//因为 16*(State[i][j]>>4)+State[i][j]&0x0f=State[i][j]
}
}
}
void Aes::InvSubBytes()
{
int i,j;
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
State[i][j]=AesiSbox[State[i][j]]; //因为 16*(State[i][j]>>4)+State[i][j]&0x0f=State[i][j]
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void Aes::ShiftRows()
{
unsigned char temp[4*4]; //Page105
int i,j;
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
temp[4*i+j]=State[i][j];
}
}
for(i=1;i<4;i++)
{
for(j=0;j<4;j++)
{
if(i==1)State[i][j]=temp[4*i+(j+1)%4]; //第一行左移1位
else if(i==2)State[i][j]=temp[4*i+(j+2)%4]; //第二行左移2位
else if(i==3)State[i][j]=temp[4*i+(j+3)%4]; //第三行左移3位
}
}
}
void Aes::InvShiftRows()
{
unsigned char temp[4*4];
int i,j;
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
temp[4*i+j]=State[i][j];
}
}
for(i=1;i<4;i++)
{
for(j=0;j<4;j++)
{
//if(i==1)State[i][j]=temp[4*i+(j-1)%4]; 在此犯了一个错误 -1%4=-1 而不是3所以采用了下面再加一个4的做法
if(i==1)State[i][j]=temp[4*i+(j+3)%4]; //第一行右移1位 j-1+4=j+3
else if(i==2)State[i][j]=temp[4*i+(j+2)%4]; //第二行右移2位 j-2+4=j+2
else if(i==3)State[i][j]=temp[4*i+(j+1)%4]; //第三行右移3位 j-3+4=j+2
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void Aes::MixColumns()
{
unsigned char temp[4*4];
int i,j;
for(j=0;j<4;j++) //2 3 1 1 列混淆矩阵 Page107
{ //1 2 3 1
for(i=0;i<4;i++) //1 1 2 3
{ //3 1 1 2
temp[4*i+j]=State[i][j];
}
}
for(j=0;j<4;j++)
{
State[0][j] = (unsigned char) ( (int)gfmultby02(temp[0+j]) ^ (int)gfmultby03(temp[4*1+j]) ^
(int)gfmultby01(temp[4*2+j]) ^ (int)gfmultby01(temp[4*3+j]) );
State[1][j] = (unsigned char) ( (int)gfmultby01(temp[0+j]) ^ (int)gfmultby02(temp[4*1+j]) ^
(int)gfmultby03(temp[4*2+j]) ^ (int)gfmultby01(temp[4*3+j]) );
State[2][j] = (unsigned char) ( (int)gfmultby01(temp[0+j]) ^ (int)gfmultby01(temp[4*1+j]) ^
(int)gfmultby02(temp[4*2+j]) ^ (int)gfmultby03(temp[4*3+j]) );
State[3][j] = (unsigned char) ( (int)gfmultby03(temp[0+j]) ^ (int)gfmultby01(temp[4*1+j]) ^
(int)gfmultby01(temp[4*2+j]) ^ (int)gfmultby02(temp[4*3+j]) );
}
}
void Aes::InvMixColumns()
{
unsigned char temp[4*4];
int i,j;
for (i = 0; i < 4; i++) // copy State into temp[]
{
for (j = 0; j < 4; j++) //0e 0b 0d 09 逆变换矩阵 Page108
{ //09 0e 0b 0d
temp[4*i+j] = State[i][j]; //0d 09 0e 0b
} //0b 0d 09 0e
}
for (j = 0; j < 4; j++)
{
State[0][j] = (unsigned char) ( (int)gfmultby0e(temp[j]) ^ (int)gfmultby0b(temp[4+j]) ^
(int)gfmultby0d(temp[4*2+j]) ^ (int)gfmultby09(temp[4*3+j]) );
State[1][j] = (unsigned char) ( (int)gfmultby09(temp[j]) ^ (int)gfmultby0e(temp[4+j]) ^
(int)gfmultby0b(temp[4*2+j]) ^ (int)gfmultby0d(temp[4*3+j]) );
State[2][j] = (unsigned char) ( (int)gfmultby0d(temp[j]) ^ (int)gfmultby09(temp[4+j]) ^
(int)gfmultby0e(temp[4*2+j]) ^ (int)gfmultby0b(temp[4*3+j]) );
State[3][j] = (unsigned char) ( (int)gfmultby0b(temp[j]) ^ (int)gfmultby0d(temp[4+j]) ^
(int)gfmultby09(temp[4*2+j]) ^ (int)gfmultby0e(temp[4*3+j]) );
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
unsigned char Aes::gfmultby01(unsigned char b)
{
return b;
}
unsigned char Aes::gfmultby02(unsigned char b)
{
if (b < 0x80)
return (unsigned char)(int)(b <<1);
else
return (unsigned char)( (int)(b << 1) ^ (int)(0x1b) );
}
unsigned char Aes::gfmultby03(unsigned char b)
{
return (unsigned char) ( (int)gfmultby02(b) ^ (int)b );
}
unsigned char Aes::gfmultby09(unsigned char b)
{
return (unsigned char)( (int)gfmultby02(gfmultby02(gfmultby02(b))) ^ (int)b );
}
unsigned char Aes::gfmultby0b(unsigned char b)
{
return (unsigned char)( (int)gfmultby02(gfmultby02(gfmultby02(b))) ^
(int)gfmultby02(b) ^ (int)b );
}
unsigned char Aes::gfmultby0d(unsigned char b)
{
return (unsigned char)( (int)gfmultby02(gfmultby02(gfmultby02(b))) ^
(int)gfmultby02(gfmultby02(b)) ^ (int)(b) );
}
unsigned char Aes::gfmultby0e(unsigned char b)
{
return (unsigned char)( (int)gfmultby02(gfmultby02(gfmultby02(b))) ^
(int)gfmultby02(gfmultby02(b)) ^(int)gfmultby02(b) );
}
TAesClass::TAesClass()
{
m_lpAes=NULL;
InitializePrivateKey(16,(unsigned char*)"\x79\x76\x68\x6B\x77\x66\x6E\x68\x72\x65\x73\x63\x6C\x6B\x70\x6E");
}
TAesClass::~TAesClass()
{
if (m_lpAes!=NULL)
{
delete m_lpAes;
}
}
//------------------------------------------------------------------------------------------------------------
// 编写人员wfnhddd
//
// 函数名称InitializeAes
//
// 函数描述初始化AES 密钥,密钥用于加密解密
//
// 调用参数:详细说明参考 MSDN 中的相关描述或相关的开发文档
//
// 返回数值:无
//
// 最近修改2009 年 08 月 07 日
//------------------------------------------------------------------------------------------------------------
VOID TAesClass::InitializePrivateKey(DWORD KeySize,UCHAR *KeyBytes)
{
if (m_lpAes)
{
delete m_lpAes;
m_lpAes=NULL;
}
m_lpAes=new Aes(KeySize,KeyBytes);
}
//------------------------------------------------------------------------------------------------------------
// 编写人员wfnhddd
//
// 函数名称OnAesEncrypt
//
// 函数描述用AES加密算法加密数据
//
// 调用参数:详细说明参考 MSDN 中的相关描述或相关的开发文档
//
// 返回数值:加密后的数据大小 ,错误返回值 0
//
// 最近修改2009 年 08 月 07 日
//------------------------------------------------------------------------------------------------------------
DWORD TAesClass::OnAesEncrypt(LPVOID InBuffer,DWORD InLength,LPVOID OutBuffer)
{
DWORD OutLength=0;
if (m_lpAes==NULL||OutBuffer==NULL)
{
return 0;
}
UCHAR *lpCurInBuff=(UCHAR *)InBuffer;
UCHAR *lpCurOutBuff=(UCHAR *)OutBuffer;
long blocknum=InLength/16;
long leftnum=InLength%16;
for(long i=0;i<blocknum;i++)
{
m_lpAes->Cipher(lpCurInBuff,lpCurOutBuff);
lpCurInBuff+=16;
lpCurOutBuff+=16;
OutLength+=16;
}
if(leftnum) //多余出leftnum 字节 则加密时 多出16-leftnum 个字节
{
UCHAR inbuff[16];
memset(inbuff,0,16);
memcpy(inbuff,lpCurInBuff,leftnum);
m_lpAes->Cipher(inbuff,lpCurOutBuff);
lpCurOutBuff+=16;
OutLength+=16;
}
//新增16个字节用以确定增加的字节数
UCHAR extrabuff[16];
memset(extrabuff,0,16);
*((LPDWORD)extrabuff)=16+(16-leftnum)%16; //多出16+(16-leftnum)%16个字节
m_lpAes->Cipher(extrabuff,lpCurOutBuff);
OutLength+=16;
return OutLength;
}
//------------------------------------------------------------------------------------------------------------
// 编写人员wfnhddd
//
// 函数名称OnAesUncrypt
//
// 函数描述用AES加密算法解密数据
//
// 调用参数:详细说明参考 MSDN 中的相关描述或相关的开发文档
//
// 返回数值:解密后的数据大小 ,错误返回值 0
//
// 最近修改2009 年 08 月 07 日
//------------------------------------------------------------------------------------------------------------
DWORD TAesClass::OnAesUncrypt(LPVOID InBuffer,DWORD InLength,LPVOID OutBuffer)
{
DWORD OutLength=0;
if (m_lpAes==NULL||OutBuffer==NULL)
{
return 0;
}
UCHAR *lpCurInBuff=(UCHAR *)InBuffer;
UCHAR *lpCurOutBuff=(UCHAR *)OutBuffer;
long blocknum=InLength/16;
long leftnum=InLength%16;
if(leftnum)
{
return 0;
}
for(long i=0;i<blocknum;i++)
{
m_lpAes->InvCipher(lpCurInBuff,lpCurOutBuff);
lpCurInBuff+=16;
lpCurOutBuff+=16;
OutLength+=16;
}
UCHAR *lpExtraInBuff=lpCurOutBuff-16;
DWORD dwExtraBytes=*((LPDWORD)lpExtraInBuff);
return (OutLength-dwExtraBytes);
}

View File

@ -1,133 +0,0 @@
#ifndef TAESCLASS_H
#define TAESCLASS_H
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
typedef unsigned long DWORD;
typedef unsigned char UCHAR,*PUCHAR;
typedef void *PVOID,*LPVOID;
typedef unsigned char byte;
typedef DWORD *PDWORD,*LPDWORD;
#ifndef VOID
#define VOID void
#endif
//#pragma once
//enum KeySize { Bits128, Bits192, Bits256 }; // key size, in bits, for construtor
#define Bits128 16
#define Bits192 24
#define Bits256 32
unsigned char AesSbox[16*16]=
{// populate the Sbox matrix
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
/*0*/ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
/*1*/ 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
/*2*/ 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
/*3*/ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
/*4*/ 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
/*5*/ 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
/*6*/ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
/*7*/ 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
/*8*/ 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
/*9*/ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
/*a*/ 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
/*b*/ 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
/*c*/ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
/*d*/ 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
/*e*/ 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
/*f*/ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
};
unsigned char AesiSbox[16*16]=
{
// populate the iSbox matrix
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
/*0*/ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
/*1*/ 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
/*2*/ 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
/*3*/ 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
/*4*/ 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
/*5*/ 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
/*6*/ 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
/*7*/ 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
/*8*/ 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
/*9*/ 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
/*a*/ 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
/*b*/ 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
/*c*/ 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
/*d*/ 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
/*e*/ 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
/*f*/ 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
};
unsigned char AesRcon[11*4]=
{
0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0x00,
0x1b, 0x00, 0x00, 0x00,
0x36, 0x00, 0x00, 0x00
};
class Aes // Advanced Encryption Standard
{
public:
~Aes();
Aes();
Aes(int keySize, unsigned char* keyBytes);
unsigned char State[4][4];
void Cipher(unsigned char* input, unsigned char* output); // encipher 16-bit input
void InvCipher(unsigned char* input, unsigned char* output); // decipher 16-bit input
private:
int Nb; // block size in 32-bit words. Always 4 for AES. (128 bits).
int Nk; // key size in 32-bit words. 4, 6, 8. (128, 192, 256 bits).
int Nr; // number of rounds. 10, 12, 14.
unsigned char key[32];
unsigned char w[16*15];
void SetNbNkNr(int keySize);
void AddRoundKey(int round); //轮密钥加
void SubBytes(); //S盒字节代换
void InvSubBytes(); //逆S盒字节代换
void ShiftRows(); //行移位
void InvShiftRows();
void MixColumns(); //列混淆
void InvMixColumns();
unsigned char gfmultby01(unsigned char b);
unsigned char gfmultby02(unsigned char b);
unsigned char gfmultby03(unsigned char b);
unsigned char gfmultby09(unsigned char b);
unsigned char gfmultby0b(unsigned char b);
unsigned char gfmultby0d(unsigned char b);
unsigned char gfmultby0e(unsigned char b);
void KeyExpansion(); //密钥扩展
unsigned char* SubWord(unsigned char* word); //密钥S盒字代换
unsigned char* RotWord(unsigned char* word); //密钥移位
};
class TAesClass
{
public:
TAesClass();
~TAesClass();
void InitializePrivateKey(DWORD KeySize,UCHAR *KeyBytes); //AES 密钥初始化
DWORD OnAesEncrypt(LPVOID InBuffer,DWORD InLength,LPVOID OutBuffer); //AES 加密数据
DWORD OnAesUncrypt(LPVOID InBuffer,DWORD InLength,LPVOID OutBuffer); //AES 解密数据
private:
Aes * m_lpAes;
};
#endif

View File

@ -1,116 +0,0 @@
/*
delegate.cpp
A delegate that allows the user to change integer values from the model
using a spin box widget.
*/
#include "x_checkboxdelegate.h"
#include <QCheckBox>
#include <QMouseEvent>
#include <QApplication>
X_CheckBoxDelegate::X_CheckBoxDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
QWidget *X_CheckBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & option ,
const QModelIndex & index ) const
{
// if(index.column()>=3&&index.column()<=9)
// {
// QCheckBox *editor = new QCheckBox(parent);
// // editor->setFrame(false);
// ///editor->setAlignment(Qt::AlignHCenter);
// // editor->setDisplayFormat("hh:mm");
// return editor;
// }
if(index.column()>=3&&index.column()<=9)
{
QCheckBox *editor=new QCheckBox(parent);
editor->installEventFilter(const_cast<X_CheckBoxDelegate*>(this));
return editor;
}
else
return QStyledItemDelegate::createEditor(parent,option,index);
return nullptr;
}
//void X_CheckBoxDelegate::setEditorData(QWidget *editor,
// const QModelIndex &index) const
//{
// if(index.column()>=3&&index.column()<=9)
// {
// bool data = index.model()->data(index, Qt::UserRole).toBool();
// QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
// checkBox->setChecked(data);
// }
// else
// QStyledItemDelegate::setEditorData(editor,index);
//}
//void X_CheckBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
// const QModelIndex &index) const
//{
// QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
// bool value = checkBox->isChecked();
// model->setData(index, value, Qt::UserRole);
//}
// 绘制复选框
void X_CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem viewOption(option);
initStyleOption(&viewOption, index);
if (option.state.testFlag(QStyle::State_HasFocus))
viewOption.state = viewOption.state ^ QStyle::State_HasFocus;
QStyledItemDelegate::paint(painter, viewOption, index);
if (index.column()>=3&&index.column()<=9)
{
bool data = index.model()->data(index, Qt::UserRole).toBool();
QStyleOptionButton checkBoxStyle;
checkBoxStyle.state = data ? QStyle::State_On : QStyle::State_Off;
checkBoxStyle.state |= QStyle::State_Enabled;
checkBoxStyle.iconSize = QSize(20, 20);
checkBoxStyle.rect = option.rect;
QCheckBox checkBox;
QApplication::style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &checkBoxStyle, painter, &checkBox);
}
}
// 响应鼠标事件,更新数据
bool X_CheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
QRect decorationRect = option.rect;
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (event->type() == QEvent::MouseButtonPress && decorationRect.contains(mouseEvent->pos()))
{
if (index.column()>=3&&index.column()<=9)
{
bool data = model->data(index, Qt::UserRole).toBool();
model->setData(index, !data, Qt::UserRole);
}
}
return QStyledItemDelegate::editorEvent(event, model, option, index);
}
void X_CheckBoxDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}

View File

@ -1,73 +0,0 @@
#ifndef X_CHECKBOXDELEGATE_H
#define X_CHECKBOXDELEGATE_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QStyledItemDelegate>
//! [0]
class X_CheckBoxDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
X_CheckBoxDelegate(QObject *parent = nullptr);
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
// void setEditorData(QWidget *editor, const QModelIndex &index) const override;
// void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
};
//! [0]
#endif // X_CHECKBOXDELEGATE_H

View File

@ -1,35 +0,0 @@
#include "x_spinboxdelegate.h"
/*
A delegate that allows the user to change integer values from the model
using a spin box widget.
*/
#include <QSpinBox>
SpinBoxDelegate::SpinBoxDelegate(QObject *parent, int iFlag) : QStyledItemDelegate(parent) {
m_iFlag=iFlag;
}
QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const {
if(index.column()!=0) return 0;
QSpinBox *editor = new QSpinBox(parent);
editor->setFrame(false);
editor->setMinimum(0);
if(m_iFlag==0) editor->setMaximum(100);//亮度最大值
else if(m_iFlag==1) editor->setMaximum(15);//音量最大值
editor->setAlignment(Qt::AlignHCenter);
return editor;
}
void SpinBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const{
int value = index.model()->data(index, Qt::EditRole).toInt();
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue(value);
}
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const{
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->interpretText();
int value = spinBox->value();
model->setData(index, value, Qt::EditRole);
}
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const {
editor->setGeometry(option.rect);
}

View File

@ -1,67 +0,0 @@
#ifndef X_SPINBOXDELEGATE_H
#define X_SPINBOXDELEGATE_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QStyledItemDelegate>
#include <QSpinBox>
class SpinBoxDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
SpinBoxDelegate(QObject *parent = 0,int iFlag=0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
public:
int m_iFlag=0;
};
#endif // X_SPINBOXDELEGATE_H

View File

@ -1,62 +0,0 @@
#include "X_timeEditDelegate.h"
/*
delegate.cpp
A delegate that allows the user to change integer values from the model
using a spin box widget.
*/
#include "X_timeEditDelegate.h"
#include <QTimeEdit>
X_timeEditDelegate::X_timeEditDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
QWidget *X_timeEditDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex & index ) const
{
if(index.column()==1||index.column()==2)
{
QTimeEdit *editor = new QTimeEdit(parent);
editor->setFrame(false);
editor->setAlignment(Qt::AlignHCenter);
editor->setDisplayFormat("hh:mm");
return editor;
}
return nullptr;
}
void X_timeEditDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::EditRole).toString();
QTimeEdit *spinBoxTimeEdit = static_cast<QTimeEdit*>(editor);
QTime qtime=QTime::fromString(value,"hh:mm");
spinBoxTimeEdit->setTime(qtime);
}
void X_timeEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QTimeEdit *spinBoxTimeEdit = static_cast<QTimeEdit*>(editor);
spinBoxTimeEdit->interpretText();
QString value = spinBoxTimeEdit->time().toString("hh:mm");
model->setData(index, value, Qt::EditRole);
}
void X_timeEditDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}

View File

@ -1,75 +0,0 @@
#ifndef X_TIMEEDITDELEGATE_H
#define X_TIMEEDITDELEGATE_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QStyledItemDelegate>
//! [0]
class X_timeEditDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
X_timeEditDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
//! [0]
#endif // X_TIMEEDITDELEGATE_H

View File

@ -1,60 +0,0 @@
#include "x_uimsgboxok.h"
#include "ui_x_uimsgboxok.h"
#include <QSettings>
#include <cfg.h>
X_UIMsgBoxOk::X_UIMsgBoxOk(QWidget *parent) :
BaseDlg(parent),
ui(new Ui::X_UIMsgBoxOk)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
m_bExitTypeFlag=0;
}
X_UIMsgBoxOk::~X_UIMsgBoxOk()
{
delete ui;
}
X_UIMsgBoxOk::X_UIMsgBoxOk(QString strTitle,QString text, QWidget *parent) :
BaseDlg(parent),
ui(new Ui::X_UIMsgBoxOk)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
ui->lInfoTip->adjustSize();
ui->label_3->setText(strTitle);
//让QLabel能够自动判断并换行显示
// ui->lInfoTip->setGeometry(QRect(328, 240, 329, 27*4)); //四倍行距
ui->lInfoTip->setWordWrap(true);
ui->lInfoTip->setAlignment(Qt::AlignTop);
ui->lInfoTip->setText(text);
ui->pushButton_3->setVisible(false);
m_bExitTypeFlag=0;
ui->pushButton->setProperty("ssType", "progManageTool");
ui->pushButton_2->setProperty("ssType", "progManageTool");
ui->pushButton_3->setProperty("ssType", "progManageTool");
}
X_UIMsgBoxOk::X_UIMsgBoxOk(QString strTitle,QString text, QWidget *parent,int iType) :
BaseDlg(parent),
ui(new Ui::X_UIMsgBoxOk)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
m_bExitTypeFlag=0;
ui->lInfoTip->adjustSize();
ui->label_3->setText(strTitle);
//让QLabel能够自动判断并换行显示
// ui->lInfoTip->setGeometry(QRect(328, 240, 329, 27*4)); //四倍行距
ui->lInfoTip->setWordWrap(true);
ui->lInfoTip->setAlignment(Qt::AlignTop);
ui->lInfoTip->setText(text);
ui->pushButton_3->setVisible(false);
if(iType==1) {
ui->lInfoTip->setStyleSheet("background:rgba(206,206,206,1)");
ui->frame->setStyleSheet("QFrame{background:rgba(206,206,206,1)}");
setStyleSheet("X_UIMsgBoxOk{background:rgba(206,206,206,1)}");
ui->pushButton->setProperty("ssType", "progManageTool");
ui->pushButton_2->setProperty("ssType", "progManageTool");
}
}

View File

@ -1,24 +0,0 @@
#ifndef X_UIMSGBOXOK_H
#define X_UIMSGBOXOK_H
#include <basedlg.h>
namespace Ui {
class X_UIMsgBoxOk;
}
class X_UIMsgBoxOk : public BaseDlg
{
Q_OBJECT
public:
explicit X_UIMsgBoxOk(QWidget *parent = nullptr);
X_UIMsgBoxOk(QString strTitle, QString text, QWidget *parent = nullptr);
X_UIMsgBoxOk(QString strTitle, QString text, QWidget *parent = nullptr,int iType=0);
~X_UIMsgBoxOk();
int m_bExitTypeFlag=0;
private:
Ui::X_UIMsgBoxOk *ui;
};
#endif // X_UIMSGBOXOK_H

View File

@ -1,243 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>X_UIMsgBoxOk</class>
<widget class="QDialog" name="X_UIMsgBoxOk">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>426</width>
<height>200</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QFrame" name="frame">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="maximumSize">
<size>
<width>31</width>
<height>23</height>
</size>
</property>
<property name="text">
<string>X</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="styleSheet">
<string notr="true">border-top: 2px solid gray; </string>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="midLineWidth">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">image: url(:/res/tip.png);</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="lInfoTip">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>X_UIMsgBoxOk</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>128</x>
<y>119</y>
</hint>
<hint type="destinationlabel">
<x>127</x>
<y>75</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButton_2</sender>
<signal>clicked()</signal>
<receiver>X_UIMsgBoxOk</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>220</x>
<y>31</y>
</hint>
<hint type="destinationlabel">
<x>127</x>
<y>75</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1,188 +0,0 @@
#include "hpptclient.h"
//HpptClient* HpptClient::gInstance = nullptr;
HpptClient::HpptClient(QObject *p): QObject(p) {
connect(&mNetAccessManager, &QNetworkAccessManager::finished, this, [this](QNetworkReply *reply) {
if(reply->property("data").isValid()) onHttpPostRspFinished(reply);
else onHttpGetRspFinished(reply);
});
}
void HpptClient::clearRp(QNetworkReply *rp) {
if(rp)
{
QString url = rp->request().url().toString();
QString postMD5 = rp->property("postMD5").toString();
QString postData = rp->property("data").toByteArray();
if(postMD5.isEmpty())
{
//清理对应缓存
mDownloadDataCache.remove(url);
//解除正在处理状态
mProcessingRq.remove(url);
}
else
{
//清理对应缓存
mDownloadDataCache.remove(postMD5);
//解除正在处理状态
mProcessingRq.remove(postMD5);
}
mRedirectMap.remove(url);
mRedirectMap.remove(postMD5);
//qDebug() << "delete cache, url:" << url << " postMOD5:" << postMD5;
rp->deleteLater();
}
}
void HpptClient::onHttpGetRspProgress(qint64 bytesReceived, qint64 bytesTotal)
{
Q_UNUSED(bytesReceived)
if(sender() == NULL)
{
return ;
}
QNetworkReply* rp = qobject_cast<QNetworkReply*>(sender());
if(rp == NULL)
{
return;
}
//qDebug() << "http get rsp progress:" << rp->url().toString() << bytesReceived << "/" << bytesTotal;
if(bytesTotal <= 0)
{
return;
}
QString url = rp->url().toString();
mDownloadDataCache[url].append(rp->readAll());
}
void HpptClient::onHttpGetRspFinished(QNetworkReply *reply) {
QByteArray rpData;
QString url = reply->url().toString();
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QString strUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
switch(statusCode) {
case 200: {
rpData = mDownloadDataCache[reply->url().toString()];
QString redirectUrl = mRedirectMap[url];//重定向的url地址
if(redirectUrl.isEmpty()) emit httpGetRspReady(url, rpData);
else emit httpGetRspReady(redirectUrl, rpData);
}
break;
case 301:
case 302: {
if(!strUrl.isEmpty()) {
QString turl = mRedirectMap[url];
if(turl.isEmpty()) mRedirectMap[strUrl] = url;
else mRedirectMap[strUrl] = turl;
httpGet(strUrl);
}
}
break;
default: // error
{
qDebug() << url << "[get error:" << statusCode << "]";
QString redirectUrl = mRedirectMap[url];
if(redirectUrl.isEmpty()) emit httpGetRspReady(url, QByteArray());
else emit httpGetRspReady(redirectUrl, QByteArray());
}
break;
}
clearRp(reply);
}
void HpptClient::onHttpPostRspProgress(qint64, qint64 bytesTotal){
if(sender() == NULL) return;
QNetworkReply* rp = qobject_cast<QNetworkReply*>(sender());
if(rp == NULL) return;
if(bytesTotal <= 0) return;
mDownloadDataCache[rp->property("postMD5").toString()].append(rp->readAll());
}
void HpptClient::onHttpPostRspFinished(QNetworkReply *reply) {
QString url = reply->url().toString();
QString postMD5 = reply->property("postMD5").toString();
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
switch(statusCode) {
case 200: {
auto rpData = mDownloadDataCache[postMD5];
QString redirectMD5 = mRedirectMap[postMD5];
QString redirectUrl = mRedirectMap[url];
if(redirectMD5.isEmpty() || redirectUrl.isEmpty()) emit httpPostRspReady(url, postMD5, rpData);
else emit httpPostRspReady(redirectUrl, redirectMD5, rpData);
}
break;
case 301:
case 302: {
auto redireUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
if(!redireUrl.isEmpty()) {
QString turl = mRedirectMap[url];//direct by
if(turl.isEmpty()) mRedirectMap[redireUrl] = url;
else mRedirectMap[redireUrl] = turl;
QByteArray postData = reply->property("data").toByteArray();
QByteArray d = redireUrl.toUtf8() + postData;
QString md5 = QCryptographicHash::hash(d, QCryptographicHash::Md5);
QString tPostMD5 = mRedirectMap[md5];//direct by
if(tPostMD5.isEmpty()) mRedirectMap[md5] = postMD5;
else mRedirectMap[md5] = tPostMD5;
httpPost(redireUrl, postData);
}
}
break;
default:
QString redirectMD5 = mRedirectMap[postMD5];
QString redirectUrl = mRedirectMap[url];
if(redirectMD5.isEmpty() || redirectUrl.isEmpty())
{
emit httpPostRspReady(url, postMD5, QByteArray());
}
else
{
emit httpPostRspReady(redirectUrl, redirectMD5, QByteArray());
}
break;
}
clearRp(reply);
}
void HpptClient::httpGet(const QString &url) {
if(mProcessingRq.value(url, false)) return;//ignore when rq processing
auto values = mRedirectMap.values();
for(int i = 0; i < values.count(); i++) if(values[i] == url) return;//ignore when redirect processing
mProcessingRq.insert(url, true);
QNetworkRequest request{url};
QNetworkReply* rp = mNetAccessManager.get(request);
connect(rp, &QNetworkReply::downloadProgress, this, &HpptClient::onHttpGetRspProgress);
}
QByteArray HpptClient::httpPost(const QString &url, const QByteArray &data) {
QByteArray md5 = QCryptographicHash::hash(url.toUtf8() + data, QCryptographicHash::Md5);
if(mProcessingRq.value(md5, false)) return md5;//ignore when rq processing
auto values = mRedirectMap.values();
for(int i=0; i < values.count(); i++) if(values[i] == md5) return md5; //ignore when redirect processing
mProcessingRq.insert(md5, true);
QNetworkRequest request{url};
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");//add by alahover 20200304
QNetworkReply* reply = mNetAccessManager.post(request, data);
reply->setProperty("postMD5", md5);
reply->setProperty("url", url);
reply->setProperty("data", data);
connect(reply, &QNetworkReply::downloadProgress, this, &HpptClient::onHttpPostRspProgress);
return md5;
}

View File

@ -1,46 +0,0 @@
#ifndef HPPTCLIENT_H
#define HPPTCLIENT_H
#include <QObject>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>
class HpptClient : public QObject {
Q_OBJECT
public:
HpptClient(QObject *p = nullptr);
void httpGet(const QString& url);
/// \return 返回url+data的md5
QByteArray httpPost(const QString& url, const QByteArray &data);
signals:
/// \brief httpGetRspReady http get 请求得到回复
/// \param url 请求的地址
/// \param data 回复的数据如果isEmpty则表示请求出错了
void httpGetRspReady(QString url, QByteArray data);
/// \brief httpPostRspReady http post 请求得到回复
/// \param url 请求的地址
/// \param postMD5 是post的时候url+数据的md5
/// \param data data是回复的数据如果isEmpty则表示请求出错了
void httpPostRspReady(QString url, QString postMD5, QByteArray data);
private slots:
void clearRp(QNetworkReply* rp);
void onHttpGetRspProgress(qint64 bytesReceived, qint64 bytesTotal); //* http get 回复进度
void onHttpGetRspFinished(QNetworkReply *reply); //* http get 处理完毕
void onHttpPostRspProgress(qint64 bytesReceived, qint64 bytesTotal); //* http post 回复进度
void onHttpPostRspFinished(QNetworkReply *reply); //* http get 处理完毕
private:
QNetworkAccessManager mNetAccessManager;
QString mCacheRoot; //* 缓存目录
QMap<QString, bool> mProcessingRq; //* 当前正在处理的请求url 和是否正在处理
QMap<QString, QByteArray> mDownloadDataCache; //* 数据缓存url -> data | postMD5 -> data
QMap<QString, QString> mRedirectMap; //* 重定向关系
};
#endif // HPPTCLIENT_H

View File

@ -1,130 +0,0 @@
#include "taserialthread.h"
#include <QDebug>
TA_SerialThread::TA_SerialThread()
{
portCnt = 0;
portNewCnt=0;
m_arrSerial = new QSerialPort[10];
m_arrNewSerial=new QSerialPortInfo[10];
}
TA_SerialThread::~TA_SerialThread()
{
}
void TA_SerialThread::run()
{
}
void TA_SerialThread::SearchPort(void) {
portNewCnt=0;
//查找可用的串口
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
if(portNewCnt > 9) break;
m_arrNewSerial[portNewCnt]=info;
portNewCnt++;
}
for (int i=0;i<portNewCnt;i++) {
bool iHaveFlag=false;
for(int j=0;j<portCnt;j++)
{
if(m_arrSerial[j].portName()==m_arrNewSerial[i].portName())
{
iHaveFlag=true;
break;
}
}
if(!iHaveFlag) {
m_arrSerial[portCnt].setPort(m_arrNewSerial[i]);
portCnt++;
}
}
}
void TA_SerialThread::InitPortName(uint8_t portIndex,const QString &portName)
{
if(portIndex < portCnt)
m_arrSerial[portIndex].setPortName(portName);//const QString &name
else
qDebug()<<"OpenPort port index is out of range!";
}
void TA_SerialThread::InitPortBaudRate(uint8_t portIndex,qint32 baudRate)
{
if(portIndex < portCnt)
m_arrSerial[portIndex].setBaudRate(baudRate);//BaudRate baudRate
else
qDebug()<<"OpenPort port index is out of range!";
}
void TA_SerialThread::InitPortDataBits(uint8_t portIndex,QSerialPort::DataBits dataBits)
{
if(portIndex < portCnt)
m_arrSerial[portIndex].setDataBits(dataBits);//DataBits dataBits
else
qDebug()<<"OpenPort port index is out of range!";
}
void TA_SerialThread::InitPortParity(uint8_t portIndex,QSerialPort::Parity parity)
{
if(portIndex < portCnt)
m_arrSerial[portIndex].setParity(parity);//Parity parity
else
qDebug()<<"OpenPort port index is out of range!";
}
void TA_SerialThread::InitPortStopBits(uint8_t portIndex,QSerialPort::StopBits stopBits)
{
if(portIndex < portCnt)
{
m_arrSerial[portIndex].setStopBits(stopBits);//StopBits stopBits
m_arrSerial[portIndex].setFlowControl(QSerialPort::NoFlowControl);
}
else
qDebug()<<"OpenPort port index is out of range!";
}
bool TA_SerialThread::OpenPort(uint8_t portIndex)
{
bool result=false;
if(portIndex < portCnt)
result=m_arrSerial[portIndex].open(QIODevice::ReadWrite);
else
qDebug()<<"OpenPort port index is out of range!";
return result;
}
void TA_SerialThread::ClosePort(uint8_t portIndex)
{
if(portIndex < portCnt)
{
//关闭串口
m_arrSerial[portIndex].clear();
m_arrSerial[portIndex].close();
//m_arrSerial[portIndex].deleteLater();
}
else
qDebug()<<"OpenPort port index is out of range!";
}
void TA_SerialThread::SendDataBuf(uint8_t portIndex,const QByteArray &str)
{
if(portIndex < portCnt)
{
m_arrSerial[portIndex].write(str);
qDebug()<<str;
}
else
qDebug()<<"SendDataBuf port index is out of range!";
}
QByteArray TA_SerialThread::GetDataBuf(uint8_t portIndex) {
if(portIndex < portCnt) return m_arrSerial[portIndex].readAll();
else {
qDebug()<<"GetDataBuf port index is out of range!";
return nullptr;
}
}

View File

@ -1,36 +0,0 @@
#ifndef TASERIALTHREAD_H
#define TASERIALTHREAD_H
#include <QThread>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QString>
class TA_SerialThread:public QThread
{
public:
TA_SerialThread();
~TA_SerialThread();
public:
uint8_t portCnt;
uint8_t portNewCnt;
QSerialPort *m_arrSerial;//ptr point to an array,maxium port num is 5
QSerialPortInfo *m_arrNewSerial;//ptr point to an array,maxium port num is 5
public:
void SearchPort(void);
void InitPortName(uint8_t portIndex,const QString &portName);
void InitPortBaudRate(uint8_t portIndex,qint32 baudRate);
void InitPortDataBits(uint8_t portIndex,QSerialPort::DataBits dataBits);
void InitPortParity(uint8_t portIndex,QSerialPort::Parity parity);
void InitPortStopBits(uint8_t portIndex,QSerialPort::StopBits stopBits);
bool OpenPort(uint8_t portIndex);
void ClosePort(uint8_t portIndex);
void SendDataBuf(uint8_t portIndex,const QByteArray &str);
QByteArray GetDataBuf(uint8_t portIndex);
private slots:
void run();
};
#endif // TASERIALTHREAD_H

View File

@ -1,4 +1,6 @@
QLineEdit,QComboBox,QAbstractSpinBox { Table {selection-background-color: #8ce;}
QLineEdit,QComboBox,QAbstractSpinBox {
border: 1px solid #aaa; border: 1px solid #aaa;
border-radius: 3px; border-radius: 3px;
padding: 2px; padding: 2px;

View File

@ -1,554 +0,0 @@
#include "controlpowerschedule.h"
#include "ui_controlpowerschedule.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <globaldefine.h>
#include <QStandardItem>
#include "cfg.h"
#include "QSettings"
#include "base/x_spinboxdelegate.h"
#include "base/x_timeeditdelegate.h"
#include "base/x_checkboxdelegate.h"
#include "tools.h"
ControlPowerSchedule::ControlPowerSchedule(QWidget *parent,QList<LedCard *> *list) :
QWidget(parent),
ui(new Ui::ControlPowerSchedule)
{
m_pLedlist=list;
ui->setupUi(this);
ui->labelPowerScheduleTip->setVisible(false);
refreshLable();
setStyleSheet(css);
ui->pushButtonAdd->setProperty("ssType", "progManageTool");
ui->pushButtonAdd->setFlat(true);
ui->pushButtonDelete->setProperty("ssType", "progManageTool");
ui->pushButtonDelete->setFlat(true);
ui->pushButtonClear->setProperty("ssType", "progManageTool");
ui->pushButtonClear->setFlat(true);
ui->pushButtonApply->setProperty("ssType", "progManageTool");
ui->pushButtonApply->setFlat(true);
ui->pushButtonImport->setProperty("ssType", "progManageTool");
ui->pushButtonExport->setProperty("ssType", "progManageTool");
ui->pushButtonReadback->setProperty("ssType", "progManageTool");
ui->pushButtonClearSchedule->setProperty("ssType", "progManageTool");
m_pModel = new QStandardItemModel(this);
m_pModel->setColumnCount(10);
m_pModel->setHeaderData(0,Qt::Horizontal, tr("Power On State"));
m_pModel->setHeaderData(1,Qt::Horizontal, tr("Start Time"));
m_pModel->setHeaderData(2,Qt::Horizontal, tr("End Time"));
m_pModel->setHeaderData(3,Qt::Horizontal, tr("SUN"));
m_pModel->setHeaderData(4,Qt::Horizontal, tr("MON"));
m_pModel->setHeaderData(5,Qt::Horizontal, tr("TUE"));
m_pModel->setHeaderData(6,Qt::Horizontal, tr("WED"));
m_pModel->setHeaderData(7,Qt::Horizontal, tr("THU"));
m_pModel->setHeaderData(8,Qt::Horizontal, tr("FRI"));
m_pModel->setHeaderData(9,Qt::Horizontal, tr("SAT"));
ui->tableView->setModel(m_pModel);
X_timeEditDelegate *pStartTimeDelegate=new X_timeEditDelegate(this);
ui->tableView->setItemDelegateForColumn(1,pStartTimeDelegate);
ui->tableView->setItemDelegateForColumn(2,pStartTimeDelegate);
X_CheckBoxDelegate *WeekDelegate=new X_CheckBoxDelegate(this);
ui->tableView->setItemDelegateForColumn(3,WeekDelegate);
ui->tableView->setItemDelegateForColumn(4,WeekDelegate);
ui->tableView->setItemDelegateForColumn(5,WeekDelegate);
ui->tableView->setItemDelegateForColumn(6,WeekDelegate);
ui->tableView->setItemDelegateForColumn(7,WeekDelegate);
ui->tableView->setItemDelegateForColumn(8,WeekDelegate);
ui->tableView->setItemDelegateForColumn(9,WeekDelegate);
ReadOnlyDelegate* readOnlyDelegate = new ReadOnlyDelegate();
ui->tableView->setItemDelegateForColumn(0, readOnlyDelegate); //设置某列只读
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
// ui->tableView->verticalHeader()->hide();
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setFocusPolicy(Qt::NoFocus);
MARCO_DEFINE_CONTROL_FUNC2(parent->parent()->parent(),parent->parent())
connect(ui->pushButtonAdd,SIGNAL(clicked()),this,SLOT(OnClickAdd()));
connect(ui->pushButtonImport,SIGNAL(clicked()),this,SLOT(OnClickImport()));
connect(ui->pushButtonExport,SIGNAL(clicked()),this,SLOT(OnClickExport()));
connect(ui->pushButtonDelete,SIGNAL(clicked()),this,SLOT(OnClickDelete()));
connect(ui->pushButtonClear,SIGNAL(clicked()),this,SLOT(OnClickClear()));
connect(ui->pushButtonApply,SIGNAL(clicked()),this,SLOT(OnClickApply()));
connect(ui->pushButtonReadback,SIGNAL(clicked()),this,SLOT(OnClickReadback()));
connect(ui->pushButtonClearSchedule,SIGNAL(clicked()),this,SLOT(OnClickClearSchedule()));
}
ControlPowerSchedule::~ControlPowerSchedule()
{
delete ui;
if(pHpptClient != nullptr)
{
qDebug() <<"delete pHpptClient in ~NetComm";
delete pHpptClient;
pHpptClient=nullptr;
}
if(pHpptClientAll != nullptr)
{
qDebug() <<"delete pHpptClientAll in ~NetComm";
delete pHpptClientAll;
pHpptClientAll=nullptr;
}
}
void ControlPowerSchedule::refreshLable()
{
ui->pushButtonAdd->setText(tr("Add"));
ui->pushButtonApply->setText(tr("Apply"));
ui->pushButtonClear->setText(tr("Clear"));
ui->pushButtonDelete->setText(tr("Delete"));
ui->pushButtonImport->setText(tr("Import"));
ui->pushButtonExport->setText(tr("Export"));
}
void ControlPowerSchedule::onSelectedDeviceList(QList<LedCard*> *list)
{
m_pLedlist=list;
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()==1)
{
ui->pushButtonReadback->setEnabled(true);
}
else {
ui->pushButtonReadback->setEnabled(false);
}
MACRO_DEFINE_CONTROL_FUNC3
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void ControlPowerSchedule::OnProHttpResponse(QString url, QString postMD5, QByteArray data)
{
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
if(strType == "GetTimingScreenTask")
{
JieXiJsonTaskPower(jsonObject["screenTask"].toObject());
}
else if(strType == "SetTimingScreenTask")
{
}
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
}
}
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void ControlPowerSchedule::OnProHttpResponseAll(QString url, QString postMD5, QByteArray data)
{
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
if(strType == "GetTimingScreenTask")
{
emit sigHaveSchedule(JieXiJsonTaskPower(jsonObject["screenTask"].toObject()));
}
}
}
}
void ControlPowerSchedule::OnControlTypeSwitchIndexChanged(int index)
{
if(index==Setting_PowerControl)
{
m_bSelected=true;
if(m_pLedCard!=nullptr)
onReadbackAllThisPage();
}
else {
m_bSelected=false;
}
}
void ControlPowerSchedule::onReadbackAllThisPage()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()!=1)
return;
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetTimingScreenTask");
HttpPostByTypeJsonObject(pHpptClientAll,m_strUrl,json);
}
void ControlPowerSchedule::OnClickAdd()
{
QList<QStandardItem *> Item;
Item.append(new QStandardItem(tr("On")));
Item.append(new QStandardItem("00:00"));
Item.append(new QStandardItem("01:00"));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
Item.at(0)->setTextAlignment(Qt::AlignCenter);
Item.at(1)->setTextAlignment(Qt::AlignCenter);
Item.at(2)->setTextAlignment(Qt::AlignCenter);
m_pModel->appendRow(Item);
//m_lineEidt[i]->installEventFilter(this);
//Item.at(0)->setdsetValidator(new QRegExpValidator(rx, this));
int i=m_pModel->rowCount()-1;
m_pModel->setData(m_pModel->index(i, 3),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 4),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 5),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 6),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 7),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 8),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 9),true,Qt::UserRole);
if(m_pModel->rowCount()>0)
{
ui->labelPowerScheduleTip->setVisible(true);
}
else {
ui->labelPowerScheduleTip->setVisible(false);
}
}
void ControlPowerSchedule::OnClickImport(){
QSettings settings;
QString strDir="/";
if(settings.value("lasOpendFileDlgtDir").isValid())
{
strDir=settings.value("lasOpendFileDlgtDir").toString();
}
QFileDialog dlg;
QString strBrightScheduleFile = QFileDialog::getOpenFileName(this, "open file dialog",
strDir,
tr("PowerSchedule (*.pjs)"));
if(strBrightScheduleFile.isEmpty())
return;
QFile fJson(strBrightScheduleFile);
if(fJson.open(QIODevice::ReadOnly)){
QJsonDocument jBrightSchedule = QJsonDocument::fromJson(fJson.readAll());
QJsonObject oTaskPower=jBrightSchedule.object();
JieXiJsonTaskPower(oTaskPower);
fJson.close();
}
}
bool ControlPowerSchedule::JieXiJsonTaskPower(QJsonObject oTaskPower)
{
OnClickClear();
QJsonArray oSchedules;
oSchedules=oTaskPower["schedules"].toArray();
if(oSchedules.count()>0)
{
ui->labelPowerScheduleTip->setVisible(true);
}
else
{
ui->labelPowerScheduleTip->setVisible(false);
}
//bool bHaveSchedule=false;
for(int i=0;i<oSchedules.count();i++)
{
QJsonObject oSchedule=oSchedules.at(i).toObject();
QList<QStandardItem *> Item;
Item.append(new QStandardItem(tr("On")));
Item.append(new QStandardItem(oSchedule["startTime"].toString()));
Item.append(new QStandardItem(oSchedule["endTime"].toString()));
Item.at(0)->setTextAlignment(Qt::AlignCenter);
Item.at(1)->setTextAlignment(Qt::AlignCenter);
Item.at(2)->setTextAlignment(Qt::AlignCenter);
m_pModel->appendRow(Item);
if(oSchedule["filterType"].toString()=="None")
{
m_pModel->setData(m_pModel->index(i, 3),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 4),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 5),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 6),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 7),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 8),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 9),true,Qt::UserRole);
}
else if(oSchedule["filterType"].toString()=="Week")
{
QJsonArray oWeeks;
oWeeks=oSchedule["weekFilter"].toArray();
for(int m=0;m<7;m++)
{
bool bHave=false;
for (int j=0;j<oWeeks.count();j++)
{
int iWeek=oWeeks.at(j).toInt();
if(iWeek==m)
{
bHave=true;
break;
}
}
m_pModel->setData(m_pModel->index(i, m+3),bHave,Qt::UserRole);
}
}
}
if(oSchedules.count()>0)
return true;
else {
return false;
}
}
void ControlPowerSchedule::OnClickExport(){
QSettings settings;
QString strDir="/";
if(settings.value("lasOpendFileDlgtDir").isValid()) {
strDir=settings.value("lasOpendFileDlgtDir").toString();
}
QFileDialog dlg;
QString saveFileName = dlg.getSaveFileName(this, tr("Save File"), strDir, tr("PowerSchedule (*.pjs)"));
if( saveFileName.isEmpty() )
return;
settings.setValue("lasOpendFileDlgtDir",saveFileName);
QJsonObject oTaskPower=GetJsonObjectPowerSchedule();
QJsonDocument tPowerScheduleJsonDoc;
tPowerScheduleJsonDoc.setObject(oTaskPower);
QFile f(saveFileName);
if(f.open(QIODevice::WriteOnly)) {
f.write(tPowerScheduleJsonDoc.toJson());
f.close();
}
}
void ControlPowerSchedule::OnClickDelete()
{
if(m_pModel->rowCount()>0)
{
QModelIndexList selected = ui->tableView->selectionModel()->selectedRows(0);
if(selected.count()>0)
m_pModel->removeRows(selected.begin()->row(),selected.count());
}
if(m_pModel->rowCount()>0)
{
ui->labelPowerScheduleTip->setVisible(true);
}
else {
ui->labelPowerScheduleTip->setVisible(false);
}
}
void ControlPowerSchedule:: OnClickClear()
{
//QModelIndexList selected = ui->tableView->selectionModel()->selectedRows(0);
if(m_pModel->rowCount()>0)
{
m_pModel->removeRows(0,m_pModel->rowCount());
}
if(m_pModel->rowCount()>0)
{
ui->labelPowerScheduleTip->setVisible(true);
}
else {
ui->labelPowerScheduleTip->setVisible(false);
}
}
void ControlPowerSchedule::OnClickApply() {
if(m_pLedlist==nullptr) return;
if(m_pLedlist->count()<=1){
if(m_pLedCard==nullptr||m_pLedlist->count()==0){
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
}
if(m_pModel->rowCount()<=0) {
auto btn = QMessageBox::question(this, tr("Tip Info"), tr("Clear schedule task?"));
if(btn == QMessageBox::Yes) {
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "CleanTimingScreenTask");
MACRO_DEFINE_TIPDLG_FUCN(tr("CleanTimingScreenTask"),tr("Success"),tr("failed"))
}
} else {
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "SetTimingScreenTask");
QJsonObject oTaskPower=GetJsonObjectPowerSchedule();
json.insert("screenTask", oTaskPower);
MACRO_DEFINE_TIPDLG_FUCN(tr("SetTimingScreenTask"),tr("Success"),tr("failed"))
}
}
void ControlPowerSchedule::OnClickReadback() {
if(m_pLedlist==nullptr) return;
if(m_pLedlist->count()<=1) {
if(m_pLedCard==nullptr||m_pLedlist->count()==0) {
QMessageBox::information(this, tr("Tip"),tr("NoSelectedController"));
return;
}
}
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetTimingScreenTask");
MACRO_DEFINE_TIPDLG_FUCN(tr("GetTimingScreenTask"),tr("Success"),tr("failed"))
}
void ControlPowerSchedule::OnClickClearSchedule()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()<=1)
{
if(m_pLedCard==nullptr||m_pLedlist->count()==0)
{
QMessageBox::information(this, tr("Tip"),tr("NoSelectedController"));
return;
}
}
auto btn = QMessageBox::question(this, tr("Tip Info"), tr("Clear schedule task?"));
if(btn == QMessageBox::Yes) {
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "CleanTimingScreenTask");
MACRO_DEFINE_TIPDLG_FUCN(tr("CleanTimingScreenTask"),tr("Success"),tr("failed"))
}
}
QJsonObject ControlPowerSchedule::GetJsonObjectPowerSchedule()
{
QJsonObject oTaskPower;
QJsonArray oItems;
oTaskPower["createDate"] = QJsonValue::Null;
oTaskPower["createBy"] = "alahover";
oTaskPower["name"] = "TimingScreen";
QJsonArray oSchedules;
for(int i=0; i<m_pModel->rowCount(); i++)
{
QJsonObject oSchedule;
oSchedule["timeType"] = "Range";
oSchedule["startTime"] = m_pModel->data(m_pModel->index(i, 1)).toString();;
oSchedule["endTime"] = m_pModel->data(m_pModel->index(i, 2)).toString();;
oSchedule["dateType"] = "All";
oSchedule["startDate"] = QJsonValue::Null;
oSchedule["endDate"] = QJsonValue::Null;
oSchedule["monthFilter"] = QJsonArray();
bool bSun=m_pModel->data(m_pModel->index(i, 3),Qt::UserRole).toBool();
bool bMon=m_pModel->data(m_pModel->index(i, 4),Qt::UserRole).toBool();
bool bTur=m_pModel->data(m_pModel->index(i, 5),Qt::UserRole).toBool();
bool bWed=m_pModel->data(m_pModel->index(i, 6),Qt::UserRole).toBool();
bool bThu=m_pModel->data(m_pModel->index(i, 7),Qt::UserRole).toBool();
bool bFri=m_pModel->data(m_pModel->index(i, 8),Qt::UserRole).toBool();
bool bSat=m_pModel->data(m_pModel->index(i, 9),Qt::UserRole).toBool();
if(bMon && bTur && bWed && bThu && bFri && bSat && bSun)
{
oSchedule["filterType"] = "None";
oSchedule["weekFilter"] = QJsonArray();
}
else {
oSchedule["filterType"] = "Week";
QJsonArray tempArray;
if( bSun)
{
tempArray.append(0);
}
if(bMon)
{
tempArray.append(1);
}
if(bTur)
{
tempArray.append(2);
}
if( bWed)
{
tempArray.append(3);
}
if( bThu)
{
tempArray.append(4);
}
if( bFri)
{
tempArray.append(5);
}
if( bSat)
{
tempArray.append(6);
}
oSchedule["weekFilter"] = tempArray;
}
oSchedules.append(oSchedule);
}
oTaskPower["schedules"] = oSchedules;
return oTaskPower;
}
void ControlPowerSchedule::DeletePostingDlg()
{
if(m_PostingDlg!=nullptr)
{
delete m_PostingDlg;
m_PostingDlg=nullptr;
}
}

View File

@ -1,77 +0,0 @@
#ifndef CONTROLPOWERSCHEDULE_H
#define CONTROLPOWERSCHEDULE_H
#include <QWidget>
#include <device/ledcard.h>
#include <communication/hpptclient.h>
#include <base/loemptydialog.h>
#include <QStandardItemModel>
#include <QStyledItemDelegate>
namespace Ui {
class ControlPowerSchedule;
}
class ControlPowerSchedule : public QWidget
{
Q_OBJECT
public:
explicit ControlPowerSchedule(QWidget *parent = nullptr,QList<LedCard *> *m_pLedlist=nullptr);
~ControlPowerSchedule();
void refreshLable();
private:
Ui::ControlPowerSchedule *ui;
protected slots:
void OnClickAdd();
void OnClickImport();
void OnClickExport();
void OnClickDelete();
void OnClickClear();
void OnClickApply();
void OnClickReadback();
void OnClickClearSchedule();
//类似的控制操作信号和槽函数和变量定义
signals:
void sigSend(QJsonObject &,QString);
void sigHaveSchedule(bool);
protected slots:
void DeletePostingDlg();
void OnProHttpResponse(QString url, QString postMD5, QByteArray data);
void OnProHttpResponseAll(QString url, QString postMD5, QByteArray data);
void onSelectedDeviceList(QList<LedCard*> *);
void onReadbackAllThisPage();
void OnControlTypeSwitchIndexChanged(int index);
private:
QList<LedCard *> *m_pLedlist=nullptr;
LedCard *m_pLedCard = nullptr;
LedCard *m_oldLedlist = nullptr;
HpptClient *pHpptClient = nullptr;
HpptClient *pHpptClientAll = nullptr;
QString m_strUrl="";
LoEmptyDialog * m_PostingDlg=nullptr;
QTimer *m_pGetAskTimer=nullptr;
bool m_bSelected=false;
QStandardItemModel * m_pModel;
bool JieXiJsonTaskPower(QJsonObject oTaskPower);
QJsonObject GetJsonObjectPowerSchedule();
};
class ReadOnlyDelegate: public QStyledItemDelegate
{
Q_OBJECT
public:
ReadOnlyDelegate(QWidget *parent = nullptr):QStyledItemDelegate(parent)
{}
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const override //final
{
Q_UNUSED(parent)
Q_UNUSED(option)
Q_UNUSED(index)
return nullptr;
}
};
#endif // CONTROLPOWERSCHEDULE_H

View File

@ -1,255 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ControlPowerSchedule</class>
<widget class="QWidget" name="ControlPowerSchedule">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Edit area</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>10</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButtonAdd">
<property name="minimumSize">
<size>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonDelete">
<property name="minimumSize">
<size>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonClear">
<property name="minimumSize">
<size>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonImport">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Import</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonExport">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelPowerScheduleTip">
<property name="text">
<string>It is power off state outside the schedule time period</string>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="tableView">
<property name="styleSheet">
<string notr="true">background-color: #FFFFFF;</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Send command</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonApply">
<property name="minimumSize">
<size>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonClearSchedule">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Clear Schedule</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonReadback">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Readback</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,154 +0,0 @@
#include "controlpowerwidget.h"
#include "gutil/qgui.h"
#include "globaldefine.h"
#include "base/waitingdlg.h"
#include "tools.h"
#include <QMessageBox>
ControlPowerWidget::ControlPowerWidget(QWidget *parent, QList<LedCard *> *list) : QWidget(parent) {
auto vBox = new VBox(this);
lbScreenCfg = new QLabel;
lbScreenCfg->setAlignment(Qt::AlignCenter);
vBox->addWidget(lbScreenCfg);
auto hBox = new HBox(vBox);
hBox->addStretch();
fdManual = new QRadioButton;
hBox->addWidget(fdManual);
hBox->addSpacing(40);
fdSchedule = new QRadioButton;
hBox->addWidget(fdSchedule);
hBox->addStretch();
auto stack = new QStackedLayout(vBox);
{
auto vBox = new VBox(stack);
vBox->addSpacing(20);
auto hBox = new HBox(vBox);
hBox->addStretch();
lbScreen = new QLabel;
hBox->addWidget(lbScreen);
fdScreen = new SwitchControl;
fdScreen->setMinimumSize(QSize(80, 33));
fdScreen->setSliderColor(QColor(0, 0, 0), QColor(0, 160, 230));
fdScreen->setBgColor(QColor(200,200,200), QColor(0x00cc00));
fdScreen->setTextColor(QColor(100,100,100), QColor(0, 160, 230));
connect(fdScreen, &SwitchControl::checkedChanged, this, [this](bool checked) {
if(gSelCards->isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "SetScreenOn");
json.insert("_type", "SetScreenOn");
json.insert("on", checked);
if(gSelCards->count() == 1) {
auto waitingDlg = new WaitingDlg(this, (checked ? tr("SetScreenOn") : tr("SetScreenOff"))+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
if(checked) foreach(auto card, *gSelCards) {
Def_CtrlSetMulti(tr("SetScreenOn"))
}
else foreach(auto card, *gSelCards) {
Def_CtrlSetMulti(tr("SetScreenOff"))
}
}
});
hBox->addWidget(fdScreen);
hBox->addStretch();
btnScreenGet = new QPushButton;
btnScreenGet->setMinimumSize(QSize(60, 30));
btnScreenGet->setProperty("ssType", "progManageTool");
connect(btnScreenGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "IsScreenOn");
json.insert("_type", "IsScreenOn");
if(gSelCards->count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("IsScreenOn")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->success();
fdScreen->setCheckedStatus(json["on"].toBool());
});
} else {
foreach(auto card, *gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) err = json["on"].toBool() ? tr("On") : tr("Off");
gFdResInfo->append(card->m_strCardId+" "+tr("IsScreenOn")+" "+err);
});
}
}
});
vBox->addWidget(btnScreenGet, 0, Qt::AlignCenter);
vBox->addStretch();
}
m_pSchedule = new ControlPowerSchedule(this, list);
connect(m_pSchedule, &ControlPowerSchedule::sigHaveSchedule, this, [=](bool b) {
if(b) fdSchedule->setChecked(true);
else fdManual->setChecked(true);
});
stack->addWidget(m_pSchedule);
connect(fdSchedule, &QRadioButton::toggled, stack, &QStackedLayout::setCurrentIndex);
fdManual->setChecked(true);
connect(gDevicePanel, &DevicePanel::sigSelectedDeviceList, this, [this] {
if(isVisible()) init();
});
transUi();
}
void ControlPowerWidget::showEvent(QShowEvent *event) {
QWidget::showEvent(event);
init();
}
void ControlPowerWidget::init() {
bool isSingle = gSelCards->count()==1;
if(! isSingle) return;
auto card = gSelCards->at(0);
QJsonObject json;
json.insert("_id", "IsScreenOn");
json.insert("_type", "IsScreenOn");
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
fdScreen->setCheckedStatus(json["on"].toBool());
});
}
void ControlPowerWidget::changeEvent(QEvent *event) {
QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi();
}
void ControlPowerWidget::transUi() {
lbScreenCfg->setText(tr("Power Configuration"));
fdManual->setText(tr("Manual"));
fdSchedule->setText(tr("Schedule"));
lbScreen->setText(tr("Power"));
fdScreen->setText(tr("Off"), tr("On"));
btnScreenGet->setText(tr("Readback"));
m_pSchedule->refreshLable();
}

View File

@ -1,29 +0,0 @@
#ifndef CONTROLPOWERWIDGET_H
#define CONTROLPOWERWIDGET_H
#include <device/controlpowerschedule.h>
#include <QRadioButton>
#include <base/switchcontrol.h>
class ControlPowerWidget : public QWidget {
Q_OBJECT
public:
explicit ControlPowerWidget(QWidget *parent = nullptr,QList<LedCard *> *m_pLedlist=nullptr);
protected:
void showEvent(QShowEvent *event) override;
void init();
void changeEvent(QEvent *) override;
void transUi();
private:
ControlPowerSchedule *m_pSchedule=nullptr;
QLabel *lbScreenCfg;
QRadioButton *fdManual;
QRadioButton *fdSchedule;
QLabel *lbScreen;
SwitchControl *fdScreen;
QPushButton *btnScreenGet;
};
#endif // CONTROLPOWERWIDGET_H

View File

@ -1,545 +0,0 @@
#include "controltestwidget.h"
#include "ui_controltestwidget.h"
#include "base/x_uimsgboxok.h"
#include "QFileDialog"
#include "QDir"
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonDocument>
#include <globaldefine.h>
#include <QTcpSocket>
#include <QHostAddress>
#include "tools.h"
ControlTestWidget::ControlTestWidget(QWidget *parent,QList<LedCard *> *list) :
QWidget(parent),
ui(new Ui::ControlTestWidget)
{
m_pLedlist=list;
ui->setupUi(this);
refreshLable();
setStyleSheet(css);
ui->pushButtonStartLine->setProperty("ssType", "progManageTool");
ui->pushButtonStartGray->setProperty("ssType", "progManageTool");
ui->pushButtonStartColor->setProperty("ssType", "progManageTool");
ui->pushButtonStopTest->setProperty("ssType", "progManageTool");
ui->pushButton->setProperty("ssType", "progManageTool");
ui->pushButton_2->setProperty("ssType", "progManageTool");
ui->pushButton_3->setProperty("ssType", "progManageTool");
ui->pushButton_4->setProperty("ssType", "progManageTool");
ui->pushButton_5->setProperty("ssType", "progManageTool");
ui->pushButton_6->setProperty("ssType", "progManageTool");
ui->pushButton_7->setProperty("ssType", "progManageTool");
ui->pushButton_8->setProperty("ssType", "progManageTool");
ui->pushButton_9->setProperty("ssType", "progManageTool");
ui->pushButton_10->setProperty("ssType", "progManageTool");
ui->pushButton_11->setProperty("ssType", "progManageTool");
ui->pushButton_12->setProperty("ssType", "progManageTool");
ui->pushButton_13->setProperty("ssType", "progManageTool");
ui->spinBoxLineSpeed->setValue(10);
ui->spinBoxLineDistance->setValue(15);
ui->spinBoxGraySpeed->setValue(10);
ui->spinBoxGrayValue->setValue(0);
ui->radioButtonWhite->setChecked(true);
ui->radioButton_White->setChecked(true);
ui->checkBoxHorizontal->setChecked(true);
ui->checkBoxVertical->setChecked(true);
ui->checkBoxSlash->setChecked(true);
ui->checkBox_red->setChecked(true);
ui->checkBox_green->setChecked(true);
ui->checkBox_blue->setChecked(true);
ui->checkBox_white->setChecked(true);
connect(ui->pushButtonStartLine,SIGNAL(clicked()),this,SLOT(OnStartTestLine()));
connect(ui->pushButtonStartGray,SIGNAL(clicked()),this,SLOT(OnStartTestGray()));
connect(ui->pushButtonStartColor,SIGNAL(clicked()),this,SLOT(OnStartTestColor()));
connect(ui->pushButtonStopTest,SIGNAL(clicked()),this,SLOT(OnStopTest()));
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(OnpushButton1()));
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(OnpushButton2()));
connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(OnpushButton3()));
connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(OnpushButton4()));
connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(OnpushButton5()));
connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(OnpushButton6()));
connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(OnpushButton7()));
connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(OnpushButton8()));
connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(OnpushButton9()));
connect(ui->pushButton_10,SIGNAL(clicked()),this,SLOT(OnpushButton0()));
connect(ui->pushButton_11,SIGNAL(clicked()),this,SLOT(OnpushButtonClear()));
connect(ui->pushButton_12,SIGNAL(clicked()),this,SLOT(OnpushButtonReset()));
connect(ui->pushButton_13,SIGNAL(clicked()),this,SLOT(OnpushButtonAnycast()));
ui->pushButton_13->setEnabled(false);
MARCO_DEFINE_CONTROL_FUNC2(parent->parent(),parent)
connect(this,SIGNAL(sigTcpSend(int)),parent->parent(),SLOT(OnControlTcpSend(int)));
ui->lineEdit->setValidator(new QIntValidator(0, 100, this));
}
ControlTestWidget::~ControlTestWidget()
{
delete ui;
if(pHpptClient != nullptr)
{
qDebug() <<"delete pHpptClient in ~NetComm";
delete pHpptClient;
pHpptClient=nullptr;
}
if(pHpptClientAll != nullptr)
{
qDebug() <<"delete pHpptClientAll in ~NetComm";
delete pHpptClientAll;
pHpptClientAll=nullptr;
}
}
void ControlTestWidget::refreshLable()
{
ui->labelTestScreen->setText(tr("Test Screen"));
ui->groupBox->setTitle(tr("Line test"));
ui->radioButtonRed->setText(tr("Red"));
ui->radioButtonGreen->setText(tr("Green"));
ui->radioButtonBlue->setText(tr("Blue"));
ui->radioButtonWhite->setText(tr("White"));
ui->radioButton_red->setText(tr("Red"));
ui->radioButton_Green->setText(tr("Green"));
ui->radioButton_Blue->setText(tr("Blue"));
ui->radioButton_White->setText(tr("White"));
ui->checkBoxVertical->setText(tr("Vertical"));
ui->checkBoxHorizontal->setText(tr("Horizontal"));
ui->checkBoxSlash->setText(tr("Slash"));
ui->label->setText(tr("Speed"));
ui->label_5->setText(tr("ms(>10)"));
ui->checkBoxHorizontal->setText(tr("Horizontal"));
ui->label_2->setText(tr("Line Distance"));
ui->pushButtonStartLine->setText(tr("Test"));
ui->groupBox_2->setTitle(tr("Gradation test"));
ui->checkBoxShowInfo->setText(tr("Only the gray value is displayed"));
ui->checkBox_red->setText(tr("Red"));
ui->checkBox_green->setText(tr("Green"));
ui->checkBox_blue->setText(tr("Blue"));
ui->checkBox_white->setText(tr("White"));
ui->label_3->setText(tr("Speed"));
ui->label_4->setText(tr("GrayValue"));
ui->pushButtonStartGray->setText(tr("Test"));
ui->groupBox_3->setTitle(tr("Color test"));
ui->checkBoxGradient->setText(tr("Gradient"));
ui->radioButton_red->setText(tr("Red"));
ui->radioButton_Green->setText(tr("Green"));
ui->radioButton_Blue->setText(tr("Blue"));
ui->radioButton_White->setText(tr("White"));
ui->pushButtonStopTest->setText(tr("Stop"));
ui->pushButton_11->setText(tr("Clear"));
ui->pushButton_12->setText(tr("Reset"));
ui->pushButton_13->setText(tr("Anycast"));
}
void ControlTestWidget::OnStartTestLine()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()<=1)
{
if(m_pLedCard==nullptr||m_pLedlist->count()==0)
{
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("NoSelectedController"),this,1);
pDlg->exec();
return;
}
}
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "TestScreen");
json.insert("mode", 1);// 0停止 1斜线 2灰度; 3:颜色4渐变
json.insert("speed", ui->spinBoxLineSpeed->value());
if(ui->radioButtonRed->isChecked())
json.insert("color", "#FFFF0000");
else if(ui->radioButtonGreen->isChecked())
json.insert("color", "#FF00FF00");
else if(ui->radioButtonBlue->isChecked())
json.insert("color", "#FF0000FF");
else
json.insert("color", "#FFFFFFFF");
json.insert("interval", ui->spinBoxLineDistance->value());
json.insert("horizonalLine", ui->checkBoxHorizontal->isChecked());
json.insert("verticalLine", ui->checkBoxVertical->isChecked());
json.insert("slantLine", ui->checkBoxSlash->isChecked());
json.insert("runLimit", ui->spinBoxGrayValue->value());
json.insert("showInfo", !ui->checkBoxShowInfo->isChecked());
json.insert("red", ui->checkBox_red->isChecked());
json.insert("green", ui->checkBox_green->isChecked());
json.insert("blue", ui->checkBox_blue->isChecked());
json.insert("white", ui->checkBox_white->isChecked());
MACRO_DEFINE_TIPDLG_FUCN(tr("StartTest"),tr("Success"),tr("failed"))
}
void ControlTestWidget::OnStartTestGray()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()<=1)
{
if(m_pLedCard==nullptr||m_pLedlist->count()==0)
{
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("NoSelectedController"),this,1);
pDlg->exec();
return;
}
}
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "TestScreen");
json.insert("mode", 2);// 0停止 1斜线 2灰度; 3:颜色4渐变
json.insert("speed", ui->spinBoxGraySpeed->value());
// qDebug()<<"speed="<<ui->spinBoxGraySpeed->value();
if(ui->radioButtonRed->isChecked())
json.insert("color", "#FFFF0000");
else if(ui->radioButtonGreen->isChecked())
json.insert("color", "#FF00FF00");
else if(ui->radioButtonBlue->isChecked())
json.insert("color", "#FF0000FF");
else
json.insert("color", "#FFFFFFFF");
json.insert("interval", ui->spinBoxLineDistance->value());
json.insert("horizonalLine", ui->checkBoxHorizontal->isChecked());
json.insert("verticalLine", ui->checkBoxVertical->isChecked());
json.insert("slantLine", ui->checkBoxSlash->isChecked());
json.insert("runLimit", ui->spinBoxGrayValue->value());
json.insert("showInfo", !ui->checkBoxShowInfo->isChecked());
json.insert("red", ui->checkBox_red->isChecked());
json.insert("green", ui->checkBox_green->isChecked());
json.insert("blue", ui->checkBox_blue->isChecked());
json.insert("white", ui->checkBox_white->isChecked());
MACRO_DEFINE_TIPDLG_FUCN(tr("StartTest"),tr("Success"),tr("failed"))
}
void ControlTestWidget::OnStartTestColor()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()<=1)
{
if(m_pLedCard==nullptr||m_pLedlist->count()==0)
{
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("NoSelectedController"),this,1);
pDlg->exec();
return;
}
}
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "TestScreen");
if(ui->checkBoxGradient->isChecked())
json.insert("mode", 4);// 0停止 1斜线 2灰度; 3:颜色4渐变
else
json.insert("mode", 3);// 0停止 1斜线 2灰度; 3:颜色4渐变
json.insert("speed", ui->spinBoxLineSpeed->value());
if(ui->radioButton_red->isChecked())
json.insert("color", "#FFFF0000");
else if(ui->radioButton_Green->isChecked())
json.insert("color", "#FF00FF00");
else if(ui->radioButton_Blue->isChecked())
json.insert("color", "#FF0000FF");
else
json.insert("color", "#FFFFFFFF");
json.insert("interval", ui->spinBoxLineDistance->value());
json.insert("horizonalLine", ui->checkBoxHorizontal->isChecked());
json.insert("verticalLine", ui->checkBoxVertical->isChecked());
json.insert("slantLine", ui->checkBoxSlash->isChecked());
json.insert("runLimit", ui->spinBoxGrayValue->value());
json.insert("showInfo", !ui->checkBoxShowInfo->isChecked());
json.insert("red", ui->checkBox_red->isChecked());
json.insert("green", ui->checkBox_green->isChecked());
json.insert("blue", ui->checkBox_blue->isChecked());
json.insert("white", ui->checkBox_white->isChecked());
MACRO_DEFINE_TIPDLG_FUCN(tr("StartTest"),tr("Success"),tr("failed"))
}
void ControlTestWidget::OnStopTest()
{
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "TestScreen");
json.insert("mode", 0);
MACRO_DEFINE_TIPDLG_FUCN(tr("StopTest"),tr("Success"),tr("failed"))
}
void ControlTestWidget::OnpushButton1()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"1");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton2()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"2");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton3()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"3");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton4()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"4");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton5()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"5");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton6()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"6");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton7()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"7");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton8()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"8");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton9()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"9");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButton0()
{
if(ui->lineEdit->text().contains("-"))
ui->lineEdit->clear();
ui->lineEdit->setText(ui->lineEdit->text()+"0");
ui->pushButton_13->setEnabled(true);
}
void ControlTestWidget::OnpushButtonClear()
{
ui->lineEdit->clear();
ui->pushButton_13->setEnabled(false);
}
void ControlTestWidget::OnpushButtonReset()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedCard==nullptr||m_pLedlist->count()==0)
{
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("NoSelectedController"),this,1);
pDlg->exec();
return;
}
int iIndex= ui->lineEdit->text().toInt();
if(m_pLedlist->count()==1)
{
SendAnycastCmd(m_pLedCard->m_strCardIp,0);
}
else {
emit sigTcpSend(iIndex);
}
ui->lineEdit->setText("-"+tr("loopback mode")+"-");
ui->pushButton_13->setEnabled(false);
}
void ControlTestWidget::OnpushButtonAnycast()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedCard==nullptr||m_pLedlist->count()==0)
{
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("NoSelectedController"),this,1);
pDlg->exec();
return;
}
int iIndex= ui->lineEdit->text().toInt();
if(m_pLedlist->count()==1)
{
SendAnycastCmd(m_pLedCard->m_strCardIp,iIndex);
}
else {
emit sigTcpSend(iIndex);
}
ui->lineEdit->setText(tr("Anycast")+" - "+ui->lineEdit->text());
ui->pushButton_13->setEnabled(false);
}
void ControlTestWidget::SendAnycastCmd(QString strIp,int iProgramIndex)
{
QTcpSocket *send = new QTcpSocket();
connect(send, SIGNAL(connected()), this, SLOT(connect_sucessful()));
connect(send, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(show_error(QAbstractSocket::SocketError)));
send->connectToHost(QHostAddress(strIp),31299);
ST_ANSY_PROGRAM_PACKET tempStreadPakcet;
tempStreadPakcet.SyncHead[0]=0x7e;
tempStreadPakcet.SyncHead[1]=0x7e;
tempStreadPakcet.SyncHead[2]=0x55;
tempStreadPakcet.ucCommType=0x97;
tempStreadPakcet.iBaoLiu=0;
tempStreadPakcet.iLength=4;
unsigned char uctemp[4]={0};
uctemp[0]=iProgramIndex;
memcpy(tempStreadPakcet.pDataBuffer,uctemp,4);
tempStreadPakcet.pDataBuffer[tempStreadPakcet.iLength]=GetCheckCodeIn8(&tempStreadPakcet.ucCommType,tempStreadPakcet.iLength+sizeof(tempStreadPakcet.iBaoLiu)+sizeof(tempStreadPakcet.ucCommType)+sizeof(tempStreadPakcet.iLength));
int iLenPacket=3*sizeof(unsigned char)+sizeof(char)+sizeof(int)+sizeof(int)+tempStreadPakcet.iLength+sizeof(char);/////除正文外的协议结构大小;
QByteArray databuf = QByteArray(reinterpret_cast<char*>(&tempStreadPakcet), iLenPacket);
if(!send->waitForConnected(10000)) //等待连接返回
{
qDebug()<<strIp<<"Connect timeout ";
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("Connect timeout"),this,1);
pDlg->exec();
send->close();
delete send;
return ;
}
send->write(databuf);
if(send->waitForBytesWritten(3000))
{
QByteArray readBuf=send->read(send->bytesAvailable());
qDebug()<<"recv anycast success ack";
if(iProgramIndex==0)
{
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("Reset loop mode")+":"+tr("success"),this,1);
pDlg->exec();
}
else {
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("Anycast")+":"+tr("success"),this,1);
pDlg->exec();
}
//emit sigOutputInfo(m_pLedCard->m_strCardId+":"+tr("receive")+"<-"+tr("Anycast")+":"+tr("success"));
}
send->close();
delete send;
}
void ControlTestWidget::onSelectedDeviceList(QList<LedCard*> *list)
{
m_pLedlist=list;
MACRO_DEFINE_CONTROL_FUNC3
}
void ControlTestWidget::OnControlTypeSwitchIndexChanged(int index)
{
if(index==Setting_Encrypt)
{
m_bSelected=true;
if(m_pLedCard!=nullptr)
onReadbackAllThisPage();
}
else {
m_bSelected=false;
}
}
void ControlTestWidget::onReadbackAllThisPage()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()!=1)
return;
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void ControlTestWidget::OnProHttpResponse(QString url, QString postMD5, QByteArray data)
{
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
}
}
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void ControlTestWidget::OnProHttpResponseAll(QString url, QString postMD5, QByteArray data)
{
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
}
}
}
void ControlTestWidget::DeletePostingDlg()
{
if(m_PostingDlg!=nullptr)
{
delete m_PostingDlg;
m_PostingDlg=nullptr;
}
}

View File

@ -1,67 +0,0 @@
#ifndef CONTROLTESTWIDGET_H
#define CONTROLTESTWIDGET_H
#include <QWidget>
#include <device/ledcard.h>
#include <communication/hpptclient.h>
#include <base/loemptydialog.h>
namespace Ui {
class ControlTestWidget;
}
class ControlTestWidget : public QWidget
{
Q_OBJECT
public:
explicit ControlTestWidget(QWidget *parent = nullptr,QList<LedCard *> *m_pLedlist=nullptr);
~ControlTestWidget();
private:
Ui::ControlTestWidget *ui;
protected slots:
void OnStartTestLine();
void OnStartTestGray();
void OnStartTestColor();
void OnStopTest();
void OnpushButton1();
void OnpushButton2();
void OnpushButton3();
void OnpushButton4();
void OnpushButton5();
void OnpushButton6();
void OnpushButton7();
void OnpushButton8();
void OnpushButton9();
void OnpushButton0();
void OnpushButtonClear();
void OnpushButtonReset();
void OnpushButtonAnycast();
void refreshLable();
//类似的控制操作信号和槽函数和变量定义
signals:
void sigTcpSend(int);
void sigSend(QJsonObject &,QString);
protected slots:
void DeletePostingDlg();
void OnProHttpResponse(QString url, QString postMD5, QByteArray data);
void OnProHttpResponseAll(QString url, QString postMD5, QByteArray data);
void onSelectedDeviceList(QList<LedCard*> *);
void onReadbackAllThisPage();
void OnControlTypeSwitchIndexChanged(int index);
private:
QList<LedCard *> *m_pLedlist=nullptr;
LedCard *m_pLedCard = nullptr;
LedCard *m_oldLedlist = nullptr;
HpptClient *pHpptClient = nullptr;
HpptClient *pHpptClientAll = nullptr;
QString m_strUrl="";
LoEmptyDialog * m_PostingDlg=nullptr;
QTimer *m_pGetAskTimer=nullptr;
bool m_bSelected=false;
void SendAnycastCmd(QString strIp,int iProgramIndex);
};
#endif // CONTROLTESTWIDGET_H

File diff suppressed because it is too large Load Diff

View File

@ -1,528 +0,0 @@
#include "controlvolumeschedule.h"
#include "ui_controlvolumeschedule.h"
#include "base/x_uimsgboxok.h"
#include "QFileDialog"
#include "QDir"
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <globaldefine.h>
#include <QStandardItem>
#include "QSettings"
#include "base/x_spinboxdelegate.h"
#include "base/x_timeeditdelegate.h"
#include "base/x_checkboxdelegate.h"
#include "tools.h"
ControlVolumeSchedule::ControlVolumeSchedule(QWidget *parent,QList<LedCard *> *list) :
QWidget(parent),
ui(new Ui::ControlVolumeSchedule)
{
m_pLedlist=list;
ui->setupUi(this);
refreshLable();
setStyleSheet(css);
ui->pushButtonAdd->setProperty("ssType", "progManageTool");
ui->pushButtonAdd->setFlat(true);
ui->pushButtonDelete->setProperty("ssType", "progManageTool");
ui->pushButtonDelete->setFlat(true);
ui->pushButtonClear->setProperty("ssType", "progManageTool");
ui->pushButtonClear->setFlat(true);
ui->pushButtonApply->setProperty("ssType", "progManageTool");
ui->pushButtonApply->setFlat(true);
ui->pushButtonImport->setProperty("ssType", "progManageTool");
ui->pushButtonExport->setProperty("ssType", "progManageTool");
ui->pushButtonReadback->setProperty("ssType", "progManageTool");
ui->lineEdit->setText("10");
m_pModel = new QStandardItemModel(this);
m_pModel->setColumnCount(10);
m_pModel->setHeaderData(0,Qt::Horizontal, tr("Volume value"));
m_pModel->setHeaderData(1,Qt::Horizontal, tr("Start Time"));
m_pModel->setHeaderData(2,Qt::Horizontal, tr("End Time"));
m_pModel->setHeaderData(3,Qt::Horizontal, tr("SUN"));
m_pModel->setHeaderData(4,Qt::Horizontal, tr("MON"));
m_pModel->setHeaderData(5,Qt::Horizontal, tr("TUE"));
m_pModel->setHeaderData(6,Qt::Horizontal, tr("WED"));
m_pModel->setHeaderData(7,Qt::Horizontal, tr("THU"));
m_pModel->setHeaderData(8,Qt::Horizontal, tr("FRI"));
m_pModel->setHeaderData(9,Qt::Horizontal, tr("SAT"));
ui->tableView->setModel(m_pModel);
SpinBoxDelegate *pVolumeDelegate=new SpinBoxDelegate(this,1);
ui->tableView->setItemDelegateForColumn(0,pVolumeDelegate);
X_timeEditDelegate *pStartTimeDelegate=new X_timeEditDelegate(this);
ui->tableView->setItemDelegateForColumn(1,pStartTimeDelegate);
ui->tableView->setItemDelegateForColumn(2,pStartTimeDelegate);
X_CheckBoxDelegate *WeekDelegate=new X_CheckBoxDelegate(this);
ui->tableView->setItemDelegateForColumn(3,WeekDelegate);
ui->tableView->setItemDelegateForColumn(4,WeekDelegate);
ui->tableView->setItemDelegateForColumn(5,WeekDelegate);
ui->tableView->setItemDelegateForColumn(6,WeekDelegate);
ui->tableView->setItemDelegateForColumn(7,WeekDelegate);
ui->tableView->setItemDelegateForColumn(8,WeekDelegate);
ui->tableView->setItemDelegateForColumn(9,WeekDelegate);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
// ui->tableView->verticalHeader()->hide();
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setFocusPolicy(Qt::NoFocus);
MARCO_DEFINE_CONTROL_FUNC2(parent->parent()->parent(),parent->parent())
connect(ui->pushButtonAdd,SIGNAL(clicked()),this,SLOT(OnClickAdd()));
connect(ui->pushButtonImport,SIGNAL(clicked()),this,SLOT(OnClickImport()));
connect(ui->pushButtonExport,SIGNAL(clicked()),this,SLOT(OnClickExport()));
connect(ui->pushButtonDelete,SIGNAL(clicked()),this,SLOT(OnClickDelete()));
connect(ui->pushButtonClear,SIGNAL(clicked()),this,SLOT(OnClickClear()));
connect(ui->pushButtonApply,SIGNAL(clicked()),this,SLOT(OnClickApply()));
connect(ui->pushButtonReadback,SIGNAL(clicked()),this,SLOT(OnClickReadback()));
}
ControlVolumeSchedule::~ControlVolumeSchedule()
{
delete ui;
if(pHpptClient != nullptr)
{
qDebug() <<"delete pHpptClient in ~NetComm";
delete pHpptClient;
pHpptClient=nullptr;
}
if(pHpptClientAll != nullptr)
{
qDebug() <<"delete pHpptClientAll in ~NetComm";
delete pHpptClientAll;
pHpptClientAll=nullptr;
}
}
void ControlVolumeSchedule::refreshLable()
{
ui->pushButtonAdd->setText(tr("Add"));
ui->pushButtonApply->setText(tr("Apply"));
ui->pushButtonClear->setText(tr("Clear"));
ui->pushButtonDelete->setText(tr("Delete"));
ui->pushButtonImport->setText(tr("Import"));
ui->pushButtonExport->setText(tr("Export"));
ui->labelVolumeScheduleTip->setText(tr("Default volume tip"));
ui->labelDefalutVolume->setText(tr("Default volume"));
}
void ControlVolumeSchedule::onSelectedDeviceList(QList<LedCard*> *list)
{
m_pLedlist=list;
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()==1)
{
ui->pushButtonReadback->setEnabled(true);
}
else {
ui->pushButtonReadback->setEnabled(false);
}
MACRO_DEFINE_CONTROL_FUNC3
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void ControlVolumeSchedule::OnProHttpResponse(QString url, QString postMD5, QByteArray data)
{
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
if(strType == "GetAutoVolumeTask")
{
JieXiJsonTaskVolume(jsonObject["taskVolume"].toObject());
}
else if(strType == "SetAutoVolumeTask")
{
}
MACRO_ASKTIME_STOP
MACRO_POSTING_DLG_UNLOCK
}
}
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void ControlVolumeSchedule::OnProHttpResponseAll(QString url, QString postMD5, QByteArray data)
{
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
qDebug()<<tr("DeviceItem OnProHttpResponse 解析json文件错误");
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
if(strType == "GetAutoVolumeTask")
{
emit sigHaveSchedule(JieXiJsonTaskVolume(jsonObject["taskVolume"].toObject()));
}
}
}
}
void ControlVolumeSchedule::OnControlTypeSwitchIndexChanged(int index)
{
if(index==Setting_Volume)
{
m_bSelected=true;
if(m_pLedCard!=nullptr)
onReadbackAllThisPage();
}
else {
m_bSelected=false;
}
}
void ControlVolumeSchedule::onReadbackAllThisPage()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()!=1)
return;
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetAutoVolumeTask");
HttpPostByTypeJsonObject(pHpptClientAll,m_strUrl,json);
}
void ControlVolumeSchedule::OnClickAdd()
{
QList<QStandardItem *> Item;
Item.append(new QStandardItem(tr("10")));
Item.append(new QStandardItem("00:00"));
Item.append(new QStandardItem("01:00"));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
// Item.append(new QStandardItem(true));
Item.at(0)->setTextAlignment(Qt::AlignCenter);
Item.at(1)->setTextAlignment(Qt::AlignCenter);
Item.at(2)->setTextAlignment(Qt::AlignCenter);
m_pModel->appendRow(Item);
//m_lineEidt[i]->installEventFilter(this);
//Item.at(0)->setdsetValidator(new QRegExpValidator(rx, this));
int i=m_pModel->rowCount()-1;
m_pModel->setData(m_pModel->index(i, 3),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 4),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 5),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 6),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 7),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 8),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 9),true,Qt::UserRole);
if(m_pModel->rowCount()>0)
{
ui->labelVolumeScheduleTip->setVisible(true);
}
else {
ui->labelVolumeScheduleTip->setVisible(false);
}
}
void ControlVolumeSchedule::OnClickImport() {
QSettings settings;
QString strDir="/";
if(settings.value("lasOpendFileDlgtDir").isValid())
{
strDir=settings.value("lasOpendFileDlgtDir").toString();
}
QFileDialog dlg;
QString strBrightScheduleFile = QFileDialog::getOpenFileName(this, "open file dialog",
strDir,
tr("Volume Schedule (*.vols)"));
if(strBrightScheduleFile.isEmpty())
return;
QFile fJson(strBrightScheduleFile);
if(fJson.open(QIODevice::ReadOnly)){
QJsonDocument jBrightSchedule = QJsonDocument::fromJson(fJson.readAll());
QJsonObject oTaskVolume=jBrightSchedule.object();
JieXiJsonTaskVolume(oTaskVolume);
fJson.close();
}
}
bool ControlVolumeSchedule::JieXiJsonTaskVolume(QJsonObject oTaskVolume)
{
OnClickClear();
QJsonArray items;
QString strDefaultVolume=QString::number(oTaskVolume["defaultVolume"].toInt());
if(!strDefaultVolume.isEmpty())
ui->lineEdit->setText(strDefaultVolume);
items=oTaskVolume["items"].toArray();
for(int i=0;i<items.count();i++)
{
QJsonObject item=items.at(i).toObject();
QJsonArray oSchedules;
oSchedules=item["schedules"].toArray();
QJsonObject oSchedule=oSchedules.at(0).toObject();
QList<QStandardItem *> Item;
Item.append(new QStandardItem(QString::number(item["volume"].toInt())));
Item.append(new QStandardItem(oSchedule["startTime"].toString()));
Item.append(new QStandardItem(oSchedule["endTime"].toString()));
Item.at(0)->setTextAlignment(Qt::AlignCenter);
Item.at(1)->setTextAlignment(Qt::AlignCenter);
Item.at(2)->setTextAlignment(Qt::AlignCenter);
//m_lineEidt[i]->installEventFilter(this);
//Item.at(0)->setdsetValidator(new QRegExpValidator(rx, this));
m_pModel->appendRow(Item);
if(oSchedule["filterType"].toString()=="None")
{
m_pModel->setData(m_pModel->index(i, 3),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 4),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 5),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 6),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 7),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 8),true,Qt::UserRole);
m_pModel->setData(m_pModel->index(i, 9),true,Qt::UserRole);
}
else if(oSchedule["filterType"].toString()=="Week")
{
QJsonArray oWeeks;
oWeeks=oSchedule["weekFilter"].toArray();
for(int m=0;m<7;m++)
{
bool bHave=false;
for (int j=0;j<oWeeks.count();j++)
{
int iWeek=oWeeks.at(j).toInt();
if(iWeek==m)
{
bHave=true;
break;
}
}
m_pModel->setData(m_pModel->index(i, m+3),bHave,Qt::UserRole);
}
}
}
if(items.count()>0)
return true;
else {
return false;
}
}
void ControlVolumeSchedule::OnClickExport() {
QSettings settings;
QString strDir="/";
if(settings.value("lasOpendFileDlgtDir").isValid()) {
strDir=settings.value("lasOpendFileDlgtDir").toString();
}
QFileDialog dlg;
QString saveFileName = dlg.getSaveFileName(this, tr("Save File"), strDir, tr("Volume Schedule (*.vols)"));
if( saveFileName.isEmpty() )
return;
settings.setValue("lasOpendFileDlgtDir",saveFileName);
QJsonObject oTaskSync=GetJsonObjectVolumeSchedule();
QJsonDocument tSyncScheduleJsonDoc;
tSyncScheduleJsonDoc.setObject(oTaskSync);
QFile f(saveFileName);
if(f.open(QIODevice::WriteOnly)) {
f.write(tSyncScheduleJsonDoc.toJson());
f.close();
}
}
void ControlVolumeSchedule::OnClickDelete()
{
if(m_pModel->rowCount()>0)
{
QModelIndexList selected = ui->tableView->selectionModel()->selectedRows(0);
if(selected.count()>0)
m_pModel->removeRows(selected.begin()->row(),selected.count());
}
if(m_pModel->rowCount()>0)
{
ui->labelVolumeScheduleTip->setVisible(true);
}
else {
ui->labelVolumeScheduleTip->setVisible(false);
}
}
void ControlVolumeSchedule:: OnClickClear()
{
//QModelIndexList selected = ui->tableView->selectionModel()->selectedRows(0);
if(m_pModel->rowCount()>0)
m_pModel->removeRows(0,m_pModel->rowCount());
if(m_pModel->rowCount()>0)
{
ui->labelVolumeScheduleTip->setVisible(true);
}
else {
ui->labelVolumeScheduleTip->setVisible(false);
}
}
void ControlVolumeSchedule::OnClickApply()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()<=1)
{
if(m_pLedCard==nullptr||m_pLedlist->count()==0)
{
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("NoSelectedController"),this,1);
pDlg->exec();
return;
}
}
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "SetAutoVolumeTask");
QJsonObject oTaskVolume=GetJsonObjectVolumeSchedule();
json.insert("taskVolume", oTaskVolume);
MACRO_DEFINE_TIPDLG_FUCN(tr("SetAutoVolumeTask"),tr("Success"),tr("failed"))
}
void ControlVolumeSchedule::OnClickReadback()
{
if(m_pLedlist==nullptr)
return;
if(m_pLedlist->count()<=1)
{
if(m_pLedCard==nullptr||m_pLedlist->count()==0)
{
X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("NoSelectedController"),this,1);
pDlg->exec();
return;
}
}
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetAutoVolumeTask");
MACRO_DEFINE_TIPDLG_FUCN(tr("GetAutoVolumeTask"),tr("Success"),tr("failed"))
}
QJsonObject ControlVolumeSchedule::GetJsonObjectVolumeSchedule()
{
QJsonObject oTaskVolume;
QJsonArray oItems;
oTaskVolume["createDate"] = QJsonValue::Null;
oTaskVolume["createBy"] = "alahover";
oTaskVolume["defaultVolume"] = ui->lineEdit->text().toInt();
oTaskVolume["volume"] = ui->lineEdit->text().toInt();
oTaskVolume["name"] = "TimingVolume";
for(int i=0; i<m_pModel->rowCount(); i++)
{
QJsonObject oItem;
oItem["volume"] = m_pModel->data(m_pModel->index(i, 0)).toInt();
QJsonArray oSchedules;
QJsonObject oSchedule;
oSchedule["timeType"] = "Range";
oSchedule["startTime"] = m_pModel->data(m_pModel->index(i, 1)).toString();;
oSchedule["endTime"] = m_pModel->data(m_pModel->index(i, 2)).toString();;
oSchedule["dateType"] = "All";
oSchedule["startDate"] = QJsonValue::Null;
oSchedule["endDate"] = QJsonValue::Null;
oSchedule["monthFilter"] = QJsonArray();
bool bSun=m_pModel->data(m_pModel->index(i, 3),Qt::UserRole).toBool();
bool bMon=m_pModel->data(m_pModel->index(i, 4),Qt::UserRole).toBool();
bool bTur=m_pModel->data(m_pModel->index(i, 5),Qt::UserRole).toBool();
bool bWed=m_pModel->data(m_pModel->index(i, 6),Qt::UserRole).toBool();
bool bThu=m_pModel->data(m_pModel->index(i, 7),Qt::UserRole).toBool();
bool bFri=m_pModel->data(m_pModel->index(i, 8),Qt::UserRole).toBool();
bool bSat=m_pModel->data(m_pModel->index(i, 9),Qt::UserRole).toBool();
if(bMon && bTur && bWed && bThu && bFri && bSat && bSun)
{
oSchedule["filterType"] = "None";
oSchedule["weekFilter"] = QJsonArray();
}
else {
oSchedule["filterType"] = "Week";
QJsonArray tempArray;
if( bSun)
{
tempArray.append(0);
}
if(bMon)
{
tempArray.append(1);
}
if(bTur)
{
tempArray.append(2);
}
if( bWed)
{
tempArray.append(3);
}
if( bThu)
{
tempArray.append(4);
}
if( bFri)
{
tempArray.append(5);
}
if( bSat)
{
tempArray.append(6);
}
oSchedule["weekFilter"] = tempArray;
}
oSchedules.append(oSchedule);
oItem["schedules"] = oSchedules;
oItems.append(oItem);
}
oTaskVolume["items"] = oItems;
return oTaskVolume;
}
void ControlVolumeSchedule::DeletePostingDlg()
{
if(m_PostingDlg!=nullptr)
{
delete m_PostingDlg;
m_PostingDlg=nullptr;
}
}

View File

@ -1,60 +0,0 @@
#ifndef CONTROLVOLUMESCHEDULE_H
#define CONTROLVOLUMESCHEDULE_H
#include <QWidget>
#include <device/ledcard.h>
#include <communication/hpptclient.h>
#include <base/loemptydialog.h>
#include <QStandardItemModel>
#include <QStyledItemDelegate>
namespace Ui {
class ControlVolumeSchedule;
}
class ControlVolumeSchedule : public QWidget
{
Q_OBJECT
public:
explicit ControlVolumeSchedule(QWidget *parent = nullptr,QList<LedCard *> *m_pLedlist=nullptr);
~ControlVolumeSchedule();
void refreshLable();
protected slots:
void OnClickAdd();
void OnClickImport();
void OnClickExport();
void OnClickDelete();
void OnClickClear();
void OnClickApply();
void OnClickReadback();
private:
Ui::ControlVolumeSchedule *ui;
//类似的控制操作信号和槽函数和变量定义
signals:
void sigSend(QJsonObject &,QString);
void sigHaveSchedule(bool);
protected slots:
void DeletePostingDlg();
void OnProHttpResponse(QString url, QString postMD5, QByteArray data);
void OnProHttpResponseAll(QString url, QString postMD5, QByteArray data);
void onSelectedDeviceList(QList<LedCard*> *);
void onReadbackAllThisPage();
void OnControlTypeSwitchIndexChanged(int index);
private:
QList<LedCard *> *m_pLedlist=nullptr;
LedCard *m_pLedCard = nullptr;
LedCard *m_oldLedlist = nullptr;
HpptClient *pHpptClient = nullptr;
HpptClient *pHpptClientAll = nullptr;
QString m_strUrl="";
LoEmptyDialog * m_PostingDlg=nullptr;
QTimer *m_pGetAskTimer=nullptr;
bool m_bSelected=false;
QStandardItemModel * m_pModel;
bool JieXiJsonTaskVolume(QJsonObject oTaskVolume);
QJsonObject GetJsonObjectVolumeSchedule();
};
#endif // CONTROLVOLUMESCHEDULE_H

View File

@ -1,251 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ControlVolumeSchedule</class>
<widget class="QWidget" name="ControlVolumeSchedule">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>708</width>
<height>447</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="labelVolumeScheduleTip">
<property name="text">
<string>Defalut volume tip</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>10</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButtonAdd">
<property name="minimumSize">
<size>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonDelete">
<property name="minimumSize">
<size>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonClear">
<property name="minimumSize">
<size>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelDefalutVolume">
<property name="text">
<string>Default Volume</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: #FFFFFF;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>(0-15)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonImport">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Import</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonExport">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableView" name="tableView">
<property name="styleSheet">
<string notr="true">background-color: #FFFFFF;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonApply">
<property name="minimumSize">
<size>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonReadback">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Readback</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,154 +0,0 @@
#include "controlvolumewidget.h"
#include "gutil/qgui.h"
#include "globaldefine.h"
#include "base/waitingdlg.h"
#include "tools.h"
#include <QMessageBox>
ControlVolumeWidget::ControlVolumeWidget(QWidget *parent,QList<LedCard *> *list) : QWidget(parent) {
auto vBox = new VBox(this);
lbVolumeControl = new QLabel;
lbVolumeControl->setAlignment(Qt::AlignCenter);
vBox->addWidget(lbVolumeControl);
auto hBox = new HBox(vBox);
hBox->addStretch();
fdManual = new QRadioButton;
hBox->addWidget(fdManual);
hBox->addSpacing(40);
fdSchedule = new QRadioButton;
hBox->addWidget(fdSchedule);
hBox->addStretch();
auto stack = new QStackedLayout(vBox);
{
auto vBox = new VBox(stack);
vBox->addSpacing(20);
auto hBox = new HBox(vBox);
hBox->addStretch();
lbVolume = new QLabel;
hBox->addWidget(lbVolume);
fdVolume = new QSlider(Qt::Horizontal);
fdVolume->setTickPosition(QSlider::TicksAbove);
fdVolume->setRange(0, 15);
connect(fdVolume, &QSlider::sliderReleased, this, [=] {
if(gSelCards->isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "SetVolume");
json.insert("_type", "SetVolume");
json.insert("volume", fdVolume->value());
if(gSelCards->count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetVolume")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, *gSelCards) {
Def_CtrlSetMulti(tr("SetVolume"))
}
}
});
hBox->addWidget(fdVolume);
auto lbCurVol = new QLabel;
lbCurVol->setMinimumWidth(30);
connect(fdVolume, &QSlider::valueChanged, lbCurVol, (void(QLabel::*)(int))&QLabel::setNum);
hBox->addWidget(lbCurVol);
hBox->addStretch();
fdVolumeGet = new QPushButton;
fdVolumeGet->setMinimumSize(QSize(60, 30));
fdVolumeGet->setProperty("ssType", "progManageTool");
connect(fdVolumeGet, &QPushButton::clicked, this, [=] {
if(gSelCards->isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "GetVolume");
json.insert("_type", "GetVolume");
if(gSelCards->count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetVolume")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->success();
fdVolume->setValue(json["volume"].toInt());
});
} else {
foreach(auto card, *gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) err = QString::number(json["volume"].toInt());
gFdResInfo->append(cardId+" "+tr("GetVolume")+" "+err);
});
}
}
});
vBox->addWidget(fdVolumeGet, 0, Qt::AlignCenter);
vBox->addStretch();
}
m_pSchedule = new ControlVolumeSchedule(this, list);
connect(m_pSchedule, &ControlVolumeSchedule::sigHaveSchedule, this, [=](bool b) {
if(b) fdSchedule->setChecked(true);
else fdManual->setChecked(true);
});
stack->addWidget(m_pSchedule);
connect(fdSchedule, &QRadioButton::toggled, stack, &QStackedLayout::setCurrentIndex);
fdManual->setChecked(true);
connect(gDevicePanel, &DevicePanel::sigSelectedDeviceList, this, [this] {
if(isVisible()) init();
});
transUi();
}
void ControlVolumeWidget::showEvent(QShowEvent *event) {
QWidget::showEvent(event);
init();
}
void ControlVolumeWidget::init() {
bool isSingle = gSelCards->count()==1;
if(! isSingle) return;
auto card = gSelCards->at(0);
QJsonObject json;
json.insert("_id", "GetVolume");
json.insert("_type", "GetVolume");
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
fdVolume->setValue(json["volume"].toInt());
});
}
void ControlVolumeWidget::changeEvent(QEvent *event) {
QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi();
}
void ControlVolumeWidget::transUi() {
lbVolumeControl->setText(tr("Volume Control"));
fdManual->setText(tr("Manual"));
fdSchedule->setText(tr("Schedule"));
lbVolume->setText(tr("Volume"));
fdVolumeGet->setText(tr("Readback"));
m_pSchedule->refreshLable();
}

View File

@ -1,31 +0,0 @@
#ifndef CONTROLVOLUMEWIDGET_H
#define CONTROLVOLUMEWIDGET_H
#include <QWidget>
#include <device/controlvolumeschedule.h>
#include "QStackedWidget"
#include <QRadioButton>
class ControlVolumeWidget : public QWidget {
Q_OBJECT
public:
explicit ControlVolumeWidget(QWidget *parent = nullptr,QList<LedCard *> *m_pLedlist=nullptr);
protected:
void showEvent(QShowEvent *event) override;
void init();
void changeEvent(QEvent *) override;
void transUi();
private:
ControlVolumeSchedule *m_pSchedule;
QLabel *lbVolumeControl;
QRadioButton *fdManual;
QRadioButton *fdSchedule;
QLabel *lbVolume;
QSlider *fdVolume;
QPushButton *fdVolumeGet;
};
#endif // CONTROLVOLUMEWIDGET_H

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,9 @@
#include "ctrlbrightpanel.h" #include "ctrlbrightpanel.h"
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
#include "gutil/qnetwork.h"
#include "globaldefine.h" #include "globaldefine.h"
#include "tools.h" #include "tools.h"
#include "deviceitem.h"
#include "xlsxdocument.h" #include "xlsxdocument.h"
#include "xlsxworkbook.h" #include "xlsxworkbook.h"
#include <QMessageBox> #include <QMessageBox>
@ -11,6 +13,7 @@
#include <QThread> #include <QThread>
#include <QSettings> #include <QSettings>
#include <QTimeEdit> #include <QTimeEdit>
#include "devicepanel.h"
CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) { CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
auto vBox = new VBox(this); auto vBox = new VBox(this);
@ -84,7 +87,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnSensiSet->setMinimumSize(60, 30); btnSensiSet->setMinimumSize(60, 30);
btnSensiSet->setProperty("ssType", "progManageTool"); btnSensiSet->setProperty("ssType", "progManageTool");
connect(btnSensiSet, &QPushButton::clicked, this, [this] { connect(btnSensiSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -92,14 +95,14 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "SetBrightnessSensitivity"); json.insert("_id", "SetBrightnessSensitivity");
json.insert("_type", "SetBrightnessSensitivity"); json.insert("_type", "SetBrightnessSensitivity");
json.insert("sensitivity", fdSensi->value()); json.insert("sensitivity", fdSensi->value());
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetBrightnessSensitivity")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("SetBrightnessSensitivity")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetBrightnessSensitivity")) Def_CtrlSetMulti(tr("SetBrightnessSensitivity"))
} }
} }
@ -110,14 +113,14 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnSensiGet->setMinimumSize(60, 30); btnSensiGet->setMinimumSize(60, 30);
btnSensiGet->setProperty("ssType", "progManageTool"); btnSensiGet->setProperty("ssType", "progManageTool");
connect(btnSensiGet, &QPushButton::clicked, this, [this] { connect(btnSensiGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetBrightnessSensitivity"); json.insert("_id", "GetBrightnessSensitivity");
json.insert("_type", "GetBrightnessSensitivity"); json.insert("_type", "GetBrightnessSensitivity");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetBrightnessSensitivity")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("GetBrightnessSensitivity")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
@ -126,9 +129,9 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
fdSensi->setValue(json["sensitivity"].toInt()); fdSensi->setValue(json["sensitivity"].toInt());
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -167,7 +170,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnMinBrightSet->setMinimumSize(60, 30); btnMinBrightSet->setMinimumSize(60, 30);
btnMinBrightSet->setProperty("ssType", "progManageTool"); btnMinBrightSet->setProperty("ssType", "progManageTool");
connect(btnMinBrightSet, &QPushButton::clicked, this, [this] { connect(btnMinBrightSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -177,16 +180,16 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
json.insert("_type", "SetMinBrightness"); json.insert("_type", "SetMinBrightness");
auto brightPercent = fdMinBright->value(); auto brightPercent = fdMinBright->value();
if(! isAdaptToOld) json.insert("minBrightnessPercentage", brightPercent); if(! isAdaptToOld) json.insert("minBrightnessPercentage", brightPercent);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
if(isAdaptToOld) json.insert("brightness", (brightPercent * gSelCards->at(0)->BrightnessLevel + 50) / 100); if(isAdaptToOld) json.insert("brightness", (brightPercent * gSelCards[0].BrightnessLevel + 50) / 100);
auto waitingDlg = new WaitingDlg(this, tr("SetMinBrightness")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("SetMinBrightness")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
if(isAdaptToOld) json.insert("brightness", (brightPercent * card->BrightnessLevel + 50) / 100); if(isAdaptToOld) json.insert("brightness", (brightPercent * card.BrightnessLevel + 50) / 100);
Def_CtrlSetMulti(tr("SetMinBrightness")); Def_CtrlSetMulti(tr("SetMinBrightness"));
} }
} }
@ -197,17 +200,17 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnMinBrightGet->setMinimumSize(60, 30); btnMinBrightGet->setMinimumSize(60, 30);
btnMinBrightGet->setProperty("ssType", "progManageTool"); btnMinBrightGet->setProperty("ssType", "progManageTool");
connect(btnMinBrightGet, &QPushButton::clicked, this, [this] { connect(btnMinBrightGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetMinBrightness"); json.insert("_id", "GetMinBrightness");
json.insert("_type", "GetMinBrightness"); json.insert("_type", "GetMinBrightness");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetMinBrightness")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("GetMinBrightness")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
auto brightLevel = card->BrightnessLevel; auto brightLevel = card.BrightnessLevel;
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSingleGetReply Def_CtrlSingleGetReply
waitingDlg->success(); waitingDlg->success();
@ -216,10 +219,10 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
fdMinBright->setValue(value); fdMinBright->setValue(value);
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
auto brightLevel = card->BrightnessLevel; auto brightLevel = card.BrightnessLevel;
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -264,7 +267,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnUpload->setMinimumSize(60, 30); btnUpload->setMinimumSize(60, 30);
btnUpload->setProperty("ssType", "progManageTool"); btnUpload->setProperty("ssType", "progManageTool");
connect(btnUpload, &QPushButton::clicked, this, [this] { connect(btnUpload, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -314,14 +317,14 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "SensorBrightnessTable"); json.insert("_id", "SensorBrightnessTable");
json.insert("_type", "SensorBrightnessTable"); json.insert("_type", "SensorBrightnessTable");
json.insert("values", values); json.insert("values", values);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SensorBrightnessTable")); auto waitingDlg = new WaitingDlg(this, tr("SensorBrightnessTable"));
Def_CtrlReqPre; Def_CtrlReqPre;
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter; Def_CtrlSetReqAfter;
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SensorBrightnessTable")); Def_CtrlSetMulti(tr("SensorBrightnessTable"));
} }
} }
@ -332,7 +335,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnTableGet->setMinimumSize(60, 30); btnTableGet->setMinimumSize(60, 30);
btnTableGet->setProperty("ssType", "progManageTool"); btnTableGet->setProperty("ssType", "progManageTool");
connect(btnTableGet, &QPushButton::clicked, this, [this] { connect(btnTableGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -346,7 +349,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
QJsonObject json; QJsonObject json;
json.insert("_id", "GetSensorBrightnessTable"); json.insert("_id", "GetSensorBrightnessTable");
json.insert("_type", "GetSensorBrightnessTable"); json.insert("_type", "GetSensorBrightnessTable");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetSensorBrightnessTable")); auto waitingDlg = new WaitingDlg(this, tr("GetSensorBrightnessTable"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card, strSensorType] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card, strSensorType] {
@ -364,7 +367,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
return; return;
} }
QString selectFilter = "*.xlsx"; QString selectFilter = "*.xlsx";
QString savingFile = QFileDialog::getSaveFileName(this, tr("Save file"), card->m_strCardId + "BrightnessTable.xlsx", "brightness(*.xlsx );", &selectFilter, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); QString savingFile = QFileDialog::getSaveFileName(this, tr("Save file"), card.id + "BrightnessTable.xlsx", "brightness(*.xlsx );", &selectFilter, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if(savingFile.isEmpty()) return; if(savingFile.isEmpty()) return;
tempQFile.copy(savingFile); tempQFile.copy(savingFile);
QXlsx::Document xlsx(savingFile); QXlsx::Document xlsx(savingFile);
@ -393,14 +396,14 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnCurBrightGet->setMinimumSize(60, 30); btnCurBrightGet->setMinimumSize(60, 30);
btnCurBrightGet->setProperty("ssType", "progManageTool"); btnCurBrightGet->setProperty("ssType", "progManageTool");
connect(btnCurBrightGet, &QPushButton::clicked, this, [this] { connect(btnCurBrightGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetCurrentSensorBrightness"); json.insert("_id", "GetCurrentSensorBrightness");
json.insert("_type", "GetCurrentSensorBrightness"); json.insert("_type", "GetCurrentSensorBrightness");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetCurrentSensorBrightness")); auto waitingDlg = new WaitingDlg(this, tr("GetCurrentSensorBrightness"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] {
@ -415,16 +418,16 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
waitingDlg->success(); waitingDlg->success();
if(json["is485"].toBool()) fdR68->setChecked(true); if(json["is485"].toBool()) fdR68->setChecked(true);
else fdRL2->setChecked(true); else fdRL2->setChecked(true);
fdCurBright->setText(QString::number(qRound(json["value"].toInt() * 100.0 / card->BrightnessLevel))+"%"); fdCurBright->setText(QString::number(qRound(json["value"].toInt() * 100.0 / card.BrightnessLevel))+"%");
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, card] { connect(reply, &QNetworkReply::finished, this, [reply, card] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) err = (json["is485"].toBool() ? "R60 " : "RL1 ") + QString::number(qRound(json["value"].toInt() * 100.0 / card->BrightnessLevel))+"%"; if(err.isEmpty()) err = (json["is485"].toBool() ? "R60 " : "RL1 ") + QString::number(qRound(json["value"].toInt() * 100.0 / card.BrightnessLevel))+"%";
gFdResInfo->append(card->m_strCardId+" "+tr("GetCurrentSensorBrightness")+" "+err); gFdResInfo->append(card.id+" "+tr("GetCurrentSensorBrightness")+" "+err);
}); });
} }
} }
@ -468,7 +471,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnFixedSet->setMinimumSize(60, 30); btnFixedSet->setMinimumSize(60, 30);
btnFixedSet->setProperty("ssType", "progManageTool"); btnFixedSet->setProperty("ssType", "progManageTool");
connect(btnFixedSet, &QPushButton::clicked, this, [this] { connect(btnFixedSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -478,16 +481,16 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
json.insert("_type", "SetBrightness"); json.insert("_type", "SetBrightness");
auto percent = fdFixedBright->value(); auto percent = fdFixedBright->value();
if(! isAdaptToOld) json.insert("brightnessPercentage", percent); if(! isAdaptToOld) json.insert("brightnessPercentage", percent);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
if(isAdaptToOld) json.insert("brightness", (percent * gSelCards->at(0)->BrightnessLevel + 50) / 100); if(isAdaptToOld) json.insert("brightness", (percent * gSelCards[0].BrightnessLevel + 50) / 100);
auto waitingDlg = new WaitingDlg(this, tr("SetBrightness")); auto waitingDlg = new WaitingDlg(this, tr("SetBrightness"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
if(isAdaptToOld) json.insert("brightness", (percent * card->BrightnessLevel + 50) / 100); if(isAdaptToOld) json.insert("brightness", (percent * card.BrightnessLevel + 50) / 100);
Def_CtrlSetMulti(tr("SetBrightness")) Def_CtrlSetMulti(tr("SetBrightness"))
} }
} }
@ -498,14 +501,14 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnFixedGet->setMinimumSize(60, 30); btnFixedGet->setMinimumSize(60, 30);
btnFixedGet->setProperty("ssType", "progManageTool"); btnFixedGet->setProperty("ssType", "progManageTool");
connect(btnFixedGet, &QPushButton::clicked, this, [this] { connect(btnFixedGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetBrightness"); json.insert("_id", "GetBrightness");
json.insert("_type", "GetBrightness"); json.insert("_type", "GetBrightness");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetBrightness")); auto waitingDlg = new WaitingDlg(this, tr("GetBrightness"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] {
@ -518,22 +521,32 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
return; return;
} }
waitingDlg->success(); waitingDlg->success();
card->bright = json["brightnessPercentage"].toInt(-1); auto bright = json["brightnessPercentage"].toInt(-1);
if(card->bright==-1) card->bright = qRound(json["brightness"].toInt() * 100.0 / card->BrightnessLevel); if(bright==-1) bright = qRound(json["brightness"].toInt() * 100.0 / card.BrightnessLevel);
fdFixedBright->setValue(card->bright); fdFixedBright->setValue(bright);
auto item = findItem(card.id);
if(item) {
item->mCard.bright = bright;
item->setData(DeviceTable_Brightness, 0, QString::number(bright)+"%");
}
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, card] { connect(reply, &QNetworkReply::finished, this, [reply, card] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) { if(err.isEmpty()) {
auto value = json["brightnessPercentage"].toInt(-1); auto bright = json["brightnessPercentage"].toInt(-1);
if(value==-1) value = qRound(json["brightness"].toInt() * 100.0 / card->BrightnessLevel); if(bright==-1) bright = qRound(json["brightness"].toInt() * 100.0 / card.BrightnessLevel);
err = QString::number(value)+"%"; err = QString::number(bright)+"%";
auto item = findItem(card.id);
if(item) {
item->mCard.bright = bright;
item->setData(DeviceTable_Brightness, 0, err);
}
} }
gFdResInfo->append(card->m_strCardId+" "+tr("Brightness")+" "+err); gFdResInfo->append(card.id+" "+tr("Brightness")+" "+err);
}); });
} }
} }
@ -723,7 +736,7 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnScheSet->setMinimumSize(QSize(60, 30)); btnScheSet->setMinimumSize(QSize(60, 30));
btnScheSet->setProperty("ssType", "progManageTool"); btnScheSet->setProperty("ssType", "progManageTool");
connect(btnScheSet, &QPushButton::clicked, this, [this] { connect(btnScheSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -732,16 +745,16 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "SetAutoBrightnessTask"); json.insert("_id", "SetAutoBrightnessTask");
json.insert("_type", "SetAutoBrightnessTask"); json.insert("_type", "SetAutoBrightnessTask");
if(! isAdaptToOld) getScheduleJson(json, 0); if(! isAdaptToOld) getScheduleJson(json, 0);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
if(isAdaptToOld) getScheduleJson(json, gSelCards->at(0)->BrightnessLevel); if(isAdaptToOld) getScheduleJson(json, gSelCards[0].BrightnessLevel);
auto waitingDlg = new WaitingDlg(this, tr("SetAutoBrightnessTask")); auto waitingDlg = new WaitingDlg(this, tr("SetAutoBrightnessTask"));
Def_CtrlReqPre; Def_CtrlReqPre;
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
if(isAdaptToOld) getScheduleJson(json, card->BrightnessLevel); if(isAdaptToOld) getScheduleJson(json, card.BrightnessLevel);
Def_CtrlSetMulti(tr("SetAutoBrightnessTask")) Def_CtrlSetMulti(tr("SetAutoBrightnessTask"))
} }
} }
@ -754,20 +767,20 @@ CtrlBrightPanel::CtrlBrightPanel(QWidget *parent) : QWidget(parent) {
btnScheGet->setMinimumSize(QSize(60, 30)); btnScheGet->setMinimumSize(QSize(60, 30));
btnScheGet->setProperty("ssType", "progManageTool"); btnScheGet->setProperty("ssType", "progManageTool");
connect(btnScheGet, &QPushButton::clicked, this, [this] { connect(btnScheGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetAutoBrightnessTask"); json.insert("_id", "GetAutoBrightnessTask");
json.insert("_type", "GetAutoBrightnessTask"); json.insert("_type", "GetAutoBrightnessTask");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetAutoBrightnessTask")); auto waitingDlg = new WaitingDlg(this, tr("GetAutoBrightnessTask"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] {
Def_CtrlSingleGetReply Def_CtrlSingleGetReply
waitingDlg->success(); waitingDlg->success();
restoreScheduleJson(json, card->BrightnessLevel); restoreScheduleJson(json, card.BrightnessLevel);
}); });
} }
}); });
@ -796,11 +809,12 @@ void CtrlBrightPanel::showEvent(QShowEvent *event) {
init(); init();
} }
void CtrlBrightPanel::init() { void CtrlBrightPanel::init() {
bool isSingle = gSelCards->count()==1; bool isSingle = gSelCards.count()==1;
btnTableGet->setEnabled(isSingle); btnTableGet->setEnabled(isSingle);
btnScheGet->setEnabled(isSingle); btnScheGet->setEnabled(isSingle);
if(! isSingle) return; if(! isSingle) return;
auto card = gSelCards->at(0); auto card = gSelCards[0];
fdFixedBright->setValue(card.bright);
mSensi = -1; mSensi = -1;
mTask = -1; mTask = -1;
@ -808,12 +822,12 @@ void CtrlBrightPanel::init() {
QJsonObject json; QJsonObject json;
json.insert("_id", "GetAutoBrightnessTask"); json.insert("_id", "GetAutoBrightnessTask");
json.insert("_type", "GetAutoBrightnessTask"); json.insert("_type", "GetAutoBrightnessTask");
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply, card] { connect(reply, &QNetworkReply::finished, this, [this, reply, card] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return; if(! err.isEmpty()) return;
mTask = restoreScheduleJson(json, card->BrightnessLevel); mTask = restoreScheduleJson(json, card.BrightnessLevel);
if(mTask) radioSchedule->setChecked(true); if(mTask) radioSchedule->setChecked(true);
else if(mSensi > 0) radioAuto->setChecked(true); else if(mSensi > 0) radioAuto->setChecked(true);
else if(mSensi == 0) radioManual->setChecked(true); else if(mSensi == 0) radioManual->setChecked(true);
@ -822,7 +836,7 @@ void CtrlBrightPanel::init() {
json = QJsonObject(); json = QJsonObject();
json.insert("_id", "GetBrightnessSensitivity"); json.insert("_id", "GetBrightnessSensitivity");
json.insert("_type", "GetBrightnessSensitivity"); json.insert("_type", "GetBrightnessSensitivity");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] { connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -837,28 +851,15 @@ void CtrlBrightPanel::init() {
json = QJsonObject(); json = QJsonObject();
json.insert("_id", "GetMinBrightness"); json.insert("_id", "GetMinBrightness");
json.insert("_type", "GetMinBrightness"); json.insert("_type", "GetMinBrightness");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply, card] { connect(reply, &QNetworkReply::finished, this, [this, reply, card] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return; if(! err.isEmpty()) return;
auto value = json["minBrightnessPercentage"].toInt(-1); auto value = json["minBrightnessPercentage"].toInt(-1);
if(value==-1) value = qRound(json["brightness"].toInt() * 100.0 / card->BrightnessLevel); if(value==-1) value = qRound(json["brightness"].toInt() * 100.0 / card.BrightnessLevel);
fdMinBright->setValue(value); fdMinBright->setValue(value);
}); });
json = QJsonObject();
json.insert("_id", "GetBrightness");
json.insert("_type", "GetBrightness");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply, card] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
card->bright = json["brightnessPercentage"].toInt(-1);
if(card->bright==-1) card->bright = qRound(json["brightness"].toInt() * 100.0 / card->BrightnessLevel);
fdFixedBright->setValue(card->bright);
});
} }
void CtrlBrightPanel::changeEvent(QEvent *event) { void CtrlBrightPanel::changeEvent(QEvent *event) {

View File

@ -6,7 +6,6 @@
#include <QPushButton> #include <QPushButton>
#include <QRadioButton> #include <QRadioButton>
#include <QCheckBox> #include <QCheckBox>
#include <QSlider>
class CtrlBrightPanel : public QWidget { class CtrlBrightPanel : public QWidget {
Q_OBJECT Q_OBJECT

View File

@ -1,5 +1,6 @@
#include "ctrlhdmipanel.h" #include "ctrlhdmipanel.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include "tools.h" #include "tools.h"
#include "globaldefine.h" #include "globaldefine.h"
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
@ -7,8 +8,10 @@
#include <QButtonGroup> #include <QButtonGroup>
#include <QTimeEdit> #include <QTimeEdit>
#include <QJsonArray> #include <QJsonArray>
#include <QSettings>
#include "devicepanel.h"
CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) { CtrlHdmiPanel::CtrlHdmiPanel() {
auto vBox = new QVBoxLayout(this); auto vBox = new QVBoxLayout(this);
lbHdmiCfg = new QLabel; lbHdmiCfg = new QLabel;
lbHdmiCfg->setAlignment(Qt::AlignCenter); lbHdmiCfg->setAlignment(Qt::AlignCenter);
@ -32,8 +35,7 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
vBox->addLayout(hBox); vBox->addLayout(hBox);
auto stacked = new QStackedLayout; auto stacked = new QStackedLayout(vBox);
vBox->addLayout(stacked);
{ {
auto vBox = new VBox(stacked); auto vBox = new VBox(stacked);
vBox->addSpacing(20); vBox->addSpacing(20);
@ -64,7 +66,7 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
btnSyncSet->setMinimumSize(60, 30); btnSyncSet->setMinimumSize(60, 30);
btnSyncSet->setProperty("ssType", "progManageTool"); btnSyncSet->setProperty("ssType", "progManageTool");
connect(btnSyncSet, &QPushButton::clicked, this, [=] { connect(btnSyncSet, &QPushButton::clicked, this, [=] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -74,14 +76,14 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
json.insert("_type", "SyncSwitch"); json.insert("_type", "SyncSwitch");
json.insert("switchOn", (bool)id); json.insert("switchOn", (bool)id);
if(id) json.insert("number", id); if(id) json.insert("number", id);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, id ? tr("SyncSwitch") : tr("AnSyncSwitch")); auto waitingDlg = new WaitingDlg(this, id ? tr("SyncSwitch") : tr("AnSyncSwitch"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
if(id) { if(id) {
Def_CtrlSetMulti(tr("SyncSwitch")) Def_CtrlSetMulti(tr("SyncSwitch"))
} else { } else {
@ -97,14 +99,14 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
btnSyncGet->setMinimumSize(60, 30); btnSyncGet->setMinimumSize(60, 30);
btnSyncGet->setProperty("ssType", "progManageTool"); btnSyncGet->setProperty("ssType", "progManageTool");
connect(btnSyncGet, &QPushButton::clicked, this, [this] { connect(btnSyncGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "IsSync"); json.insert("_id", "IsSync");
json.insert("_type", "IsSync"); json.insert("_type", "IsSync");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("IsSync")); auto waitingDlg = new WaitingDlg(this, tr("IsSync"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -117,9 +119,9 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
else fdHdmi->setChecked(true); else fdHdmi->setChecked(true);
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -247,14 +249,14 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
btnScheSet->setProperty("ssType", "progManageTool"); btnScheSet->setProperty("ssType", "progManageTool");
btnScheSet->setMinimumSize(QSize(60, 30)); btnScheSet->setMinimumSize(QSize(60, 30));
connect(btnScheSet, &QPushButton::clicked, this, [this] { connect(btnScheSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "SetTimingHdmiInTask"); json.insert("_id", "SetTimingHdmiInTask");
json.insert("_type", "SetTimingHdmiInTask"); json.insert("_type", "SetTimingHdmiInTask");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
json.insert("HdmiInTask", getScheduleJson()); json.insert("HdmiInTask", getScheduleJson());
auto waitingDlg = new WaitingDlg(this, tr("SetTimingHdmiInTask")); auto waitingDlg = new WaitingDlg(this, tr("SetTimingHdmiInTask"));
Def_CtrlReqPre; Def_CtrlReqPre;
@ -262,7 +264,7 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
json.insert("HdmiInTask", getScheduleJson()); json.insert("HdmiInTask", getScheduleJson());
Def_CtrlSetMulti(tr("SetTimingHdmiInTask")) Def_CtrlSetMulti(tr("SetTimingHdmiInTask"))
} }
@ -275,14 +277,14 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
btnScheGet->setMinimumSize(QSize(0, 30)); btnScheGet->setMinimumSize(QSize(0, 30));
btnScheGet->setProperty("ssType", "progManageTool"); btnScheGet->setProperty("ssType", "progManageTool");
connect(btnScheGet, &QPushButton::clicked, this, [this] { connect(btnScheGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetTimingHdmiInTask"); json.insert("_id", "GetTimingHdmiInTask");
json.insert("_type", "GetTimingHdmiInTask"); json.insert("_type", "GetTimingHdmiInTask");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetTimingHdmiInTask")); auto waitingDlg = new WaitingDlg(this, tr("GetTimingHdmiInTask"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -297,12 +299,8 @@ CtrlHdmiPanel::CtrlHdmiPanel(QWidget *parent) : QWidget(parent) {
hBox->addStretch(); hBox->addStretch();
} }
auto m_buttonGroup = new QButtonGroup; connect(fdSchedule, &QRadioButton::toggled, stacked, &QStackedLayout::setCurrentIndex);
m_buttonGroup->addButton(fdManual, 0);
m_buttonGroup->addButton(fdSchedule, 1);
connect(m_buttonGroup, &QButtonGroup::idClicked, stacked, &QStackedLayout::setCurrentIndex);
fdManual->setChecked(true); fdManual->setChecked(true);
stacked->setCurrentIndex(0);
connect(gDevicePanel, &DevicePanel::sigSelectedDeviceList, this, [this] { connect(gDevicePanel, &DevicePanel::sigSelectedDeviceList, this, [this] {
if(isVisible()) init(); if(isVisible()) init();
@ -316,19 +314,19 @@ void CtrlHdmiPanel::showEvent(QShowEvent *event) {
} }
void CtrlHdmiPanel::init() { void CtrlHdmiPanel::init() {
bool isSingle = gSelCards->count()==1; bool isSingle = gSelCards.count()==1;
btnScheGet->setEnabled(isSingle); btnScheGet->setEnabled(isSingle);
if(! isSingle) { if(! isSingle) {
fdHdmi2->setVisible(true); fdHdmi2->setVisible(true);
return; return;
} }
auto card = gSelCards->at(0); auto card = gSelCards[0];
fdHdmi2->setVisible(card->m_strCardId.startsWith("m8s", Qt::CaseInsensitive)); fdHdmi2->setVisible(card.id.startsWith("m8s", Qt::CaseInsensitive));
QJsonObject json; QJsonObject json;
json.insert("_id", "IsSync"); json.insert("_id", "IsSync");
json.insert("_type", "IsSync"); json.insert("_type", "IsSync");
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] { connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -425,7 +423,7 @@ QJsonObject CtrlHdmiPanel::getScheduleJson() {
} }
return QJsonObject{ return QJsonObject{
{"createBy", "alahover"}, {"createBy", "alahover"},
{"name", "TimingScreen"}, {"name", "TimingHdmi"},
{"schedules", schedules} {"schedules", schedules}
}; };
} }

View File

@ -1,7 +1,6 @@
#ifndef CTRLHDMIPANEL_H #ifndef CTRLHDMIPANEL_H
#define CTRLHDMIPANEL_H #define CTRLHDMIPANEL_H
#include "base/switchcontrol.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include <QLabel> #include <QLabel>
#include <QRadioButton> #include <QRadioButton>
@ -10,7 +9,7 @@
class CtrlHdmiPanel : public QWidget { class CtrlHdmiPanel : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit CtrlHdmiPanel(QWidget *parent = nullptr); CtrlHdmiPanel();
void restoreScheduleJson(QJsonObject oTaskSync); void restoreScheduleJson(QJsonObject oTaskSync);
QJsonObject getScheduleJson(); QJsonObject getScheduleJson();
protected: protected:

View File

@ -2,6 +2,7 @@
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
#include "globaldefine.h" #include "globaldefine.h"
#include "tools.h" #include "tools.h"
#include "devicepanel.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "gutil/qnetwork.h" #include "gutil/qnetwork.h"
#include <QJsonArray> #include <QJsonArray>
@ -101,7 +102,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnLanSet->setMinimumSize(QSize(60, 30)); btnLanSet->setMinimumSize(QSize(60, 30));
btnLanSet->setProperty("ssType", "progManageTool"); btnLanSet->setProperty("ssType", "progManageTool");
connect(btnLanSet, &QPushButton::clicked, this, [this] { connect(btnLanSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -144,14 +145,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
json.insert("netMask", mask); json.insert("netMask", mask);
json.insert("gateWay", gateWay); json.insert("gateWay", gateWay);
json.insert("dns", dns); json.insert("dns", dns);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetEthernet")); auto waitingDlg = new WaitingDlg(this, tr("SetEthernet"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetEthernet")) Def_CtrlSetMulti(tr("SetEthernet"))
} }
} }
@ -164,14 +165,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnLanGet->setMinimumSize(QSize(60, 30)); btnLanGet->setMinimumSize(QSize(60, 30));
btnLanGet->setProperty("ssType", "progManageTool"); btnLanGet->setProperty("ssType", "progManageTool");
connect(btnLanGet, &QPushButton::clicked, this, [this] { connect(btnLanGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetEthernet"); json.insert("_id", "GetEthernet");
json.insert("_type", "GetEthernet"); json.insert("_type", "GetEthernet");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetEthernet")); auto waitingDlg = new WaitingDlg(this, tr("GetEthernet"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -190,9 +191,9 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
fdDns->setText(json["dnsAddr"].toString()); fdDns->setText(json["dnsAddr"].toString());
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -254,14 +255,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnScan->setMinimumWidth(60); btnScan->setMinimumWidth(60);
btnScan->setProperty("ssType", "progManageTool"); btnScan->setProperty("ssType", "progManageTool");
connect(btnScan, &QPushButton::clicked, this, [this] { connect(btnScan, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetWifiList"); json.insert("_id", "GetWifiList");
json.insert("_type", "GetWifiList"); json.insert("_type", "GetWifiList");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetWifiList")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("GetWifiList")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -327,7 +328,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnWiFiSet->setMinimumSize(QSize(60, 30)); btnWiFiSet->setMinimumSize(QSize(60, 30));
btnWiFiSet->setProperty("ssType", "progManageTool"); btnWiFiSet->setProperty("ssType", "progManageTool");
connect(btnWiFiSet, &QPushButton::clicked, this, [this] { connect(btnWiFiSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -342,35 +343,35 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
json2.insert("_type", "ConfigurationWiFi"); json2.insert("_type", "ConfigurationWiFi");
json2.insert("ssid", fdWifiName->currentText()); json2.insert("ssid", fdWifiName->currentText());
json2.insert("password", fdWifiPassword->text()); json2.insert("password", fdWifiPassword->text());
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("ConfigurationWiFi")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("ConfigurationWiFi")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QString err = checkReplyForJson(reply); QString err = checkReplyForJson(reply);
if(! err.isEmpty()) { if(! err.isEmpty()) {
waitingDlg->close(); waitingDlg->close();
QMessageBox::critical(this, tr("Error"), err); QMessageBox::critical(this, tr("Error"), err);
return; return;
} }
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json2); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json2);
waitingDlg->connAbort(reply); waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QString err = checkReplyForJson(reply); QString err = checkReplyForJson(reply);
if(! err.isEmpty()) { if(! err.isEmpty()) {
gFdResInfo->append(card->m_strCardId+" "+tr("ConfigurationWiFi")+" "+err); gFdResInfo->append(card.id+" "+tr("ConfigurationWiFi")+" "+err);
return; return;
} }
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json2); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json2);
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QString err = checkReplyForJson(reply); QString err = checkReplyForJson(reply);
gFdResInfo->append(card->m_strCardId+" "+tr("ConfigurationWiFi")+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err)); gFdResInfo->append(card.id+" "+tr("ConfigurationWiFi")+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));
}); });
}); });
} }
@ -381,14 +382,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
json.insert("_type", "ConfigurationHotSpot"); json.insert("_type", "ConfigurationHotSpot");
json.insert("apName", fdHotspotName->text()); json.insert("apName", fdHotspotName->text());
json.insert("password", fdHotspotPassword->text()); json.insert("password", fdHotspotPassword->text());
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("ConfigurationHotSpot")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("ConfigurationHotSpot")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("ConfigurationHotSpot")); Def_CtrlSetMulti(tr("ConfigurationHotSpot"));
} }
} }
@ -401,14 +402,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnWiFiGet->setMinimumSize(QSize(60, 30)); btnWiFiGet->setMinimumSize(QSize(60, 30));
btnWiFiGet->setProperty("ssType", "progManageTool"); btnWiFiGet->setProperty("ssType", "progManageTool");
connect(btnWiFiGet, &QPushButton::clicked, this, [this] { connect(btnWiFiGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "IsPortableHotSpot"); json.insert("_id", "IsPortableHotSpot");
json.insert("_type", "IsPortableHotSpot"); json.insert("_type", "IsPortableHotSpot");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("IsPortableHotSpot")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("IsPortableHotSpot")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -421,9 +422,9 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
else fdIsHotspot->setChecked(true); else fdIsHotspot->setChecked(true);
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -464,7 +465,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
fdMcc->setEnabled(checked); fdMcc->setEnabled(checked);
fdCarrierName->setEnabled(checked); fdCarrierName->setEnabled(checked);
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -472,14 +473,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "SetSwitchSimData"); json.insert("_id", "SetSwitchSimData");
json.insert("_type", "SetSwitchSimData"); json.insert("_type", "SetSwitchSimData");
json.insert("enable", checked); json.insert("enable", checked);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetSwitchSimData")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("SetSwitchSimData")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetSwitchSimData")) Def_CtrlSetMulti(tr("SetSwitchSimData"))
} }
} }
@ -490,14 +491,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnSIMStatusGet->setMinimumHeight(30); btnSIMStatusGet->setMinimumHeight(30);
btnSIMStatusGet->setProperty("ssType", "progManageTool"); btnSIMStatusGet->setProperty("ssType", "progManageTool");
connect(btnSIMStatusGet, &QPushButton::clicked, this, [this] { connect(btnSIMStatusGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetSIMStatus"); json.insert("_id", "GetSIMStatus");
json.insert("_type", "GetSIMStatus"); json.insert("_type", "GetSIMStatus");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetSIMStatus")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("GetSIMStatus")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -678,7 +679,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnAPNCusSet->setMinimumSize(QSize(60, 30)); btnAPNCusSet->setMinimumSize(QSize(60, 30));
btnAPNCusSet->setProperty("ssType", "progManageTool"); btnAPNCusSet->setProperty("ssType", "progManageTool");
connect(btnAPNCusSet, &QPushButton::clicked, this, [=] { connect(btnAPNCusSet, &QPushButton::clicked, this, [=] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -697,14 +698,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
json.insert("mmsproxy", fdCus_mmsProxy->text()); json.insert("mmsproxy", fdCus_mmsProxy->text());
json.insert("mmsport", fdCus_mmsPort->text()); json.insert("mmsport", fdCus_mmsPort->text());
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetAPN")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("SetAPN")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetAPN")) Def_CtrlSetMulti(tr("SetAPN"))
} }
} }
@ -716,14 +717,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnAPNCusGet->setMinimumSize(QSize(60, 30)); btnAPNCusGet->setMinimumSize(QSize(60, 30));
btnAPNCusGet->setProperty("ssType", "progManageTool"); btnAPNCusGet->setProperty("ssType", "progManageTool");
connect(btnAPNCusGet, &QPushButton::clicked, this, [=] { connect(btnAPNCusGet, &QPushButton::clicked, this, [=] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetCurrentAPN"); json.insert("_id", "GetCurrentAPN");
json.insert("_type", "GetCurrentAPN"); json.insert("_type", "GetCurrentAPN");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetCurrentAPN")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("GetCurrentAPN")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
@ -742,9 +743,9 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
fdCus_mmsPort->setText(json["mmsport"].toString()); fdCus_mmsPort->setText(json["mmsport"].toString());
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -780,7 +781,7 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
fdFightModel->setTextColor(QColor(100,100,100),QColor(0, 160, 230)); fdFightModel->setTextColor(QColor(100,100,100),QColor(0, 160, 230));
fdFightModel->setText(tr("OFF"), tr("ON")); fdFightModel->setText(tr("OFF"), tr("ON"));
connect(fdFightModel, &SwitchControl::checkedChanged, this, [=](bool checked) { connect(fdFightModel, &SwitchControl::checkedChanged, this, [=](bool checked) {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -788,14 +789,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "ContrFlightMode"); json.insert("_id", "ContrFlightMode");
json.insert("_type", "ContrFlightMode"); json.insert("_type", "ContrFlightMode");
json.insert("state", checked); json.insert("state", checked);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("ContrFlightMode")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("ContrFlightMode")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("ContrFlightMode")) Def_CtrlSetMulti(tr("ContrFlightMode"))
} }
} }
@ -806,14 +807,14 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
btnFlightModelGet->setMinimumSize(QSize(0, 30)); btnFlightModelGet->setMinimumSize(QSize(0, 30));
btnFlightModelGet->setProperty("ssType", "progManageTool"); btnFlightModelGet->setProperty("ssType", "progManageTool");
connect(btnFlightModelGet, &QPushButton::clicked, this, [this] { connect(btnFlightModelGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetFlightModeState"); json.insert("_id", "GetFlightModeState");
json.insert("_type", "GetFlightModeState"); json.insert("_type", "GetFlightModeState");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetFlightModeState")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("GetFlightModeState")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -823,9 +824,9 @@ CtrlNetworkPanel::CtrlNetworkPanel(QWidget *parent) : QWidget(parent) {
fdFightModel->update(); fdFightModel->update();
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -851,16 +852,16 @@ void CtrlNetworkPanel::showEvent(QShowEvent *event) {
init(); init();
} }
void CtrlNetworkPanel::init() { void CtrlNetworkPanel::init() {
bool isSingle = gSelCards->count()==1; bool isSingle = gSelCards.count()==1;
btnScan->setEnabled(isSingle); btnScan->setEnabled(isSingle);
if(! isSingle) return; if(! isSingle) return;
auto card = gSelCards->at(0); auto card = gSelCards[0];
QJsonObject json; QJsonObject json;
json.insert("_id", "GetEthernet"); json.insert("_id", "GetEthernet");
json.insert("_type", "GetEthernet"); json.insert("_type", "GetEthernet");
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] { connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -882,7 +883,7 @@ void CtrlNetworkPanel::init() {
json = QJsonObject(); json = QJsonObject();
json.insert("_id", "GetWifiList"); json.insert("_id", "GetWifiList");
json.insert("_type", "GetWifiList"); json.insert("_type", "GetWifiList");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -894,7 +895,7 @@ void CtrlNetworkPanel::init() {
QJsonObject json; QJsonObject json;
json.insert("_id", "IsPortableHotSpot"); json.insert("_id", "IsPortableHotSpot");
json.insert("_type", "IsPortableHotSpot"); json.insert("_type", "IsPortableHotSpot");
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] { connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -912,7 +913,7 @@ void CtrlNetworkPanel::init() {
json = QJsonObject(); json = QJsonObject();
json.insert("_id", "GetSwitchSimData"); json.insert("_id", "GetSwitchSimData");
json.insert("_type", "GetSwitchSimData"); json.insert("_type", "GetSwitchSimData");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -926,7 +927,7 @@ void CtrlNetworkPanel::init() {
json = QJsonObject(); json = QJsonObject();
json.insert("_id", "GetAPNList"); json.insert("_id", "GetAPNList");
json.insert("_type", "GetAPNList"); json.insert("_type", "GetAPNList");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -948,12 +949,12 @@ void CtrlNetworkPanel::init() {
} }
}); });
getCurrentAPN(card->m_strCardIp); getCurrentAPN(card.ip);
json = QJsonObject(); json = QJsonObject();
json.insert("_id", "GetFlightModeState"); json.insert("_id", "GetFlightModeState");
json.insert("_type", "GetFlightModeState"); json.insert("_type", "GetFlightModeState");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);

View File

@ -1,9 +1,6 @@
#ifndef CTRLNETWORKPANEL_H #ifndef CTRLNETWORKPANEL_H
#define CTRLNETWORKPANEL_H #define CTRLNETWORKPANEL_H
#include <device/ledcard.h>
#include <communication/hpptclient.h>
#include <base/loemptydialog.h>
#include "base/switchcontrol.h" #include "base/switchcontrol.h"
#include <QRadioButton> #include <QRadioButton>
#include <QButtonGroup> #include <QButtonGroup>
@ -12,6 +9,8 @@
#include <QGroupBox> #include <QGroupBox>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QPushButton>
#include <QLabel>
struct ApnInfo { struct ApnInfo {
QString apn; QString apn;

View File

@ -0,0 +1,429 @@
#include "ctrlpowerpanel.h"
#include "globaldefine.h"
#include "deviceitem.h"
#include "devicepanel.h"
#include "base/waitingdlg.h"
#include "gutil/qnetwork.h"
#include "tools.h"
#include <QMessageBox>
#include <QTimeEdit>
#include <QJsonArray>
#include <QSettings>
CtrlPowerPanel::CtrlPowerPanel() {
auto vBox = new VBox(this);
lbScreenCfg = new QLabel;
lbScreenCfg->setAlignment(Qt::AlignCenter);
vBox->addWidget(lbScreenCfg);
auto hBox = new HBox(vBox);
hBox->addStretch();
fdManual = new QRadioButton;
hBox->addWidget(fdManual);
hBox->addSpacing(40);
fdSchedule = new QRadioButton;
hBox->addWidget(fdSchedule);
hBox->addStretch();
auto stack = new QStackedLayout(vBox);
{
auto vBox = new VBox(stack);
vBox->addSpacing(20);
auto hBox = new HBox(vBox);
hBox->addStretch();
lbScreen = new QLabel;
hBox->addWidget(lbScreen);
fdScreen = new SwitchControl;
fdScreen->setMinimumSize(QSize(80, 33));
fdScreen->setSliderColor(QColor(0, 0, 0), QColor(0, 160, 230));
fdScreen->setBgColor(QColor(200,200,200), QColor(0x00cc00));
fdScreen->setTextColor(QColor(100,100,100), QColor(0, 160, 230));
connect(fdScreen, &SwitchControl::checkedChanged, this, [this](bool checked) {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "SetScreenOn");
json.insert("_type", "SetScreenOn");
json.insert("on", checked);
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, (checked ? tr("SetScreenOn") : tr("SetScreenOff"))+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
if(checked) foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetScreenOn"))
}
else foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetScreenOff"))
}
}
});
hBox->addWidget(fdScreen);
hBox->addStretch();
btnScreenGet = new QPushButton;
btnScreenGet->setMinimumSize(QSize(60, 30));
btnScreenGet->setProperty("ssType", "progManageTool");
connect(btnScreenGet, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "IsScreenOn");
json.insert("_type", "IsScreenOn");
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("IsScreenOn")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSingleGetReply
waitingDlg->success();
fdScreen->setCheckedStatus(json["on"].toBool());
auto item = findItem(card.id);
if(item) {
item->mCard.isScreenOn = json["on"].toBool();
item->setForeground(DeviceTable_Power, item->mCard.isScreenOn ? Qt::green : Qt::red);
item->setData(DeviceTable_Power, 0, item->mCard.isScreenOn ? tr("On") : tr("Off"));
}
});
} else {
foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) {
err = json["on"].toBool() ? tr("On") : tr("Off");
auto item = findItem(card.id);
if(item) {
item->mCard.isScreenOn = json["on"].toBool();
item->setForeground(DeviceTable_Power, item->mCard.isScreenOn ? Qt::green : Qt::red);
item->setData(DeviceTable_Power, 0, err);
}
}
gFdResInfo->append(card.id+" "+tr("IsScreenOn")+" "+err);
});
}
}
});
vBox->addWidget(btnScreenGet, 0, Qt::AlignCenter);
vBox->addStretch();
}
{
auto vBox = new VBox(stack);
auto hBox = new HBox(vBox);
hBox->setSpacing(10);
tableSche = new Table({
{"start", "", 100},
{"end", "", 100},
{"0", "", 60},
{"1", "", 60},
{"2", "", 60},
{"3", "", 60},
{"4", "", 60},
{"5", "", 60},
{"6", "", 60}
});
tableSche->setDefs();
pushButtonAdd = new QPushButton;
pushButtonAdd->setMinimumSize(QSize(60, 30));
pushButtonAdd->setProperty("ssType", "progManageTool");
connect(pushButtonAdd, &QPushButton::clicked, this, [this] {
int row = tableSche->appendRow();
auto timeEdit = new QTimeEdit(QTime(0, 0));
timeEdit->setDisplayFormat("HH:mm");
timeEdit->setAlignment(Qt::AlignCenter);
tableSche->setCellWidget(row, "start", timeEdit);
timeEdit = new QTimeEdit(QTime(1, 0));
timeEdit->setDisplayFormat("HH:mm");
timeEdit->setAlignment(Qt::AlignCenter);
tableSche->setCellWidget(row, "end", timeEdit);
for(int i=0; i<7; i++) {
auto fd = new QCheckBox;
fd->setChecked(true);
tableSche->setCellWidget(row, QString::number(i), fd);
}
});
hBox->addWidget(pushButtonAdd);
pushButtonDelete = new QPushButton;
pushButtonDelete->setMinimumSize(QSize(60, 30));
pushButtonDelete->setProperty("ssType", "progManageTool");
connect(pushButtonDelete, &QPushButton::clicked, this, [this] {
auto selected = tableSche->selectedRanges();
if(! selected.isEmpty()) tableSche->model()->removeRows(selected[0].topRow(), selected[0].rowCount());
});
hBox->addWidget(pushButtonDelete);
pushButtonClear = new QPushButton;
pushButtonClear->setMinimumSize(QSize(60, 30));
pushButtonClear->setProperty("ssType", "progManageTool");
connect(pushButtonClear, &QPushButton::clicked, tableSche, &Table::clearRows);
hBox->addWidget(pushButtonClear);
hBox->addStretch();
pushButtonImport = new QPushButton;
pushButtonImport->setMinimumSize(QSize(0, 30));
pushButtonImport->setProperty("ssType", "progManageTool");
connect(pushButtonImport, &QPushButton::clicked, this, [this] {
auto dir = QSettings().value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("PowerSchedule (*.pjs)"));
if(scheFile.isEmpty()) return;
QFile scheQFile(scheFile);
if(! scheQFile.open(QIODevice::ReadOnly)) return;
auto data = scheQFile.readAll();
scheQFile.close();
restoreScheduleJson(QJsonDocument::fromJson(data).object());
});
hBox->addWidget(pushButtonImport);
pushButtonExport = new QPushButton;
pushButtonExport->setMinimumSize(QSize(0, 30));
pushButtonExport->setProperty("ssType", "progManageTool");
connect(pushButtonExport, &QPushButton::clicked, this, [this] {
QSettings settings;
auto dir = settings.value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("PowerSchedule (*.pjs)"));
if(scheFile.isEmpty()) return;
settings.setValue("CtrlScheduleDir", QFileInfo(scheFile).absolutePath());
QFile scheQFile(scheFile);
if(! scheQFile.open(QIODevice::WriteOnly)) return;
scheQFile.write(QJsonDocument(getScheduleJson()).toJson());
scheQFile.close();
});
hBox->addWidget(pushButtonExport);
labelPowerScheduleTip = new QLabel;
labelPowerScheduleTip->setWordWrap(true);
vBox->addWidget(labelPowerScheduleTip);
vBox->addWidget(tableSche);
hBox = new HBox(vBox);
hBox->addStretch();
pushButtonApply = new QPushButton;
pushButtonApply->setProperty("ssType", "progManageTool");
pushButtonApply->setMinimumSize(QSize(60, 30));
connect(pushButtonApply, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
if(tableSche->rowCount()==0) clearSche();
else {
QJsonObject json;
json.insert("_id", "SetTimingScreenTask");
json.insert("_type", "SetTimingScreenTask");
json.insert("screenTask", getScheduleJson());
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetTimingScreenTask"));
Def_CtrlReqPre;
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetTimingScreenTask"))
}
}
}
});
hBox->addWidget(pushButtonApply);
hBox->addStretch();
pushButtonClearSchedule = new QPushButton;
pushButtonClearSchedule->setMinimumSize(QSize(0, 30));
pushButtonClearSchedule->setProperty("ssType", "progManageTool");
connect(pushButtonClearSchedule, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
clearSche();
});
hBox->addWidget(pushButtonClearSchedule);
hBox->addStretch();
pushButtonReadback = new QPushButton;
pushButtonReadback->setMinimumSize(QSize(0, 30));
pushButtonReadback->setProperty("ssType", "progManageTool");
connect(pushButtonReadback, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "GetTimingScreenTask");
json.insert("_type", "GetTimingScreenTask");
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetTimingScreenTask"));
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->success();
restoreScheduleJson(json["screenTask"].toObject());
});
}
});
hBox->addWidget(pushButtonReadback);
hBox->addStretch();
}
connect(fdSchedule, &QRadioButton::toggled, stack, &QStackedLayout::setCurrentIndex);
fdManual->setChecked(true);
connect(gDevicePanel, &DevicePanel::sigSelectedDeviceList, this, [this] {
if(isVisible()) init();
});
transUi();
}
void CtrlPowerPanel::showEvent(QShowEvent *event) {
QWidget::showEvent(event);
init();
}
void CtrlPowerPanel::init() {
bool isSingle = gSelCards.count()==1;
pushButtonReadback->setEnabled(isSingle);
if(! isSingle) return;
auto card = gSelCards[0];
fdScreen->setCheckedStatus(card.isScreenOn);
QJsonObject json;
json.insert("_id", "GetTimingScreenTask");
json.insert("_type", "GetTimingScreenTask");
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply, card] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
if(restoreScheduleJson(json["screenTask"].toObject())) fdSchedule->setChecked(true);
else fdManual->setChecked(true);
});
}
void CtrlPowerPanel::changeEvent(QEvent *event) {
QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi();
}
void CtrlPowerPanel::transUi() {
lbScreenCfg->setText(tr("Power Configuration"));
fdManual->setText(tr("Manual"));
fdSchedule->setText(tr("Schedule"));
lbScreen->setText(tr("Power"));
fdScreen->setText(tr("Off"), tr("On"));
btnScreenGet->setText(tr("Readback"));
tableSche->setHeaderText("start", tr("Start Time"));
tableSche->setHeaderText("end", tr("End Time"));
tableSche->setHeaderText("0", tr("SUN"));
tableSche->setHeaderText("1", tr("MON"));
tableSche->setHeaderText("2", tr("TUE"));
tableSche->setHeaderText("3", tr("WED"));
tableSche->setHeaderText("4", tr("THU"));
tableSche->setHeaderText("5", tr("FRI"));
tableSche->setHeaderText("6", tr("SAT"));
pushButtonAdd->setText(tr("Add"));
pushButtonApply->setText(tr("Apply"));
pushButtonClear->setText(tr("Clear"));
pushButtonDelete->setText(tr("Delete"));
pushButtonImport->setText(tr("Import"));
pushButtonExport->setText(tr("Export"));
labelPowerScheduleTip->setText(tr("It is power off state outside the schedule time period"));
pushButtonClearSchedule->setText(tr("Clear Schedule"));
pushButtonReadback->setText(tr("Readback"));
}
bool CtrlPowerPanel::restoreScheduleJson(QJsonObject oTaskSync) {
tableSche->setRowCount(0);
auto schedules = oTaskSync["schedules"].toArray();
foreach(QJsonValue schedule, schedules) {
int row = tableSche->rowCount();
tableSche->insertRow(row);
auto timeEdit = new QTimeEdit(QTime::fromString(schedule["startTime"].toString()+":00"));
timeEdit->setDisplayFormat("HH:mm");
timeEdit->setAlignment(Qt::AlignCenter);
tableSche->setCellWidget(row, "start", timeEdit);
timeEdit = new QTimeEdit(QTime::fromString(schedule["endTime"].toString()+":00"));
timeEdit->setDisplayFormat("HH:mm");
timeEdit->setAlignment(Qt::AlignCenter);
tableSche->setCellWidget(row, "end", timeEdit);
if(schedule["filterType"].toString()=="None") for(int i=0; i<7; i++) {
auto fd = new QCheckBox;
fd->setChecked(true);
tableSche->setCellWidget(row, QString::number(i), fd);
} else if(schedule["filterType"].toString()=="Week") {
auto weekFilter = schedule["weekFilter"].toArray();
for(int i=0; i<7; i++) {
auto fd = new QCheckBox;
if(weekFilter.contains(i)) fd->setChecked(true);
tableSche->setCellWidget(row, QString::number(i), fd);
}
}
}
return schedules.count() > 0;
}
QJsonObject CtrlPowerPanel::getScheduleJson() {
QJsonArray schedules;
for(int i=0; i<tableSche->rowCount(); i++) {
QJsonObject schedule;
schedule["timeType"] = "Range";
schedule["startTime"] = static_cast<QTimeEdit*>(tableSche->cellWidget(i, "start"))->text();
schedule["endTime"] = static_cast<QTimeEdit*>(tableSche->cellWidget(i, "end"))->text();
schedule["dateType"] = "All";
schedule["monthFilter"] = QJsonArray();
QJsonArray weekFilter;
for(int d=0; d<7; d++) if(static_cast<QCheckBox*>(tableSche->cellWidget(i, QString::number(d)))->isChecked()) weekFilter.append(d);
if(weekFilter.size()>=7) {
schedule["filterType"] = "None";
weekFilter = QJsonArray();
} else schedule["filterType"] = "Week";
schedule["weekFilter"] = weekFilter;
schedules.append(schedule);
}
return QJsonObject{
{"createBy", "alahover"},
{"name", "TimingScreen"},
{"schedules", schedules}
};
}
void CtrlPowerPanel::clearSche() {
auto btn = QMessageBox::question(this, tr("Tip Info"), tr("Clear schedule task?"));
if(btn != QMessageBox::Yes) return;
QJsonObject json;
json.insert("_id", "CleanTimingScreenTask");
json.insert("_type", "CleanTimingScreenTask");
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("CleanTimingScreenTask"));
Def_CtrlReqPre;
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("CleanTimingScreenTask"))
}
}
}

View File

@ -0,0 +1,43 @@
#ifndef CTRLPOWERPANEL_H
#define CTRLPOWERPANEL_H
#include "gutil/qgui.h"
#include <QLabel>
#include <QRadioButton>
#include <QPushButton>
#include <base/switchcontrol.h>
class CtrlPowerPanel : public QWidget {
Q_OBJECT
public:
CtrlPowerPanel();
bool restoreScheduleJson(QJsonObject oTaskSync);
QJsonObject getScheduleJson();
void clearSche();
protected:
void showEvent(QShowEvent *event) override;
void init();
void changeEvent(QEvent *) override;
void transUi();
private:
QLabel *lbScreenCfg;
QRadioButton *fdManual;
QRadioButton *fdSchedule;
QLabel *lbScreen;
SwitchControl *fdScreen;
QPushButton *btnScreenGet;
QPushButton *pushButtonAdd;
QPushButton *pushButtonDelete;
QPushButton *pushButtonClear;
QPushButton *pushButtonImport;
QPushButton *pushButtonExport;
QLabel *labelPowerScheduleTip;
Table *tableSche;
QPushButton *pushButtonApply;
QPushButton *pushButtonClearSchedule;
QPushButton *pushButtonReadback;
};
#endif // CTRLPOWERPANEL_H

View File

@ -1,11 +1,14 @@
#include "ctrlpwdpanel.h" #include "ctrlpwdpanel.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
#include "QFileDialog" #include "QFileDialog"
#include <QMessageBox> #include <QMessageBox>
#include <QJsonObject> #include <QJsonObject>
#include <globaldefine.h> #include "globaldefine.h"
#include "tools.h" #include "tools.h"
#include "deviceitem.h"
#include "devicepanel.h"
CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) { CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
auto vBox = new VBox(this); auto vBox = new VBox(this);
@ -51,7 +54,7 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
btnPwdSet->setMinimumSize(60, 30); btnPwdSet->setMinimumSize(60, 30);
btnPwdSet->setProperty("ssType", "progManageTool"); btnPwdSet->setProperty("ssType", "progManageTool");
connect(btnPwdSet, &QPushButton::clicked, this, [this] { connect(btnPwdSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -78,10 +81,10 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
json.insert("_type", "SetControllerPassword"); json.insert("_type", "SetControllerPassword");
json.insert("pwd", fdOldPwd->text()); json.insert("pwd", fdOldPwd->text());
json.insert("newPwd", fdNewPwd->text()); json.insert("newPwd", fdNewPwd->text());
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetControllerPassword")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("SetControllerPassword")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) { if(! err.isEmpty()) {
@ -99,15 +102,19 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
fdOldPwd->show(); fdOldPwd->show();
btnPwdClear->show(); btnPwdClear->show();
btnPwdSet->setText(tr("Modify password")); btnPwdSet->setText(tr("Modify password"));
card->bPassword = true; auto item = findItem(card.id);
if(item) {
item->mCard.hasPassword = true;
item->init();
}
fdNewPwd->clear(); fdNewPwd->clear();
fdPwdAgain->clear(); fdPwdAgain->clear();
fdOldPwd->clear(); fdOldPwd->clear();
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) { if(err.isEmpty()) {
@ -118,10 +125,14 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
fdOldPwd->show(); fdOldPwd->show();
btnPwdClear->show(); btnPwdClear->show();
btnPwdSet->setText(tr("Modify password")); btnPwdSet->setText(tr("Modify password"));
card->bPassword = true; auto item = findItem(card.id);
if(item) {
item->mCard.hasPassword = true;
item->init();
}
} }
} }
gFdResInfo->append(card->m_strCardId+" "+tr("SetControllerPassword")+" "+err); gFdResInfo->append(card.id+" "+tr("SetControllerPassword")+" "+err);
}); });
} }
} }
@ -132,7 +143,7 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
btnPwdClear->setMinimumSize(60, 30); btnPwdClear->setMinimumSize(60, 30);
btnPwdClear->setProperty("ssType", "progManageTool"); btnPwdClear->setProperty("ssType", "progManageTool");
connect(btnPwdClear, &QPushButton::clicked, this, [this] { connect(btnPwdClear, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -145,10 +156,10 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
json.insert("_type", "SetControllerPassword"); json.insert("_type", "SetControllerPassword");
json.insert("pwd", fdOldPwd->text()); json.insert("pwd", fdOldPwd->text());
json.insert("newPwd",""); json.insert("newPwd","");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetControllerPassword")+" ..."); auto waitingDlg = new WaitingDlg(this, tr("SetControllerPassword")+" ...");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) { if(! err.isEmpty()) {
@ -166,15 +177,19 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
fdOldPwd->hide(); fdOldPwd->hide();
btnPwdClear->hide(); btnPwdClear->hide();
btnPwdSet->setText(tr("Set encryption")); btnPwdSet->setText(tr("Set encryption"));
card->bPassword = false; auto item = findItem(card.id);
if(item) {
item->mCard.hasPassword = false;
item->init();
}
fdNewPwd->clear(); fdNewPwd->clear();
fdPwdAgain->clear(); fdPwdAgain->clear();
fdOldPwd->clear(); fdOldPwd->clear();
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) { if(err.isEmpty()) {
@ -185,10 +200,14 @@ CtrlPwdPanel::CtrlPwdPanel(QWidget *parent) : QWidget(parent) {
fdOldPwd->hide(); fdOldPwd->hide();
btnPwdClear->hide(); btnPwdClear->hide();
btnPwdSet->setText(tr("Set encryption")); btnPwdSet->setText(tr("Set encryption"));
card->bPassword = false; auto item = findItem(card.id);
if(item) {
item->mCard.hasPassword = false;
item->init();
}
} }
} }
gFdResInfo->append(card->m_strCardId+" "+tr("SetControllerPassword")+" "+err); gFdResInfo->append(card.id+" "+tr("SetControllerPassword")+" "+err);
}); });
} }
} }
@ -209,24 +228,13 @@ void CtrlPwdPanel::showEvent(QShowEvent *event) {
init(); init();
} }
void CtrlPwdPanel::init() { void CtrlPwdPanel::init() {
bool isSingle = gSelCards->count()==1; bool isSingle = gSelCards.count()==1;
if(! isSingle) return; if(! isSingle) return;
auto card = gSelCards->at(0); auto card = gSelCards[0];
lbOldPwd->setVisible(card.hasPassword);
QJsonObject json; fdOldPwd->setVisible(card.hasPassword);
json.insert("_id", "HasControllerPassword"); btnPwdClear->setVisible(card.hasPassword);
json.insert("_type", "HasControllerPassword"); btnPwdSet->setText(card.hasPassword ? tr("Modify password") : tr("Set encryption"));
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, card, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
card->bPassword = json["result"].toBool();
lbOldPwd->setVisible(card->bPassword);
fdOldPwd->setVisible(card->bPassword);
btnPwdClear->setVisible(card->bPassword);
btnPwdSet->setText(card->bPassword ? tr("Modify password") : tr("Set encryption"));
});
} }
void CtrlPwdPanel::changeEvent(QEvent *event) { void CtrlPwdPanel::changeEvent(QEvent *event) {
QWidget::changeEvent(event); QWidget::changeEvent(event);

View File

@ -0,0 +1,530 @@
#include "ctrltestpanel.h"
#include "tools.h"
#include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include "base/waitingdlg.h"
#include <QFileDialog>
#include <QLineEdit>
#include <QJsonObject>
#include <QJsonDocument>
#include "globaldefine.h"
#include <QButtonGroup>
#include <QMessageBox>
#include <QHostAddress>
CtrlTestPanel::CtrlTestPanel(QWidget *parent) : QWidget(parent) {
auto vBox = new VBox(this);
labelTestScreen = new QLabel;
labelTestScreen->setAlignment(Qt::AlignCenter);
vBox->addWidget(labelTestScreen);
auto hBox = new HBox(vBox);
auto vv = new VBox(hBox);
groupBox = new QGroupBox;
auto vvv = new VBox(groupBox);
auto hhh = new HBox(vvv);
hhh->addStretch();
radioButtonRed = new QRadioButton;
hhh->addWidget(radioButtonRed);
radioButtonGreen = new QRadioButton;
hhh->addWidget(radioButtonGreen);
radioButtonBlue = new QRadioButton;
hhh->addWidget(radioButtonBlue);
radioButtonWhite = new QRadioButton;
hhh->addWidget(radioButtonWhite);
hhh->addStretch();
hhh = new HBox(vvv);
hhh->addStretch();
checkBoxVertical = new QCheckBox;
hhh->addWidget(checkBoxVertical);
checkBoxSlash = new QCheckBox;
hhh->addWidget(checkBoxSlash);
checkBoxHorizontal = new QCheckBox;
hhh->addWidget(checkBoxHorizontal);
hhh->addStretch();
hhh = new HBox(vvv);
hhh->addStretch();
label = new QLabel;
hhh->addWidget(label);
spinBoxLineSpeed = new QSpinBox;
spinBoxLineSpeed->setMaximum(99999);
hhh->addWidget(spinBoxLineSpeed);
label_5 = new QLabel;
hhh->addWidget(label_5);
hhh->addSpacing(20);
label_2 = new QLabel;
hhh->addWidget(label_2);
spinBoxLineDistance = new QSpinBox;
spinBoxLineDistance->setMaximum(128);
hhh->addWidget(spinBoxLineDistance);
label_6 = new QLabel;
hhh->addWidget(label_6);
hhh->addStretch();
pushButtonStartLine = new QPushButton;
pushButtonStartLine->setMinimumSize(QSize(60, 30));
pushButtonStartLine->setMaximumSize(QSize(80, 16777215));
vvv->addWidget(pushButtonStartLine, 0, Qt::AlignHCenter);
vv->addWidget(groupBox);
groupBox_2 = new QGroupBox;
vvv = new VBox(groupBox_2);
checkBoxShowInfo = new QCheckBox;
vvv->addWidget(checkBoxShowInfo, 0, Qt::AlignLeft);
hhh = new HBox(vvv);
hhh->addStretch();
checkBox_red = new QCheckBox;
hhh->addWidget(checkBox_red);
checkBox_green = new QCheckBox;
hhh->addWidget(checkBox_green);
checkBox_blue = new QCheckBox;
hhh->addWidget(checkBox_blue);
checkBox_white = new QCheckBox;
hhh->addWidget(checkBox_white);
hhh->addStretch();
hhh = new HBox(vvv);
hhh->addStretch();
label_3 = new QLabel;
hhh->addWidget(label_3);
spinBoxGraySpeed = new QSpinBox;
spinBoxGraySpeed->setMinimumSize(QSize(60, 0));
spinBoxGraySpeed->setMinimum(10);
spinBoxGraySpeed->setMaximum(99999);
hhh->addWidget(spinBoxGraySpeed);
label_8 = new QLabel;
hhh->addWidget(label_8);
label_4 = new QLabel;
hhh->addWidget(label_4);
spinBoxGrayValue = new QSpinBox;
spinBoxGrayValue->setMaximum(255);
hhh->addWidget(spinBoxGrayValue);
label_7 = new QLabel;
hhh->addWidget(label_7);
hhh->addStretch();
pushButtonStartGray = new QPushButton;
pushButtonStartGray->setMinimumSize(QSize(60, 30));
pushButtonStartGray->setMaximumSize(QSize(80, 16777215));
vvv->addWidget(pushButtonStartGray, 0, Qt::AlignHCenter);
vv->addWidget(groupBox_2);
groupBox_3 = new QGroupBox;
vvv = new VBox(groupBox_3);
checkBoxGradient = new QCheckBox;
vvv->addWidget(checkBoxGradient);
hhh = new HBox(vvv);
hhh->addStretch();
radioButton_red = new QRadioButton;
hhh->addWidget(radioButton_red);
radioButton_Green = new QRadioButton;
hhh->addWidget(radioButton_Green);
radioButton_Blue = new QRadioButton;
hhh->addWidget(radioButton_Blue);
radioButton_White = new QRadioButton;
hhh->addWidget(radioButton_White);
hhh->addStretch();
pushButtonStartColor = new QPushButton;
pushButtonStartColor->setMinimumSize(QSize(60, 30));
pushButtonStartColor->setMaximumSize(QSize(80, 16777215));
vvv->addWidget(pushButtonStartColor, 0, Qt::AlignHCenter);
vv->addWidget(groupBox_3);
hhh = new HBox(vv);
hhh->addStretch();
pushButtonStopTest = new QPushButton;
pushButtonStopTest->setMinimumSize(QSize(60, 30));
hhh->addWidget(pushButtonStopTest);
hhh->addStretch();
vv->addStretch();
auto line = new QFrame;
line->setFrameShape(QFrame::VLine);
line->setFrameShadow(QFrame::Sunken);
hBox->addWidget(line);
hBox->addStretch();
vv = new VBox(hBox);
lineEdit = new QLineEdit;
lineEdit->setMinimumSize(QSize(0, 36));
lineEdit->setMaximumSize(QSize(194, 16777215));
lineEdit->setAutoFillBackground(false);
lineEdit->setStyleSheet(QString::fromUtf8("color: rgb(0, 255, 0);\n"
"background-color: rgb(0, 0, 0);"));
lineEdit->setAlignment(Qt::AlignCenter);
vv->addWidget(lineEdit);
auto gridLayout = new Grid(vv);
auto btngrp = new QButtonGroup(this);
for(int i=0; i<10; ++i) {
auto btn = new QPushButton(QString::number(i));
btn->setFixedSize(60, 30);
btn->setProperty("ssType", "progManageTool");
btngrp->addButton(btn, i);
}
gridLayout->addWidget(btngrp->button(1), 0, 0);
gridLayout->addWidget(btngrp->button(2), 0, 1);
gridLayout->addWidget(btngrp->button(3), 0, 2);
gridLayout->addWidget(btngrp->button(4), 1, 0);
gridLayout->addWidget(btngrp->button(5), 1, 1);
gridLayout->addWidget(btngrp->button(6), 1, 2);
gridLayout->addWidget(btngrp->button(7), 2, 0);
gridLayout->addWidget(btngrp->button(8), 2, 1);
gridLayout->addWidget(btngrp->button(9), 2, 2);
gridLayout->addWidget(btngrp->button(0), 3, 0);
connect(btngrp, &QButtonGroup::idClicked, this, [=](int id) {
if(lineEdit->text().contains("-")) lineEdit->clear();
lineEdit->setText(lineEdit->text() + QString::number(id));
pushButton_13->setEnabled(true);
});
pushButton_11 = new QPushButton;
pushButton_11->setFixedSize(QSize(60, 30));
gridLayout->addWidget(pushButton_11, 3, 1, 1, 1);
pushButton_12 = new QPushButton;
pushButton_12->setFixedSize(QSize(60, 30));
gridLayout->addWidget(pushButton_12, 3, 2, 1, 1);
pushButton_13 = new QPushButton;
vv->addWidget(pushButton_13);
vv->addStretch();
hBox->addStretch();
vBox->addStretch();
pushButtonStartLine->setProperty("ssType", "progManageTool");
pushButtonStartGray->setProperty("ssType", "progManageTool");
pushButtonStartColor->setProperty("ssType", "progManageTool");
pushButtonStopTest->setProperty("ssType", "progManageTool");
pushButton_11->setProperty("ssType", "progManageTool");
pushButton_12->setProperty("ssType", "progManageTool");
pushButton_13->setProperty("ssType", "progManageTool");
spinBoxLineSpeed->setValue(10);
spinBoxLineDistance->setValue(15);
spinBoxGraySpeed->setValue(10);
spinBoxGrayValue->setValue(0);
radioButtonWhite->setChecked(true);
radioButton_White->setChecked(true);
checkBoxHorizontal->setChecked(true);
checkBoxVertical->setChecked(true);
checkBoxSlash->setChecked(true);
checkBox_red->setChecked(true);
checkBox_green->setChecked(true);
checkBox_blue->setChecked(true);
checkBox_white->setChecked(true);
connect(pushButtonStartLine, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "TestScreen");
json.insert("_type", "TestScreen");
json.insert("mode", 1);// 0停止 1斜线 2灰度; 3:颜色4渐变
json.insert("speed", spinBoxLineSpeed->value());
if(radioButtonRed->isChecked())
json.insert("color", "#FFFF0000");
else if(radioButtonGreen->isChecked())
json.insert("color", "#FF00FF00");
else if(radioButtonBlue->isChecked())
json.insert("color", "#FF0000FF");
else
json.insert("color", "#FFFFFFFF");
json.insert("interval", spinBoxLineDistance->value());
json.insert("horizonalLine", checkBoxHorizontal->isChecked());
json.insert("verticalLine", checkBoxVertical->isChecked());
json.insert("slantLine", checkBoxSlash->isChecked());
json.insert("runLimit", spinBoxGrayValue->value());
json.insert("showInfo", !checkBoxShowInfo->isChecked());
json.insert("red", checkBox_red->isChecked());
json.insert("green", checkBox_green->isChecked());
json.insert("blue", checkBox_blue->isChecked());
json.insert("white", checkBox_white->isChecked());
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("StartTest")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("StartTest"))
}
}
});
connect(pushButtonStartGray, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "TestScreen");
json.insert("_type", "TestScreen");
json.insert("mode", 2);// 0停止 1斜线 2灰度; 3:颜色4渐变
json.insert("speed", spinBoxGraySpeed->value());
// qDebug()<<"speed="<<spinBoxGraySpeed->value();
if(radioButtonRed->isChecked())
json.insert("color", "#FFFF0000");
else if(radioButtonGreen->isChecked())
json.insert("color", "#FF00FF00");
else if(radioButtonBlue->isChecked())
json.insert("color", "#FF0000FF");
else
json.insert("color", "#FFFFFFFF");
json.insert("interval", spinBoxLineDistance->value());
json.insert("horizonalLine", checkBoxHorizontal->isChecked());
json.insert("verticalLine", checkBoxVertical->isChecked());
json.insert("slantLine", checkBoxSlash->isChecked());
json.insert("runLimit", spinBoxGrayValue->value());
json.insert("showInfo", !checkBoxShowInfo->isChecked());
json.insert("red", checkBox_red->isChecked());
json.insert("green", checkBox_green->isChecked());
json.insert("blue", checkBox_blue->isChecked());
json.insert("white", checkBox_white->isChecked());
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("StartTest")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("StartTest"))
}
}
});
connect(pushButtonStartColor, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "TestScreen");
json.insert("_type", "TestScreen");
if(checkBoxGradient->isChecked())
json.insert("mode", 4);// 0停止 1斜线 2灰度; 3:颜色4渐变
else
json.insert("mode", 3);// 0停止 1斜线 2灰度; 3:颜色4渐变
json.insert("speed", spinBoxLineSpeed->value());
if(radioButton_red->isChecked())
json.insert("color", "#FFFF0000");
else if(radioButton_Green->isChecked())
json.insert("color", "#FF00FF00");
else if(radioButton_Blue->isChecked())
json.insert("color", "#FF0000FF");
else
json.insert("color", "#FFFFFFFF");
json.insert("interval", spinBoxLineDistance->value());
json.insert("horizonalLine", checkBoxHorizontal->isChecked());
json.insert("verticalLine", checkBoxVertical->isChecked());
json.insert("slantLine", checkBoxSlash->isChecked());
json.insert("runLimit", spinBoxGrayValue->value());
json.insert("showInfo", !checkBoxShowInfo->isChecked());
json.insert("red", checkBox_red->isChecked());
json.insert("green", checkBox_green->isChecked());
json.insert("blue", checkBox_blue->isChecked());
json.insert("white", checkBox_white->isChecked());
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("StartTest")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("StartTest"))
}
}
});
connect(pushButtonStopTest, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "TestScreen");
json.insert("_type", "TestScreen");
json.insert("mode", 0);
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("StopTest")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("StopTest"))
}
}
});
connect(pushButton_11, &QPushButton::clicked, this, [=] {
lineEdit->clear();
pushButton_13->setEnabled(false);
});
connect(pushButton_12, &QPushButton::clicked, this, [=] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
int iIndex = lineEdit->text().toInt();
if(gSelCards.count()==1) SendAnycastCmd(gSelCards[0], 0, true);
else {
foreach(auto card, gSelCards) SendAnycastCmd(card, iIndex, false);
}
lineEdit->setText("-"+tr("loopback mode")+"-");
pushButton_13->setEnabled(false);
});
connect(pushButton_13, &QPushButton::clicked, this, [=] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
int iIndex = lineEdit->text().toInt();
if(gSelCards.count()==1) SendAnycastCmd(gSelCards[0], iIndex, true);
else foreach(auto card, gSelCards) SendAnycastCmd(card, iIndex, false);
lineEdit->setText(tr("Anycast")+" - "+lineEdit->text());
pushButton_13->setEnabled(false);
});
pushButton_13->setEnabled(false);
lineEdit->setValidator(new QIntValidator(0, 100, this));
transUi();
}
void CtrlTestPanel::changeEvent(QEvent *event) {
QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi();
}
void CtrlTestPanel::transUi() {
labelTestScreen->setText(tr("Test Screen"));
groupBox->setTitle(tr("Line test"));
radioButtonRed->setText(tr("Red"));
radioButtonGreen->setText(tr("Green"));
radioButtonBlue->setText(tr("Blue"));
radioButtonWhite->setText(tr("White"));
radioButton_red->setText(tr("Red"));
radioButton_Green->setText(tr("Green"));
radioButton_Blue->setText(tr("Blue"));
radioButton_White->setText(tr("White"));
checkBoxVertical->setText(tr("Vertical"));
checkBoxHorizontal->setText(tr("Horizontal"));
checkBoxSlash->setText(tr("Slash"));
label->setText(tr("Speed"));
label_5->setText(tr("ms(>10)"));
checkBoxHorizontal->setText(tr("Horizontal"));
label_2->setText(tr("Line Distance"));
pushButtonStartLine->setText(tr("Test"));
groupBox_2->setTitle(tr("Gradation test"));
checkBoxShowInfo->setText(tr("Only the gray value is displayed"));
checkBox_red->setText(tr("Red"));
checkBox_green->setText(tr("Green"));
checkBox_blue->setText(tr("Blue"));
checkBox_white->setText(tr("White"));
label_3->setText(tr("Speed"));
label_4->setText(tr("GrayValue"));
pushButtonStartGray->setText(tr("Test"));
pushButtonStartColor->setText(tr("Test"));
groupBox_3->setTitle(tr("Color test"));
checkBoxGradient->setText(tr("Gradient"));
radioButton_red->setText(tr("Red"));
radioButton_Green->setText(tr("Green"));
radioButton_Blue->setText(tr("Blue"));
radioButton_White->setText(tr("White"));
pushButtonStopTest->setText(tr("Stop"));
pushButton_11->setText(tr("Clear"));
pushButton_12->setText(tr("Reset"));
pushButton_13->setText(tr("Anycast"));
}
void CtrlTestPanel::SendAnycastCmd(LedCard card, int iProgramIndex, bool isSingle) {
QTcpSocket *send = new QTcpSocket();
connect(send, SIGNAL(connected()), this, SLOT(connect_sucessful()));
connect(send, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(show_error(QAbstractSocket::SocketError)));
send->connectToHost(QHostAddress(card.ip),31299);
ST_ANSY_PROGRAM_PACKET tempStreadPakcet;
tempStreadPakcet.SyncHead[0]=0x7e;
tempStreadPakcet.SyncHead[1]=0x7e;
tempStreadPakcet.SyncHead[2]=0x55;
tempStreadPakcet.ucCommType=0x97;
tempStreadPakcet.iBaoLiu=0;
tempStreadPakcet.iLength=4;
unsigned char uctemp[4]={0};
uctemp[0]=iProgramIndex;
memcpy(tempStreadPakcet.pDataBuffer,uctemp,4);
tempStreadPakcet.pDataBuffer[tempStreadPakcet.iLength]=GetCheckCodeIn8(&tempStreadPakcet.ucCommType,tempStreadPakcet.iLength+sizeof(tempStreadPakcet.iBaoLiu)+sizeof(tempStreadPakcet.ucCommType)+sizeof(tempStreadPakcet.iLength));
int iLenPacket=3*sizeof(unsigned char)+sizeof(char)+sizeof(int)+sizeof(int)+tempStreadPakcet.iLength+sizeof(char);/////除正文外的协议结构大小;
QByteArray databuf = QByteArray(reinterpret_cast<char*>(&tempStreadPakcet), iLenPacket);
if(!send->waitForConnected(10000)) //等待连接返回
{
if(isSingle) QMessageBox::information(this, tr("Tip"), tr("Connect timeout"));
else gFdResInfo->append(card.id+":"+tr("receive")+"<-"+tr("Connect")+":"+tr("timeout"));
send->close();
delete send;
return;
}
send->write(databuf);
if(send->waitForBytesWritten(3000)) {
send->read(send->bytesAvailable());
if(isSingle) QMessageBox::information(this, tr("Tip"), (iProgramIndex==0 ? tr("Reset loop mode") : tr("Anycast"))+":"+tr("success"));
else gFdResInfo->append(card.id+":"+tr("receive")+"<-"+tr("Anycast")+":"+tr("success"));
}
send->close();
delete send;
}

View File

@ -0,0 +1,68 @@
#ifndef CTRLTESTPANEL_H
#define CTRLTESTPANEL_H
#include "globaldefine.h"
#include <QScrollArea>
#include <QGroupBox>
#include <QRadioButton>
#include <QCheckBox>
#include <QSpinBox>
#include <QLabel>
#include <QPushButton>
class CtrlTestPanel : public QWidget {
Q_OBJECT
public:
explicit CtrlTestPanel(QWidget *parent = nullptr);
protected:
void changeEvent(QEvent *) override;
void transUi();
signals:
void sigSend(QJsonObject &,QString);
private:
void SendAnycastCmd(LedCard, int, bool);
QLabel *labelTestScreen;
QGroupBox *groupBox;
QRadioButton *radioButtonRed;
QRadioButton *radioButtonGreen;
QRadioButton *radioButtonBlue;
QRadioButton *radioButtonWhite;
QCheckBox *checkBoxVertical;
QCheckBox *checkBoxSlash;
QCheckBox *checkBoxHorizontal;
QLabel *label;
QSpinBox *spinBoxLineSpeed;
QLabel *label_5;
QLabel *label_2;
QSpinBox *spinBoxLineDistance;
QLabel *label_6;
QPushButton *pushButtonStartLine;
QGroupBox *groupBox_2;
QCheckBox *checkBoxShowInfo;
QCheckBox *checkBox_red;
QCheckBox *checkBox_green;
QCheckBox *checkBox_blue;
QCheckBox *checkBox_white;
QLabel *label_3;
QSpinBox *spinBoxGraySpeed;
QLabel *label_8;
QLabel *label_4;
QSpinBox *spinBoxGrayValue;
QLabel *label_7;
QPushButton *pushButtonStartGray;
QGroupBox *groupBox_3;
QCheckBox *checkBoxGradient;
QRadioButton *radioButton_red;
QRadioButton *radioButton_Green;
QRadioButton *radioButton_Blue;
QRadioButton *radioButton_White;
QPushButton *pushButtonStartColor;
QPushButton *pushButtonStopTest;
QLineEdit *lineEdit;
QPushButton *pushButton_11;
QPushButton *pushButton_12;
QPushButton *pushButton_13;
};
#endif // CTRLTESTPANEL_H

View File

@ -1,11 +1,13 @@
#include "ctrlverifyclockpanel.h" #include "ctrlverifyclockpanel.h"
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
#include "gutil/qnetwork.h"
#include "globaldefine.h" #include "globaldefine.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "tools.h" #include "tools.h"
#include <QMessageBox> #include <QMessageBox>
#include <QLineEdit> #include <QLineEdit>
#include <QButtonGroup> #include <QButtonGroup>
#include "devicepanel.h"
CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) { CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
auto vBox = new VBox(this); auto vBox = new VBox(this);
@ -103,7 +105,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
fdTimeZoneSet = new QPushButton; fdTimeZoneSet = new QPushButton;
connect(fdTimeZoneSet, &QPushButton::clicked, this, [this] { connect(fdTimeZoneSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -111,14 +113,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "SetTimezone"); json.insert("_id", "SetTimezone");
json.insert("_type", "SetTimezone"); json.insert("_type", "SetTimezone");
json.insert("timezone", fdTimezone->currentText()); json.insert("timezone", fdTimezone->currentText());
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetTimezone")); auto waitingDlg = new WaitingDlg(this, tr("SetTimezone"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetTimezone")) Def_CtrlSetMulti(tr("SetTimezone"))
} }
} }
@ -137,7 +139,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnLangSet = new QPushButton; btnLangSet = new QPushButton;
connect(btnLangSet, &QPushButton::clicked, this, [this] { connect(btnLangSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -145,14 +147,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "SetLanguage"); json.insert("_id", "SetLanguage");
json.insert("_type", "SetLanguage"); json.insert("_type", "SetLanguage");
json.insert("language", fdIsCn->isChecked() ? 1 : 0); json.insert("language", fdIsCn->isChecked() ? 1 : 0);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, "设置语言"); auto waitingDlg = new WaitingDlg(this, "设置语言");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti("设置语言") Def_CtrlSetMulti("设置语言")
} }
} }
@ -161,14 +163,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnLangGet = new QPushButton; btnLangGet = new QPushButton;
connect(btnLangGet, &QPushButton::clicked, this, [this] { connect(btnLangGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetLanguage"); json.insert("_id", "GetLanguage");
json.insert("_type", "GetLanguage"); json.insert("_type", "GetLanguage");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, "获取语言"); auto waitingDlg = new WaitingDlg(this, "获取语言");
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -178,9 +180,9 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
else fdIsEn->setChecked(true); else fdIsEn->setChecked(true);
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -209,7 +211,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnSyncTime = new QPushButton(tr("Verify to Computer time")); btnSyncTime = new QPushButton(tr("Verify to Computer time"));
btnSyncTime->setMinimumSize(QSize(60, 30)); btnSyncTime->setMinimumSize(QSize(60, 30));
connect(btnSyncTime, &QPushButton::clicked, this, [this] { connect(btnSyncTime, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -217,14 +219,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "SyncTime"); json.insert("_id", "SyncTime");
json.insert("_type", "SyncTime"); json.insert("_type", "SyncTime");
json.insert("time", QDateTime::currentDateTime().toMSecsSinceEpoch()); json.insert("time", QDateTime::currentDateTime().toMSecsSinceEpoch());
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SyncTime")); auto waitingDlg = new WaitingDlg(this, tr("SyncTime"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SyncTime")) Def_CtrlSetMulti(tr("SyncTime"))
} }
} }
@ -240,14 +242,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnDateGet = new QPushButton; btnDateGet = new QPushButton;
btnDateGet->setMinimumSize(QSize(0, 30)); btnDateGet->setMinimumSize(QSize(0, 30));
connect(btnDateGet, &QPushButton::clicked, this, [this] { connect(btnDateGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetControllerDate"); json.insert("_id", "GetControllerDate");
json.insert("_type", "GetControllerDate"); json.insert("_type", "GetControllerDate");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetControllerDate")); auto waitingDlg = new WaitingDlg(this, tr("GetControllerDate"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -256,9 +258,9 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
labelCurTime->setText(json["date"].toString()); labelCurTime->setText(json["date"].toString());
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -362,7 +364,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnSyncSet = new QPushButton(groupBox); btnSyncSet = new QPushButton(groupBox);
btnSyncSet->setMinimumSize(QSize(60, 30)); btnSyncSet->setMinimumSize(QSize(60, 30));
connect(btnSyncSet, &QPushButton::clicked, this, [this] { connect(btnSyncSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -381,14 +383,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
json.insert("checkNtpTime", lineEdit_3->text().toInt()); json.insert("checkNtpTime", lineEdit_3->text().toInt());
} else if(fdIsGPS->isChecked()) json.insert("time", "gps"); } else if(fdIsGPS->isChecked()) json.insert("time", "gps");
else if(fdIsLan->isChecked()) json.insert("time", "Lan"); else if(fdIsLan->isChecked()) json.insert("time", "Lan");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetingSyncMethod")); auto waitingDlg = new WaitingDlg(this, tr("SetingSyncMethod"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetingSyncMethod")) Def_CtrlSetMulti(tr("SetingSyncMethod"))
} }
} }
@ -398,14 +400,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
fdSyncGet = new QPushButton; fdSyncGet = new QPushButton;
fdSyncGet->setMinimumSize(QSize(60, 30)); fdSyncGet->setMinimumSize(QSize(60, 30));
connect(fdSyncGet, &QPushButton::clicked, this, [this] { connect(fdSyncGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetingSyncMethod"); json.insert("_id", "GetingSyncMethod");
json.insert("_type", "GetingSyncMethod"); json.insert("_type", "GetingSyncMethod");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetingSyncMethod")); auto waitingDlg = new WaitingDlg(this, tr("GetingSyncMethod"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -414,9 +416,9 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
dealGetSync(json); dealGetSync(json);
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QByteArray data; QByteArray data;
@ -484,7 +486,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnLoraMasterSet = new QPushButton(groupBox); btnLoraMasterSet = new QPushButton(groupBox);
btnLoraMasterSet->setMinimumSize(QSize(0, 30)); btnLoraMasterSet->setMinimumSize(QSize(0, 30));
connect(btnLoraMasterSet, &QPushButton::clicked, this, [this] { connect(btnLoraMasterSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -493,18 +495,18 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
json.insert("_type", "MasterSlaveSwitch"); json.insert("_type", "MasterSlaveSwitch");
bool isMaster = buttonGroup_2->checkedId()==0; bool isMaster = buttonGroup_2->checkedId()==0;
json.insert("master", isMaster); json.insert("master", isMaster);
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, isMaster ? tr("MasterSwitch ") : tr("SlaveSwitch ")); auto waitingDlg = new WaitingDlg(this, isMaster ? tr("MasterSwitch ") : tr("SlaveSwitch "));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, card, isMaster] { connect(reply, &QNetworkReply::finished, this, [reply, card, isMaster] {
QString err = checkReplyForJson(reply); QString err = checkReplyForJson(reply);
gFdResInfo->append(card->m_strCardId+" "+(isMaster ? tr("MasterSwitch ") : tr("SlaveSwitch "))+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err)); gFdResInfo->append(card.id+" "+(isMaster ? tr("MasterSwitch ") : tr("SlaveSwitch "))+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));
}); });
} }
} }
@ -514,14 +516,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnLoraMasterGet = new QPushButton(groupBox); btnLoraMasterGet = new QPushButton(groupBox);
btnLoraMasterGet->setMinimumSize(QSize(0, 30)); btnLoraMasterGet->setMinimumSize(QSize(0, 30));
connect(btnLoraMasterGet, &QPushButton::clicked, this, [this] { connect(btnLoraMasterGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "IsMasterSlave"); json.insert("_id", "IsMasterSlave");
json.insert("_type", "IsMasterSlave"); json.insert("_type", "IsMasterSlave");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("IsMasterSlave")); auto waitingDlg = new WaitingDlg(this, tr("IsMasterSlave"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -532,9 +534,9 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
fdSlave->setChecked(! isMaster); fdSlave->setChecked(! isMaster);
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -572,7 +574,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnNtpSet = new QPushButton; btnNtpSet = new QPushButton;
btnNtpSet->setMinimumSize(QSize(60, 30)); btnNtpSet->setMinimumSize(QSize(60, 30));
connect(btnNtpSet, &QPushButton::clicked, this, [this] { connect(btnNtpSet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
@ -580,14 +582,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
json.insert("_id", "SetNtpServer"); json.insert("_id", "SetNtpServer");
json.insert("_type", "SetNtpServer"); json.insert("_type", "SetNtpServer");
json.insert("ntpServer", fdNtpServer->text()); json.insert("ntpServer", fdNtpServer->text());
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetNtpServer")); auto waitingDlg = new WaitingDlg(this, tr("SetNtpServer"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter Def_CtrlSetReqAfter
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetNtpServer")) Def_CtrlSetMulti(tr("SetNtpServer"))
} }
} }
@ -597,14 +599,14 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
btnNtpGet = new QPushButton; btnNtpGet = new QPushButton;
btnNtpGet->setMinimumSize(QSize(60, 30)); btnNtpGet->setMinimumSize(QSize(60, 30));
connect(btnNtpGet, &QPushButton::clicked, this, [this] { connect(btnNtpGet, &QPushButton::clicked, this, [this] {
if(gSelCards->isEmpty()) { if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController")); QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return; return;
} }
QJsonObject json; QJsonObject json;
json.insert("_id", "GetNtpServer"); json.insert("_id", "GetNtpServer");
json.insert("_type", "GetNtpServer"); json.insert("_type", "GetNtpServer");
if(gSelCards->count() == 1) { if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetNtpServer")); auto waitingDlg = new WaitingDlg(this, tr("GetNtpServer"));
Def_CtrlReqPre Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] { connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
@ -613,9 +615,9 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel(QWidget *parent) : QWidget(parent) {
fdNtpServer->setText(json["ntpServer"].toString()); fdNtpServer->setText(json["ntpServer"].toString());
}); });
} else { } else {
foreach(auto card, *gSelCards) { foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card->m_strCardId; auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] { connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -673,14 +675,14 @@ void CtrlVerifyClockPanel::showEvent(QShowEvent *event) {
init(); init();
} }
void CtrlVerifyClockPanel::init() { void CtrlVerifyClockPanel::init() {
bool isSingle = gSelCards->count()==1; bool isSingle = gSelCards.count()==1;
if(! isSingle) return; if(! isSingle) return;
auto card = gSelCards->at(0); auto card = gSelCards[0];
QJsonObject json; QJsonObject json;
json.insert("_id", "GetingSyncMethod"); json.insert("_id", "GetingSyncMethod");
json.insert("_type", "GetingSyncMethod"); json.insert("_type", "GetingSyncMethod");
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] { connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -691,7 +693,7 @@ void CtrlVerifyClockPanel::init() {
json = QJsonObject(); json = QJsonObject();
json.insert("_id", "GetTimezone"); json.insert("_id", "GetTimezone");
json.insert("_type", "GetTimezone"); json.insert("_type", "GetTimezone");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] { connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -702,7 +704,7 @@ void CtrlVerifyClockPanel::init() {
json = QJsonObject(); json = QJsonObject();
json.insert("_id", "GetLanguage"); json.insert("_id", "GetLanguage");
json.insert("_type", "GetLanguage"); json.insert("_type", "GetLanguage");
reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json); reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] { connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);

View File

@ -1,14 +1,13 @@
#ifndef CTRLVERIFYCLOCKPANEL_H #ifndef CTRLVERIFYCLOCKPANEL_H
#define CTRLVERIFYCLOCKPANEL_H #define CTRLVERIFYCLOCKPANEL_H
#include "ledcard.h"
#include <communication/hpptclient.h>
#include <base/loemptydialog.h>
#include <QComboBox> #include <QComboBox>
#include <QRadioButton> #include <QRadioButton>
#include <QGroupBox> #include <QGroupBox>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QCheckBox> #include <QCheckBox>
#include <QLabel>
#include <QPushButton>
class CtrlVerifyClockPanel : public QWidget { class CtrlVerifyClockPanel : public QWidget {
Q_OBJECT Q_OBJECT

View File

@ -0,0 +1,450 @@
#include "ctrlvolumepanel.h"
#include "globaldefine.h"
#include "base/waitingdlg.h"
#include "gutil/qnetwork.h"
#include "tools.h"
#include <QMessageBox>
#include <QJsonArray>
#include <QTimeEdit>
#include <QSettings>
#include "devicepanel.h"
CtrlVolumePanel::CtrlVolumePanel() {
auto vBox = new VBox(this);
lbVolumeControl = new QLabel;
lbVolumeControl->setAlignment(Qt::AlignCenter);
vBox->addWidget(lbVolumeControl);
auto hBox = new HBox(vBox);
hBox->addStretch();
fdManual = new QRadioButton;
hBox->addWidget(fdManual);
hBox->addSpacing(40);
fdSchedule = new QRadioButton;
hBox->addWidget(fdSchedule);
hBox->addStretch();
auto stack = new QStackedLayout(vBox);
{
auto vBox = new VBox(stack);
vBox->addSpacing(20);
auto hBox = new HBox(vBox);
hBox->addStretch();
lbVolume = new QLabel;
hBox->addWidget(lbVolume);
fdVolume = new QSlider(Qt::Horizontal);
fdVolume->setTickPosition(QSlider::TicksAbove);
fdVolume->setRange(0, 15);
connect(fdVolume, &QSlider::sliderReleased, this, [=] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "SetVolume");
json.insert("_type", "SetVolume");
json.insert("volume", fdVolume->value());
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetVolume")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetVolume"))
}
}
});
hBox->addWidget(fdVolume);
auto lbCurVol = new QLabel;
lbCurVol->setMinimumWidth(30);
connect(fdVolume, &QSlider::valueChanged, lbCurVol, (void(QLabel::*)(int))&QLabel::setNum);
hBox->addWidget(lbCurVol);
hBox->addStretch();
fdVolumeGet = new QPushButton;
fdVolumeGet->setMinimumSize(QSize(60, 30));
fdVolumeGet->setProperty("ssType", "progManageTool");
connect(fdVolumeGet, &QPushButton::clicked, this, [=] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "GetVolume");
json.insert("_type", "GetVolume");
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetVolume")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg] {
Def_CtrlSingleGetReply
waitingDlg->success();
fdVolume->setValue(json["volume"].toInt());
});
} else {
foreach(auto card, gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
auto cardId = card.id;
connect(reply, &QNetworkReply::finished, this, [reply, cardId] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(err.isEmpty()) err = QString::number(json["volume"].toInt());
gFdResInfo->append(cardId+" "+tr("GetVolume")+" "+err);
});
}
}
});
vBox->addWidget(fdVolumeGet, 0, Qt::AlignCenter);
vBox->addStretch();
}
{
auto vBox = new VBox(stack);
hBox = new HBox(vBox);
fdScheTip = new QLabel;
fdScheTip->setWordWrap(true);
hBox->addWidget(fdScheTip);
hBox = new HBox(vBox);
btnScheAdd = new QPushButton;
btnScheAdd->setMinimumSize(60, 30);
btnScheAdd->setProperty("ssType", "progManageTool");
connect(btnScheAdd, &QPushButton::clicked, this, [this] {
int row = tableSche->appendRow();
auto cellWgt = new QWidget;
auto hBox = new QHBoxLayout(cellWgt);
auto slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 15);
slider->setValue(10);
hBox->addWidget(slider);
auto lb = new QLabel(QString::number(slider->value()));
connect(slider, &QSlider::valueChanged, lb, (void(QLabel::*)(int))&QLabel::setNum);
hBox->addWidget(lb);
tableSche->setCellWidget(row, "vol", cellWgt);
auto timeEdit = new QTimeEdit(QTime(0, 0));
timeEdit->setDisplayFormat("HH:mm");
timeEdit->setAlignment(Qt::AlignCenter);
tableSche->setCellWidget(row, "start", timeEdit);
timeEdit = new QTimeEdit(QTime(1, 0));
timeEdit->setDisplayFormat("HH:mm");
timeEdit->setAlignment(Qt::AlignCenter);
tableSche->setCellWidget(row, "end", timeEdit);
for(int i=0; i<7; i++) {
auto fd = new QCheckBox;
fd->setChecked(true);
tableSche->setCellWidget(row, QString::number(i), fd);
}
});
hBox->addWidget(btnScheAdd);
btnScheDel = new QPushButton;
btnScheDel->setMinimumSize(60, 30);
btnScheDel->setProperty("ssType", "progManageTool");
connect(btnScheDel, &QPushButton::clicked, this, [this] {
auto selected = tableSche->selectedRanges();
if(! selected.isEmpty()) tableSche->model()->removeRows(selected[0].topRow(), selected[0].rowCount());
});
hBox->addWidget(btnScheDel);
btnScheClear = new QPushButton;
btnScheClear->setMinimumSize(60, 30);
btnScheClear->setProperty("ssType", "progManageTool");
connect(btnScheClear, &QPushButton::clicked, this, [this] {tableSche->setRowCount(0);});
hBox->addWidget(btnScheClear);
lbDefBright = new QLabel;
hBox->addWidget(lbDefBright);
fdDefBright = new QSlider(Qt::Horizontal);
fdDefBright->setFixedWidth(120);
fdDefBright->setRange(0, 15);
fdDefBright->setValue(10);
hBox->addWidget(fdDefBright);
auto lbDefBrightValue = new QLabel;
lbDefBrightValue->setNum(fdDefBright->value());
lbDefBrightValue->setMinimumWidth(30);
lbDefBrightValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
connect(fdDefBright, &QSlider::valueChanged, lbDefBrightValue, (void(QLabel::*)(int))&QLabel::setNum);
hBox->addWidget(lbDefBrightValue);
hBox->addStretch();
btnScheImport = new QPushButton;
btnScheImport->setMinimumSize(QSize(60, 30));
btnScheImport->setProperty("ssType", "progManageTool");
connect(btnScheImport, &QPushButton::clicked, this, [this] {
auto dir = QSettings().value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("Volume Schedule (*.vols)"));
if(scheFile.isEmpty()) return;
QFile scheQFile(scheFile);
if(! scheQFile.open(QIODevice::ReadOnly)) return;
auto data = scheQFile.readAll();
scheQFile.close();
restoreScheduleJson(QJsonDocument::fromJson(data).object());
});
hBox->addWidget(btnScheImport);
btnScheExport = new QPushButton;
btnScheExport->setMinimumSize(QSize(60, 30));
btnScheExport->setProperty("ssType", "progManageTool");
connect(btnScheExport, &QPushButton::clicked, this, [this] {
QSettings settings;
auto dir = settings.value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("Volume Schedule (*.vols)"));
if(scheFile.isEmpty()) return;
settings.setValue("CtrlScheduleDir", QFileInfo(scheFile).absolutePath());
QFile scheQFile(scheFile);
if(! scheQFile.open(QIODevice::WriteOnly)) return;
scheQFile.write(QJsonDocument(getScheduleJson()).toJson());
scheQFile.close();
});
hBox->addWidget(btnScheExport);
tableSche = new Table({
{"vol", "", 300},
{"start", "", 100},
{"end", "", 100},
{"0", "", 60},
{"1", "", 60},
{"2", "", 60},
{"3", "", 60},
{"4", "", 60},
{"5", "", 60},
{"6", "", 60}
});
tableSche->setDefs();
vBox->addWidget(tableSche);
hBox = new HBox(vBox);
hBox->addStretch();
btnScheSet = new QPushButton;
btnScheSet->setMinimumSize(QSize(60, 30));
btnScheSet->setProperty("ssType", "progManageTool");
connect(btnScheSet, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "SetAutoVolumeTask");
json.insert("_type", "SetAutoVolumeTask");
json.insert("taskVolume", getScheduleJson());
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetAutoVolumeTask"));
Def_CtrlReqPre;
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
Def_CtrlSetMulti(tr("SetAutoVolumeTask"))
}
}
});
hBox->addWidget(btnScheSet);
hBox->addStretch();
btnScheGet = new QPushButton;
btnScheGet->setMinimumSize(QSize(60, 30));
btnScheGet->setProperty("ssType", "progManageTool");
connect(btnScheGet, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
QJsonObject json;
json.insert("_id", "GetAutoVolumeTask");
json.insert("_type", "GetAutoVolumeTask");
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("GetAutoVolumeTask"));
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [this, reply, waitingDlg, card] {
Def_CtrlSingleGetReply
waitingDlg->success();
restoreScheduleJson(json["taskVolume"].toObject());
});
}
});
hBox->addWidget(btnScheGet);
hBox->addStretch();
}
connect(fdSchedule, &QRadioButton::toggled, stack, &QStackedLayout::setCurrentIndex);
fdManual->setChecked(true);
connect(gDevicePanel, &DevicePanel::sigSelectedDeviceList, this, [this] {
if(isVisible()) init();
});
transUi();
}
void CtrlVolumePanel::showEvent(QShowEvent *event) {
QWidget::showEvent(event);
init();
}
void CtrlVolumePanel::init() {
bool isSingle = gSelCards.count()==1;
btnScheGet->setEnabled(isSingle);
if(! isSingle) return;
auto card = gSelCards[0];
QJsonObject json;
json.insert("_id", "GetVolume");
json.insert("_type", "GetVolume");
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
fdVolume->setValue(json["volume"].toInt());
});
json = QJsonObject();
json.insert("_id", "GetAutoVolumeTask");
json.insert("_type", "GetAutoVolumeTask");
reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [this, reply, card] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
if(restoreScheduleJson(json["taskVolume"].toObject())) fdSchedule->setChecked(true);
else fdManual->setChecked(true);
});
}
void CtrlVolumePanel::changeEvent(QEvent *event) {
QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi();
}
void CtrlVolumePanel::transUi() {
lbVolumeControl->setText(tr("Volume Control"));
fdManual->setText(tr("Manual"));
fdSchedule->setText(tr("Schedule"));
lbVolume->setText(tr("Volume"));
fdVolumeGet->setText(tr("Readback"));
lbDefBright->setText(tr("Default volume"));
btnScheAdd->setText(tr("Add"));
btnScheClear->setText(tr("Clear"));
btnScheDel->setText(tr("Delete"));
btnScheImport->setText(tr("Import"));
btnScheExport->setText(tr("Export"));
tableSche->setHeaderText("vol", tr("Volume value"));
tableSche->setHeaderText("start", tr("Start Time"));
tableSche->setHeaderText("end", tr("End Time"));
tableSche->setHeaderText("0", tr("SUN"));
tableSche->setHeaderText("1", tr("MON"));
tableSche->setHeaderText("2", tr("TUE"));
tableSche->setHeaderText("3", tr("WED"));
tableSche->setHeaderText("4", tr("THU"));
tableSche->setHeaderText("5", tr("FRI"));
tableSche->setHeaderText("6", tr("SAT"));
btnScheSet->setText(tr("Apply"));
btnScheGet->setText(tr("Readback"));
fdScheTip->setText(tr("Default volume tip"));
}
bool CtrlVolumePanel::restoreScheduleJson(QJsonObject json) {
tableSche->setRowCount(0);
fdDefBright->setValue(json["defaultVolume"].toInt());
auto items = json["items"].toArray();
for(int i=0; i<items.size(); i++) {
auto schedule = items.at(i)["schedules"][0];
int row = tableSche->rowCount();
tableSche->insertRow(row);
auto cellWgt = new QWidget;
auto hBox = new QHBoxLayout(cellWgt);
auto slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 15);
slider->setValue(items.at(i)["volume"].toInt());
hBox->addWidget(slider);
auto lb = new QLabel;
lb->setNum(slider->value());
connect(slider, &QSlider::valueChanged, lb, (void(QLabel::*)(int))&QLabel::setNum);
hBox->addWidget(lb);
tableSche->setCellWidget(row, "vol", cellWgt);
auto timeEdit = new QTimeEdit(QTime::fromString(schedule["startTime"].toString(), "HH:mm"));
timeEdit->setDisplayFormat("HH:mm");
timeEdit->setAlignment(Qt::AlignCenter);
tableSche->setCellWidget(row, "start", timeEdit);
timeEdit = new QTimeEdit(QTime::fromString(schedule["endTime"].toString(), "HH:mm"));
timeEdit->setDisplayFormat("HH:mm");
timeEdit->setAlignment(Qt::AlignCenter);
tableSche->setCellWidget(row, "end", timeEdit);
if(schedule["filterType"].toString()=="None") for(int i=0; i<7; i++) {
auto fd = new QCheckBox;
fd->setChecked(true);
tableSche->setCellWidget(row, QString::number(i), fd);
} else if(schedule["filterType"].toString()=="Week") {
auto weekFilter = schedule["weekFilter"].toArray();
for(int i=0; i<7; i++) {
auto fd = new QCheckBox;
if(weekFilter.contains(i)) fd->setChecked(true);
tableSche->setCellWidget(row, QString::number(i), fd);
}
}
}
return items.count() > 0;
}
QJsonObject CtrlVolumePanel::getScheduleJson() {
QJsonArray items;
for(int i=0; i<tableSche->rowCount(); i++) {
QJsonObject item;
item.insert("volume", static_cast<QSlider*>(tableSche->cellWidget(i, "vol")->layout()->itemAt(0)->widget())->value());
QJsonObject schedule;
schedule["timeType"] = "Range";
schedule["startTime"] = static_cast<QTimeEdit*>(tableSche->cellWidget(i, "start"))->text();
schedule["endTime"] = static_cast<QTimeEdit*>(tableSche->cellWidget(i, "end"))->text();
schedule["dateType"] = "All";
schedule["monthFilter"] = QJsonArray();
QJsonArray weekFilter;
for(int d=0; d<7; d++) if(static_cast<QCheckBox*>(tableSche->cellWidget(i, QString::number(d)))->isChecked()) weekFilter.append(d);
if(weekFilter.size()>=7) {
schedule["filterType"] = "None";
weekFilter = QJsonArray();
} else schedule["filterType"] = "Week";
schedule["weekFilter"] = weekFilter;
item.insert("schedules", QJsonArray{schedule});
items.append(item);
}
auto def = fdDefBright->value();
return QJsonObject{
{"createBy", "alahover"},
{"name", "TimingVolume"},
{"defaultVolume", def},
{"volume", def},
{"items", items}
};
}

View File

@ -0,0 +1,44 @@
#ifndef CTRLVOLUMEPANEL_H
#define CTRLVOLUMEPANEL_H
#include "gutil/qgui.h"
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
class CtrlVolumePanel : public QWidget {
Q_OBJECT
public:
CtrlVolumePanel();
protected:
void showEvent(QShowEvent *event) override;
void init();
void changeEvent(QEvent *) override;
void transUi();
private:
bool restoreScheduleJson(QJsonObject);
QJsonObject getScheduleJson();
QLabel *lbVolumeControl;
QRadioButton *fdManual;
QRadioButton *fdSchedule;
QLabel *lbVolume;
QSlider *fdVolume;
QPushButton *fdVolumeGet;
QLabel *fdScheTip;
QPushButton *btnScheAdd;
QPushButton *btnScheDel;
QPushButton *btnScheClear;
QLabel *lbDefBright;
QSlider *fdDefBright;
QPushButton *btnScheImport;
QPushButton *btnScheExport;
Table *tableSche;
QPushButton *btnScheSet;
QPushButton *btnScheGet;
};
#endif // CTRLVOLUMEPANEL_H

View File

@ -1,48 +0,0 @@
#include "ledcard.h"
LedCard::LedCard(QObject *p) : QObject(p) {
}
void LedCard::copyLedCardHTTPGetParam(LedCard *p)
{
m_strCardId = p->m_strCardId;
m_strCardIp = p->m_strCardIp;
if(p->m_strCardRemarkName!="")
m_strCardRemarkName=p->m_strCardRemarkName;
starterversionName = p->starterversionName ;
starterPort = p->starterPort ;
androidVersion = p->androidVersion ;
iHttpGetId = p->iHttpGetId ;
androidHeight = p->androidHeight ;
androidWidth = p->androidWidth ;
lastActive = p->lastActive ;
}
void LedCard::copyLedCardHTTPPostParam(LedCard *p)
{
strIMEI =p->strIMEI ;
HardVersion =p->HardVersion ;
BrightnessLevel =p->BrightnessLevel ;
ScreenResolution =p->ScreenResolution ;
FirmwareVersion =p->FirmwareVersion ;
}
bool LedCard::CompareHTTPGetParam(LedCard *p) {
//这里只比较httpGet devicelist打算应答
if(m_strCardIp!=p->m_strCardIp) return false;
if(m_strCardRemarkName!=p->m_strCardRemarkName) return false;
if(starterversionName!=p->starterversionName) return false;
if(androidVersion!=p->androidVersion) return false;
if(androidWidth!=p->androidWidth) return false;
if(androidHeight!=p->androidHeight) return false;
return true;
}
bool LedCard::CompareHTTPPostParam(LedCard *p)
{
//这里只比较httpGet devicelist打算应答
if(strIMEI!=p->strIMEI) return false;
if(HardVersion!=p->HardVersion) return false;
if(BrightnessLevel!=p->BrightnessLevel) return false;
if(ScreenResolution!=p->ScreenResolution) return false;
if(FirmwareVersion!=p->FirmwareVersion) return false;
return true;
}

View File

@ -1,60 +0,0 @@
#ifndef LEDCARD_H
#define LEDCARD_H
#include <QObject>
#include <QDebug>
class LedCard : public QObject {
Q_OBJECT
Q_PROPERTY(QString strCardId MEMBER m_strCardId NOTIFY CardIdChanged)
Q_PROPERTY(QString strCardIp MEMBER m_strCardIp NOTIFY CardIpChanged)
Q_PROPERTY(qint32 iCardWidth MEMBER m_iWidth NOTIFY WidthChanged)
Q_PROPERTY(qint32 iCardHeight MEMBER m_iHeight NOTIFY HeightChanged)
Q_PROPERTY(QString strCardRemarkName MEMBER m_strCardRemarkName NOTIFY CardRemarkNameChanged)
public:
LedCard(QObject *p = nullptr);
~LedCard(){
qDebug()<<"~~~~LedCard";
}
signals:
void CardIdChanged(const QString &);
void CardIpChanged(const QString &);
void WidthChanged(qint32 t);
void HeightChanged(qint32 t);
void CardRemarkNameChanged(const QString &);
public:
//属性
QString m_strCardId;
QString m_strCardIp;
qint32 m_iWidth = 0;
qint32 m_iHeight = 0;
QString m_strCardRemarkName = "";
QString starterversionName = "";
int starterPort = 0;
QString androidVersion = "";
int iHttpGetId = 0;
int androidHeight = 0;
int bright{100};
int androidWidth = 0;
int lastActive = 0;
QString strIMEI="";
QString HardVersion="0000";
int BrightnessLevel=255;
QString ScreenResolution="";
QString FirmwareVersion="";
QString strXixunplayerVersion="";
int strXixunplayerVersionCode=0;
bool bPassword=false;
void copyLedCardHTTPGetParam(LedCard *p);
void copyLedCardHTTPPostParam(LedCard *p);
bool CompareHTTPGetParam(LedCard *p);
bool CompareHTTPPostParam(LedCard *p);
//状态
bool m_bLockStatus=true;
bool m_bPowerStatus=true;
bool m_bOnLine=true;
};
#endif // LEDCARD_H

View File

@ -3,7 +3,8 @@
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "gutil/qnetwork.h" #include "gutil/qnetwork.h"
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
#include "tools.h" #include "devicepanel.h"
#include "deviceitem.h"
#include <QAction> #include <QAction>
#include <QFileDialog> #include <QFileDialog>
#include <QLineEdit> #include <QLineEdit>
@ -143,7 +144,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
QMessageBox::information(this, tr("Tip"), tr("Is upgrading now. Please wait")); QMessageBox::information(this, tr("Tip"), tr("Is upgrading now. Please wait"));
return; return;
} }
if(item->mCard->bPassword && item->mCard->m_bLockStatus && item->m_lockFlag) { if(item->mCard.hasPassword && item->mCard.isLocked && item->m_lockFlag) {
item->setResult(tr("This screen is encrypted"), Qt::red); item->setResult(tr("This screen is encrypted"), Qt::red);
return; return;
} }
@ -194,7 +195,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
item->setResult(tr("Uploading")+" ..."); item->setResult(tr("Uploading")+" ...");
item->mProgress->setValue(0); item->mProgress->setValue(0);
item->isUpdating = true; item->isUpdating = true;
NetReq req("http://"+item->mCard->m_strCardIp+":2016/upload?type="+(isApk ? "software":"hardware")); NetReq req("http://"+item->mCard.ip+":2016/upload?type="+(isApk ? "software":"hardware"));
auto reply = req.timeout(120000).type("multipart/form-data; boundary="+Boundary).post(data); auto reply = req.timeout(120000).type("multipart/form-data; boundary="+Boundary).post(data);
connect(reply, &QNetworkReply::uploadProgress, item->mProgress, [item](qint64 bytesSent, qint64 bytesTotal) { connect(reply, &QNetworkReply::uploadProgress, item->mProgress, [item](qint64 bytesSent, qint64 bytesTotal) {
if(bytesTotal<=0) return; if(bytesTotal<=0) return;
@ -219,7 +220,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
json.insert("_id", "SynchronousHardwareVersion"); json.insert("_id", "SynchronousHardwareVersion");
json.insert("_type", "SynchronousHardwareVersion"); json.insert("_type", "SynchronousHardwareVersion");
} }
auto reply = NetReq("http://"+item->mCard->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, item->mProgress, [=] { connect(reply, &QNetworkReply::finished, item->mProgress, [=] {
item->isUpdating = false; item->isUpdating = false;
QString err = errStrWithData(reply); QString err = errStrWithData(reply);
@ -271,7 +272,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
json.insert("_id", "UninstallSoftware"); json.insert("_id", "UninstallSoftware");
json.insert("_type", "UninstallSoftware"); json.insert("_type", "UninstallSoftware");
json.insert("packageName", strApkName); json.insert("packageName", strApkName);
auto reply = NetReq("http://"+item->mCard->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, item, strApkName] { connect(reply, &QNetworkReply::finished, this, [reply, item, strApkName] {
QString err = errStrWithData(reply); QString err = errStrWithData(reply);
if(! err.isEmpty()) { if(! err.isEmpty()) {
@ -297,7 +298,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
json.insert("_id", "IsSoftwareRunning"); json.insert("_id", "IsSoftwareRunning");
json.insert("_type", "IsSoftwareRunning"); json.insert("_type", "IsSoftwareRunning");
json.insert("packageName", strApkName); json.insert("packageName", strApkName);
auto reply = NetReq("http://"+item->mCard->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, item, strApkName] { connect(reply, &QNetworkReply::finished, this, [reply, item, strApkName] {
QJsonDocument json; QJsonDocument json;
QString err = errStrWithData(reply, &json); QString err = errStrWithData(reply, &json);
@ -325,9 +326,9 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
connect(btnRefresh, &QPushButton::clicked, this, [this, label] { connect(btnRefresh, &QPushButton::clicked, this, [this, label] {
table->clear(); table->clear();
table->onCheckAll(false); table->onCheckAll(false);
int iCount = gDevicePanel->mLedCards.count(); int cnt = gDevicePanel->mDeviceTable->topLevelItemCount();
for(int i=0;i<iCount;i++) onAddLedCard(gDevicePanel->mLedCards.at(i)); for(int i=0; i<cnt; i++) onAddLedCard(static_cast<DeviceItem*>(gDevicePanel->mDeviceTable->topLevelItem(i))->mCard);
label->setText(tr("All")+":"+QString::number(iCount)); label->setText(tr("All")+":"+QString::number(cnt));
}); });
hBox->addWidget(btnRefresh); hBox->addWidget(btnRefresh);
@ -395,17 +396,17 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
table->header()->setSectionResizeMode(Upgrade_CONNECTION_VERSION, QHeaderView::ResizeToContents); table->header()->setSectionResizeMode(Upgrade_CONNECTION_VERSION, QHeaderView::ResizeToContents);
table->header()->setSectionResizeMode(Upgrade_UPDATE_VERSION, QHeaderView::ResizeToContents); table->header()->setSectionResizeMode(Upgrade_UPDATE_VERSION, QHeaderView::ResizeToContents);
int iCount = gDevicePanel->mLedCards.count(); int cnt = gDevicePanel->mDeviceTable->topLevelItemCount();
for(int i=0; i<iCount; i++) onAddLedCard(gDevicePanel->mLedCards.at(i)); for(int i=0; i<cnt; i++) onAddLedCard(static_cast<DeviceItem*>(gDevicePanel->mDeviceTable->topLevelItem(i))->mCard);
label->setText(tr("All")+":"+QString::number(iCount)); label->setText(tr("All")+":"+QString::number(cnt));
} }
void UpgradeApkDialog::onAddLedCard(LedCard *card) { void UpgradeApkDialog::onAddLedCard(LedCard card) {
int iExistFlg=0; int iExistFlg=0;
int cnt = table->topLevelItemCount(); int cnt = table->topLevelItemCount();
for(int i=0; i<cnt; i++) { for(int i=0; i<cnt; i++) {
QString strTempCardId=static_cast<wUpgradeApkItem*>(table->topLevelItem(i))->mCard->m_strCardId; QString strTempCardId=static_cast<wUpgradeApkItem*>(table->topLevelItem(i))->mCard.id;
if(strTempCardId == card->m_strCardId) { if(strTempCardId == card.id) {
iExistFlg=1; iExistFlg=1;
static_cast<wUpgradeApkItem*>(table->topLevelItem(i))->SetItemParam(card); static_cast<wUpgradeApkItem*>(table->topLevelItem(i))->SetItemParam(card);
break; break;

View File

@ -16,7 +16,7 @@ protected slots:
void FilterProgram(const QString &strtemp); void FilterProgram(const QString &strtemp);
private: private:
void onAddLedCard(LedCard *p); void onAddLedCard(LedCard p);
LoQTreeWidget *table; LoQTreeWidget *table;
QTreeWidgetItem *m_headerItem=nullptr; QTreeWidgetItem *m_headerItem=nullptr;

View File

@ -1,6 +1,8 @@
#include "wupgradeapkitem.h" #include "wupgradeapkitem.h"
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
#include "deviceitem.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include <QMessageBox> #include <QMessageBox>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
@ -9,7 +11,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QInputDialog> #include <QInputDialog>
wUpgradeApkItem::wUpgradeApkItem(LedCard *pLedCard, LoQTreeWidget *parent) : QTreeWidgetItem(UserType), mCard(pLedCard), m_parent(parent) { wUpgradeApkItem::wUpgradeApkItem(LedCard pLedCard, LoQTreeWidget *parent) : QTreeWidgetItem(UserType), mCard(pLedCard), m_parent(parent) {
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
setCheckState(0, Qt::Unchecked); setCheckState(0, Qt::Unchecked);
m_parent->addTopLevelItem(this); m_parent->addTopLevelItem(this);
@ -30,7 +32,7 @@ wUpgradeApkItem::wUpgradeApkItem(LedCard *pLedCard, LoQTreeWidget *parent) : QTr
vBox->addWidget(btnUnlock); vBox->addWidget(btnUnlock);
m_parent->setItemWidget(this, Upgrade_ENCRYPT, wgt); m_parent->setItemWidget(this, Upgrade_ENCRYPT, wgt);
QObject::connect(btnUnlock, &QPushButton::clicked, mProgress, [this] { QObject::connect(btnUnlock, &QPushButton::clicked, mProgress, [this] {
if(! mCard->m_bLockStatus) return; if(! mCard.isLocked) return;
bool ok; bool ok;
auto pwd = QInputDialog::getText(treeWidget(), QObject::tr("Input password"), QObject::tr("Input password"), QLineEdit::Password, QString(), &ok); auto pwd = QInputDialog::getText(treeWidget(), QObject::tr("Input password"), QObject::tr("Input password"), QLineEdit::Password, QString(), &ok);
if(! ok) return; if(! ok) return;
@ -40,7 +42,7 @@ wUpgradeApkItem::wUpgradeApkItem(LedCard *pLedCard, LoQTreeWidget *parent) : QTr
json.insert("pwd", pwd); json.insert("pwd", pwd);
auto waitingDlg = new WaitingDlg(treeWidget(), QObject::tr("VerifyPassword")+" ..."); auto waitingDlg = new WaitingDlg(treeWidget(), QObject::tr("VerifyPassword")+" ...");
waitingDlg->show(); waitingDlg->show();
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
waitingDlg->connAbort(reply); waitingDlg->connAbort(reply);
QObject::connect(reply, &QNetworkReply::finished, mProgress, [=] { QObject::connect(reply, &QNetworkReply::finished, mProgress, [=] {
QJsonDocument json; QJsonDocument json;
@ -56,8 +58,13 @@ wUpgradeApkItem::wUpgradeApkItem(LedCard *pLedCard, LoQTreeWidget *parent) : QTr
return; return;
} }
waitingDlg->success(); waitingDlg->success();
mCard->m_bLockStatus = false; mCard.isLocked = false;
btnUnlock->setIcon(QIcon(":/res/device/UnLock.png")); btnUnlock->setIcon(QIcon(":/res/device/UnLock.png"));
auto item = findItem(mCard.id);
if(item) {
item->mCard.isLocked = false;
item->btnUnlock->setIcon(QIcon(":/res/device/UnLock.png"));
}
}); });
}); });
@ -68,7 +75,7 @@ void wUpgradeApkItem::OnCheckFpgaVersions() {
QJsonObject json; QJsonObject json;
json.insert("_id", "CheckHardwareVersions"); json.insert("_id", "CheckHardwareVersions");
json.insert("_type", "CheckHardwareVersions"); json.insert("_type", "CheckHardwareVersions");
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
QObject::connect(reply, &QNetworkReply::finished, mProgress, [reply, this] { QObject::connect(reply, &QNetworkReply::finished, mProgress, [reply, this] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -88,7 +95,7 @@ void wUpgradeApkItem::OnCheckSoftVersions() {
QJsonObject json; QJsonObject json;
json.insert("_id", "CheckSoftVersions"); json.insert("_id", "CheckSoftVersions");
json.insert("_type", "CheckSoftVersions"); json.insert("_type", "CheckSoftVersions");
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
QObject::connect(reply, &QNetworkReply::finished, mProgress, [reply, this] { QObject::connect(reply, &QNetworkReply::finished, mProgress, [reply, this] {
QJsonDocument json; QJsonDocument json;
QString err = checkReplyForJson(reply, &json); QString err = checkReplyForJson(reply, &json);
@ -114,19 +121,19 @@ void wUpgradeApkItem::setResult(QString tip, QColor color) {
setToolTip(Upgrade_Remark, tip); setToolTip(Upgrade_Remark, tip);
setForeground(Upgrade_Remark, color); setForeground(Upgrade_Remark, color);
} }
void wUpgradeApkItem::SetItemParam(LedCard *card) { void wUpgradeApkItem::SetItemParam(LedCard card) {
mCard->m_strCardId = card->m_strCardId; mCard.id = card.id;
mCard->m_strCardIp = card->m_strCardIp; mCard.ip = card.ip;
mCard->m_bOnLine = card->m_bOnLine; mCard.isOnline = card.isOnline;
setData(Upgrade_SCREEN_ID, 0, card->m_strCardId); setData(Upgrade_SCREEN_ID, 0, card.id);
setData(Upgrade_SCREEN_IP, 0, card->m_strCardIp); setData(Upgrade_SCREEN_IP, 0, card.ip);
setData(Upgrade_REMARK_NAME, 0, card->m_strCardRemarkName); setData(Upgrade_REMARK_NAME, 0, card.alias);
m_ImageOnline->setPixmap(QPixmap(mCard->m_bOnLine ? ":/res/device/O_Online.png" : ":/res/device/O_Offline.png")); m_ImageOnline->setPixmap(QPixmap(mCard.isOnline ? ":/res/device/O_Online.png" : ":/res/device/O_Offline.png"));
OnCheckSoftVersions(); OnCheckSoftVersions();
OnCheckFpgaVersions(); OnCheckFpgaVersions();
if(! card->bPassword) btnUnlock->hide(); if(! card.hasPassword) btnUnlock->hide();
else { else {
if(! btnUnlock->isVisible()) btnUnlock->show(); if(! btnUnlock->isVisible()) btnUnlock->show();
btnUnlock->setIcon(QIcon(card->m_bLockStatus ? ":/res/device/Lock.png" : ":/res/device/UnLock.png")); //如果已经验证通过密码显示绿色图标 没有验证显示蓝色锁图标 btnUnlock->setIcon(QIcon(card.isLocked ? ":/res/device/Lock.png" : ":/res/device/UnLock.png")); //如果已经验证通过密码显示绿色图标 没有验证显示蓝色锁图标
} }
} }

View File

@ -1,26 +1,23 @@
#ifndef WUPGRADEAPKITEM_H #ifndef WUPGRADEAPKITEM_H
#define WUPGRADEAPKITEM_H #define WUPGRADEAPKITEM_H
#include <QTreeWidget> #include "globaldefine.h"
#include <QTreeWidgetItem>
#include <QDir> #include <QDir>
#include <QDateTime> #include <QDateTime>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonDocument> #include <QJsonDocument>
#include <QPushButton> #include <QPushButton>
#include <base/loqtreewidget.h> #include <base/loqtreewidget.h>
#include <device/ledcard.h>
#include <communication/hpptclient.h>
#include <QProgressBar> #include <QProgressBar>
#include <QLabel> #include <QLabel>
class wUpgradeApkItem : public QTreeWidgetItem { class wUpgradeApkItem : public QTreeWidgetItem {
public: public:
explicit wUpgradeApkItem(LedCard *pLedCard, LoQTreeWidget *parent); explicit wUpgradeApkItem(LedCard card, LoQTreeWidget *parent);
void SetItemParam(LedCard *p); void SetItemParam(LedCard p);
void setResult(QString, QColor cr = Qt::blue); void setResult(QString, QColor cr = Qt::blue);
LedCard *mCard = nullptr; LedCard mCard;
bool isUpdating{false}; bool isUpdating{false};
bool m_lockFlag=true; bool m_lockFlag=true;
QLabel *m_ImageOnline=nullptr; QLabel *m_ImageOnline=nullptr;

View File

@ -1,20 +1,15 @@
#include "devicectrlpanel.h" #include "devicectrlpanel.h"
#include "devicepanel.h" #include "devicepanel.h"
#include "tools.h" #include "tools.h"
#include <QEvent> #include "device/ctrlbrightpanel.h"
#include <QGridLayout> #include "device/ctrlpowerpanel.h"
#include <QButtonGroup> #include "device/ctrlnetworkpanel.h"
#include <QToolButton> #include "device/ctrlverifyclockpanel.h"
#include "device/ctrlhdmipanel.h"
#include <device/ctrlbrightpanel.h> #include "device/ctrlvolumepanel.h"
#include <device/controlpowerwidget.h> #include "device/ctrlpwdpanel.h"
#include <device/ctrlnetworkpanel.h> #include "device/ctrladvancedpanel.h"
#include <device/ctrlverifyclockpanel.h> #include "device/ctrltestpanel.h"
#include <device/ctrlhdmipanel.h>
#include <device/controlvolumewidget.h>
#include <device/ctrlpwdpanel.h>
#include <device/ctrladvancedpanel.h>
#include <device/controltestwidget.h>
QTextEdit *gFdResInfo; QTextEdit *gFdResInfo;
@ -54,18 +49,17 @@ DeviceCtrlPanel::DeviceCtrlPanel(DevicePanel *parent) : QWidget(parent), mDevWgt
curIndex = index; curIndex = index;
if(wgts[index]==0) { if(wgts[index]==0) {
if(index==Setting_Bright) wgts[index] = new CtrlBrightPanel(this); if(index==Setting_Bright) wgts[index] = new CtrlBrightPanel(this);
else if(index==Setting_PowerControl) wgts[index] = new ControlPowerWidget(this, gSelCards); else if(index==Setting_PowerControl) wgts[index] = new CtrlPowerPanel;
else if(index==Setting_NetCfg) wgts[index] = new CtrlNetworkPanel(this); else if(index==Setting_NetCfg) wgts[index] = new CtrlNetworkPanel(this);
else if(index==Setting_VerifyClock) wgts[index] = new CtrlVerifyClockPanel(this); else if(index==Setting_VerifyClock) wgts[index] = new CtrlVerifyClockPanel(this);
else if(index==Setting_Encrypt) wgts[index] = new CtrlPwdPanel(this); else if(index==Setting_Encrypt) wgts[index] = new CtrlPwdPanel(this);
else if(index==Setting_HDMI) wgts[index] = new CtrlHdmiPanel(this); else if(index==Setting_HDMI) wgts[index] = new CtrlHdmiPanel;
else if(index==Setting_Volume) wgts[index] = new ControlVolumeWidget(this, gSelCards); else if(index==Setting_Volume) wgts[index] = new CtrlVolumePanel;
else if(index==Setting_Advanced) wgts[index] = new CtrlAdvancedPanel(this); else if(index==Setting_Advanced) wgts[index] = new CtrlAdvancedPanel(this);
else if(index==Setting_Test) wgts[index] = new ControlTestWidget(this, gSelCards); else if(index==Setting_Test) wgts[index] = new CtrlTestPanel(this);
} }
scrollArea->takeWidget(); scrollArea->takeWidget();
scrollArea->setWidget(wgts[index]); scrollArea->setWidget(wgts[index]);
emit sigSwitchIndexChanged(curIndex);
}); });
vBox->addLayout(hBox); vBox->addLayout(hBox);
@ -98,14 +92,17 @@ DeviceCtrlPanel::DeviceCtrlPanel(DevicePanel *parent) : QWidget(parent), mDevWgt
vBox->addLayout(hBox); vBox->addLayout(hBox);
connect(mDevWgt, &DevicePanel::sigSelectedDeviceList, this, [this]() { fdInfo->hide();
if(gSelCards->count() < 2) { btnClear->hide();
if(gSelCards->count()==1) mDevWgt->fdCardNumInfo->setText(tr("Current Screen")+": "+gSelCards->at(0)->m_strCardId);
connect(mDevWgt, &DevicePanel::sigSelectedDeviceList, this, [this] {
if(gSelCards.count() < 2) {
if(gSelCards.count()==1) mDevWgt->fdCardNumInfo->setText(tr("Current Screen")+": "+gSelCards[0].id);
else mDevWgt->fdCardNumInfo->setText(tr("Current Screen")+": "+tr("none")); else mDevWgt->fdCardNumInfo->setText(tr("Current Screen")+": "+tr("none"));
fdInfo->hide(); fdInfo->hide();
btnClear->hide(); btnClear->hide();
} else { } else {
mDevWgt->fdCardNumInfo->setText(tr("Multi screen operation")+". "+tr("selected num")+": "+QString::number(gSelCards->count())); mDevWgt->fdCardNumInfo->setText(tr("Multi screen operation")+". "+tr("selected num")+": "+QString::number(gSelCards.count()));
fdInfo->clear(); fdInfo->clear();
fdInfo->show(); fdInfo->show();
btnClear->show(); btnClear->show();
@ -121,6 +118,14 @@ void DeviceCtrlPanel::changeEvent(QEvent *event) {
QWidget::changeEvent(event); QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi(); if(event->type() == QEvent::LanguageChange) transUi();
} }
void DeviceCtrlPanel::showEvent(QShowEvent *event) {
QWidget::showEvent(event);
mDevWgt->mDeviceTable->setSelectionMode(QAbstractItemView::SingleSelection);
}
void DeviceCtrlPanel::hideEvent(QHideEvent *event) {
QWidget::hideEvent(event);
mDevWgt->mDeviceTable->setSelectionMode(QAbstractItemView::NoSelection);
}
void DeviceCtrlPanel::transUi() { void DeviceCtrlPanel::transUi() {
mBtnGrp->button(Setting_Bright)->setText(tr("Brightness Adjustment")); mBtnGrp->button(Setting_Bright)->setText(tr("Brightness Adjustment"));
mBtnGrp->button(Setting_PowerControl)->setText(tr("Power Control")); mBtnGrp->button(Setting_PowerControl)->setText(tr("Power Control"));
@ -132,12 +137,8 @@ void DeviceCtrlPanel::transUi() {
mBtnGrp->button(Setting_Volume)->setText(tr("Volume Adj.")); mBtnGrp->button(Setting_Volume)->setText(tr("Volume Adj."));
mBtnGrp->button(Setting_Test)->setText(tr("Test")); mBtnGrp->button(Setting_Test)->setText(tr("Test"));
if(gSelCards->count() < 1) mDevWgt->fdCardNumInfo->setText(tr("Current Screen")+": "+tr("none")); if(gSelCards.count() < 1) mDevWgt->fdCardNumInfo->setText(tr("Current Screen")+": "+tr("none"));
else if(gSelCards->count()==1) mDevWgt->fdCardNumInfo->setText(tr("Current Screen")+": "+gSelCards->at(0)->m_strCardId); else if(gSelCards.count()==1) mDevWgt->fdCardNumInfo->setText(tr("Current Screen")+": "+gSelCards[0].id);
else mDevWgt->fdCardNumInfo->setText(tr("Multi screen operation")+". "+tr("selected num")+": "+QString::number(gSelCards->count())); else mDevWgt->fdCardNumInfo->setText(tr("Multi screen operation")+". "+tr("selected num")+": "+QString::number(gSelCards.count()));
btnClear->setText(tr("Clear")); btnClear->setText(tr("Clear"));
} }
void DeviceCtrlPanel::OnOutputInfo(QString strInfo) {
if(isVisible() && fdInfo->isVisible()) fdInfo->append(strInfo);
}

View File

@ -2,7 +2,6 @@
#define DEVICECTRLPANEL_H #define DEVICECTRLPANEL_H
#include "globaldefine.h" #include "globaldefine.h"
#include "device/ledcard.h"
#include <QScrollArea> #include <QScrollArea>
#include <QPushButton> #include <QPushButton>
#include <QToolButton> #include <QToolButton>
@ -17,13 +16,10 @@ public:
QTextEdit *fdInfo; QTextEdit *fdInfo;
protected: protected:
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
void changeEvent(QEvent *) override; void changeEvent(QEvent *) override;
void transUi(); void transUi();
signals:
void sigSwitchIndexChanged(int index);
public slots:
void OnOutputInfo(QString strInfo);
private: private:
DevicePanel *mDevWgt; DevicePanel *mDevWgt;
QButtonGroup *mBtnGrp; QButtonGroup *mBtnGrp;

View File

@ -1,27 +1,18 @@
#include "deviceitem.h" #include "deviceitem.h"
#include "globaldefine.h"
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include <QMessageBox> #include <QMessageBox>
#include <QJsonArray>
#include <QJsonDocument>
#include <QPainter> #include <QPainter>
#include <globaldefine.h>
#include <QSettings>
#include <cfg.h>
#include <QHttpMultiPart>
#include <QUuid>
#include <QBuffer>
#include <QThread>
#include <QTcpSocket>
#include <QHostAddress>
#include <QInputDialog> #include <QInputDialog>
#include <QJsonObject>
DeviceItem::DeviceItem(LedCard *pLedCard, LoQTreeWidget *parent) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) { DeviceItem::DeviceItem(LoQTreeWidget *parent) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) {
mCard = pLedCard;
pHpptClient = new HpptClient(this);
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
setCheckState(0, Qt::Unchecked); setCheckState(0, Qt::Unchecked);
m_parent->addTopLevelItem(this); m_parent->addTopLevelItem(this);
m_bnCardDetailInfo = new QPushButton(); m_bnCardDetailInfo = new QPushButton();
m_bnCardDetailInfo->setToolTip(tr("GetScreenDetailInfo")); m_bnCardDetailInfo->setToolTip(tr("GetScreenDetailInfo"));
m_bnCardDetailInfo->setCursor(QCursor(Qt::PointingHandCursor)); m_bnCardDetailInfo->setCursor(QCursor(Qt::PointingHandCursor));
@ -32,22 +23,7 @@ QPushButton {
} }
QPushButton:hover{background-color: #ccc;} QPushButton:hover{background-color: #ccc;}
)rrr"); )rrr");
connect(m_bnCardDetailInfo, &QPushButton::clicked, this, [this]{ m_parent->setItemWidget(this, DeviceTable_Info, m_bnCardDetailInfo);
QString strTip="";
strTip.append(tr("cur brightness:")).append(QString::number(mCard->bright)).append("\r\n");
//strTip.append("cardsystem apk version:"+QString::number(m_LedCard.iCardSystemVersion)+"\r\n");
//strTip.append("device apk:"+m_LedCard.starterversionName+"\r\n");
strTip.append(tr("android version:")).append(mCard->androidVersion).append("\r\n");
//strTip.append(tr("android width:")+QString::number(m_LedCard.androidWidth)+"\r\n");
//strTip.append(tr("android height:")+QString::number(m_LedCard.androidHeight)+"\r\n");
strTip.append(tr("IMEI:")).append(mCard->strIMEI).append("\r\n");
strTip.append(tr("HardWard Version:")).append(mCard->HardVersion).append("\r\n");
strTip.append(tr("MAX Brightness level:")).append(QString::number(mCard->BrightnessLevel)).append("\r\n");
strTip.append(tr("Android OS Resolution:")).append(mCard->ScreenResolution).append("\r\n");
strTip.append(tr("Firmware Version:")).append(mCard->FirmwareVersion).append("\r\n");
strTip.append(tr("Player Version:")).append(mCard->strXixunplayerVersion).append("\r\n");
QMessageBox::information(treeWidget(), tr("Detail Info"), strTip);
});
m_bnReadbackPic = new QPushButton(); m_bnReadbackPic = new QPushButton();
m_bnReadbackPic->setToolTip(tr("ReadbackPic")); m_bnReadbackPic->setToolTip(tr("ReadbackPic"));
@ -65,7 +41,7 @@ QPushButton:hover{background-color: #ccc;}
json.insert("_type", "GetScreenshotFull"); json.insert("_type", "GetScreenshotFull");
auto waitingDlg = new WaitingDlg(treeWidget(), tr("GetScreenshotFull")+" ..."); auto waitingDlg = new WaitingDlg(treeWidget(), tr("GetScreenshotFull")+" ...");
waitingDlg->show(); waitingDlg->show();
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(120000).post(json); auto reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
waitingDlg->connAbort(reply); waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
waitingDlg->close(); waitingDlg->close();
@ -79,24 +55,17 @@ QPushButton:hover{background-color: #ccc;}
dlg.exec(); dlg.exec();
}); });
}); });
m_ImageOnline = new QLabel();
mCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/device/O_Online.png"));
setData(DeviceTable_ID, 0, mCard->m_strCardId);
setData(DeviceTable_IP, 0, mCard->m_strCardIp);
setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(mCard->m_iWidth).arg(mCard->m_iHeight));
m_parent->setItemWidget(this, DeviceTable_Info, m_bnCardDetailInfo);
m_parent->setItemWidget(this, DeviceTable_Screenshot, m_bnReadbackPic); m_parent->setItemWidget(this, DeviceTable_Screenshot, m_bnReadbackPic);
m_parent->setItemWidget(this, DeviceTable_Online, m_ImageOnline);
m_ImageOnline = new QLabel;
m_ImageOnline->setPixmap(QPixmap(":/res/device/O_Online.png"));
m_ImageOnline->setAlignment(Qt::AlignCenter); m_ImageOnline->setAlignment(Qt::AlignCenter);
m_parent->setItemWidget(this, DeviceTable_Online, m_ImageOnline);
btnUnlock = new QPushButton; btnUnlock = new QPushButton;
btnUnlock->setMaximumHeight(40); btnUnlock->setMaximumHeight(40);
if(mCard->bPassword) btnUnlock->setIcon(QIcon(mCard->m_bLockStatus ? ":/res/device/Lock.png" : ":/res/device/UnLock.png"));
else btnUnlock->hide();
connect(btnUnlock, &QPushButton::clicked, this, [this] { connect(btnUnlock, &QPushButton::clicked, this, [this] {
if(! mCard->m_bLockStatus) return; if(! mCard.isLocked) return;
bool ok; bool ok;
auto pwd = QInputDialog::getText(treeWidget(), tr("Input password"), tr("Input password"), QLineEdit::Password, QString(), &ok); auto pwd = QInputDialog::getText(treeWidget(), tr("Input password"), tr("Input password"), QLineEdit::Password, QString(), &ok);
if(! ok) return; if(! ok) return;
@ -106,7 +75,7 @@ QPushButton:hover{background-color: #ccc;}
json.insert("pwd", pwd); json.insert("pwd", pwd);
auto waitingDlg = new WaitingDlg(treeWidget(), tr("VerifyPassword")+" ..."); auto waitingDlg = new WaitingDlg(treeWidget(), tr("VerifyPassword")+" ...");
waitingDlg->show(); waitingDlg->show();
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(60000).post(json); auto reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(60000).post(json);
waitingDlg->connAbort(reply); waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
@ -122,7 +91,7 @@ QPushButton:hover{background-color: #ccc;}
return; return;
} }
waitingDlg->success(); waitingDlg->success();
mCard->m_bLockStatus = false; mCard.isLocked = false;
btnUnlock->setIcon(QIcon(":/res/device/UnLock.png")); btnUnlock->setIcon(QIcon(":/res/device/UnLock.png"));
}); });
}); });
@ -133,297 +102,96 @@ QPushButton:hover{background-color: #ccc;}
m_parent->setItemWidget(this, DeviceTable_Password, wgt); m_parent->setItemWidget(this, DeviceTable_Password, wgt);
for(int i=1; i<DeviceTable_Screenshot; i++) setTextAlignment(i, Qt::AlignCenter); for(int i=1; i<DeviceTable_Screenshot; i++) setTextAlignment(i, Qt::AlignCenter);
//启动心跳监测设备在线和下线3次超时表示下线
DeviceItemHttpPost();
connect(&mHeartbeatTimer, &QTimer::timeout, this, [this] {
m_HeartbeatCount++;
QJsonObject json4;
json4.insert("_id", getRandomString(10));
json4.insert("_type", "GetCardName");
HttpPostByTypeJsonObject(json4);
if(m_HeartbeatCount>10) {
//下线
mCard->m_bOnLine=false;
m_ImageOnline->setPixmap(QPixmap(":/res/device/O_Offline.png"));
} else {
//在线
mCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/device/O_Online.png"));
}
});
mHeartbeatTimer.start(60000);
m_pGetAskTimer=new QTimer(this);
connect(pHpptClient,SIGNAL(httpPostRspReady(QString , QString , QByteArray)),this,SLOT(OnProHttpResponse(QString , QString , QByteArray)));
//连接item的响应信号到信息输出框的显示槽函数
connect(this,SIGNAL(sigOutputInfo(QString)),parent->parent(),SLOT(OnOutputInfo(QString)));
}
DeviceItem::~DeviceItem() {
mHeartbeatTimer.stop();
if(pHpptClient) {
delete pHpptClient;
pHpptClient=nullptr;
}
} }
void DeviceItem::SetMainTabWidgetIndex(int index){ void DeviceItem::init() {
m_intIndexFlagOfInfoOrControl=index; setData(DeviceTable_ID, 0, mCard.id);
DeviceItemHttpPost(); setData(DeviceTable_IP, 0, mCard.ip);
setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(mCard.mWidth).arg(mCard.mHeight));
if(mCard.hasPassword) btnUnlock->setIcon(QIcon(mCard.isLocked ? ":/res/device/Lock.png" : ":/res/device/UnLock.png"));
else btnUnlock->hide();
} }
//针对这个ITEM通过POST获取控制卡的信息两种情况下会调用创建该Item初始化后二、手动刷新
void DeviceItem::DeviceItemHttpPost() { void DeviceItem::DeviceItemHttpPost() {
if(m_intIndexFlagOfInfoOrControl!=MainPage_DeviceManager) return;
QJsonObject json; QJsonObject json;
json.insert("_id", getRandomString(10)); json.insert("_id", "GetBuildInformation");
json.insert("_type", "GetBuildInformation");
auto reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
mCard.BrightnessLevel = json["BrightnessLevel"].toInt();
mCard.FirmwareVersion = json["FirmwareVersion"].toString();
mCard.HardVersion = json["HardVersion"].toString();
mCard.ScreenResolution = json["ScreenResolution"].toString();
auto androidVersion = json["AndroidVersion"].toString();
if(! androidVersion.isEmpty()) mCard.androidVersion = androidVersion;
});
json = QJsonObject();
json.insert("_id", "GetScreenSize");
json.insert("_type", "GetScreenSize"); json.insert("_type", "GetScreenSize");
HttpPostByTypeJsonObject(json); reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
QJsonObject json1; connect(reply, &QNetworkReply::finished, this, [=] {
json1.insert("_id", getRandomString(10)); QJsonDocument json;
json1.insert("_type", "GetBrightness"); QString err = checkReplyForJson(reply, &json);
HttpPostByTypeJsonObject(json1); if(! err.isEmpty()) return;
QJsonObject json2; mCard.mWidth = json["width"].toInt();
json2.insert("_id", getRandomString(10)); mCard.mHeight = json["height"].toInt();
json2.insert("_type", "IsScreenOn"); setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(mCard.mWidth).arg(mCard.mHeight));
HttpPostByTypeJsonObject(json2); });
QJsonObject json4; json = QJsonObject();
json4.insert("_id", getRandomString(10)); json.insert("_id", "GetBrightness");
json4.insert("_type", "GetBuildInformation"); json.insert("_type", "GetBrightness");
HttpPostByTypeJsonObject(json4); reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
QJsonObject json5; connect(reply, &QNetworkReply::finished, this, [=] {
json5.insert("_id", getRandomString(10)); QJsonDocument json;
json5.insert("_type", "CheckSoftVersions"); QString err = checkReplyForJson(reply, &json);
HttpPostByTypeJsonObject(json5); if(! err.isEmpty()) return;
QJsonObject json8; mCard.bright = json["brightnessPercentage"].toInt(-1);
json8.insert("_id", getRandomString(10)); if(mCard.bright==-1) mCard.bright = qRound(json["brightness"].toInt() * 100.0 / mCard.BrightnessLevel);
json8.insert("_type", "GetCardAlias"); setData(DeviceTable_Brightness, 0, QString::number(mCard.bright)+"%");
HttpPostByTypeJsonObject(json8); });
json = QJsonObject();
{ json.insert("_id", "IsScreenOn");
QJsonObject json; json.insert("_type", "IsScreenOn");
json.insert("_id", "HasControllerPassword"); reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
json.insert("_type", "HasControllerPassword"); connect(reply, &QNetworkReply::finished, this, [=] {
auto reply = NetReq("http://"+mCard->m_strCardIp+":2016/settings").timeout(120000).post(json); QJsonDocument json;
connect(reply, &QNetworkReply::finished, mCard, [=] { QString err = checkReplyForJson(reply, &json);
QJsonDocument json; if(! err.isEmpty()) return;
QString err = checkReplyForJson(reply, &json); mCard.isScreenOn = json["on"].toBool();
if(! err.isEmpty()) return; setForeground(DeviceTable_Power, mCard.isScreenOn ? Qt::green : Qt::red);
mCard->bPassword = json["result"].toBool(); setData(DeviceTable_Power, 0, mCard.isScreenOn ? tr("On") : tr("Off"));
if(mCard->bPassword) {//加过密 });
btnUnlock->show(); json = QJsonObject();
btnUnlock->setIcon(QIcon(mCard->m_bLockStatus ? ":/res/device/Lock.png" : ":/res/device/UnLock.png")); json.insert("_id", "GetCardAlias");
} else btnUnlock->hide();
});
}
}
void DeviceItem::OnControlTcpSend(int iProgramIndex) {
QTcpSocket *send = new QTcpSocket();
connect(send, SIGNAL(connected()), this, SLOT(connect_sucessful()));
connect(send, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(show_error(QAbstractSocket::SocketError)));
send->connectToHost(QHostAddress(mCard->m_strCardIp),31299);
ST_ANSY_PROGRAM_PACKET tempStreadPakcet;
tempStreadPakcet.SyncHead[0]=0x7e;
tempStreadPakcet.SyncHead[1]=0x7e;
tempStreadPakcet.SyncHead[2]=0x55;
tempStreadPakcet.ucCommType=0x97;
tempStreadPakcet.iBaoLiu=0;
tempStreadPakcet.iLength=4;
unsigned char uctemp[4]={0};
uctemp[0]=iProgramIndex;
memcpy(tempStreadPakcet.pDataBuffer,uctemp,4);
tempStreadPakcet.pDataBuffer[tempStreadPakcet.iLength]=GetCheckCodeIn8(&tempStreadPakcet.ucCommType,tempStreadPakcet.iLength+sizeof(tempStreadPakcet.iBaoLiu)+sizeof(tempStreadPakcet.ucCommType)+sizeof(tempStreadPakcet.iLength));
int iLenPacket=3*sizeof(unsigned char)+sizeof(char)+sizeof(int)+sizeof(int)+tempStreadPakcet.iLength+sizeof(char);/////除正文外的协议结构大小;
QByteArray databuf = QByteArray(reinterpret_cast<char*>(&tempStreadPakcet), iLenPacket);
if(!send->waitForConnected(10000)) //等待连接返回
{
qDebug()<<mCard->m_strCardIp<<"Connect timeout ";
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("Connect")+":"+tr("timeout"));
send->close();
delete send;
return ;
}
send->write(databuf);
if(send->waitForBytesWritten(3000))
{
send->read(send->bytesAvailable());
qDebug()<<"recv anycast success ack";
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("Anycast")+":"+tr("success"));
}
send->close();
delete send;
}
void DeviceItem::HttpPostByTypeJsonObject(QJsonObject json)
{
QJsonDocument doc;
doc.setObject(json);
QByteArray post_loginArray = doc.toJson(QJsonDocument::Compact);
m_strUrl="http://"+mCard->m_strCardIp+":2016/settings";
if(mCard->m_strCardId.left(2)!="M8" && mCard->m_strCardId.left(2)!="m8")
{
if(json["_type"]!="GetAllScreenSizeM80") pHpptClient->httpPost(m_strUrl,post_loginArray);
}
else pHpptClient->httpPost(m_strUrl,post_loginArray);
}
void DeviceItem::HttpGetLedCardWidthHeight()
{
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetScreenSize");
HttpPostByTypeJsonObject(json);
}
void DeviceItem::HttpGetLedCardRemarkName(){
QJsonObject json;
json.insert("_id", getRandomString(10));
json.insert("_type", "GetCardAlias"); json.insert("_type", "GetCardAlias");
HttpPostByTypeJsonObject(json); reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
mCard.alias = QString::fromUtf8(QByteArray::fromBase64(json["alias"].toString().toLatin1()));
setData(DeviceTable_Remark, 0, mCard.alias);
});
json = QJsonObject();
json.insert("_id", "HasControllerPassword");
json.insert("_type", "HasControllerPassword");
reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
mCard.hasPassword = json["result"].toBool();
if(mCard.hasPassword) {//加过密
btnUnlock->show();
btnUnlock->setIcon(QIcon(mCard.isLocked ? ":/res/device/Lock.png" : ":/res/device/UnLock.png"));
} else btnUnlock->hide();
});
} }
void DeviceItem::refreshLable(){
if(mCard->m_bPowerStatus){
this->setForeground(DeviceTable_Power, Qt::green);
setData(DeviceTable_Power, 0, tr("on"));
} else {
this->setForeground(DeviceTable_Power, Qt::red);
setData(DeviceTable_Power, 0, tr("off"));
}
}
//获取到httpPost的应答如果参数变化需要出发修改控件item的内容
void DeviceItem::OnProHttpResponse(QString url, QString postMD5, QByteArray data) {
Q_UNUSED(postMD5)
//qDebug()<< url + "\r\n"+m_strUrl;
if(url == m_strUrl)
{
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(data,&parseJsonErr);
if(!(parseJsonErr.error == QJsonParseError::NoError))
{
if(data.size()==0)
qDebug()<<"json is empty";
else
qDebug()<<"DeviceItem OnProHttpResponse 解析json文件错误";
return;
}
QJsonObject jsonObject = document.object();
QString strType=jsonObject["_type"].toString();
if(jsonObject["success"].toBool()==true)
{
if(strType=="GetScreenSize" )
{
if(mCard->m_iWidth!=jsonObject["width"].toInt()||mCard->m_iHeight!=jsonObject["height"].toInt())
{
mCard->m_iWidth=jsonObject["width"].toInt();
mCard->m_iHeight=jsonObject["height"].toInt();
}
setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(mCard->m_iWidth).arg(mCard->m_iHeight));
}
else if(strType=="GetCardAlias" )
{
mCard->m_strCardRemarkName = QString::fromUtf8(QByteArray::fromBase64(jsonObject["alias"].toString().toLatin1()));
setData(DeviceTable_Remark,0,mCard->m_strCardRemarkName);
}
else if(strType=="GetCardName")
{
m_HeartbeatCount=0;
mCard->m_bOnLine=true;
m_ImageOnline->setPixmap(QPixmap(":/res/device/O_Online.png"));
}
else if(strType=="GetBuildInformation" )
{
mCard->strIMEI=jsonObject["IMEI"].toString();
mCard->HardVersion=jsonObject["HardVersion"].toString();
mCard->BrightnessLevel=jsonObject["BrightnessLevel"].toInt();
mCard->ScreenResolution=jsonObject["ScreenResolution"].toString();
mCard->FirmwareVersion=jsonObject["FirmwareVersion"].toString();
}
else if(strType=="CheckSoftVersions")
{
foreach(QJsonValue value, jsonObject["apps"].toArray()) {
QJsonObject oApp = value.toObject();
if(oApp["packageName"].toString().contains("xixunplayer"))
{
mCard->strXixunplayerVersion=oApp["versionName"].toString();
mCard->strXixunplayerVersionCode=oApp["versionCode"].toInt();
}
}
}
else if(strType == "AliIotSetting")
{
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("AliIotSetting")+":"+tr("success"));
}
else if(strType == "IsScreenOn")
{
{
mCard->m_bPowerStatus=jsonObject["on"].toBool();
if(mCard->m_bPowerStatus) {
this->setForeground(DeviceTable_Power, Qt::green);
setData(DeviceTable_Power, 0, tr("on"));
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetScreenStatus")+tr("success")+","+tr("Status")+":"+tr("on"));
} else {
this->setForeground(DeviceTable_Power, Qt::red);
setData(DeviceTable_Power, 0, tr("off"));
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetScreenStatus")+tr("success")+","+tr("Status")+":"+tr("off"));
}
}
} else if(strType == "GetBrightness") {
mCard->bright = jsonObject["brightnessPercentage"].toInt(-1);
if(mCard->bright==-1) mCard->bright = qRound(jsonObject["brightness"].toInt() * 100.0 / mCard->BrightnessLevel);
QString bright = QString::number(mCard->bright);
setData(DeviceTable_Brightness, 0, QString::number(mCard->bright)+"%");
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("GetBrightness")+tr("success")+","+tr("brightness")+"="+bright+"%");
}
else if(strType == "SetAutoBrightnessTask")
{
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetAutoBrightnessTask")+":"+tr("success"));
}
else if(strType == "SetAutoVolumeTask")
{
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetAutoVolumeTask")+":"+tr("success"));
}
else if(strType == "SetTimingScreenTask")
{
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("SetTimingScreenTask")+":"+tr("success"));
}
else if(strType == "TestScreen")
{
emit sigOutputInfo(mCard->m_strCardId+":"+tr("receive")+"<-"+tr("TestScreen")+":"+tr("success"));
}
}
}
}
QPixmap DeviceItem::Base64_To_Image(QByteArray bytearray,QString SavePath)
{
QByteArray Ret_bytearray;
Ret_bytearray = QByteArray::fromBase64(bytearray);
QBuffer buffer(&Ret_bytearray);
buffer.open(QIODevice::WriteOnly);
QPixmap imageresult;
imageresult.loadFromData(Ret_bytearray);
if(SavePath != "")
{
qDebug() <<"save" ;
imageresult.save(SavePath);
}
return imageresult;
}
void DeviceItem::DeletePostingDlg()
{
if(m_PostingDlg!=nullptr)
{
delete m_PostingDlg;
m_PostingDlg=nullptr;
}
}
ImgDlg::ImgDlg(const QByteArray &data, QWidget *parent) : QDialog(parent) { ImgDlg::ImgDlg(const QByteArray &data, QWidget *parent) : QDialog(parent) {
setWindowFlag(Qt::WindowContextHelpButtonHint, 0); setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
setWindowTitle(tr("Screenshot")); setWindowTitle(tr("Screenshot"));

View File

@ -1,17 +1,11 @@
#ifndef DEVICEITEM_H #ifndef DEVICEITEM_H
#define DEVICEITEM_H #define DEVICEITEM_H
#include <QTreeWidget>
#include <QDir>
#include <QDateTime>
#include <QJsonObject>
#include <QJsonDocument>
#include <QPushButton> #include <QPushButton>
#include <base/loqtreewidget.h> #include <base/loqtreewidget.h>
#include <device/ledcard.h> #include "globaldefine.h"
#include <communication/hpptclient.h>
#include <QLabel> #include <QLabel>
#include <QMap> #include <QDialog>
#include <base/loemptydialog.h>
enum DeviceTableField { enum DeviceTableField {
DeviceTable_Check = 0, DeviceTable_Check = 0,
@ -32,43 +26,20 @@ class DeviceItem : public QObject, public QTreeWidgetItem {
friend class DevicePanel; friend class DevicePanel;
Q_OBJECT Q_OBJECT
public: public:
explicit DeviceItem(LedCard *pLedCard, LoQTreeWidget *parent); explicit DeviceItem(LoQTreeWidget *parent);
~DeviceItem(); void init();
void HttpPostByTypeJsonObject(QJsonObject json);
void OnControlTcpSend(int iProgramIndex);
void refreshLable();
void SetMainTabWidgetIndex(int index);
//http获取控制卡信息的函数
void HttpGetLedCardWidthHeight();
void HttpGetLedCardRemarkName();
QPixmap Base64_To_Image(QByteArray bytearray,QString SavePath);
LedCard *mCard{0};
QTimer mHeartbeatTimer;
signals:
void sigOutputInfo(QString);
public slots:
void DeletePostingDlg();
void OnProHttpResponse(QString url, QString postMD5, QByteArray data);
void DeviceItemHttpPost(); void DeviceItemHttpPost();
LedCard mCard;
QPushButton *btnUnlock = nullptr;
private: private:
int m_intIndexFlagOfInfoOrControl=0; QPushButton *m_bnCardDetailInfo = nullptr;
QPushButton *m_bnCardDetailInfo = nullptr;// QPushButton *m_bnReadbackPic = nullptr;
QPushButton *m_bnReadbackPic = nullptr;//
QPushButton *btnUnlock = nullptr;//
QLabel *m_ImageOnline=nullptr; QLabel *m_ImageOnline=nullptr;
LoQTreeWidget *m_parent = nullptr; LoQTreeWidget *m_parent = nullptr;
HpptClient *pHpptClient = nullptr;
QString m_strUrl="";
int m_HeartbeatCount=0;
LoEmptyDialog * m_PostingDlg=nullptr;
QTimer *m_pGetAskTimer=nullptr;
}; };
class ImgDlg : public QDialog { class ImgDlg : public QDialog {
Q_OBJECT
public: public:
explicit ImgDlg(const QByteArray &, QWidget *parent = 0); explicit ImgDlg(const QByteArray &, QWidget *parent = 0);
QImage mImg; QImage mImg;

View File

@ -1,7 +1,9 @@
#include "devicepanel.h" #include "devicepanel.h"
#include "devicectrlpanel.h" #include "globaldefine.h"
#include "tools.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include "base/waitingdlg.h"
#include "deviceitem.h"
#include <QAction> #include <QAction>
#include <QBoxLayout> #include <QBoxLayout>
#include <QEvent> #include <QEvent>
@ -10,13 +12,23 @@
#include <QNetworkDatagram> #include <QNetworkDatagram>
#include <QNetworkInterface> #include <QNetworkInterface>
#include <QMessageBox> #include <QMessageBox>
#include <QJsonArray>
#include <QJsonObject>
#include <QStyledItemDelegate>
DevicePanel *gDevicePanel; DevicePanel *gDevicePanel;
QList<LedCard*> *gSelCards; void setCard(LedCard &card, const QString &addr, const QJsonDocument &json) {
//设备管理响应页面 if(! addr.isEmpty()) card.ip = addr;
else {
card.ip = json["newIp"].toString();
if(card.ip.isEmpty()) card.ip = json["ip"].toString();
}
card.mWidth = json["width"].toInt();
card.mHeight = json["height"].toInt();
card.androidVersion = json["androidVersion"].toString();
}
DevicePanel::DevicePanel(QSettings &settings, QWidget *parent) : QWidget(parent) { DevicePanel::DevicePanel(QSettings &settings, QWidget *parent) : QWidget(parent) {
gDevicePanel = this; gDevicePanel = this;
gSelCards = &mSelCards;
setAutoFillBackground(true); setAutoFillBackground(true);
QPalette pal; QPalette pal;
pal.setBrush(QPalette::Window, QColor(0xeeeeee)); pal.setBrush(QPalette::Window, QColor(0xeeeeee));
@ -98,7 +110,6 @@ QComboBox QAbstractItemView::item:selected {background-color: #09c;}
btnRefresh = new QPushButton(tr("Refresh"), areaFlash); btnRefresh = new QPushButton(tr("Refresh"), areaFlash);
btnRefresh->setGeometry(0, 0, 75, areaFlash->height()); btnRefresh->setGeometry(0, 0, 75, areaFlash->height());
connect(btnRefresh, &QPushButton::clicked, this, [this] { connect(btnRefresh, &QPushButton::clicked, this, [this] {
mLedCards.clear();
mDeviceTable->onCheckAll(false); mDeviceTable->onCheckAll(false);
mDeviceTable->clear(); mDeviceTable->clear();
nDeviceNum->setText("0"); nDeviceNum->setText("0");
@ -118,6 +129,7 @@ QPushButton:hover {background-color: #08b;}
mHBox = new QHBoxLayout(); mHBox = new QHBoxLayout();
mDeviceTable = new LoQTreeWidget(this); mDeviceTable = new LoQTreeWidget(this);
mDeviceTable->setSelectionMode(QAbstractItemView::NoSelection);
mDeviceTable->setIndentation(0); mDeviceTable->setIndentation(0);
mDeviceTable->setSortingEnabled(true); mDeviceTable->setSortingEnabled(true);
mHBox->addWidget(mDeviceTable); mHBox->addWidget(mDeviceTable);
@ -134,36 +146,79 @@ QPushButton:hover {background-color: #08b;}
bool ok = true; bool ok = true;
if(senderAddress.protocol()==QUdpSocket::IPv6Protocol) senderAddress.setAddress(senderAddress.toIPv4Address(&ok)); if(senderAddress.protocol()==QUdpSocket::IPv6Protocol) senderAddress.setAddress(senderAddress.toIPv4Address(&ok));
auto addr = ok ? senderAddress.toString() : ""; auto addr = ok ? senderAddress.toString() : "";
DeviceItem *item;
if(data.startsWith("{\"")) { if(data.startsWith("{\"")) {
QJsonParseError error; QJsonParseError error;
QJsonDocument document = QJsonDocument::fromJson(gram.data(), &error); QJsonDocument json = QJsonDocument::fromJson(gram.data(), &error);
if(error.error != QJsonParseError::NoError) { if(error.error != QJsonParseError::NoError) {
qDebug()<<"DeviceItem OnProHttpResponse 解析json文件错误"; qDebug()<<"DeviceItem OnProHttpResponse 解析json文件错误";
continue; continue;
} }
parseInfo(document.object(), addr); auto cardId = json["cardId"].toString();
int cnt = mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) if((item = (DeviceItem *)mDeviceTable->topLevelItem(i))->mCard.id==cardId) {
item->mCard.id = cardId;
item->mCard.isOnline = true;
setCard(item->mCard, addr, json);
item->init();
goto end;
}
item = new DeviceItem(mDeviceTable);
item->mCard.id = cardId;
setCard(item->mCard, addr, json);
} else { } else {
auto bytes = gram.data(); auto bytes = gram.data();
auto packet = (Packet *)bytes.data(); auto packet = (UDPPacket *)bytes.data();
LedCard *pLedCard = new LedCard(this);//alahover 没有释放 int cnt = mDeviceTable->topLevelItemCount();
pLedCard->m_strCardId = packet->serialCode; for(int i=0; i<cnt; i++) if((item = (DeviceItem *)mDeviceTable->topLevelItem(i))->mCard.id==packet->serialCode) {
pLedCard->m_strCardIp = addr; item->mCard.id = packet->serialCode;
for(int i=0;i<mLedCards.count();i++) if(mLedCards.at(i)->m_strCardId==pLedCard->m_strCardId ) {//如果已经存在在列表中 item->mCard.isOnline = true;
auto pOldLedCard = mLedCards.at(i);//获取到旧的对象指针 item->mCard.ip = addr;
pOldLedCard->m_bOnLine = true; item->init();
if(pOldLedCard->CompareHTTPGetParam(pLedCard)==false) {//如果ip地址变化了 goto end;
pOldLedCard->copyLedCardHTTPGetParam(pLedCard);
addLedCard(pOldLedCard);//发送信号到界面
} else {
//post失败的概率比较小所以这里是否需要平凡的更新不需要刻意屏蔽该操作改为在其他点击操作中进行
clearUdpHeartbeat(pOldLedCard);
}
delete pLedCard;
return;
} }
mLedCards.append(pLedCard); item = new DeviceItem(mDeviceTable);
addLedCard(pLedCard);//发送信号到界面 item->mCard.id = packet->serialCode;
item->mCard.ip = addr;
} }
connect(item->m_bnCardDetailInfo, &QPushButton::clicked, item, [=] {
QJsonObject json;
json.insert("_id", "CheckSoftVersions");
json.insert("_type", "CheckSoftVersions");
auto waitingDlg = new WaitingDlg(this, tr("CheckSoftVersions")+" ...");
waitingDlg->show();
auto card = item->mCard;
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSingleGetReply
waitingDlg->close();
QString strTip;
strTip.append(tr("Current Brightness")).append(": ").append(QString::number(item->mCard.bright)).append("%").append("\n");
strTip.append(tr("Brightness Level")).append(": ").append(QString::number(item->mCard.BrightnessLevel)).append("\n");
strTip.append(tr("Android OS Resolution")).append(": ").append(item->mCard.ScreenResolution).append("\n");
strTip.append(tr("Android Version")).append(": ").append(item->mCard.androidVersion).append("\n");
strTip.append(tr("FPGA Version")).append(": ").append(item->mCard.HardVersion).append("\n");
strTip.append(tr("Firmware Version")).append(": ").append(item->mCard.FirmwareVersion).append("\n");
foreach(QJsonValue value, json["apps"].toArray()) {
QJsonObject app = value.toObject();
if(app["packageName"].toString().contains("xixunplayer")) strTip.append(tr("Player Version")).append(": ").append(app["versionName"].toString()).append("\n");
}
QMessageBox::information(this, tr("Detail Info"), strTip);
});
});
item->init();
item->DeviceItemHttpPost();
nDeviceNum->setText(QString::number(mDeviceTable->topLevelItemCount()));
{
QJsonObject json;
json.insert("_id", "SyncTime");
json.insert("_type", "SyncTime");
json.insert("time", QDateTime::currentDateTime().toMSecsSinceEpoch());
auto reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(60000).post(json);
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
}
end:;
} }
}); });
@ -190,8 +245,12 @@ QPushButton:hover {background-color: #08b;}
mDeviceTable->header()->setSectionResizeMode(DeviceTable_Screenshot, QHeaderView::Fixed); mDeviceTable->header()->setSectionResizeMode(DeviceTable_Screenshot, QHeaderView::Fixed);
mDeviceTable->setColumnWidth(DeviceTable_Screenshot, 72); mDeviceTable->setColumnWidth(DeviceTable_Screenshot, 72);
connect(mDeviceTable, SIGNAL(sigCheckStateChanged(int)), this, SLOT(onCheckStateChanged(int))); connect(mDeviceTable, &LoQTreeWidget::sigCheckStateChanged, this, [=] {
mDeviceTable->setSelectionMode(QAbstractItemView::SingleSelection); gSelCards.clear();
int cnt = mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) if(mDeviceTable->topLevelItem(i)->checkState(0) == Qt::Checked) gSelCards.append(static_cast<DeviceItem*>(mDeviceTable->topLevelItem(i))->mCard);
emit sigSelectedDeviceList();
});
mDeviceTable->hideColumn(0); mDeviceTable->hideColumn(0);
mDeviceTable->fdIsSelAll->hide(); mDeviceTable->fdIsSelAll->hide();
@ -227,7 +286,7 @@ QPushButton:hover {background-color: #08b;}
QMessageBox::warning(this, tr("Attention"), tr("Please input IP address!")); QMessageBox::warning(this, tr("Attention"), tr("Please input IP address!"));
return; return;
} }
QByteArray data = QJsonDocument({{"action", "getInfo"}}).toJson(QJsonDocument::Compact); QByteArray data = QJsonDocument(QJsonObject{{"action", "getInfo"}}).toJson(QJsonDocument::Compact);
foreach(auto ip, ips) if(mUdpSocket.writeDatagram(data, QHostAddress(ip), 22222) != data.length()) qDebug() << "Specify IP write Failed." << ip; foreach(auto ip, ips) if(mUdpSocket.writeDatagram(data, QHostAddress(ip), 22222) != data.length()) qDebug() << "Specify IP write Failed." << ip;
specifyIPDlg->accept(); specifyIPDlg->accept();
}); });
@ -250,7 +309,7 @@ DevicePanel::~DevicePanel() {
} }
void DevicePanel::sendGetInfo() { void DevicePanel::sendGetInfo() {
const QByteArray data = QJsonDocument({{"action", "getInfo"}}).toJson(QJsonDocument::Compact); const QByteArray data = QJsonDocument(QJsonObject{{"action", "getInfo"}}).toJson(QJsonDocument::Compact);
uchar ccc[]{0x7E, 0x7E, 0x7E, 0x90, 0x42, 0x72, 0x6F, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x21, uchar ccc[]{0x7E, 0x7E, 0x7E, 0x90, 0x42, 0x72, 0x6F, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x21,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x9F}; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x9F};
if(mUdpSocket.writeDatagram(data, QHostAddress("255.255.255.255"), 22222) != data.length()) qDebug() << "getInfo write to 255.255.255.255 failed"; if(mUdpSocket.writeDatagram(data, QHostAddress("255.255.255.255"), 22222) != data.length()) qDebug() << "getInfo write to 255.255.255.255 failed";
@ -275,32 +334,6 @@ void DevicePanel::sendGetInfo() {
} }
} }
void DevicePanel::ShowDevicesInfoOrControlWidget(int index){
m_intIndexFlagOfInfoOrControl=index;
if(index==MainPage_DeviceManager) { //设备信息列表页面
mDeviceTable->hideColumn(0);
mDeviceTable->fdIsSelAll->hide();
if(mDeviceCtrlPanel!=nullptr) {
for(int j=DeviceTable_ScreenSize;j<DeviceTable_End;j++) mDeviceTable->showColumn(j);
mDeviceTable->setMaximumWidth(0xffffff);
mDeviceCtrlPanel->hide();
fdCardNumInfo->hide();
}
} else if(index==MainPage_Setting) { //终端控制页面
mDeviceTable->showColumn(0);
mDeviceTable->fdIsSelAll->show();
for(int j=DeviceTable_ScreenSize; j<DeviceTable_End; j++) mDeviceTable->hideColumn(j);
if(mDeviceCtrlPanel==nullptr) mHBox->addWidget(mDeviceCtrlPanel = new DeviceCtrlPanel(this));
else mDeviceCtrlPanel->show();
fdCardNumInfo->show();
mDeviceTable->setMaximumWidth(340);
GetSelectDeviceNum();
emit sigSelectedDeviceList(&mSelCards);
}
int cnt = mDeviceTable->topLevelItemCount();
if(cnt>0)//切换到终点管理页面是刷新列表中控制卡的状态参数
for(int i=0; i<cnt; i++) static_cast<DeviceItem*>(mDeviceTable->topLevelItem(i))->SetMainTabWidgetIndex(m_intIndexFlagOfInfoOrControl);
}
void DevicePanel::changeEvent(QEvent *event) { void DevicePanel::changeEvent(QEvent *event) {
QWidget::changeEvent(event); QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi(); if(event->type() == QEvent::LanguageChange) transUi();
@ -322,157 +355,8 @@ void DevicePanel::transUi() {
m_headerItem->setText(DeviceTable_Info, tr("More Info")); m_headerItem->setText(DeviceTable_Info, tr("More Info"));
auto cnt = mDeviceTable->topLevelItemCount(); auto cnt = mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) static_cast<DeviceItem*>(mDeviceTable->topLevelItem(i))->refreshLable();
}
void DevicePanel::OnControlTcpSend(int iProgramIndex){
int cnt = mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) if(mDeviceTable->topLevelItem(i)->checkState(0) == Qt::Checked) static_cast<DeviceItem*>(mDeviceTable->topLevelItem(i))->OnControlTcpSend(iProgramIndex);
}
void DevicePanel::OnControlSendJson(QJsonObject &json,QString strFanYi){
int cnt = mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) if(mDeviceTable->topLevelItem(i)->checkState(0) == Qt::Checked) {
DeviceItem *item = static_cast<DeviceItem*>(mDeviceTable->topLevelItem(i));
item->HttpPostByTypeJsonObject(json);
QString strCardId=item->mCard->m_strCardId;
mDeviceCtrlPanel->OnOutputInfo(strCardId+":"+tr("send")+"->"+strFanYi);
}
}
int DevicePanel::GetSelectDeviceNum() {
int cnt = mDeviceTable->topLevelItemCount();
int iSelectCount=0;
mSelCards.clear();
for(int i=0; i<cnt; i++) if(mDeviceTable->topLevelItem(i)->checkState(0) == Qt::Checked) {
iSelectCount++;
mSelCards.append(static_cast<DeviceItem*>(mDeviceTable->topLevelItem(i))->mCard);
}
return iSelectCount;
}
void DevicePanel::OnOutputInfo(QString strInfo) {
if(m_intIndexFlagOfInfoOrControl==MainPage_Setting && mDeviceCtrlPanel!=nullptr) mDeviceCtrlPanel->OnOutputInfo(strInfo);
}
void DevicePanel::onCheckStateChanged(int f){
Q_UNUSED(f);
if(m_intIndexFlagOfInfoOrControl==MainPage_Setting){
GetSelectDeviceNum();
emit sigSelectedDeviceList(&mSelCards);
}
}
void DevicePanel::addLedCard(LedCard *card) {
int cnt = mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) { for(int i=0; i<cnt; i++) {
auto item = static_cast<DeviceItem*>(mDeviceTable->topLevelItem(i)); auto item = (DeviceItem*) mDeviceTable->topLevelItem(i);
if(item->mCard->m_strCardId != card->m_strCardId) continue; item->setData(DeviceTable_Power, 0, item->mCard.isScreenOn ? tr("On") : tr("Off"));
item->setData(DeviceTable_ID, 0, card->m_strCardId);
item->setData(DeviceTable_IP, 0, card->m_strCardIp);
item->setData(DeviceTable_ScreenSize, 0, QString("%1 x %2").arg(card->m_iWidth).arg(card->m_iHeight));
return;
}
new DeviceItem(card, mDeviceTable);
nDeviceNum->setText(QString::number(mDeviceTable->topLevelItemCount()));
QJsonObject json;
json.insert("_id", "SyncTime");
json.insert("_type", "SyncTime");
json.insert("time", QDateTime::currentDateTime().toMSecsSinceEpoch());
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
}
void DevicePanel::clearUdpHeartbeat(LedCard *p) {
int cnt = mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) {
auto item = static_cast<DeviceItem*>(mDeviceTable->topLevelItem(i));
if(item->mCard->m_strCardId != p->m_strCardId) continue;
item->m_HeartbeatCount = 0;
if(item->m_ImageOnline) {
item->mCard->m_bOnLine = true;
item->m_ImageOnline->setPixmap(QPixmap(":/res/device/O_Online.png"));
}
return;
}
}
void DevicePanel::parseInfo(const QJsonObject &subObj, const QString &strIp) {
LedCard *pLedCard = new LedCard(this);//alahover 没有释放
pLedCard->m_strCardId=subObj["cardId"].toString();
if(! strIp.isEmpty()) pLedCard->m_strCardIp = strIp;
else {
pLedCard->m_strCardIp = subObj["newIp"].toString();
if(pLedCard->m_strCardIp.isEmpty()) pLedCard->m_strCardIp = subObj["ip"].toString();
}
pLedCard->m_iWidth=subObj["width"].toInt();
pLedCard->m_iHeight=subObj["height"].toInt();
pLedCard->starterversionName=subObj["versionName"].toString();
pLedCard->starterPort=subObj["starterPort"].toInt();
pLedCard->androidVersion=subObj["androidVersion"].toString();
pLedCard->iHttpGetId=subObj["id"].toInt();
pLedCard->androidHeight=subObj["androidHeight"].toInt();
pLedCard->androidWidth=subObj["androidWidth"].toInt();
pLedCard->lastActive=subObj["lastActive"].toInt();
for(int i=0;i<mLedCards.count();i++) if(mLedCards.at(i)->m_strCardId==pLedCard->m_strCardId ) { //如果已经存在在列表中
auto pOldLedCard = mLedCards.at(i);//获取到旧的对象指针
pOldLedCard->m_bOnLine = true;
if(! pOldLedCard->CompareHTTPGetParam(pLedCard)) {//如果ip地址变化了
pOldLedCard->copyLedCardHTTPGetParam(pLedCard);
addLedCard(pOldLedCard);//发送信号到界面
} else {
//post失败的概率比较小所以这里是否需要平凡的更新不需要刻意屏蔽该操作改为在其他点击操作中进行
clearUdpHeartbeat(pOldLedCard);
}
delete pLedCard;
return;
}
mLedCards.append(pLedCard);
addLedCard(pLedCard);//发送信号到界面
}
STREAM_PACKET LedOkMakeStreamPacket(int iComType,int iLen,unsigned char *ucBuf,QString str) {
STREAM_PACKET Temp;
memset(&Temp, 0, sizeof(STREAM_PACKET));
if(iLen>2048) return Temp;
memset(Temp.SyncHead, 0x7e, 3);
memset(Temp.ucSerialCode,0x00,20);
char* ch;
QByteArray ba = str.toLatin1(); // must
ch=ba.data();
memcpy(Temp.ucSerialCode,ch,ba.size());
Temp.iLength=iLen;
Temp.ucCommType=iComType;
memcpy(Temp.pDataBuffer,ucBuf,iLen);
Temp.pDataBuffer[Temp.iLength] = GetCheckCodeIn8(&Temp.ucCommType,Temp.iLength+sizeof(Temp.ucCommType)+sizeof(char)*20+sizeof(Temp.iLength));
return Temp;
}
//UDP多网卡广播
void DevicePanel::RestoreLedCardIpByUdpCmd() {
QList<QNetworkInterface> networkinterfaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interfaces, networkinterfaces) {//networkinterfaces负责提供主机的IP地址和网络接口的列表
foreach (QNetworkAddressEntry entry, interfaces.addressEntries()) {//QNetworkAddressEntry存储了一个IP地址子网掩码和广播地址
entry.setBroadcast(QHostAddress::Broadcast);
QHostAddress broadcastAddress("255.255.255.255");
entry.setBroadcast(QHostAddress::Broadcast);
RESTORE_IP stTempIp;
memset(&stTempIp,0x00,sizeof(RESTORE_IP));
QString strNew=entry.ip().toString();
int itempOffset = strNew.lastIndexOf(".");
QString sstrNew=strNew.left(itempOffset)+".254";
if(sstrNew.length()<=20) memcpy(stTempIp.cNewIp,sstrNew.toLatin1().data(),sstrNew.length());
QString strMask=entry.netmask().toString();
if(strMask.length()<=20)
memcpy(stTempIp.cMask,strMask.toLatin1().data(),strMask.length());
QString strGateway=entry.ip().toString();
if(strGateway.length()<=20)
memcpy(stTempIp.cGateway,strGateway.toLatin1().data(),strGateway.length());
if(strGateway.length()<=20)
memcpy(stTempIp.cDns,strGateway.toLatin1().data(),strGateway.length());
STREAM_PACKET tempStreadPacket = LedOkMakeStreamPacket(COMMAND_ONLY_RESET_CARD_IP, 80, (unsigned char *)&stTempIp,"Broadcast!");
int iLenPacket=tempStreadPacket.iLength+sizeof(int)+3*sizeof(unsigned char)+sizeof(char)+20*sizeof(char)+sizeof(char);/////除正文外的协议结构大小;
QUdpSocket *tempUdpSocket = new QUdpSocket(this);
if(!tempUdpSocket->bind(entry.ip())) break;
tempUdpSocket->writeDatagram((char *)&tempStreadPacket,iLenPacket,broadcastAddress, 31296);
}
} }
} }

View File

@ -1,17 +1,16 @@
#ifndef DEVICEPANEL_H #ifndef DEVICEPANEL_H
#define DEVICEPANEL_H #define DEVICEPANEL_H
#include "deviceitem.h" #include "base/loqtreewidget.h"
#include <QFile> #include <QLabel>
#include <QBoxLayout> #include <QTimer>
#include <QPainter> #include <QPushButton>
#include <QStyledItemDelegate>
#include <QUdpSocket> #include <QUdpSocket>
#include <QTreeWidgetItem>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QTextEdit> #include <QTextEdit>
#include <QSettings> #include <QSettings>
#include <QHBoxLayout>
class DeviceCtrlPanel; class DeviceCtrlPanel;
class DevicePanel : public QWidget { class DevicePanel : public QWidget {
@ -28,34 +27,18 @@ public:
QTimer mUdpTimer; QTimer mUdpTimer;
QDialog *specifyIPDlg{0}; QDialog *specifyIPDlg{0};
QTextEdit *fdIP{0}; QTextEdit *fdIP{0};
void addLedCard(LedCard *); int mainPanelIdx{0};
void clearUdpHeartbeat(LedCard *); DeviceCtrlPanel *mDeviceCtrlPanel{0};
void parseInfo(const QJsonObject &subObj,const QString &strIp);
void RestoreLedCardIpByUdpCmd();
QList<LedCard *> mLedCards;
protected:
void changeEvent(QEvent *) override;
void transUi();
public slots:
void ShowDevicesInfoOrControlWidget(int index);
protected slots:
void onCheckStateChanged(int f);
void OnControlSendJson(QJsonObject &json,QString strFanYi);
void OnControlTcpSend(int iProgramIndex);
void OnOutputInfo(QString);
signals:
void sigSelectedDeviceList(QList<LedCard *> *);
private:
QLabel *label_3, *nDeviceNum; QLabel *label_3, *nDeviceNum;
QComboBox *bnSpecifyIP; QComboBox *bnSpecifyIP;
QPushButton *btnRefresh; QPushButton *btnRefresh;
QTreeWidgetItem *m_headerItem; QTreeWidgetItem *m_headerItem;
QHBoxLayout *mHBox{0}; QHBoxLayout *mHBox{0};
DeviceCtrlPanel *mDeviceCtrlPanel{0}; protected:
int m_intIndexFlagOfInfoOrControl{0}; void changeEvent(QEvent *) override;
int GetSelectDeviceNum(); void transUi();
QList<LedCard*> mSelCards; signals:
void sigSelectedDeviceList();
}; };
#endif // DEVICEPANEL_H #endif // DEVICEPANEL_H

View File

@ -1,16 +1,29 @@
#include <globaldefine.h> #include "globaldefine.h"
#include "devicepanel.h"
#include "deviceitem.h"
#include <QDir> #include <QDir>
#include <QDateTime> #include <QDateTime>
#include <QCoreApplication> #include <QCoreApplication>
#include <QMessageBox> #include <QMessageBox>
#include <QMetaEnum> #include <QMetaEnum>
QList<LedCard> gSelCards;
bool gVideoCompress = true; bool gVideoCompress = true;
bool gVideoTranscoding = true; bool gVideoTranscoding = true;
bool gTextAntialiasing = false; bool gTextAntialiasing = false;
bool gShowLoraScreen = false; bool gShowLoraScreen = false;
bool gWidthSplit = false; bool gWidthSplit = false;
DeviceItem *findItem(QString id) {
int cnt = gDevicePanel->mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; ++i) {
auto item = (DeviceItem*) gDevicePanel->mDeviceTable->topLevelItem(i);
if(item==0) continue;
if(item->mCard.id==id) return item;
}
return 0;
}
QString replyErr(QNetworkReply *reply) { QString replyErr(QNetworkReply *reply) {
reply->deleteLater(); reply->deleteLater();
auto error = reply->error(); auto error = reply->error();
@ -59,24 +72,6 @@ QString checkReplyForJson(QNetworkReply *reply, QJsonDocument *outJson, QByteArr
return ""; return "";
} }
QString getRandomString(int len) {
static const char table[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const int tableSize = sizeof(table) - 1;
QString str;
str.resize(len);
for(int i=0; i<len; i++) str[i] = table[rand() % tableSize];
return str;
}
bool isFileExist(QString fullFileName)
{
QFileInfo fileInfo(fullFileName);
if(fileInfo.isFile())
{
return true;
}
return false;
}
quint64 dirFileSize(const QString &path) { quint64 dirFileSize(const QString &path) {
QDir dir(path); QDir dir(path);
quint64 size = 0; quint64 size = 0;
@ -87,25 +82,13 @@ quint64 dirFileSize(const QString &path) {
return size; return size;
} }
void HttpPostByTypeJsonObject(HpptClient *pHpptClient, QString strUrl, QJsonObject json) { bool copyDir(const QString &source, const QString &destination, bool override) {
pHpptClient->httpPost(strUrl, QJsonDocument(json).toJson(QJsonDocument::Compact));
}
bool copyDir(const QString &source, const QString &destination, bool override)
{
QDir directory(source); QDir directory(source);
if (!directory.exists()) if(!directory.exists()) return false;
{
return false;
}
QString srcPath = QDir::toNativeSeparators(source); QString srcPath = QDir::toNativeSeparators(source);
if (!srcPath.endsWith(QDir::separator())) if(!srcPath.endsWith(QDir::separator())) srcPath += QDir::separator();
srcPath += QDir::separator();
QString dstPath = QDir::toNativeSeparators(destination); QString dstPath = QDir::toNativeSeparators(destination);
if (!dstPath.endsWith(QDir::separator())) if (!dstPath.endsWith(QDir::separator())) dstPath += QDir::separator();
dstPath += QDir::separator();
bool error = false; bool error = false;
QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden); QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
@ -133,8 +116,6 @@ bool copyDir(const QString &source, const QString &destination, bool override)
} }
} }
} }
return !error; return !error;
} }
unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize) { unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize) {

View File

@ -1,11 +1,27 @@
#ifndef GLOBALDEFINE_H #ifndef GLOBALDEFINE_H
#define GLOBALDEFINE_H #define GLOBALDEFINE_H
#include "gutil/qnetwork.h"
#include <QString>
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonDocument> #include <QJsonDocument>
#include <communication/hpptclient.h> #include <QNetworkReply>
class LedCard {
public:
QString id;
QString ip;
int mWidth{0};
int mHeight{0};
int bright{100};
int BrightnessLevel{255};
QString FirmwareVersion;
QString HardVersion = "0000";
QString ScreenResolution;
QString androidVersion;
QString alias;
bool hasPassword{false};
bool isLocked{true};
bool isScreenOn{true};
bool isOnline{true};
};
enum { enum {
MainPage_DeviceManager = 0, MainPage_DeviceManager = 0,
@ -21,7 +37,7 @@ struct RESTORE_IP {
char cGateway[20]; char cGateway[20];
char cDns[20]; char cDns[20];
}; };
struct Packet { struct UDPPacket {
unsigned char SyncHead[3]; unsigned char SyncHead[3];
unsigned char ucCommType; unsigned char ucCommType;
char serialCode[20]; char serialCode[20];
@ -145,7 +161,9 @@ enum _NET_COMMU_TYPE {
COMMAND_CONNECT_COLSE_ANSWER COMMAND_CONNECT_COLSE_ANSWER
}; };
class DevicePanel;
extern DevicePanel *gDevicePanel;
extern QList<LedCard> gSelCards;
extern bool gVideoCompress; extern bool gVideoCompress;
extern bool gVideoTranscoding; extern bool gVideoTranscoding;
extern bool gTextAntialiasing; extern bool gTextAntialiasing;
@ -153,9 +171,6 @@ extern bool gShowLoraScreen;
extern bool gWidthSplit; extern bool gWidthSplit;
extern quint64 dirFileSize(const QString &path); extern quint64 dirFileSize(const QString &path);
extern bool isFileExist(QString fullFileName);
extern QString getRandomString(int length);
extern void HttpPostByTypeJsonObject(HpptClient *pHpptClient, QString strUrl,QJsonObject json);
extern bool copyDir(const QString &source, const QString &destination, bool override); extern bool copyDir(const QString &source, const QString &destination, bool override);
extern unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize); extern unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize);
@ -171,6 +186,8 @@ enum _ENUM_CONTRL_WIDGET {
Setting_Test, Setting_Test,
Setting_End, Setting_End,
}; };
class DeviceItem;
extern DeviceItem *findItem(QString id);
QString replyErr(QNetworkReply *); QString replyErr(QNetworkReply *);
QString checkReply(QNetworkReply *, QJsonDocument * = 0); QString checkReply(QNetworkReply *, QJsonDocument * = 0);
@ -178,8 +195,8 @@ QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0, QByteArray * = 0
#define Def_CtrlReqPre \ #define Def_CtrlReqPre \
waitingDlg->show();\ waitingDlg->show();\
auto card = gSelCards->at(0);\ auto card = gSelCards[0];\
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);\ auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);\
waitingDlg->connAbort(reply); waitingDlg->connAbort(reply);
#define Def_CtrlSetReqAfter \ #define Def_CtrlSetReqAfter \
@ -201,75 +218,10 @@ QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0, QByteArray * = 0
} }
#define Def_CtrlSetMulti(tip) \ #define Def_CtrlSetMulti(tip) \
auto reply = NetReq("http://"+card->m_strCardIp+":2016/settings").timeout(120000).post(json);\ auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);\
connect(reply, &QNetworkReply::finished, card, [=] {\ connect(reply, &QNetworkReply::finished, gFdResInfo, [=] {\
QString err = checkReplyForJson(reply);\ QString err = checkReplyForJson(reply);\
gFdResInfo->append(card->m_strCardId+" "+tip+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));\ gFdResInfo->append(card.id+" "+tip+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));\
}); });
#define CHECK_CARD_SELECTED \
if(gSelCards->isEmpty()) {\
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));\
return;\
}
#define MACRO_DEFINE_TIPDLG_FUCN(TIP,SUCCESS,FAILED) \
if(gSelCards->count()==1) {\
HttpPostByTypeJsonObject(pHpptClient, m_strUrl, json);\
if(m_PostingDlg==nullptr) {\
m_PostingDlg = new LoEmptyDialog(this);\
connect(m_PostingDlg,SIGNAL(sigClose()),this,SLOT(DeletePostingDlg()));\
connect(m_pGetAskTimer,SIGNAL(timeout()),m_PostingDlg,SLOT(TimerOutUnlock()));\
m_PostingDlg->lock(TIP,SUCCESS,FAILED);\
m_pGetAskTimer->start(5000);\
m_PostingDlg->exec();\
}\
} else if(gSelCards->count() > 1) emit sigSend(json,TIP);
#define MACRO_DEFINE_TIPDLG_ALL_FUCN(READBACK,SUCCESS,FAILED) \
if(gSelCards->count()==1) {\
if(m_PostingDlg==nullptr) {\
m_PostingDlg = new LoEmptyDialog(this);\
connect(m_PostingDlg,SIGNAL(sigClose()),this,SLOT(DeletePostingDlg()));\
connect(m_pGetAskTimer,SIGNAL(timeout()),m_PostingDlg,SLOT(TimerOutUnlock()));\
m_PostingDlg->lock(READBACK+" "+gSelCards->at(0)->m_strCardId,SUCCESS,FAILED);\
m_pGetAskTimer->start(5000);\
m_PostingDlg->exec();\
}\
}\
#define MARCO_DEFINE_CONTROL_FUNC2(PARENT,PARENT1) \
pHpptClient = new HpptClient(this);\
connect(pHpptClient,SIGNAL(httpPostRspReady(QString , QString , QByteArray )),this,SLOT(OnProHttpResponse(QString , QString , QByteArray)));\
pHpptClientAll = new HpptClient(this);\
connect(pHpptClientAll,SIGNAL(httpPostRspReady(QString , QString , QByteArray )),this,SLOT(OnProHttpResponseAll(QString , QString , QByteArray)));\
m_pGetAskTimer=new QTimer(this);\
connect(PARENT1,SIGNAL(sigSwitchIndexChanged(int)),this,SLOT(OnControlTypeSwitchIndexChanged(int)));\
connect(PARENT,SIGNAL(sigSelectedDeviceList(QList<LedCard *> *)),this,SLOT(onSelectedDeviceList(QList<LedCard *> *)));\
connect(this,SIGNAL(sigSend(QJsonObject &,QString)),PARENT,SLOT(OnControlSendJson(QJsonObject &,QString)));\
onSelectedDeviceList(list);
#define MACRO_ASKTIME_STOP \
if(m_pGetAskTimer && m_pGetAskTimer->isActive()) m_pGetAskTimer->stop();
#define MACRO_POSTING_DLG_UNLOCK \
if(m_PostingDlg && m_PostingDlg->getLockStatus()) m_PostingDlg->unlock();
#define MACRO_DEFINE_CONTROL_FUNC3 \
if(m_pLedlist!=nullptr)\
{\
if(m_pLedlist->count()==1)\
{\
m_pLedCard=list->at(0);\
m_strUrl="http://"+m_pLedCard->m_strCardIp+":2016/settings";\
if(m_oldLedlist!=m_pLedCard&&m_bSelected==true)\
{\
m_oldLedlist=m_pLedCard;\
onReadbackAllThisPage();\
}\
}\
}
#endif // GLOBALDEFINE_H #endif // GLOBALDEFINE_H

View File

@ -3,6 +3,8 @@
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "cfg.h" #include "cfg.h"
#include "tools.h" #include "tools.h"
#include "globaldefine.h"
#include "devicectrlpanel.h"
#include "device/upgradeapkdialog.h" #include "device/upgradeapkdialog.h"
#include <QColorDialog> #include <QColorDialog>
#include <QDesktopServices> #include <QDesktopServices>
@ -15,6 +17,8 @@
#include <QHeaderView> #include <QHeaderView>
#include <QStandardPaths> #include <QStandardPaths>
#include "QSimpleUpdater.h" #include "QSimpleUpdater.h"
#include "deviceitem.h"
#include "devicepanel.h"
extern QPoint gPlayPos; extern QPoint gPlayPos;
@ -307,9 +311,9 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
auto hBox = new QHBoxLayout(); auto hBox = new QHBoxLayout();
hBox->setSpacing(2); hBox->setSpacing(2);
hBox->addSpacing(144);
mBtnGrp = new QButtonGroup(this); mBtnGrp = new QButtonGroup(this);
hBox->addSpacing(144);
for(int i=0; i<MainPage_End; i++) { for(int i=0; i<MainPage_End; i++) {
auto btn = new ImgBtn(); auto btn = new ImgBtn();
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
@ -331,30 +335,34 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
wgts[MainPage_Setting] = mDevicePanel; wgts[MainPage_Setting] = mDevicePanel;
wgts[MainPage_LoraScreen] = m_wGuangYingPinWidget; wgts[MainPage_LoraScreen] = m_wGuangYingPinWidget;
vBox->addWidget(wgts[curIndex]);//初始化响应页面为终端管理页面 vBox->addWidget(wgts[mDevicePanel->mainPanelIdx]);//初始化响应页面为终端管理页面
mBtnGrp->button(curIndex)->setChecked(true); mBtnGrp->button(mDevicePanel->mainPanelIdx)->setChecked(true);
connect(mBtnGrp, &QButtonGroup::idToggled, this, [this, vBox](int id, bool checked) { connect(mBtnGrp, &QButtonGroup::idToggled, this, [this, vBox](int id, bool checked) {
if(!checked || id==curIndex) return; if(!checked || id==mDevicePanel->mainPanelIdx) return;
if((id==MainPage_DeviceManager && curIndex==MainPage_Setting) || (id==MainPage_Setting && curIndex==MainPage_DeviceManager)){ if((id!=MainPage_DeviceManager || mDevicePanel->mainPanelIdx!=MainPage_Setting) && (id!=MainPage_Setting || mDevicePanel->mainPanelIdx!=MainPage_DeviceManager)){
mDevicePanel->ShowDevicesInfoOrControlWidget(id); vBox->replaceWidget(wgts[mDevicePanel->mainPanelIdx], wgts[id]);
curIndex = id; wgts[mDevicePanel->mainPanelIdx]->setParent(0);
} else { }
vBox->replaceWidget(wgts[curIndex], wgts[id]); mDevicePanel->mainPanelIdx = id;
wgts[curIndex]->setParent(0); if(id==MainPage_DeviceManager) { //设备信息列表页面
curIndex = id; mDevicePanel->mDeviceTable->hideColumn(0);
if(curIndex == MainPage_DeviceManager || curIndex == MainPage_Setting) { mDevicePanel->mDeviceTable->fdIsSelAll->hide();
//开启UDP定时器 if(mDevicePanel->mDeviceCtrlPanel) {
mDevicePanel->mUdpTimer.start(60000); for(int j=DeviceTable_ScreenSize;j<DeviceTable_End;j++) mDevicePanel->mDeviceTable->showColumn(j);
int cnt = mDevicePanel->mDeviceTable->topLevelItemCount(); mDevicePanel->mDeviceTable->setMaximumWidth(0xffffff);
for(int i=0; i<cnt; i++) { mDevicePanel->mDeviceCtrlPanel->hide();
auto item = static_cast<DeviceItem*>(mDevicePanel->mDeviceTable->topLevelItem(i)); mDevicePanel->fdCardNumInfo->hide();
item->mHeartbeatTimer.start(60000);
item->DeviceItemHttpPost();
}
mDevicePanel->ShowDevicesInfoOrControlWidget(id);
} }
} else if(id==MainPage_Setting) { //终端控制页面
mDevicePanel->mDeviceTable->showColumn(0);
mDevicePanel->mDeviceTable->fdIsSelAll->show();
for(int j=DeviceTable_ScreenSize; j<DeviceTable_End; j++) mDevicePanel->mDeviceTable->hideColumn(j);
if(mDevicePanel->mDeviceCtrlPanel==0) mDevicePanel->mHBox->addWidget(mDevicePanel->mDeviceCtrlPanel = new DeviceCtrlPanel(mDevicePanel));
else mDevicePanel->mDeviceCtrlPanel->show();
mDevicePanel->fdCardNumInfo->show();
mDevicePanel->mDeviceTable->setMaximumWidth(340);
} }
}); });
@ -364,7 +372,40 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
m_pOneKeyCheckCard->setProperty("ssType", "progManageTool"); m_pOneKeyCheckCard->setProperty("ssType", "progManageTool");
connect(m_pOneKeyCheckCard, &QPushButton::clicked, this, [this] { connect(m_pOneKeyCheckCard, &QPushButton::clicked, this, [this] {
auto res = QMessageBox::warning(this, tr("Tip Info"), tr("RestoreLedCardIpByUdpTip"), QMessageBox::Ok, QMessageBox::Cancel); auto res = QMessageBox::warning(this, tr("Tip Info"), tr("RestoreLedCardIpByUdpTip"), QMessageBox::Ok, QMessageBox::Cancel);
if(res == QMessageBox::Ok) mDevicePanel->RestoreLedCardIpByUdpCmd(); if(res != QMessageBox::Ok) return;
QList<QNetworkInterface> networkinterfaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interfaces, networkinterfaces) {//networkinterfaces负责提供主机的IP地址和网络接口的列表
foreach (QNetworkAddressEntry entry, interfaces.addressEntries()) {//QNetworkAddressEntry存储了一个IP地址子网掩码和广播地址
entry.setBroadcast(QHostAddress::Broadcast);
QHostAddress broadcastAddress("255.255.255.255");
entry.setBroadcast(QHostAddress::Broadcast);
RESTORE_IP stTempIp;
memset(&stTempIp,0x00,sizeof(RESTORE_IP));
QString strNew=entry.ip().toString();
int itempOffset = strNew.lastIndexOf(".");
QString sstrNew=strNew.left(itempOffset)+".254";
if(sstrNew.length()<=20) memcpy(stTempIp.cNewIp,sstrNew.toLatin1().data(),sstrNew.length());
QString strMask=entry.netmask().toString();
if(strMask.length()<=20) memcpy(stTempIp.cMask,strMask.toLatin1().data(),strMask.length());
QString strGateway=entry.ip().toString();
if(strGateway.length()<=20) memcpy(stTempIp.cGateway,strGateway.toLatin1().data(),strGateway.length());
if(strGateway.length()<=20) memcpy(stTempIp.cDns,strGateway.toLatin1().data(),strGateway.length());
STREAM_PACKET packet;
memset(&packet, 0, sizeof(STREAM_PACKET));
memset(packet.SyncHead, 0x7e, 3);
memset(packet.ucSerialCode, 0x00, 20);
QByteArray ba("Broadcast!");
memcpy(packet.ucSerialCode, ba.data(), ba.size());
packet.iLength = 80;
packet.ucCommType = COMMAND_ONLY_RESET_CARD_IP;
memcpy(packet.pDataBuffer, &stTempIp, 80);
packet.pDataBuffer[packet.iLength] = GetCheckCodeIn8(&packet.ucCommType,packet.iLength+sizeof(packet.ucCommType)+sizeof(char)*20+sizeof(packet.iLength));
int iLenPacket = packet.iLength+sizeof(int)+3*sizeof(unsigned char)+sizeof(char)+20*sizeof(char)+sizeof(char);/////除正文外的协议结构大小;
QUdpSocket *tempUdpSocket = new QUdpSocket(this);
if(!tempUdpSocket->bind(entry.ip())) break;
tempUdpSocket->writeDatagram((char *)&packet,iLenPacket,broadcastAddress, 31296);
}
}
}); });
hBox->addWidget(m_pOneKeyCheckCard); hBox->addWidget(m_pOneKeyCheckCard);
hBox->addStretch(); hBox->addStretch();

View File

@ -4,7 +4,7 @@
#include "base/loqtitlebar.h" #include "base/loqtitlebar.h"
#include "basewin.h" #include "basewin.h"
#include "devicepanel.h" #include "devicepanel.h"
#include "devicectrlpanel.h" #include "globaldefine.h"
#include "mguangyingpinwidget.h" #include "mguangyingpinwidget.h"
#include "progpanel.h" #include "progpanel.h"
#include <QTranslator> #include <QTranslator>
@ -33,7 +33,6 @@ private:
QButtonGroup *mBtnGrp; QButtonGroup *mBtnGrp;
QWidget *wgts[MainPage_End]{}; QWidget *wgts[MainPage_End]{};
int curIndex{0};
QPushButton *m_pOneKeyCheckCard; QPushButton *m_pOneKeyCheckCard;
DevicePanel *mDevicePanel; DevicePanel *mDevicePanel;
ProgPanel *mProgPanel; ProgPanel *mProgPanel;

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,55 @@
#ifndef MGUANGYINGPINWIDGET_H #ifndef MGUANGYINGPINWIDGET_H
#define MGUANGYINGPINWIDGET_H #define MGUANGYINGPINWIDGET_H
#include <QWidget>
#include "communication/taserialthread.h"
#include <QUdpSocket> #include <QUdpSocket>
#include <QNetworkInterface> #include <QNetworkInterface>
namespace Ui { #include <QtSerialPort/QSerialPort>
class mGuangYingPinWidget;
} #include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QVBoxLayout>
#define MACRO_ANSY_PROGRAM(PROGRAM_INDEX) \ #define MACRO_ANSY_PROGRAM(PROGRAM_INDEX) \
if(ui->groupBox_com->isChecked())\ if(groupBox_com->isChecked()) {\
{\ if(pushButtonMainOpen->text()==tr("Close")) Set_program_buf_and_send(comboBox_SPortName->currentIndex(),PROGRAM_INDEX);\
if(ui->pushButtonMainOpen->text()==tr("Close"))\ if(pushButtonAuxOpen->text()==tr("Close")) Set_program_buf_and_send(comboBox_SPortNameAux->currentIndex(),PROGRAM_INDEX);\
Set_program_buf_and_send(ui->comboBox_SPortName->currentIndex(),PROGRAM_INDEX);\
if(ui->pushButtonAuxOpen->text()==tr("Close"))\
Set_program_buf_and_send(ui->comboBox_SPortNameAux->currentIndex(),PROGRAM_INDEX);\
}\ }\
if(ui->groupBox_Network->isChecked())\ if(groupBox_Network->isChecked()) Set_program_buf_and_send_by_udp(PROGRAM_INDEX);
{\
Set_program_buf_and_send_by_udp(PROGRAM_INDEX);\ class TA_SerialThread {
} public:
TA_SerialThread();
uint8_t portCnt;
uint8_t portNewCnt;
QSerialPort *m_arrSerial;//ptr point to an array,maxium port num is 5
QSerialPortInfo *m_arrNewSerial;//ptr point to an array,maxium port num is 5
void SearchPort(void);
void InitPortName(uint8_t portIndex,const QString &portName);
void InitPortBaudRate(uint8_t portIndex,qint32 baudRate);
void InitPortDataBits(uint8_t portIndex,QSerialPort::DataBits dataBits);
void InitPortParity(uint8_t portIndex,QSerialPort::Parity parity);
void InitPortStopBits(uint8_t portIndex,QSerialPort::StopBits stopBits);
bool OpenPort(uint8_t portIndex);
void ClosePort(uint8_t portIndex);
void SendDataBuf(uint8_t portIndex,const QByteArray &str);
QByteArray GetDataBuf(uint8_t portIndex);
};
class mGuangYingPinWidget : public QWidget { class mGuangYingPinWidget : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit mGuangYingPinWidget(QWidget *parent = nullptr); explicit mGuangYingPinWidget(QWidget *parent = nullptr);
~mGuangYingPinWidget();
protected: protected:
void changeEvent(QEvent *) override; void changeEvent(QEvent *) override;
void transUi(); void transUi();
@ -71,7 +95,6 @@ public slots:
void OnBrightnessSetByChanged(int icurValue); void OnBrightnessSetByChanged(int icurValue);
void OnRefresh(void); void OnRefresh(void);
private: private:
Ui::mGuangYingPinWidget *ui;
TA_SerialThread *sPortThread; TA_SerialThread *sPortThread;
volatile uint32_t m_recvNum; volatile uint32_t m_recvNum;
volatile uint32_t m_sendNum; volatile uint32_t m_sendNum;
@ -90,6 +113,120 @@ private:
void mymidelay(int imlsec); void mymidelay(int imlsec);
QString ByteArrayToHexString(QByteArray &ba); QString ByteArrayToHexString(QByteArray &ba);
QGroupBox *groupBox_com;
QHBoxLayout *horizontalLayout_29;
QVBoxLayout *verticalLayout_2;
QGroupBox *groupBoxMain;
QVBoxLayout *verticalLayout_6;
QHBoxLayout *horizontalLayout_6;
QLabel *label_PortName;
QComboBox *comboBox_SPortName;
QHBoxLayout *horizontalLayout_9;
QLabel *label_BaudRate;
QComboBox *comboBox_SPortBaud;
QHBoxLayout *horizontalLayout_15;
QLabel *label_DataBit;
QComboBox *comboBox_SPortDataBit;
QHBoxLayout *horizontalLayout_17;
QLabel *label_OEBit;
QComboBox *comboBox_SPortOEBit;
QHBoxLayout *horizontalLayout_18;
QLabel *label_StopBit;
QComboBox *comboBox_SPortStopBit;
QHBoxLayout *horizontalLayout_22;
QLabel *label_ComStatus;
QGraphicsView *graphicsView_ComStatus;
QHBoxLayout *horizontalLayout_4;
QPushButton *pushButtonMainOpen;
QVBoxLayout *verticalLayout_3;
QGroupBox *groupBoxAux;
QVBoxLayout *verticalLayout_8;
QHBoxLayout *horizontalLayout_7;
QLabel *label_PortNameAux;
QComboBox *comboBox_SPortNameAux;
QHBoxLayout *horizontalLayout_24;
QLabel *label_BaudRateAux;
QComboBox *comboBox_SPortBaudAux;
QHBoxLayout *horizontalLayout_25;
QLabel *label_DataBitAux;
QComboBox *comboBox_SPortDataBitAux;
QHBoxLayout *horizontalLayout_26;
QLabel *label_OEBitAux;
QComboBox *comboBox_SPortOEBitAux;
QHBoxLayout *horizontalLayout_27;
QLabel *label_StopBitAux;
QComboBox *comboBox_SPortStopBitAux;
QHBoxLayout *horizontalLayout_28;
QLabel *label_ComStatusAux;
QGraphicsView *graphicsView_ComStatusAux;
QHBoxLayout *horizontalLayout_5;
QPushButton *pushButtonAuxOpen;
QPushButton *pushButtonRefresh;
QGroupBox *groupBox_Network;
QSpacerItem *horizontalSpacer;
QVBoxLayout *verticalLayout_9;
QGroupBox *groupBoxParam;
QVBoxLayout *verticalLayout_10;
QHBoxLayout *horizontalLayout_20;
QLabel *label_ResendTimes;
QLineEdit *lineEdit_ResendTimes;
QHBoxLayout *horizontalLayout_23;
QLabel *label_DelayMill;
QLineEdit *lineEdit_DelayMill;
QSpacerItem *verticalSpacer;
QSpacerItem *horizontalSpacer_2;
QVBoxLayout *verticalLayout_4;
QHBoxLayout *horizontalLayout_14;
QHBoxLayout *horizontalLayout_16;
QVBoxLayout *verticalLayout_5;
QHBoxLayout *horizontalLayout_13;
QPushButton *pushButton1;
QPushButton *pushButton2;
QPushButton *pushButton3;
QPushButton *pushButton4;
QPushButton *pushButton5;
QHBoxLayout *horizontalLayout_12;
QPushButton *pushButton6;
QPushButton *pushButton7;
QPushButton *pushButton8;
QPushButton *pushButton9;
QPushButton *pushButton10;
QHBoxLayout *horizontalLayout_11;
QPushButton *pushButton11;
QPushButton *pushButton12;
QPushButton *pushButton13;
QPushButton *pushButton14;
QPushButton *pushButton15;
QHBoxLayout *horizontalLayout_10;
QPushButton *pushButton16;
QPushButton *pushButton17;
QPushButton *pushButton18;
QPushButton *pushButton19;
QPushButton *pushButton20;
QVBoxLayout *verticalLayout_7;
QHBoxLayout *horizontalLayout_19;
QLabel *label_ProgramNum;
QSpinBox *spinBox_ProgramIndex;
QPushButton *pushButtonSend;
QPushButton *pushButtonPrevious;
QPushButton *pushButtonNext;
QPushButton *pushButtonLoop;
QSpacerItem *horizontalSpacer_7;
QHBoxLayout *horizontalLayout_21;
QLabel *label_BrightNess;
QSpinBox *spinBox_BrightnessValue;
QPushButton *pushButtonBrightnessSet;
QPushButton *pushButtonScreenOff;
QPushButton *pushButtonScreenOn;
QSpacerItem *horizontalSpacer_18;
QSpacerItem *verticalSpacer_2;
QHBoxLayout *horizontalLayout_2;
QSpacerItem *horizontalSpacer_3;
QPushButton *pushButtonClearLog;
QCheckBox *checkBoxDebug;
QHBoxLayout *horizontalLayout_3;
QHBoxLayout *horizontalLayout_8;
QTextEdit *textEditReadBuf;
}; };
#endif // MGUANGYINGPINWIDGET_H #endif // MGUANGYINGPINWIDGET_H

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,5 @@
#include "progpanel.h" #include "progpanel.h"
#include "globaldefine.h" #include "globaldefine.h"
#include "tools.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "cfg.h" #include "cfg.h"
#include "player/playwin.h" #include "player/playwin.h"
@ -12,6 +11,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QStandardPaths> #include <QStandardPaths>
#include <QProgressBar> #include <QProgressBar>
#include <QFileDialog>
ProgPanel::ProgPanel(QSettings &settings, QWidget *parent) : QWidget(parent) { ProgPanel::ProgPanel(QSettings &settings, QWidget *parent) : QWidget(parent) {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
@ -420,7 +420,9 @@ void ProgPanel::FilterProgram(const QString &strtemp){
} }
ProgPortDlg::ProgPortDlg(QWidget *parent, QString title) : QDialog(parent) { ProgPortDlg::ProgPortDlg(QWidget *parent, QString title) : QDialog(parent) {
#ifdef Q_OS_WIN
setWindowFlag(Qt::WindowContextHelpButtonHint, 0); setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
#endif
resize(600, 400); resize(600, 400);
setWindowTitle(title); setWindowTitle(title);
@ -444,6 +446,6 @@ ProgPortDlg::ProgPortDlg(QWidget *parent, QString title) : QDialog(parent) {
hBox->addWidget(bnOK); hBox->addWidget(bnOK);
auto bnDone = new QPushButton(tr("Done")); auto bnDone = new QPushButton(tr("Done"));
connect(bnDone, &QPushButton::clicked, this, &BaseDlg::accept); connect(bnDone, &QPushButton::clicked, this, &QDialog::accept);
hBox->addWidget(bnDone); hBox->addWidget(bnDone);
} }

View File

@ -40,6 +40,7 @@ private:
}; };
class ProgPortDlg : public QDialog { class ProgPortDlg : public QDialog {
Q_OBJECT
public: public:
ProgPortDlg(QWidget *parent, QString title); ProgPortDlg(QWidget *parent, QString title);

View File

@ -7,6 +7,7 @@
#include <QFontComboBox> #include <QFontComboBox>
#include <QSpinBox> #include <QSpinBox>
#include <QToolButton> #include <QToolButton>
#include <QLabel>
EDClock::EDClock(EBase *multiWin) : EBase(multiWin) { EDClock::EDClock(EBase *multiWin) : EBase(multiWin) {
mType = EBase::DClock; mType = EBase::DClock;

View File

@ -14,6 +14,8 @@
#include <QTextCodec> #include <QTextCodec>
#include <QTimeEdit> #include <QTimeEdit>
#include <QToolButton> #include <QToolButton>
#include <QPainter>
#include <QLabel>
static QColor charColors[]{"#fff","#f00","#f00","#f0f","#c0c","#ff0","#f80","#0f0","#0f0","#0a0","#0a0","#7b0","#00f","#00f","#0af","#0ef"}; static QColor charColors[]{"#fff","#f00","#f00","#f0f","#c0c","#ff0","#f80","#0f0","#0f0","#0a0","#0a0","#7b0","#00f","#00f","#0af","#0ef"};

View File

@ -10,6 +10,7 @@
#include <QProcess> #include <QProcess>
#include <QSettings> #include <QSettings>
#include <QSpinBox> #include <QSpinBox>
#include <QPainter>
EVideo *EVideo::create(const QString &file, PageListItem *pageItem, EBase *multiWin) { EVideo *EVideo::create(const QString &file, PageListItem *pageItem, EBase *multiWin) {
int64_t dur; int64_t dur;

View File

@ -9,6 +9,7 @@
#include <QJsonArray> #include <QJsonArray>
#include <QProcess> #include <QProcess>
#include <QMessageBox> #include <QMessageBox>
#include <QPainter>
GenTmpThread::GenTmpThread(ProgItem *progItem, const QString &prog_name, const QString &zip_file, const QString &password) : mProgItem(progItem), prog_name(prog_name), zip_file(zip_file), password(password) { GenTmpThread::GenTmpThread(ProgItem *progItem, const QString &prog_name, const QString &zip_file, const QString &password) : mProgItem(progItem), prog_name(prog_name), zip_file(zip_file), password(password) {
connect(this, &QThread::finished, this, &QThread::deleteLater); connect(this, &QThread::finished, this, &QThread::deleteLater);
@ -90,7 +91,7 @@ void GenTmpThread::run() {
//如果是usb更新则生成压缩包网络发送则不需要 //如果是usb更新则生成压缩包网络发送则不需要
if(! zip_file.isEmpty()) { if(! zip_file.isEmpty()) {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WIN
QStringList args{"a", zip_file, dstDir+"/*"}; QStringList args{"a", zip_file, dstDir+"/*"};
if(! password.isEmpty()) args << "-p"+password; if(! password.isEmpty()) args << "-p"+password;
QProcess::execute("7z.exe", args); QProcess::execute("7z.exe", args);

View File

@ -3,9 +3,10 @@
#include "globaldefine.h" #include "globaldefine.h"
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QDialogButtonBox>
ProgCreateDlg::ProgCreateDlg(QString name, int width, int height, QString remarks, QString widths, QWidget *parent) : QDialog(parent) { ProgCreateDlg::ProgCreateDlg(QString name, int width, int height, QString remarks, QString widths, QWidget *parent) : QDialog(parent) {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WIN
setWindowFlag(Qt::WindowContextHelpButtonHint, 0); setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
#endif #endif
setWindowTitle(tr("Solution Information")); setWindowTitle(tr("Solution Information"));
@ -77,14 +78,8 @@ ProgCreateDlg::ProgCreateDlg(QString name, int width, int height, QString remark
vBox->addSpacing(6); vBox->addSpacing(6);
hBox = new HBox(vBox); auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
hBox->addStretch(); connect(btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
auto bnOK = new QPushButton(tr("OK")); vBox->addWidget(btnBox);
connect(bnOK, &QPushButton::clicked, this, &QDialog::accept);
hBox->addWidget(bnOK);
auto bnCancel = new QPushButton(tr("Cancel"));
connect(bnCancel, &QPushButton::clicked, this, &QDialog::reject);
hBox->addWidget(bnCancel);
} }

View File

@ -544,7 +544,8 @@ void ProgEditorWin::closeEvent(QCloseEvent *event) {
#endif #endif
} }
//停止每个页面元素的播放,将节目目录下的每个页面的文件夹另命名 //停止每个页面元素的播放,将节目目录下的每个页面的文件夹另命名
void ProgEditorWin::save() { bool ProgEditorWin::save() {
auto rtn = true;
//停止每个幻灯片的元素 //停止每个幻灯片的元素
int cnt = listPage->count(); int cnt = listPage->count();
for(int i=0; i<cnt; i++) { for(int i=0; i<cnt; i++) {
@ -552,10 +553,16 @@ void ProgEditorWin::save() {
foreach(auto item, items) static_cast<EBase*>(item)->freeFiles(); foreach(auto item, items) static_cast<EBase*>(item)->freeFiles();
} }
QDir progDir(mProgItem->mProgDir); QDir progDir(mProgItem->mProgDir);
if(! progDir.exists() && ! progDir.mkdir(mProgItem->mProgDir)) return; if(! progDir.exists() && ! progDir.mkdir(mProgItem->mProgDir)) {
QMessageBox::critical(this, tr("Error"), tr("Create Dir failed")+": "+mProgItem->mProgDir);
return 0;
}
QStringList pageNames = progDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); QStringList pageNames = progDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
foreach(QString pageName, pageNames) { foreach(QString pageName, pageNames) {
if(! progDir.rename(pageName, pageName + PAGEDEL_SUFFIX)) QMessageBox::critical(this, tr("Error"), tr("Rename fail when saving")+" "+pageName); if(! progDir.rename(pageName, pageName + PAGEDEL_SUFFIX)) {
rtn = 0;
QMessageBox::critical(this, tr("Error"), tr("Rename fail when saving")+" "+pageName);
}
} }
//保存每个页面的元素和页面属性到page.json文档 //保存每个页面的元素和页面属性到page.json文档
mPageJsons.clear(); mPageJsons.clear();
@ -565,21 +572,24 @@ void ProgEditorWin::save() {
} }
pageNames = progDir.entryList(QStringList("*" PAGEDEL_SUFFIX)); pageNames = progDir.entryList(QStringList("*" PAGEDEL_SUFFIX));
foreach(QString pageName, pageNames) { foreach(QString pageName, pageNames) {
if(! QDir(mProgItem->mProgDir + "/" + pageName).removeRecursively()) QMessageBox::critical(this, tr("Error"), tr("Remove Recursively fail when saving")+" "+pageName); if(! QDir(mProgItem->mProgDir + "/" + pageName).removeRecursively()) {
rtn = 0;
QMessageBox::critical(this, tr("Error"), tr("Remove Recursively fail when saving")+" "+pageName);
}
} }
for(int i=0; i<cnt; i++) { for(int i=0; i<cnt; i++) {
auto items = static_cast<PageListItem*>(listPage->item(i))->mScene->items(); auto items = static_cast<PageListItem*>(listPage->item(i))->mScene->items();
foreach(auto item, items) static_cast<EBase*>(item)->loadFiles(); foreach(auto item, items) static_cast<EBase*>(item)->loadFiles();
} }
return rtn;
} }
void ProgEditorWin::onSave() { void ProgEditorWin::onSave() {
auto waitingDlg = new WaitingDlg(this, tr("Saving..."), tr("Success")); auto waitingDlg = new WaitingDlg(this, tr("Saving..."), tr("Success"));
waitingDlg->btnAbort->hide(); waitingDlg->btnAbort->hide();
//dlg->lock(tr("Saving..."),tr("Success"),tr("Save failed"));
waitingDlg->show(); waitingDlg->show();
save(); if(save()) waitingDlg->success();
waitingDlg->success(); else waitingDlg->close();
waitingDlg->exec(); waitingDlg->exec();
this->mProgItem->m_last = QDateTime::currentDateTime(); this->mProgItem->m_last = QDateTime::currentDateTime();
this->mProgItem->m_fsize = dirFileSize(this->mProgItem->mProgDir); this->mProgItem->m_fsize = dirFileSize(this->mProgItem->mProgDir);

View File

@ -17,7 +17,7 @@ protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
private: private:
bool isProgChanged(); bool isProgChanged();
void save(); bool save();
void UdpSendJson(QJsonObject json); void UdpSendJson(QJsonObject json);
QListWidget *listPage; QListWidget *listPage;

View File

@ -1,5 +1,4 @@
#include "sendprogramdialog.h" #include "sendprogramdialog.h"
#include "tools.h"
#include "cfg.h" #include "cfg.h"
#include "wProgramPublishItem.h" #include "wProgramPublishItem.h"
#include "sendprogthread.h" #include "sendprogthread.h"
@ -8,9 +7,11 @@
#include <QLineEdit> #include <QLineEdit>
#include <QHeaderView> #include <QHeaderView>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include "deviceitem.h"
#include "devicepanel.h"
SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialog(parent), mProgName(progName) { SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialog(parent), mProgName(progName) {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WIN
setWindowFlag(Qt::WindowMaximizeButtonHint); setWindowFlag(Qt::WindowMaximizeButtonHint);
#endif #endif
setWindowTitle(tr("Publish")+" "+mProgName); setWindowTitle(tr("Publish")+" "+mProgName);
@ -86,7 +87,7 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo
if(item->checkState(0) != Qt::Checked) continue; if(item->checkState(0) != Qt::Checked) continue;
auto row = static_cast<wProgramPublishItem*>(item); auto row = static_cast<wProgramPublishItem*>(item);
if(row->mIsSending) continue; if(row->mIsSending) continue;
if(row->mLedCard->bPassword && row->mLedCard->m_bLockStatus) { if(row->mLedCard.hasPassword && row->mLedCard.isLocked) {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, tr("This screen is encrypted")); row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, tr("This screen is encrypted"));
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::red); row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::red);
continue; continue;
@ -100,7 +101,7 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo
} }
row->mIsSending = true; row->mIsSending = true;
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, ""); row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, "");
auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", row->mLedCard->m_strCardIp, 3333); auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", row->mLedCard.ip, 3333);
connect(sendProg, &SendProgThread::emErr, row, [this, row](QString strTip) { connect(sendProg, &SendProgThread::emErr, row, [this, row](QString strTip) {
row->mIsSending = false; row->mIsSending = false;
if(strTip=="OK") { if(strTip=="OK") {
@ -138,13 +139,13 @@ void SendProgramDialog::sendNext() {
if(item->checkState(0) != Qt::Checked) continue; if(item->checkState(0) != Qt::Checked) continue;
auto row = static_cast<wProgramPublishItem*>(item); auto row = static_cast<wProgramPublishItem*>(item);
if(row->mIsSending) continue; if(row->mIsSending) continue;
if(row->mLedCard->bPassword && row->mLedCard->m_bLockStatus) continue; if(row->mLedCard.hasPassword && row->mLedCard.isLocked) continue;
if(! row->data(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0).toString().startsWith(" ")) continue; if(! row->data(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0).toString().startsWith(" ")) continue;
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, ""); row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, "");
row->fdProgress->setValue(0); row->fdProgress->setValue(0);
row->mIsSending = true; row->mIsSending = true;
mWaitCnt--; mWaitCnt--;
auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", row->mLedCard->m_strCardIp, 3333); auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", row->mLedCard.ip, 3333);
connect(sendProg, &SendProgThread::emErr, row, [this, row](QString strTip) { connect(sendProg, &SendProgThread::emErr, row, [this, row](QString strTip) {
row->mIsSending = false; row->mIsSending = false;
if(strTip=="OK") { if(strTip=="OK") {
@ -165,16 +166,16 @@ void SendProgramDialog::sendNext() {
} }
void SendProgramDialog::onRefresh() { void SendProgramDialog::onRefresh() {
int iCount = gDevicePanel->mLedCards.count(); int cnt = gDevicePanel->mDeviceTable->topLevelItemCount();
for(int i=0; i<iCount; i++) onAddLedCard(gDevicePanel->mLedCards.at(i)); for(int i=0; i<cnt; i++) onAddLedCard(static_cast<DeviceItem*>(gDevicePanel->mDeviceTable->topLevelItem(i))->mCard);
label->setText(tr("All")+":"+QString::number(iCount)); label->setText(tr("All")+":"+QString::number(cnt));
} }
void SendProgramDialog::onAddLedCard(LedCard *p) { void SendProgramDialog::onAddLedCard(LedCard p) {
int iExistFlg=0; int iExistFlg=0;
int cnt = wDevicePublishList->topLevelItemCount(); int cnt = wDevicePublishList->topLevelItemCount();
for(int i=0; i<cnt; i++) { for(int i=0; i<cnt; i++) {
QString strTempCardId=static_cast<wProgramPublishItem*>(wDevicePublishList->topLevelItem(i))->mLedCard->m_strCardId; QString strTempCardId=static_cast<wProgramPublishItem*>(wDevicePublishList->topLevelItem(i))->mLedCard.id;
if(strTempCardId == p->m_strCardId) { if(strTempCardId == p.id) {
iExistFlg=1; iExistFlg=1;
static_cast<wProgramPublishItem*>(wDevicePublishList->topLevelItem(i))->SetItemParam(p); static_cast<wProgramPublishItem*>(wDevicePublishList->topLevelItem(i))->SetItemParam(p);
break; break;

View File

@ -3,8 +3,8 @@
#include <QDialog> #include <QDialog>
#include <QLabel> #include <QLabel>
#include "device/ledcard.h"
#include "base/loqtreewidget.h" #include "base/loqtreewidget.h"
#include "globaldefine.h"
class SendProgramDialog : public QDialog { class SendProgramDialog : public QDialog {
Q_OBJECT Q_OBJECT
@ -19,7 +19,7 @@ protected slots:
void FilterProgram(const QString &strtemp); void FilterProgram(const QString &strtemp);
private: private:
void sendNext(); void sendNext();
void onAddLedCard(LedCard *p); void onAddLedCard(LedCard);
LoQTreeWidget *wDevicePublishList; LoQTreeWidget *wDevicePublishList;
int mWaitCnt{0}; int mWaitCnt{0};

View File

@ -1,6 +1,8 @@
#include "wprogrampublishitem.h" #include "wprogrampublishitem.h"
#include "gutil/qgui.h" #include "gutil/qgui.h"
#include "base/waitingdlg.h" #include "base/waitingdlg.h"
#include "gutil/qnetwork.h"
#include "deviceitem.h"
#include <QMessageBox> #include <QMessageBox>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonDocument> #include <QJsonDocument>
@ -9,7 +11,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMetaEnum> #include <QMetaEnum>
wProgramPublishItem::wProgramPublishItem(LedCard *pLedCard, LoQTreeWidget *parent, QString strProgramName, QString strProgramPath) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) { wProgramPublishItem::wProgramPublishItem(LedCard pLedCard, LoQTreeWidget *parent, QString strProgramName, QString strProgramPath) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) {
m_strProgramName = strProgramName; m_strProgramName = strProgramName;
m_strProgramPath = strProgramPath; m_strProgramPath = strProgramPath;
mLedCard = pLedCard; mLedCard = pLedCard;
@ -34,7 +36,7 @@ wProgramPublishItem::wProgramPublishItem(LedCard *pLedCard, LoQTreeWidget *paren
vBox->addWidget(btnUnlock); vBox->addWidget(btnUnlock);
m_parent->setItemWidget(this, ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT, wgt); m_parent->setItemWidget(this, ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT, wgt);
connect(btnUnlock, &QPushButton::clicked, this, [this] { connect(btnUnlock, &QPushButton::clicked, this, [this] {
if(! mLedCard->m_bLockStatus) return; if(! mLedCard.isLocked) return;
bool ok; bool ok;
auto pwd = QInputDialog::getText(treeWidget(), tr("Input password"), tr("Input password"), QLineEdit::Password, QString(), &ok); auto pwd = QInputDialog::getText(treeWidget(), tr("Input password"), tr("Input password"), QLineEdit::Password, QString(), &ok);
if(! ok) return; if(! ok) return;
@ -44,7 +46,7 @@ wProgramPublishItem::wProgramPublishItem(LedCard *pLedCard, LoQTreeWidget *paren
json.insert("pwd", pwd); json.insert("pwd", pwd);
auto waitingDlg = new WaitingDlg(treeWidget(), tr("VerifyPassword")+" ..."); auto waitingDlg = new WaitingDlg(treeWidget(), tr("VerifyPassword")+" ...");
waitingDlg->show(); waitingDlg->show();
auto reply = NetReq("http://"+mLedCard->m_strCardIp+":2016/settings").timeout(60000).post(json); auto reply = NetReq("http://"+mLedCard.ip+":2016/settings").timeout(60000).post(json);
waitingDlg->connAbort(reply); waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [=] { connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json; QJsonDocument json;
@ -60,23 +62,28 @@ wProgramPublishItem::wProgramPublishItem(LedCard *pLedCard, LoQTreeWidget *paren
return; return;
} }
waitingDlg->success(); waitingDlg->success();
mLedCard->m_bLockStatus = false; mLedCard.isLocked = false;
btnUnlock->setIcon(QIcon(":/res/device/UnLock.png")); btnUnlock->setIcon(QIcon(":/res/device/UnLock.png"));
auto item = findItem(mLedCard.id);
if(item) {
item->mCard.isLocked = false;
item->btnUnlock->setIcon(QIcon(":/res/device/UnLock.png"));
}
}); });
}); });
SetItemParam(mLedCard); SetItemParam(mLedCard);
} }
void wProgramPublishItem::SetItemParam(LedCard *card) { void wProgramPublishItem::SetItemParam(LedCard card) {
setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, 0, card->m_strCardId); setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, 0, card.id);
setData(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, 0, card->m_strCardRemarkName); setData(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, 0, card.alias);
setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, 0, card->m_strCardIp); setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, 0, card.ip);
setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE, 0, QString("%1 x %2").arg(card->m_iWidth).arg(card->m_iHeight)); setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE, 0, QString("%1 x %2").arg(card.mWidth).arg(card.mHeight));
m_ImageOnline->setPixmap(QPixmap(mLedCard->m_bOnLine ? ":/res/device/O_Online.png" : ":/res/device/O_Offline.png")); m_ImageOnline->setPixmap(QPixmap(mLedCard.isOnline ? ":/res/device/O_Online.png" : ":/res/device/O_Offline.png"));
if(! card->bPassword) btnUnlock->hide(); if(! card.hasPassword) btnUnlock->hide();
else { else {
if(! btnUnlock->isVisible()) btnUnlock->show(); if(! btnUnlock->isVisible()) btnUnlock->show();
btnUnlock->setIcon(QIcon(card->m_bLockStatus ? ":/res/device/Lock.png" : ":/res/device/UnLock.png")); //如果已经验证通过密码显示绿色图标 没有验证显示蓝色锁图标 btnUnlock->setIcon(QIcon(card.isLocked ? ":/res/device/Lock.png" : ":/res/device/UnLock.png")); //如果已经验证通过密码显示绿色图标 没有验证显示蓝色锁图标
} }
} }

View File

@ -8,19 +8,16 @@
#include <QLabel> #include <QLabel>
#include <QProgressBar> #include <QProgressBar>
#include <QPushButton> #include <QPushButton>
#include <QTreeWidget> #include "base/loqtreewidget.h"
#include <QTreeWidgetItem> #include "globaldefine.h"
#include <base/loqtreewidget.h>
#include <communication/hpptclient.h>
#include <device/ledcard.h>
class wProgramPublishItem : public QObject, public QTreeWidgetItem { class wProgramPublishItem : public QObject, public QTreeWidgetItem {
Q_OBJECT Q_OBJECT
public: public:
explicit wProgramPublishItem(LedCard *pLedCard, LoQTreeWidget *parent = nullptr, QString strProgramName="",QString strProgramPath=""); explicit wProgramPublishItem(LedCard pLedCard, LoQTreeWidget *parent = nullptr, QString strProgramName="",QString strProgramPath="");
void SetItemParam(LedCard *p); void SetItemParam(LedCard p);
LedCard *mLedCard{nullptr}; LedCard mLedCard;
QProgressBar *fdProgress{nullptr}; QProgressBar *fdProgress{nullptr};
bool mIsSending{false}; bool mIsSending{false};

View File

@ -1,10 +1,7 @@
#include "tools.h" #include "tools.h"
#include "cfg.h"
#include "globaldefine.h"
#include "program/pagelistitem.h"
#include "base/x_uimsgboxok.h"
#include <QBuffer> #include <QBuffer>
#include <QJsonArray> #include <QJsonArray>
#include <QPainter>
void Tools::timerEvent(QTimerEvent *event) { void Tools::timerEvent(QTimerEvent *event) {
if(timer_id==event->timerId()) emit sTick(); if(timer_id==event->timerId()) emit sTick();

View File

@ -1,9 +1,7 @@
#ifndef TOOLS_H #ifndef TOOLS_H
#define TOOLS_H #define TOOLS_H
#include "devicepanel.h"
#include "program/progitem.h" #include "program/progitem.h"
#include "device/ledcard.h"
#include <QApplication> #include <QApplication>
#include <QBrush> #include <QBrush>
#include <QColor> #include <QColor>
@ -15,8 +13,6 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
const QString str0_9[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; const QString str0_9[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
extern DevicePanel *gDevicePanel;
extern QList<LedCard*> *gSelCards;
extern QTextEdit *gFdResInfo; extern QTextEdit *gFdResInfo;
extern QString gFileHome; extern QString gFileHome;
extern ProgItem *gProgItem; extern ProgItem *gProgItem;

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff