qt/LedOK/devicepanel.cpp

599 lines
25 KiB
C++
Raw Normal View History

2023-05-25 10:00:00 +08:00
#include "devicepanel.h"
2023-05-15 16:06:10 +08:00
#include "globaldefine.h"
2023-04-18 14:14:46 +08:00
#include "gutil/qgui.h"
2023-05-15 16:06:10 +08:00
#include "gutil/qnetwork.h"
#include "deviceitem.h"
2023-08-01 11:42:41 +08:00
#include "device/ctrlbrightpanel.h"
#include "device/ctrlpowerpanel.h"
#include "device/ctrlnetworkpanel.h"
#include "device/ctrlverifyclockpanel.h"
#include "device/ctrlhdmipanel.h"
#include "device/ctrlvolumepanel.h"
#include "device/ctrlpwdpanel.h"
#include "device/ctrladvancedpanel.h"
#include "device/ctrltestpanel.h"
2022-08-25 18:37:24 +08:00
#include <QAction>
#include <QNetworkDatagram>
2022-09-28 18:21:57 +08:00
#include <QNetworkInterface>
#include <QMessageBox>
2023-05-15 16:06:10 +08:00
#include <QJsonArray>
#include <QStyledItemDelegate>
2023-08-01 11:42:41 +08:00
#include <QToolButton>
2023-10-23 11:44:22 +08:00
#include <QPainter>
2022-08-25 18:37:24 +08:00
DevicePanel *gDevicePanel;
2023-08-01 11:42:41 +08:00
QTextEdit *gFdResInfo;
2023-05-15 16:06:10 +08:00
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();
}
2023-05-16 18:03:53 +08:00
if(card.mWidth==0) card.mWidth = json["width"].toInt();
if(card.mHeight==0) card.mHeight = json["height"].toInt();
2023-05-15 16:06:10 +08:00
card.androidVersion = json["androidVersion"].toString();
}
2022-09-30 18:08:39 +08:00
DevicePanel::DevicePanel(QSettings &settings, QWidget *parent) : QWidget(parent) {
2022-08-25 18:37:24 +08:00
gDevicePanel = this;
setAutoFillBackground(true);
QPalette pal;
pal.setBrush(QPalette::Window, QColor(0xeeeeee));
setPalette(pal);
auto vBox = new VBox(this);
2022-08-25 18:37:24 +08:00
vBox->setContentsMargins(0, 0, 0, 0);
vBox->setSpacing(0);
auto hBox = new HBox(vBox);
2022-08-25 18:37:24 +08:00
hBox->setContentsMargins(6, 2, 6, 2);
hBox->setSpacing(2);
auto label = new QLabel();
2023-08-01 11:42:41 +08:00
label->setPixmap({":/res/DeviceNum_All.png"});
2022-08-25 18:37:24 +08:00
label->setScaledContents(true);
label->setFixedSize(33, 24);
hBox->addWidget(label);
label_3 = new QLabel(tr("All"));
hBox->addWidget(label_3);
2023-10-23 11:44:22 +08:00
nDeviceNum = new QLabel;
2022-08-25 18:37:24 +08:00
nDeviceNum->setFixedSize(40, 20);
hBox->addWidget(nDeviceNum);
2023-10-23 11:44:22 +08:00
auto fdSearch = new QLineEdit;
2022-08-25 18:37:24 +08:00
fdSearch->setClearButtonEnabled(true);
fdSearch->setFixedSize(220, 30);
2023-04-18 14:14:46 +08:00
fdSearch->addAction(new QAction(QIcon(":/res/program/bnSearch.png"), QString()), QLineEdit::LeadingPosition);
2022-08-25 18:37:24 +08:00
fdSearch->setStyleSheet("border: 1px solid #aaaaaa;");
2023-10-23 11:44:22 +08:00
connect(fdSearch, &QLineEdit::textChanged, this, [=](const QString &text) {
2023-04-18 14:14:46 +08:00
auto cnt = mDeviceTable->topLevelItemCount();
2023-10-23 11:44:22 +08:00
int sel = 0, unsel = 0;
for(int i=0; i<cnt; i++) {
auto item = mDeviceTable->item(i);
item->setHidden(! (text.isEmpty() || item->text("id").contains(text) || item->text("alias").contains(text) || item->text("ip").contains(text)));
if(item->isHidden()) item->setCheckState("check", Qt::Unchecked);
else (item->checkState("check")==Qt::Checked ? sel : unsel)++;
mDeviceTable->fdCheckAll->blockSignals(true);
mDeviceTable->fdCheckAll->setCheckState(sel==0 ? Qt::Unchecked : unsel ? Qt::PartiallyChecked : Qt::Checked);
mDeviceTable->fdCheckAll->blockSignals(false);
emit mDeviceTable->selChanged();
2023-04-18 14:14:46 +08:00
}
});
2022-08-25 18:37:24 +08:00
hBox->addWidget(fdSearch);
hBox->addSpacing(10);
fdCardNumInfo = new QLabel(tr("Current Screen")+": "+tr("none"));
fdCardNumInfo->setStyleSheet("QLabel{color: #15f;}");
fdCardNumInfo->hide();
hBox->addWidget(fdCardNumInfo);
hBox->addStretch();
auto areaFlash = new QWidget();
areaFlash->setFixedSize(100, 34);
bnSpecifyIP = new QComboBox(areaFlash);
bnSpecifyIP->addItem(tr("Specify IP"));
bnSpecifyIP->setGeometry(0, 0, areaFlash->width(), areaFlash->height());
bnSpecifyIP->setItemDelegate(new QStyledItemDelegate);
connect(bnSpecifyIP, &QComboBox::textActivated, this, [this] {
2022-09-28 18:21:57 +08:00
mUdpTimer.stop();
specifyIPDlg->exec();
mUdpTimer.start(30000);
2022-08-25 18:37:24 +08:00
});
bnSpecifyIP->setStyleSheet(R"rrr(
QComboBox {
border: none;
border-radius: 5px;
background-color: #19c;
}
QComboBox:hover {background-color: #08b;}
QComboBox::drop-down {width: 25px;}
2023-08-01 11:42:41 +08:00
QComboBox::down-arrow {image: url(:/res/FlashArrow.png);}
2022-08-25 18:37:24 +08:00
QComboBox QAbstractItemView::item {
height: 28px;
color: #fff;
}
QComboBox QAbstractItemView::item:selected {background-color: #09c;}
)rrr");
2022-09-28 18:21:57 +08:00
btnRefresh = new QPushButton(tr("Refresh"), areaFlash);
btnRefresh->setGeometry(0, 0, 75, areaFlash->height());
connect(btnRefresh, &QPushButton::clicked, this, [this] {
2022-08-25 18:37:24 +08:00
mDeviceTable->clear();
2023-10-23 11:44:22 +08:00
mDeviceTable->fdCheckAll->setCheckState(Qt::Unchecked);
2022-08-25 18:37:24 +08:00
nDeviceNum->setText("0");
sendGetInfo();
});
2022-09-28 18:21:57 +08:00
btnRefresh->setStyleSheet(R"rrr(
2022-08-25 18:37:24 +08:00
QPushButton {
border-radius: 5px;
background-color: #19c;
color: #fff;
}
QPushButton:hover {background-color: #08b;}
)rrr");
hBox->addWidget(areaFlash);
2023-10-23 11:44:22 +08:00
mHBox = new HBox(vBox);
auto table = new LoQTreeWidget;
table->addCol("#", "", 20);
table->addCol("check", "", 28).margin(2);
table->addCol("id", "ID", 130, QHeaderView::Stretch).alignC();
table->addCol("online", "", 40);
table->addCol("ip", "IP", 130, QHeaderView::Stretch).alignC();
table->addCol("screenSize", "", 100, QHeaderView::Stretch).alignC();
table->addCol("alias", "", 130, QHeaderView::Stretch).alignC();
table->addCol("brightness", "", 80).alignC();
table->addCol("power", "", 80).alignC();
table->addCol("password", "", 72);
table->addCol("info", "", 72);
table->addCol("screenshot", "", 72);
table->setDefs()->setHeaderAlignC();
table->addFd();
table->setSelectionMode(QAbstractItemView::NoSelection);
table->minRowHeight = 36;
table->setSortingEnabled(true);
table->hideColumn("check");
table->fdCheckAll->hide();
table->sortItems("id", Qt::AscendingOrder);
connect(table, &LoQTreeWidget::selChanged, table, [=] {
2023-08-07 16:24:33 +08:00
gSelCards.clear();
2023-10-23 11:44:22 +08:00
int cnt = table->topLevelItemCount();
for(int i=0; i<cnt; i++) if(table->item(i)->checkState("check") == Qt::Checked) gSelCards.append(static_cast<DeviceItem*>(table->topLevelItem(i))->mCard);
2023-08-07 16:24:33 +08:00
emit sigSelectedDeviceList();
});
2023-10-23 11:44:22 +08:00
mHBox->addWidget(mDeviceTable = table);
2023-08-07 16:24:33 +08:00
2022-09-28 18:21:57 +08:00
connect(&mUdpTimer, &QTimer::timeout, this, &DevicePanel::sendGetInfo);
connect(&mUdpSocket, &QUdpSocket::readyRead, this, [this] {
while(mUdpSocket.hasPendingDatagrams()) {
auto gram = mUdpSocket.receiveDatagram();
2022-08-25 18:37:24 +08:00
auto data = gram.data();
if(data.isEmpty()) continue;
auto senderAddress = gram.senderAddress();
bool ok = true;
if(senderAddress.protocol()==QUdpSocket::IPv6Protocol) senderAddress.setAddress(senderAddress.toIPv4Address(&ok));
2022-09-26 18:10:47 +08:00
auto addr = ok ? senderAddress.toString() : "";
2023-05-15 16:06:10 +08:00
DeviceItem *item;
2022-08-25 18:37:24 +08:00
if(data.startsWith("{\"")) {
QJsonParseError error;
2023-05-15 16:06:10 +08:00
QJsonDocument json = QJsonDocument::fromJson(gram.data(), &error);
2022-08-25 18:37:24 +08:00
if(error.error != QJsonParseError::NoError) {
qDebug()<<"DeviceItem OnProHttpResponse 解析json文件错误";
continue;
}
2023-05-15 16:06:10 +08:00
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) {
2023-08-01 11:42:41 +08:00
item->mCard.isOnline = true;
2023-05-15 16:06:10 +08:00
setCard(item->mCard, addr, json);
item->init();
goto end;
}
item = new DeviceItem(mDeviceTable);
item->mCard.id = cardId;
setCard(item->mCard, addr, json);
2022-08-25 18:37:24 +08:00
} else {
2022-09-30 18:08:39 +08:00
auto bytes = gram.data();
2023-05-15 16:06:10 +08:00
auto packet = (UDPPacket *)bytes.data();
int cnt = mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) if((item = (DeviceItem *)mDeviceTable->topLevelItem(i))->mCard.id==packet->serialCode) {
item->mCard.isOnline = true;
item->mCard.ip = addr;
item->init();
goto end;
2022-09-28 18:21:57 +08:00
}
2023-05-15 16:06:10 +08:00
item = new DeviceItem(mDeviceTable);
item->mCard.id = packet->serialCode;
item->mCard.ip = addr;
2022-08-25 18:37:24 +08:00
}
2023-10-23 11:44:22 +08:00
item->init();
{
auto btn = new QPushButton;
btn->setCursor(QCursor(Qt::PointingHandCursor));
btn->setIcon(QIcon(":/res/info.png"));
btn->setIconSize({26, 26});
item->setCellWidget("info", btn);
connect(btn, &QPushButton::clicked, btn, [=] {
QString msgpre;
msgpre.append(tr("Current Brightness")).append(": ").append(QString::number(item->mCard.bright)).append("%").append("\n");
msgpre.append(tr("Brightness Level")).append(": ").append(QString::number(item->mCard.BrightnessLevel)).append("\n");
msgpre.append(tr("Android OS Resolution")).append(": ").append(item->mCard.ScreenResolution).append("\n");
msgpre.append(tr("Android Version")).append(": ").append(item->mCard.androidVersion).append("\n");
msgpre.append(tr("FPGA Version")).append(": ").append(item->mCard.HardVersion).append("\n");
msgpre.append(tr("Firmware Version")).append(": ").append(item->mCard.FirmwareVersion).append("\n");
msgpre.append("IMEI: ").append(item->mCard.IMEI).append("\n");
QMessageBox msgBox(QMessageBox::Information, item->mCard.id+" "+tr("Detail Info"), msgpre + tr("Player Version")+": "+tr("Getting")+" ...");
QJsonObject json;
json.insert("_id", "CheckSoftVersions");
json.insert("_type", "CheckSoftVersions");
auto card = item->mCard;
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
ConnReply(reply, &msgBox) [=, &msgBox] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) {
msgBox.setText(msgpre + tr("Player Version")+": "+err);
2023-05-25 10:00:00 +08:00
return;
}
2023-10-23 11:44:22 +08:00
auto apps = json["apps"].toArray();
foreach(QJsonValue value, apps) {
QJsonObject app = value.toObject();
if(app["packageName"].toString().contains("xixunplayer")) {
msgBox.setText(msgpre + tr("Player Version")+": "+app["versionName"].toString());
return;
}
}
msgBox.setText(msgpre + tr("Player Version")+":");
});
msgBox.exec();
2023-05-15 16:06:10 +08:00
});
2023-10-23 11:44:22 +08:00
}
init(item);
2023-05-15 16:06:10 +08:00
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:;
2022-08-25 18:37:24 +08:00
}
});
specifyIPDlg = new QDialog(this);
specifyIPDlg->setWindowTitle(tr("Specify IP"));
vBox = new VBox(specifyIPDlg);
vBox->addStretch();
label = new QLabel(tr("Specify IP list"));
label->setAlignment(Qt::AlignCenter);
vBox->addWidget(label);
fdIP = new QTextEdit;
auto ipstr = settings.value("SpecifyIP").toString();
if(! ipstr.isEmpty()) fdIP->setText(ipstr);
fdIP->setPlaceholderText("192.168.1.1\n192.168.1.2\n ...");
fdIP->setMinimumWidth(160);
vBox->addWidget(fdIP);
hBox = new HBox(vBox);
hBox->addStretch();
auto bnSearch = new QPushButton(tr("Search"));
2023-10-23 11:44:22 +08:00
connect(bnSearch, &QPushButton::clicked, fdIP, [this] {
QString ipsStr = fdIP->toPlainText();
if(ipsStr.isEmpty()) {
2023-05-11 11:47:00 +08:00
QMessageBox::warning(this, tr("Attention"), tr("Please input IP address!"));
return;
}
auto ips = ipsStr.split("\n", Qt::SkipEmptyParts);
if(ips.isEmpty()) {
2023-05-11 11:47:00 +08:00
QMessageBox::warning(this, tr("Attention"), tr("Please input IP address!"));
return;
}
2023-05-15 16:06:10 +08:00
QByteArray data = QJsonDocument(QJsonObject{{"action", "getInfo"}}).toJson(QJsonDocument::Compact);
2023-05-11 11:47:00 +08:00
foreach(auto ip, ips) if(mUdpSocket.writeDatagram(data, QHostAddress(ip), 22222) != data.length()) qDebug() << "Specify IP write Failed." << ip;
specifyIPDlg->accept();
});
hBox->addWidget(bnSearch);
auto btnCancel = new QPushButton(tr("Cancel"));
connect(btnCancel, &QPushButton::clicked, specifyIPDlg, &QDialog::reject);
hBox->addWidget(btnCancel);
hBox->addStretch();
2022-08-25 18:37:24 +08:00
transUi();
sendGetInfo();
mUdpTimer.start(30000);
2022-08-25 18:37:24 +08:00
}
DevicePanel::~DevicePanel() {
2022-09-28 18:21:57 +08:00
mUdpSocket.close();
mUdpTimer.stop();
2022-08-25 18:37:24 +08:00
}
void DevicePanel::sendGetInfo() {
2023-08-01 11:42:41 +08:00
auto data = QJsonDocument(QJsonObject{{"action", "getInfo"}}).toJson(QJsonDocument::Compact);
2023-04-18 14:14:46 +08:00
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};
if(mUdpSocket.writeDatagram(data, QHostAddress("255.255.255.255"), 22222) != data.length()) qDebug() << "getInfo write to 255.255.255.255 failed";
if(mUdpSocket.writeDatagram((char *)ccc, sizeof(ccc), QHostAddress("255.255.255.255"), 31296) != sizeof(ccc)) qDebug() << "getInfo write to 255.255.255.255 failed";
2023-08-01 11:42:41 +08:00
auto networkinterfaces = QNetworkInterface::allInterfaces();
foreach(auto face, networkinterfaces) {
2022-08-25 18:37:24 +08:00
auto flags = face.flags();
bool can = (flags & QNetworkInterface::IsRunning) && (flags & QNetworkInterface::CanBroadcast) && ! (flags & QNetworkInterface::IsLoopBack);
if(! can) continue;
auto addrEntries = face.addressEntries();
foreach(QNetworkAddressEntry addrEntry, addrEntries) {
auto ip = addrEntry.ip();
if(ip.protocol()!=QAbstractSocket::IPv4Protocol) continue;
auto broadcast = addrEntry.broadcast();
2023-04-18 14:14:46 +08:00
if(mUdpSocket.writeDatagram(data, broadcast, 22222) != data.length()) qDebug() << "getInfo write failed." << ip.toString() << "->" << broadcast.toString();
2022-08-25 18:37:24 +08:00
}
}
auto ipstr = fdIP->toPlainText();
if(! ipstr.isEmpty()) {
auto ips = ipstr.split("\n", Qt::SkipEmptyParts);
2023-04-18 14:14:46 +08:00
foreach(auto ip, ips) if(mUdpSocket.writeDatagram(data, QHostAddress(ip), 22222) != data.length()) qDebug() << "getInfo specify IP write failed." << ip;
}
2022-08-25 18:37:24 +08:00
}
void DevicePanel::changeEvent(QEvent *event) {
QWidget::changeEvent(event);
if(event->type() == QEvent::LanguageChange) transUi();
}
void DevicePanel::transUi() {
2022-09-28 18:21:57 +08:00
btnRefresh->setText(tr("Refresh"));
2022-08-25 18:37:24 +08:00
bnSpecifyIP->setItemText(0,tr("Specify IP"));
label_3->setText(tr("All"));
2023-10-23 11:44:22 +08:00
mDeviceTable->setHeaderText("online", tr("Online"));
mDeviceTable->setHeaderText("id", tr("Screen ID"));
mDeviceTable->setHeaderText("screenSize", tr("Screen Size"));
mDeviceTable->setHeaderText("alias", tr("Alias"));
mDeviceTable->setHeaderText("brightness", tr("Screen Brightness"));
mDeviceTable->setHeaderText("power", tr("Power Status"));
mDeviceTable->setHeaderText("password", tr("Security"));
mDeviceTable->setHeaderText("info", tr("More Info"));
mDeviceTable->setHeaderText("screenshot", tr("Screenshot"));
2022-08-25 18:37:24 +08:00
auto cnt = mDeviceTable->topLevelItemCount();
2022-09-28 18:21:57 +08:00
for(int i=0; i<cnt; i++) {
2023-10-23 11:44:22 +08:00
auto item = (DeviceItem*) mDeviceTable->item(i);
item->setText("power", item->mCard.isScreenOn ? tr("On") : tr("Off"));
2022-09-28 18:21:57 +08:00
}
2023-08-01 11:42:41 +08:00
transCtrl();
}
void DevicePanel::transCtrl() {
if(mDeviceCtrlPanel) {
mBtnGrp->button(Setting_Bright)->setText(tr("Brightness Adj."));
mBtnGrp->button(Setting_PowerControl)->setText(tr("Power Control"));
mBtnGrp->button(Setting_NetCfg)->setText(tr("Net Config"));
mBtnGrp->button(Setting_VerifyClock)->setText(tr("Time Sync"));
mBtnGrp->button(Setting_HDMI)->setText(tr("Video source"));
mBtnGrp->button(Setting_Encrypt)->setText(tr("Password"));
mBtnGrp->button(Setting_Advanced)->setText(tr("Advanced"));
mBtnGrp->button(Setting_Volume)->setText(tr("Volume Adj."));
mBtnGrp->button(Setting_Test)->setText(tr("Test"));
if(gSelCards.count() < 1) fdCardNumInfo->setText(tr("Current Screen")+": "+tr("none"));
else if(gSelCards.count()==1) fdCardNumInfo->setText(tr("Current Screen")+": "+gSelCards[0].id);
else fdCardNumInfo->setText(tr("Multi screen operation")+". "+tr("selected num")+": "+QString::number(gSelCards.count()));
btnClear->setText(tr("Clear"));
}
}
void DevicePanel::newCtrl() {
mHBox->addWidget(mDeviceCtrlPanel = new QWidget);
auto vBox = new QVBoxLayout(mDeviceCtrlPanel);
vBox->setContentsMargins(0,0,0,0);
vBox->setSpacing(0);
auto hBox = new QHBoxLayout;
hBox->setSpacing(2);
mBtnGrp = new QButtonGroup(mDeviceCtrlPanel);
for(int i=0; i<Setting_End; i++) {
auto btn = new QToolButton;
auto policy = btn->sizePolicy();
policy.setHorizontalPolicy(QSizePolicy::Preferred);
btn->setSizePolicy(policy);
btn->setIconSize(QSize(48, 48));
btn->setCheckable(true);
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
btn->setProperty("ss", "CtrlTab");
hBox->addWidget(btn);
mBtnGrp->addButton(btn, i);
}
mBtnGrp->button(Setting_Bright)->setIcon(QIcon(":/res/bnBrightnessAdjustMent_s.png"));
mBtnGrp->button(Setting_PowerControl)->setIcon(QIcon(":/res/bnPowerControl_s.png"));
mBtnGrp->button(Setting_NetCfg)->setIcon(QIcon(":/res/bnNetConfig_s.png"));
mBtnGrp->button(Setting_VerifyClock)->setIcon(QIcon(":/res/bnVerifyClock_s.png"));
mBtnGrp->button(Setting_Encrypt)->setIcon(QIcon(":/res/encrypt.png"));
mBtnGrp->button(Setting_HDMI)->setIcon(QIcon(":/res/Hdmi.png"));
mBtnGrp->button(Setting_Volume)->setIcon(QIcon(":/res/volume.png"));
mBtnGrp->button(Setting_Advanced)->setIcon(QIcon(":/res/AdvParam.png"));
mBtnGrp->button(Setting_Test)->setIcon(QIcon(":/res/test.png"));
connect(mBtnGrp, &QButtonGroup::idToggled, this, [this](int index, bool checked) {
if(!checked || index==curIndex) return;
curIndex = index;
if(wgts[index]==0) {
if(index==Setting_Bright) wgts[index] = new CtrlBrightPanel;
else if(index==Setting_PowerControl) wgts[index] = new CtrlPowerPanel;
else if(index==Setting_NetCfg) wgts[index] = new CtrlNetworkPanel;
else if(index==Setting_VerifyClock) wgts[index] = new CtrlVerifyClockPanel;
else if(index==Setting_Encrypt) wgts[index] = new CtrlPwdPanel;
else if(index==Setting_HDMI) wgts[index] = new CtrlHdmiPanel;
else if(index==Setting_Volume) wgts[index] = new CtrlVolumePanel;
else if(index==Setting_Advanced) wgts[index] = new CtrlAdvancedPanel;
else if(index==Setting_Test) wgts[index] = new CtrlTestPanel;
}
scrollArea->takeWidget();
scrollArea->setWidget(wgts[index]);
wgts[index]->setFocus();
});
vBox->addLayout(hBox);
auto line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
vBox->addWidget(line);
2023-10-23 11:44:22 +08:00
hBox = new QHBoxLayout;
2023-08-01 11:42:41 +08:00
2023-10-23 11:44:22 +08:00
scrollArea = new QScrollArea;
2023-08-01 11:42:41 +08:00
scrollArea->setWidgetResizable(true);
hBox->addWidget(scrollArea);
auto vBox2 = new QVBoxLayout();
fdInfo = new QTextEdit();
gFdResInfo = fdInfo;
fdInfo->setReadOnly(true);
fdInfo->setMaximumWidth(360);
vBox2->addWidget(fdInfo);
btnClear = new QPushButton(tr("Clear"));
btnClear->setMinimumHeight(30);
btnClear->setProperty("ssType", "progManageTool");
connect(btnClear, &QPushButton::clicked, fdInfo, &QTextEdit::clear);
vBox2->addWidget(btnClear);
hBox->addLayout(vBox2);
vBox->addLayout(hBox);
fdInfo->hide();
btnClear->hide();
2023-10-23 11:44:22 +08:00
connect(this, &DevicePanel::sigSelectedDeviceList, fdInfo, [this] {
2023-08-01 11:42:41 +08:00
if(gSelCards.count() < 2) {
if(gSelCards.count()==1) fdCardNumInfo->setText(tr("Current Screen")+": "+gSelCards[0].id);
else fdCardNumInfo->setText(tr("Current Screen")+": "+tr("none"));
fdInfo->hide();
btnClear->hide();
} else {
fdCardNumInfo->setText(tr("Multi screen operation")+". "+tr("selected num")+": "+QString::number(gSelCards.count()));
fdInfo->clear();
fdInfo->show();
btnClear->show();
}
});
mBtnGrp->button(0)->setChecked(true);
transCtrl();
2022-09-28 18:21:57 +08:00
}
2023-10-23 11:44:22 +08:00
void DevicePanel::init(DeviceItem *item) {
QJsonObject json;
json.insert("_id", "GetBuildInformation");
json.insert("_type", "GetBuildInformation");
auto reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
ConnReply(reply, item->fdOnline) [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
item->mCard.BrightnessLevel = json["BrightnessLevel"].toInt();
item->mCard.FirmwareVersion = json["FirmwareVersion"].toString();
item->mCard.HardVersion = json["HardVersion"].toString();
item->mCard.ScreenResolution = json["ScreenResolution"].toString();
item->mCard.IMEI = json["IMEI"].toString();
auto androidVersion = json["AndroidVersion"].toString();
if(! androidVersion.isEmpty()) item->mCard.androidVersion = androidVersion;
});
if(item->mCard.mWidth==0 || item->mCard.mHeight==0) {
json = QJsonObject();
json.insert("_id", "GetScreenSize");
json.insert("_type", "GetScreenSize");
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
ConnReply(reply, item->fdOnline) [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
item->mCard.mWidth = json["width"].toInt();
item->mCard.mHeight = json["height"].toInt();
item->setText("screenSize", QString("%1 x %2").arg(item->mCard.mWidth).arg(item->mCard.mHeight));
});
}
json = QJsonObject();
json.insert("_id", "GetBrightness");
json.insert("_type", "GetBrightness");
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
ConnReply(reply, item->fdOnline) [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
item->mCard.bright = json["brightnessPercentage"].toInt(-1);
if(item->mCard.bright==-1) item->mCard.bright = qRound(json["brightness"].toInt() * 100.0 / item->mCard.BrightnessLevel);
item->setText("brightness", QString::number(item->mCard.bright)+"%");
});
json = QJsonObject();
json.insert("_id", "IsScreenOn");
json.insert("_type", "IsScreenOn");
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
ConnReply(reply, item->fdOnline) [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
item->mCard.isScreenOn = json["on"].toBool();
item->setForeground("power"**mDeviceTable, item->mCard.isScreenOn ? Qt::green : Qt::red);
item->setText("power", item->mCard.isScreenOn ? tr("On") : tr("Off"));
});
json = QJsonObject();
json.insert("_id", "GetCardAlias");
json.insert("_type", "GetCardAlias");
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
ConnReply(reply, item->fdOnline) [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
item->mCard.alias = QString::fromUtf8(QByteArray::fromBase64(json["alias"].toString().toLatin1()));
item->setText("alias", item->mCard.alias);
});
json = QJsonObject();
json.insert("_id", "HasControllerPassword");
json.insert("_type", "HasControllerPassword");
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
ConnReply(reply, item->fdOnline) [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) return;
item->mCard.hasPassword = json["result"].toBool();
if(item->mCard.hasPassword) {//加过密
item->btnUnlock->show();
item->btnUnlock->setIcon(QIcon(item->mCard.isLocked ? ":/res/Lock.png" : ":/res/UnLock.png"));
} else item->btnUnlock->hide();
});
}
ImgDlg::ImgDlg(const QByteArray &data, QWidget *parent) : QDialog(parent) {
setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
setWindowTitle(tr("Screenshot"));
mImg.loadFromData(data);
auto www = mImg.width();
auto hhh = mImg.height();
if(www <= 1600 && hhh <= 900) resize(www, hhh);
else if(www > hhh) resize(900 * www / hhh, 900);
else resize(1600, 1600 * hhh / www);
}
void ImgDlg::paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.drawImage(rect(), mImg);
}